source: events/src/test/java/geniusweb/actions/OfferTest.java@ 52

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

Fixed small issues in domaineditor.

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