source: party/src/test/java/geniusweb/party/inform/ActionDoneTest.java@ 21

Last change on this file since 21 was 21, checked in by bart, 4 years ago

Version 1.5.

File size: 3.1 KB
Line 
1package geniusweb.party.inform;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.math.BigDecimal;
7import java.net.URISyntaxException;
8import java.util.Arrays;
9import java.util.HashMap;
10import java.util.List;
11import java.util.Map;
12
13import org.junit.Before;
14import org.junit.Test;
15
16import com.fasterxml.jackson.core.JsonParseException;
17import com.fasterxml.jackson.core.JsonProcessingException;
18import com.fasterxml.jackson.databind.JsonMappingException;
19import com.fasterxml.jackson.databind.ObjectMapper;
20
21import geniusweb.actions.Accept;
22import geniusweb.actions.PartyId;
23import geniusweb.inform.ActionDone;
24import geniusweb.inform.Inform;
25import geniusweb.issuevalue.Bid;
26import geniusweb.issuevalue.DiscreteValue;
27import geniusweb.issuevalue.NumberValue;
28import geniusweb.issuevalue.Value;
29import tudelft.utilities.junit.GeneralTests;
30
31public class ActionDoneTest extends GeneralTests<ActionDone> {
32
33 private ActionDone finished1, finished1a, finished2;
34
35 private String asJson = "{\"ActionDone\":{\"action\":{\"accept\":{\"actor\":\"me\",\"bid\":{\"issuevalues\":{\"issue3\":9012,\"issue2\":1,\"issue1\":\"b\"}}}}}}";
36
37 private PartyId me = new PartyId("me");
38
39 @Before
40 public void before() throws URISyntaxException {
41 final String ISSUE1 = "issue1";
42 final String ISSUE2 = "issue2";
43 final Value VALUE1 = new DiscreteValue("value1");
44 final Value VALUE2 = new NumberValue("10");
45
46 Map<String, Value> issuevalues = new HashMap<>();
47 issuevalues.put(ISSUE1, new DiscreteValue("b"));
48 issuevalues.put(ISSUE2, new NumberValue(BigDecimal.ONE));
49 issuevalues.put("issue3", new NumberValue(new BigDecimal("9012")));
50 Bid bid = new Bid(issuevalues);
51
52 Map<String, Value> issuevaluesb = new HashMap<>();
53 issuevaluesb.put(ISSUE1, new DiscreteValue("b"));
54 issuevaluesb.put(ISSUE2, new NumberValue(BigDecimal.ONE));
55 Bid bidb = new Bid(issuevaluesb);
56
57 // bidc and bidd have values swapped, so different issuevalues.
58 Map<String, Value> issuevaluesc = new HashMap<>();
59 issuevaluesc.put(ISSUE1, VALUE1);
60 issuevaluesc.put(ISSUE2, VALUE2);
61
62 finished1 = new ActionDone(new Accept(me, bid));
63 finished1a = new ActionDone(new Accept(me, bid));
64 finished2 = new ActionDone(new Accept(me, bidb));
65 }
66
67 @Override
68 public List<List<ActionDone>> getGeneralTestData() {
69 return Arrays.asList(Arrays.asList(finished1, finished1a),
70 Arrays.asList(finished2));
71 }
72
73 @Override
74 public List<String> getGeneralTestStrings() {
75 return Arrays.asList("ActionDone.*Accept.*", "ActionDone.*Accept.*");
76 }
77
78 @Test
79 public void nullTest() throws URISyntaxException {
80 new ActionDone(null);
81 }
82
83 @Test
84 public void testSerialize() throws JsonProcessingException {
85 ObjectMapper jackson = new ObjectMapper();
86
87 String json = jackson.writeValueAsString(finished1);
88 System.out.println(json);
89 assertEquals(asJson, json);
90 }
91
92 @Test
93 public void testDeserialize()
94 throws JsonParseException, JsonMappingException, IOException {
95 ObjectMapper jackson = new ObjectMapper();
96 ActionDone p = (ActionDone) jackson.readValue(asJson, Inform.class);
97 System.out.println(p);
98 assertEquals(finished1, p);
99 }
100
101}
Note: See TracBrowser for help on using the repository browser.