1 | package testcode.actions;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 |
|
---|
5 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
6 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | *
|
---|
10 | * Bit hacky, similar to junit test but avoiding junit because not yet
|
---|
11 | * supported.
|
---|
12 | */
|
---|
13 | public class ActionsUse {
|
---|
14 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
15 |
|
---|
16 | private static final PartyId id = new PartyId("party1");
|
---|
17 | private static final PartyId id2 = new PartyId("party2");
|
---|
18 | private static Bid bid;
|
---|
19 | private static Bid bidb;
|
---|
20 | // issue 2 is NUMBER and thus serializes with leading '='
|
---|
21 | private final String acceptstring = "{\"Accept\":{\"actor\":\"party1\",\"bid\":\"issuevalues\"}}";
|
---|
22 |
|
---|
23 | private static Accept accept, accept1, accept2, acceptb;
|
---|
24 |
|
---|
25 | // workaround for #118
|
---|
26 | public ActionsUse() {
|
---|
27 | }
|
---|
28 |
|
---|
29 | public void before() {
|
---|
30 | bid = new Bid("issuevalues");
|
---|
31 | accept = new Accept(id, bid);
|
---|
32 | accept1 = new Accept(id, bid);
|
---|
33 |
|
---|
34 | accept2 = new Accept(id2, bid);
|
---|
35 |
|
---|
36 | // values swapped, so different issuevalues.
|
---|
37 | bidb = new Bid("issuevaluesb");
|
---|
38 | acceptb = new Accept(id, bidb);
|
---|
39 |
|
---|
40 | }
|
---|
41 |
|
---|
42 | public void serializeAcceptTest() throws JsonProcessingException {
|
---|
43 | before();
|
---|
44 | System.out.println("serializeAcceptTest");
|
---|
45 | System.out.println(jackson.writeValueAsString(accept));
|
---|
46 | assertEquals(acceptstring,
|
---|
47 | jackson.writeValueAsString(accept).replace(" ", ""));
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void deserializeAcceptTest() throws IOException {
|
---|
51 | before();
|
---|
52 | System.out.println("deserializeAcceptTest");
|
---|
53 | Action act = jackson.readValue(acceptstring, Action.class);
|
---|
54 | System.out.println(act);
|
---|
55 | assertEquals(accept, act);
|
---|
56 | System.out.println("All tests OK");
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | *
|
---|
61 | * @param args
|
---|
62 | * @throws IOException
|
---|
63 | */
|
---|
64 | public static void main(String[] args) throws IOException {
|
---|
65 | ActionsUse a = new ActionsUse();
|
---|
66 | a.before();
|
---|
67 | a.serializeAcceptTest();
|
---|
68 | a = new ActionsUse();
|
---|
69 | a.before();
|
---|
70 | a.deserializeAcceptTest();
|
---|
71 | }
|
---|
72 |
|
---|
73 | private void assertEquals(Object a, Object b) {
|
---|
74 | if (!(a.equals(b)))
|
---|
75 | throw new AssertionError(
|
---|
76 | "Expected " + a.toString() + " , got " + b.toString());
|
---|
77 | }
|
---|
78 | }
|
---|