[44] | 1 | package geniusweb.inform;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 |
|
---|
| 5 | import java.io.IOException;
|
---|
| 6 | import java.util.Arrays;
|
---|
| 7 | import java.util.Collections;
|
---|
| 8 | import java.util.HashSet;
|
---|
| 9 | import java.util.List;
|
---|
| 10 |
|
---|
| 11 | import org.junit.Before;
|
---|
| 12 | import org.junit.Test;
|
---|
| 13 |
|
---|
| 14 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
| 15 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
| 16 |
|
---|
| 17 | import geniusweb.actions.PartyId;
|
---|
| 18 | import geniusweb.issuevalue.Bid;
|
---|
| 19 | import geniusweb.issuevalue.DiscreteValue;
|
---|
| 20 | import geniusweb.issuevalue.Value;
|
---|
| 21 | import tudelft.utilities.junit.GeneralTests;
|
---|
| 22 |
|
---|
| 23 | public 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 | }
|
---|