source: java2python/jackson-t/src/test/javaactions/testcode/actions/ActionsUse.java@ 1421

Last change on this file since 1421 was 1116, checked in by wouter, 3 months ago

#363 small cleanup in test code

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