source: events/src/test/java/geniusweb/inform/VotingTest.java@ 53

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

Fixed small issues in domaineditor.

File size: 2.4 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.List;
9import java.util.Map;
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.Offer;
19import geniusweb.actions.PartyId;
20import geniusweb.issuevalue.Bid;
21import geniusweb.issuevalue.DiscreteValue;
22import tudelft.utilities.junit.GeneralTests;
23
24public class VotingTest extends GeneralTests<Voting> {
25
26 private PartyId party1 = new PartyId("party1");
27 private Bid bid1 = new Bid("iss", new DiscreteValue("val1"));
28 private Bid bid2 = new Bid("iss", new DiscreteValue("val2"));
29
30 private Map<PartyId, Integer> powers1 = Collections.singletonMap(party1, 2);
31 private Map<PartyId, Integer> powers2 = Collections.singletonMap(party1, 3);
32
33 private final Voting voting1 = new Voting(
34 Arrays.asList(new Offer(party1, bid1)), powers1);
35 private final Voting voting1a = new Voting(
36 Arrays.asList(new Offer(party1, bid1)), powers1);
37 private final Voting voting2 = new Voting(
38 Arrays.asList(new Offer(party1, bid2)), powers1);
39 private final Voting voting3 = new Voting(
40 Arrays.asList(new Offer(party1, bid1)), powers2);
41
42 private String asJson = "{\"Voting\":{\"offers\":[{\"Offer\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}}}}],\"powers\":{\"party1\":2}}}";
43
44 @Override
45 public List<List<Voting>> getGeneralTestData() {
46 return Arrays.asList(Arrays.asList(voting1, voting1a),
47 Arrays.asList(voting2), Arrays.asList(voting3));
48 }
49
50 @Override
51 public List<String> getGeneralTestStrings() {
52 return Arrays.asList("Voting.*Bid.*iss.*val1.*party1.*2.*",
53 "Voting.*Bid.*iss.*val2.*party1.*2.*",
54 "Voting.*Bid.*iss.*val1.*party1.*3.*");
55 }
56
57 @Test
58 public void testSerialize() throws JsonProcessingException {
59 ObjectMapper jackson = new ObjectMapper();
60
61 String json = jackson.writeValueAsString(voting1);
62 System.out.println(json);
63 assertEquals(asJson, json);
64 }
65
66 @Test
67 public void testDeserialize()
68 throws JsonParseException, JsonMappingException, IOException {
69 ObjectMapper jackson = new ObjectMapper();
70 Inform p = jackson.readValue(asJson, Inform.class);
71 System.out.println(p);
72 assertEquals(voting1, p);
73 }
74
75}
Note: See TracBrowser for help on using the repository browser.