source: events/src/test/java/geniusweb/actions/ComparisonTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 20 months ago

Fixed small issues in domaineditor.

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