1 | package geniusweb.inform;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.Collections;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.junit.Before;
|
---|
11 | import org.junit.Test;
|
---|
12 |
|
---|
13 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
14 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
15 |
|
---|
16 | import geniusweb.actions.PartyId;
|
---|
17 | import geniusweb.issuevalue.Bid;
|
---|
18 | import geniusweb.issuevalue.DiscreteValue;
|
---|
19 | import geniusweb.issuevalue.Value;
|
---|
20 | import tudelft.utilities.junit.GeneralTests;
|
---|
21 |
|
---|
22 | public class FinishedTest extends GeneralTests<Finished> {
|
---|
23 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
24 |
|
---|
25 | private static final PartyId id = new PartyId("party1");
|
---|
26 | private static final PartyId id2 = new PartyId("party2");
|
---|
27 | private final static Value VALUE1 = new DiscreteValue("value1");
|
---|
28 | private static Bid bid = new Bid(
|
---|
29 | Collections.singletonMap("issue1", VALUE1));
|
---|
30 |
|
---|
31 | private final String finishedstring = "{\"Finished\":{\"agreements\":{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}}}";
|
---|
32 |
|
---|
33 | private final static Agreements agrees1 = new Agreements(
|
---|
34 | Collections.singletonMap(id, bid));
|
---|
35 | private final static Agreements agrees2 = new Agreements(
|
---|
36 | Collections.singletonMap(id2, bid));
|
---|
37 |
|
---|
38 | private final static Finished finished1 = new Finished(agrees1);
|
---|
39 | private final static Finished finished1a = new Finished(agrees1);
|
---|
40 | private final static Finished finished2 = new Finished(agrees2);
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public List<List<Finished>> getGeneralTestData() {
|
---|
44 | return Arrays.asList(Arrays.asList(finished1, finished1a),
|
---|
45 | Arrays.asList(finished2));
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public List<String> getGeneralTestStrings() {
|
---|
50 | return Arrays.asList("Finished.*party1.*Bid.*",
|
---|
51 | "Finished.*party2.*Bid.*");
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Before
|
---|
55 | public void before() {
|
---|
56 |
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Test
|
---|
60 | public void serializeAcceptTest() throws JsonProcessingException {
|
---|
61 | System.out.println(jackson.writeValueAsString(finished1));
|
---|
62 | assertEquals(finishedstring, jackson.writeValueAsString(finished1));
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Test
|
---|
66 | public void deserializeAcceptTest() throws IOException {
|
---|
67 | Inform act = jackson.readValue(finishedstring, Inform.class);
|
---|
68 | assertEquals(finished1, act);
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Test(expected = NullPointerException.class)
|
---|
72 | public void testNull() {
|
---|
73 | new Finished(null);
|
---|
74 | }
|
---|
75 |
|
---|
76 | }
|
---|