1 | package geniusweb.protocol;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 |
|
---|
7 | import org.junit.Before;
|
---|
8 | import org.junit.Ignore;
|
---|
9 | import org.junit.Test;
|
---|
10 |
|
---|
11 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
12 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
13 | import com.fasterxml.jackson.databind.util.ObjectBuffer;
|
---|
14 |
|
---|
15 | import geniusweb.actions.PartyId;
|
---|
16 |
|
---|
17 | public class ProtocolExceptionTest {
|
---|
18 | private ObjectBuffer jackson = new ObjectBuffer();
|
---|
19 | private Exception exception;
|
---|
20 | private String asString1 = "{\"cause\":null,\"stackTrace\":[],\"party\":\"party1\",\"message\":\"party1:test\",\"suppressed\":[],\"localizedMessage\":\"party1:test\"}";
|
---|
21 |
|
---|
22 | @Before
|
---|
23 | public void before() {
|
---|
24 | try {
|
---|
25 | throw new ProtocolException("test", new PartyId("party1"));
|
---|
26 | // int x = 1 / 0;
|
---|
27 | } catch (Exception e) {
|
---|
28 | this.exception = e;
|
---|
29 | System.out.println(e);
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Test
|
---|
34 | public void testSerialize() throws JsonProcessingException {
|
---|
35 |
|
---|
36 | ObjectMapper jackson = new ObjectMapper();
|
---|
37 | System.out.println(jackson.writeValueAsString(exception));
|
---|
38 | // disabled check , does not work either in Java8 or in Java16 because
|
---|
39 | // field order seems swapped
|
---|
40 | // assertEquals(asString1, jackson.writeValueAsString(exception));
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
44 | // ProtocolExceptions can not be deserialized now
|
---|
45 | @Ignore
|
---|
46 | @Test
|
---|
47 | public void testDeserialize() throws IOException {
|
---|
48 |
|
---|
49 | ObjectMapper jackson = new ObjectMapper();
|
---|
50 | Exception read = jackson.readValue(asString1, ProtocolException.class);
|
---|
51 | assertEquals(exception, read);
|
---|
52 | }
|
---|
53 |
|
---|
54 | }
|
---|