source: events/src/test/java/geniusweb/actions/VoteTest.java@ 26

Last change on this file since 26 was 26, checked in by bart, 4 years ago

Voting requests now contain Offers. Fixed windows whitespace issue. Partiesserver now supports up to 8 parties simultaneously.

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