source: protocol/src/test/java/geniusweb/protocol/ProtocolExceptionTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.5 KB
Line 
1package geniusweb.protocol;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6
7import org.junit.Before;
8import org.junit.Ignore;
9import org.junit.Test;
10
11import com.fasterxml.jackson.core.JsonProcessingException;
12import com.fasterxml.jackson.databind.ObjectMapper;
13import com.fasterxml.jackson.databind.util.ObjectBuffer;
14
15import geniusweb.actions.PartyId;
16
17public 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}
Note: See TracBrowser for help on using the repository browser.