[381] | 1 | package testcode.actions;
|
---|
[380] | 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Derived from AcceptTest in GeniusWeb.
|
---|
| 5 | */
|
---|
| 6 | import static org.junit.Assert.assertEquals;
|
---|
| 7 |
|
---|
| 8 | import java.io.IOException;
|
---|
| 9 |
|
---|
[381] | 10 | import org.junit.Before;
|
---|
[380] | 11 | import org.junit.Test;
|
---|
| 12 |
|
---|
| 13 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
| 14 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
| 15 |
|
---|
| 16 | public class ActionsTest {
|
---|
| 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 |
|
---|
[381] | 28 | @Before
|
---|
| 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 | @Test
|
---|
| 43 | public void serializeAcceptTest() throws JsonProcessingException {
|
---|
| 44 | System.out.println("serializeAcceptTest");
|
---|
| 45 | System.out.println(jackson.writeValueAsString(accept));
|
---|
| 46 | assertEquals(acceptstring, jackson.writeValueAsString(accept));
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | @Test
|
---|
| 50 | public void deserializeAcceptTest() throws IOException {
|
---|
| 51 | System.out.println("deserializeAcceptTest");
|
---|
| 52 | Action act = jackson.readValue(acceptstring, Action.class);
|
---|
| 53 | System.out.println(act);
|
---|
| 54 | assertEquals(accept, act);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public static void main(String[] args) throws IOException {
|
---|
[381] | 58 | ActionsTest a = new ActionsTest();
|
---|
| 59 | a.before();
|
---|
| 60 | a.serializeAcceptTest();
|
---|
| 61 | a = new ActionsTest();
|
---|
| 62 | a.before();
|
---|
| 63 | a.deserializeAcceptTest();
|
---|
[380] | 64 | }
|
---|
| 65 | }
|
---|