source: events/src/test/java/actions/AcceptTest.java@ 14

Last change on this file since 14 was 1, checked in by bart, 5 years ago

Initial Release

File size: 2.8 KB
Line 
1package actions;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.util.Arrays;
7import java.util.HashMap;
8import java.util.LinkedList;
9import java.util.List;
10import java.util.Map;
11
12import org.junit.Before;
13import org.junit.Test;
14
15import com.fasterxml.jackson.core.JsonProcessingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18import geniusweb.actions.Accept;
19import geniusweb.actions.Action;
20import geniusweb.actions.PartyId;
21import geniusweb.issuevalue.Bid;
22import geniusweb.issuevalue.DiscreteValue;
23import geniusweb.issuevalue.NumberValue;
24import geniusweb.issuevalue.Value;
25import tudelft.utilities.junit.GeneralTests;
26
27public class AcceptTest extends GeneralTests<Accept> {
28 private final ObjectMapper jackson = new ObjectMapper();
29
30 private static final PartyId id = new PartyId("party1");
31 private static final PartyId id2 = new PartyId("party2");
32 private final static Map<String, Value> issuevalues = new HashMap<String, Value>();
33 private final static Map<String, Value> issuevaluesb = new HashMap<String, Value>();
34 private static Bid bid;
35 private static Bid bidb;
36 private final static String ISSUE1 = "issue1";
37 private final static Value VALUE1 = new DiscreteValue("value1");
38 private final static String ISSUE2 = "issue2";
39 private final static Value VALUE2 = new NumberValue("10");
40 // issue 2 is NUMBER and thus serializes with leading '='
41 private final String acceptstring = "{\"accept\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}";
42
43 private static Accept accept, accept1, accept2, acceptb;
44
45 static {
46 issuevalues.put(ISSUE1, VALUE1);
47 issuevalues.put(ISSUE2, VALUE2);
48 bid = new Bid(issuevalues);
49 accept = new Accept(id, bid);
50 accept1 = new Accept(id, bid);
51
52 accept2 = new Accept(id2, bid);
53
54 // values swapped, so different issuevalues.
55 issuevaluesb.put(ISSUE1, VALUE2);
56 issuevaluesb.put(ISSUE2, VALUE2);
57 bidb = new Bid(issuevaluesb);
58 acceptb = new Accept(id, bidb);
59
60 }
61
62 @Override
63 public List<List<Accept>> getGeneralTestData() {
64 List<List<Accept>> list = new LinkedList<>();
65 list.add(Arrays.asList(accept, accept1));
66 list.add(Arrays.asList(accept2));
67 list.add(Arrays.asList(acceptb));
68 return list;
69 }
70
71 @Override
72 public List<String> getGeneralTestStrings() {
73 return Arrays.asList("Accept.*" + id + ".*]", "Accept.*" + id2 + ".*]",
74 "Accept.*" + id + ".*]");
75 }
76
77 @Before
78 public void before() {
79
80 }
81
82 @Test
83 public void serializeAcceptTest() throws JsonProcessingException {
84 System.out.println(jackson.writeValueAsString(accept));
85 assertEquals(acceptstring, jackson.writeValueAsString(accept));
86 }
87
88 @Test
89 public void deserializeAcceptTest() throws IOException {
90 Action act = jackson.readValue(acceptstring, Action.class);
91 assertEquals(accept, act);
92 }
93
94}
Note: See TracBrowser for help on using the repository browser.