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

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

#115 handle field translation - static and non-static fields are handled separately in different parts of th code

File size: 1.8 KB
Line 
1package testcode.actions;
2
3/**
4 * Derived from AcceptTest in GeniusWeb.
5 */
6import static org.junit.Assert.assertEquals;
7
8import java.io.IOException;
9
10import org.junit.Before;
11import org.junit.Test;
12
13import com.fasterxml.jackson.core.JsonProcessingException;
14import com.fasterxml.jackson.databind.ObjectMapper;
15
16public class ActionsUse {
17 private final ObjectMapper jackson = new ObjectMapper();
18
19 private static final PartyId id = new PartyId("party1");
20 private static final PartyId id2 = new PartyId("party2");
21 private static Bid bid;
22 private static Bid bidb;
23 // issue 2 is NUMBER and thus serializes with leading '='
24 private final String acceptstring = "{\"Accept\":{\"actor\":\"party1\",\"bid\":\"issuevalues\"}}";
25
26 private static Accept accept, accept1, accept2, acceptb;
27
28 // workaround for #118
29 public ActionsUse() {
30 }
31
32 @Before
33 public void before() {
34 bid = new Bid("issuevalues");
35 accept = new Accept(id, bid);
36 accept1 = new Accept(id, bid);
37
38 accept2 = new Accept(id2, bid);
39
40 // values swapped, so different issuevalues.
41 bidb = new Bid("issuevaluesb");
42 acceptb = new Accept(id, bidb);
43
44 }
45
46 @Test
47 public void serializeAcceptTest() throws JsonProcessingException {
48 System.out.println("serializeAcceptTest");
49 System.out.println(jackson.writeValueAsString(accept));
50 assertEquals(acceptstring, jackson.writeValueAsString(accept));
51 }
52
53 @Test
54 public void deserializeAcceptTest() throws IOException {
55 System.out.println("deserializeAcceptTest");
56 Action act = jackson.readValue(acceptstring, Action.class);
57 System.out.println(act);
58 assertEquals(accept, act);
59 }
60
61 public static void main(String[] args) throws IOException {
62 ActionsUse a = new ActionsUse();
63 a.before();
64 a.serializeAcceptTest();
65 a = new ActionsUse();
66 a.before();
67 a.deserializeAcceptTest();
68 }
69}
Note: See TracBrowser for help on using the repository browser.