source: events/src/test/java/actions/OfferTest.java@ 14

Last change on this file since 14 was 1, checked in by bart, 5 years ago

Initial Release

File size: 2.4 KB
Line 
1package actions;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.util.Arrays;
7import java.util.HashMap;
8import java.util.List;
9import java.util.Map;
10
11import org.junit.Test;
12
13import com.fasterxml.jackson.core.JsonProcessingException;
14import com.fasterxml.jackson.databind.ObjectMapper;
15
16import geniusweb.actions.Action;
17import geniusweb.actions.Offer;
18import geniusweb.actions.PartyId;
19import geniusweb.issuevalue.Bid;
20import geniusweb.issuevalue.DiscreteValue;
21import geniusweb.issuevalue.NumberValue;
22import geniusweb.issuevalue.Value;
23import tudelft.utilities.junit.GeneralTests;
24
25public class OfferTest extends GeneralTests<Offer> {
26 private final ObjectMapper jackson = new ObjectMapper();
27
28 private static final PartyId id = new PartyId("party1");
29 private static final Map<String, Value> issuevalues = new HashMap<String, Value>();
30 private static final Map<String, Value> issuevaluesb = new HashMap<String, Value>();
31 private static Bid bid;
32 private static Bid bidb;
33 private static final String ISSUE1 = "issue1";
34 private static final Value VALUE1 = new DiscreteValue("value1");
35 private static final String ISSUE2 = "issue2";
36 private static final Value VALUE2 = new NumberValue("10");
37 private static final String acceptstring = "{\"offer\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}";
38
39 private static Offer offer;
40 private static Offer offer1;
41 private static Offer offerb;
42
43 static {
44 issuevalues.put(ISSUE1, VALUE1);
45 issuevalues.put(ISSUE2, VALUE2);
46 bid = new Bid(issuevalues);
47 offer = new Offer(id, bid);
48 offer1 = new Offer(id, bid);
49
50 // values swapped, so different issuevalues.
51 issuevaluesb.put(ISSUE1, VALUE2);
52 issuevaluesb.put(ISSUE2, VALUE2);
53 bidb = new Bid(issuevaluesb);
54 offerb = new Offer(id, bidb);
55
56 }
57
58 @Override
59 public List<List<Offer>> getGeneralTestData() {
60 return Arrays.asList(Arrays.asList(offer, offer1),
61 Arrays.asList(offerb));
62 }
63
64 @Override
65 public List<String> getGeneralTestStrings() {
66 return Arrays.asList("Offer\\[.*" + id + ".*Bid.*\\]",
67 "Offer\\[.*" + id + ".*Bid.*\\]");
68 }
69
70 @Test
71 public void serializeAcceptTest() throws JsonProcessingException {
72 System.out.println(jackson.writeValueAsString(offer));
73 assertEquals(acceptstring, jackson.writeValueAsString(offer));
74 }
75
76 @Test
77 public void deserializeAcceptTest() throws IOException {
78 Action act = jackson.readValue(acceptstring, Action.class);
79 assertEquals(offer, act);
80 }
81
82}
Note: See TracBrowser for help on using the repository browser.