source: events/src/test/java/geniusweb/actions/AcceptTest.java@ 48

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

Added java logconverter to add utilities to log results. Fixed
bug in python ProgressTime.

File size: 2.7 KB
RevLine 
[48]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.LinkedList;
9import java.util.List;
10import java.util.Map;
11
12import org.junit.Before;
13import org.junit.Test;
14
15import com.fasterxml.jackson.core.JsonProcessingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18import geniusweb.issuevalue.Bid;
19import geniusweb.issuevalue.DiscreteValue;
20import geniusweb.issuevalue.NumberValue;
21import geniusweb.issuevalue.Value;
22import tudelft.utilities.junit.GeneralTests;
23
24public class AcceptTest extends GeneralTests<Accept> {
25 private final ObjectMapper jackson = new ObjectMapper();
26
27 private static final PartyId id = new PartyId("party1");
28 private static final PartyId id2 = new PartyId("party2");
29 private final static Map<String, Value> issuevalues = new HashMap<String, Value>();
30 private final static Map<String, Value> issuevaluesb = new HashMap<String, Value>();
31 private static Bid bid;
32 private static Bid bidb;
33 private final static String ISSUE1 = "issue1";
34 private final static Value VALUE1 = new DiscreteValue("value1");
35 private final static String ISSUE2 = "issue2";
36 private final static Value VALUE2 = new NumberValue("10");
37 // issue 2 is NUMBER and thus serializes with leading '='
38 private final String acceptstring = "{\"Accept\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}";
39
40 private static Accept accept, accept1, accept2, acceptb;
41
42 static {
43 issuevalues.put(ISSUE1, VALUE1);
44 issuevalues.put(ISSUE2, VALUE2);
45 bid = new Bid(issuevalues);
46 accept = new Accept(id, bid);
47 accept1 = new Accept(id, bid);
48
49 accept2 = new Accept(id2, bid);
50
51 // values swapped, so different issuevalues.
52 issuevaluesb.put(ISSUE1, VALUE2);
53 issuevaluesb.put(ISSUE2, VALUE2);
54 bidb = new Bid(issuevaluesb);
55 acceptb = new Accept(id, bidb);
56
57 }
58
59 @Override
60 public List<List<Accept>> getGeneralTestData() {
61 List<List<Accept>> list = new LinkedList<>();
62 list.add(Arrays.asList(accept, accept1));
63 list.add(Arrays.asList(accept2));
64 list.add(Arrays.asList(acceptb));
65 return list;
66 }
67
68 @Override
69 public List<String> getGeneralTestStrings() {
70 return Arrays.asList("Accept.*" + id + ".*]", "Accept.*" + id2 + ".*]",
71 "Accept.*" + id + ".*]");
72 }
73
74 @Before
75 public void before() {
76
77 }
78
79 @Test
80 public void serializeAcceptTest() throws JsonProcessingException {
81 System.out.println(jackson.writeValueAsString(accept));
82 assertEquals(acceptstring, jackson.writeValueAsString(accept));
83 }
84
85 @Test
86 public void deserializeAcceptTest() throws IOException {
87 Action act = jackson.readValue(acceptstring, Action.class);
88 assertEquals(accept, act);
89 }
90
91}
Note: See TracBrowser for help on using the repository browser.