source: events/src/test/java/geniusweb/actions/VoteWithValueTest.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.2 KB
Line 
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 VoteWithValueTest extends GeneralTests<VoteWithValue> {
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 votestring = "{\"VoteWithValue\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"minPower\":1,\"maxPower\":2,\"value\":10}}";
38
39 private static VoteWithValue vote1, vote1a, vote2, vote3, vote4, vote5,
40 vote6;
41
42 static {
43 issuevalues.put(ISSUE1, VALUE1);
44 issuevalues.put(ISSUE2, VALUE2);
45 bid = new Bid(issuevalues);
46 vote1 = new VoteWithValue(id, bid, 1, 2, 10);
47 vote1a = new VoteWithValue(id, bid, 1, 2, 10);
48
49 vote2 = new VoteWithValue(id2, bid, 1, 2, 10);
50
51 // values swapped, so different issuevalues.
52 issuevaluesb.put(ISSUE1, VALUE2);
53 issuevaluesb.put(ISSUE2, VALUE2);
54 bidb = new Bid(issuevaluesb);
55 vote3 = new VoteWithValue(id, bidb, 1, 2, 10);
56
57 vote4 = new VoteWithValue(id, bid, 2, 2, 10);
58 vote5 = new VoteWithValue(id, bid, 1, 3, 10);
59
60 vote6 = new VoteWithValue(id, bid, 1, 2, 20);
61
62 }
63
64 @Override
65 public List<List<VoteWithValue>> getGeneralTestData() {
66 return Arrays.asList(Arrays.asList(vote1, vote1a), Arrays.asList(vote2),
67 Arrays.asList(vote3), Arrays.asList(vote4),
68 Arrays.asList(vote5), Arrays.asList(vote6));
69 }
70
71 @Override
72 public List<String> getGeneralTestStrings() {
73 return Arrays.asList(
74 "VoteWithValue.*party1.*issue2=10.*issue1=.value1.*1.*2.*10.*",
75 "VoteWithValue.*party2.*issue2=10.*issue1=.value1.*1.*2.*10.*",
76 "VoteWithValue.*party1.*issue2=10.*issue1=10.*1.*2.*10.*",
77 "VoteWithValue.*party1.*issue2=10.*issue1=.value1.*2.*2.*10.*",
78 "VoteWithValue.*party1.*issue2=10.*issue1=.value1.*1.*3.*10.*",
79 "VoteWithValue.*party1.*issue2=10.*issue1=.value1.*1.*2.*20.*");
80 }
81
82 @Before
83 public void before() {
84
85 }
86
87 @Test
88 public void serializeTest() throws JsonProcessingException {
89 System.out.println(jackson.writeValueAsString(vote1));
90 assertEquals(votestring, jackson.writeValueAsString(vote1));
91 }
92
93 @Test
94 public void deserializeAcceptTest() throws IOException {
95 Action act = jackson.readValue(votestring, Action.class);
96 assertEquals(vote1, act);
97 }
98
99}
Note: See TracBrowser for help on using the repository browser.