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
RevLine 
[381]1package testcode.actions;
[380]2
3import java.io.IOException;
4
5import com.fasterxml.jackson.core.JsonProcessingException;
6import com.fasterxml.jackson.databind.ObjectMapper;
7
[389]8/**
9 *
10 * Bit hacky, similar to junit test but avoiding junit because not yet
11 * supported.
12 */
[384]13public class ActionsUse {
[380]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
[388]25 // workaround for #118
26 public ActionsUse() {
27 }
28
[381]29 public void before() {
[380]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 {
[389]43 before();
[380]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 {
[389]50 before();
[380]51 System.out.println("deserializeAcceptTest");
52 Action act = jackson.readValue(acceptstring, Action.class);
53 System.out.println(act);
54 assertEquals(accept, act);
[389]55 System.out.println("All tests OK");
[380]56 }
57
[389]58 /**
59 *
60 * @param args
61 * @throws IOException
62 */
[380]63 public static void main(String[] args) throws IOException {
[384]64 ActionsUse a = new ActionsUse();
[381]65 a.before();
66 a.serializeAcceptTest();
[384]67 a = new ActionsUse();
[381]68 a.before();
69 a.deserializeAcceptTest();
[380]70 }
[389]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 }
[380]77}
Note: See TracBrowser for help on using the repository browser.