source: events/src/test/java/actions/ElicitComparisonTest.java@ 13

Last change on this file since 13 was 10, checked in by bart, 5 years ago

Update 28 jan 2020

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