source: java2python/src/test/java/testcode/actions/ActionsUse.java@ 390

Last change on this file since 390 was 389, checked in by wouter, 2 years ago

#115 fix more issues, try harder (in Stub etc) to find original call and fix the function call name according to its modifiers.

File size: 2.0 KB
Line 
1package testcode.actions;
2
3import java.io.IOException;
4
5import com.fasterxml.jackson.core.JsonProcessingException;
6import com.fasterxml.jackson.databind.ObjectMapper;
7
8/**
9 *
10 * Bit hacky, similar to junit test but avoiding junit because not yet
11 * supported.
12 */
13public 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, jackson.writeValueAsString(accept));
47 }
48
49 public void deserializeAcceptTest() throws IOException {
50 before();
51 System.out.println("deserializeAcceptTest");
52 Action act = jackson.readValue(acceptstring, Action.class);
53 System.out.println(act);
54 assertEquals(accept, act);
55 System.out.println("All tests OK");
56 }
57
58 /**
59 *
60 * @param args
61 * @throws IOException
62 */
63 public static void main(String[] args) throws IOException {
64 ActionsUse a = new ActionsUse();
65 a.before();
66 a.serializeAcceptTest();
67 a = new ActionsUse();
68 a.before();
69 a.deserializeAcceptTest();
70 }
71
72 private void assertEquals(Object a, Object b) {
73 if (!(a.equals(b)))
74 throw new AssertionError(
75 "Expected " + a.toString() + " , got " + b.toString());
76 }
77}
Note: See TracBrowser for help on using the repository browser.