source: events/src/test/java/geniusweb/inform/AgreementsTest.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.9 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.Before;
12import org.junit.Test;
13
14import com.fasterxml.jackson.core.JsonProcessingException;
15import com.fasterxml.jackson.databind.ObjectMapper;
16
17import geniusweb.actions.PartyId;
18import geniusweb.issuevalue.Bid;
19import geniusweb.issuevalue.DiscreteValue;
20import geniusweb.issuevalue.Value;
21import tudelft.utilities.junit.GeneralTests;
22
23public class AgreementsTest extends GeneralTests<Agreements> {
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 Value VALUE1 = new DiscreteValue("value1");
29 private static Bid bid = new Bid(
30 Collections.singletonMap("issue1", VALUE1));
31 private static Bid bid2 = new Bid(
32 Collections.singletonMap("issue2", VALUE1));
33
34 private final String finishedstring = "{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}";
35
36 private final static Agreements agrees1 = new Agreements(
37 Collections.singletonMap(id, bid));
38 private final static Agreements agrees1a = new Agreements(
39 Collections.singletonMap(id, bid));
40 private final static Agreements agrees2 = new Agreements(
41 Collections.singletonMap(id2, bid));
42 private final static Agreements agrees3 = new Agreements(
43 Collections.singletonMap(id, bid2));
44
45 @Override
46 public List<List<Agreements>> getGeneralTestData() {
47 return Arrays.asList(Arrays.asList(agrees1, agrees1a),
48 Arrays.asList(agrees2), Arrays.asList(agrees3));
49 }
50
51 @Override
52 public List<String> getGeneralTestStrings() {
53 return Arrays.asList("Agreements.*party1.*Bid.*issue1.*",
54 "Agreements.*party2.*Bid.*issue1.*",
55 "Agreements.*party1.*Bid.*issue2.*");
56 }
57
58 @Before
59 public void before() {
60
61 }
62
63 @Test
64 public void serializeAcceptTest() throws JsonProcessingException {
65 System.out.println(jackson.writeValueAsString(agrees1));
66 assertEquals(finishedstring, jackson.writeValueAsString(agrees1));
67 }
68
69 @Test
70 public void deserializeAcceptTest() throws IOException {
71 Agreements act = jackson.readValue(finishedstring, Agreements.class);
72 assertEquals(agrees1, act);
73 }
74
75 @SuppressWarnings("unused")
76 @Test
77 public void testNull() {
78 new Agreements();
79 }
80
81 @Test(expected = IllegalArgumentException.class)
82 public void testWithAlreadyActed() {
83 agrees1.with(agrees1);
84 }
85
86 @Test
87 public void testWith() {
88 Agreements agrees = agrees1.with(agrees2);
89 assertEquals(bid, agrees.getMap().get(id));
90 assertEquals(bid, agrees.getMap().get(id2));
91 }
92
93 @Test
94 public void testBidConstructor() {
95 Agreements agrees = new Agreements(bid,
96 new HashSet<PartyId>(Arrays.asList(id, id2)));
97 assertEquals(bid, agrees.getMap().get(id));
98 assertEquals(bid, agrees.getMap().get(id2));
99 }
100}
Note: See TracBrowser for help on using the repository browser.