source: events/src/test/java/geniusweb/actions/ElicitComparisonTest.java@ 38

Last change on this file since 38 was 35, checked in by bart, 3 years ago

Fixed windows time-out.

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