source: events/src/test/java/geniusweb/inform/OptInTest.java@ 38

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

Fixed windows time-out.

File size: 2.8 KB
Line 
1package geniusweb.inform;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.util.Arrays;
7import java.util.Collections;
8import java.util.HashSet;
9import java.util.List;
10
11import org.junit.Test;
12
13import com.fasterxml.jackson.core.JsonParseException;
14import com.fasterxml.jackson.core.JsonProcessingException;
15import com.fasterxml.jackson.databind.JsonMappingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18import geniusweb.actions.PartyId;
19import geniusweb.actions.Vote;
20import geniusweb.actions.Votes;
21import geniusweb.issuevalue.Bid;
22import geniusweb.issuevalue.DiscreteValue;
23import tudelft.utilities.junit.GeneralTests;
24
25public class OptInTest extends GeneralTests<OptIn> {
26
27 private Bid bid1 = new Bid("iss", new DiscreteValue("val1"));
28 private Bid bid2 = new Bid("iss", new DiscreteValue("val2"));
29 private PartyId partyA = new PartyId("partyA");
30 private PartyId partyB = new PartyId("partyB");
31
32 private final Vote voteA1 = new Vote(partyA, bid1, 2, 9);
33 private final Vote voteB1 = new Vote(partyB, bid1, 2, 9);
34 private final Vote voteB2 = new Vote(partyB, bid2, 2, 9);
35
36 private Votes votesA = new Votes(partyA, Collections.singleton(voteA1));
37 private Votes votesB = new Votes(partyB,
38 new HashSet<>(Arrays.asList(voteB1, voteB2)));
39
40 private final OptIn optIn1 = new OptIn(Arrays.asList(votesA, votesB));
41 private final OptIn optIn1a = new OptIn(Arrays.asList(votesA, votesB));
42 private final OptIn optIn2 = new OptIn(Arrays.asList(votesA));
43
44 private String asJson = "{\"OptIn\":{\"votes\":[{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9}}]}},{\"Votes\":{\"actor\":\"partyB\",\"votes\":[{\"Vote\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val2\"}},\"minPower\":2,\"maxPower\":9}},{\"Vote\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9}}]}}]}}";
45
46 @Override
47 public List<List<OptIn>> getGeneralTestData() {
48 return Arrays.asList(Arrays.asList(optIn1, optIn1a),
49 Arrays.asList(optIn2));
50 }
51
52 @Override
53 public List<String> getGeneralTestStrings() {
54 return Arrays.asList(
55 "OptIn.*Votes.*Vote.*partyA.*iss.*val1.*2.*Votes.*Vote.*partyB.*iss.*val2.*.*2.*Vote.*partyB.*iss.*val1.*2.*",
56 "OptIn.*Votes.*Vote.*partyA.*iss.*val.*2.*");
57 }
58
59 @Test
60 public void testSerialize() throws JsonProcessingException {
61 ObjectMapper jackson = new ObjectMapper();
62
63 String json = jackson.writeValueAsString(optIn1);
64 System.out.println(json);
65 assertEquals(asJson, json);
66 }
67
68 @Test
69 public void testDeserialize()
70 throws JsonParseException, JsonMappingException, IOException {
71 ObjectMapper jackson = new ObjectMapper();
72 Inform p = jackson.readValue(asJson, Inform.class);
73 System.out.println(p);
74 assertEquals(optIn1, p);
75 }
76
77}
Note: See TracBrowser for help on using the repository browser.