package geniusweb.actions; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.Before; import org.junit.Test; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import geniusweb.issuevalue.Bid; import geniusweb.issuevalue.DiscreteValue; import geniusweb.issuevalue.NumberValue; import geniusweb.issuevalue.Value; import tudelft.utilities.junit.GeneralTests; public class ElicitComparisonTest extends GeneralTests { private final ObjectMapper jackson = new ObjectMapper(); private static final PartyId id = new PartyId("party1"); private static final PartyId id2 = new PartyId("party2"); private final static Map issuevalues = new HashMap(); private final static Map issuevaluesb = new HashMap(); private static Bid bid; private static Bid bidb; private final static String ISSUE1 = "issue1"; private final static Value VALUE1 = new DiscreteValue("value1"); private final static String ISSUE2 = "issue2"; private final static Value VALUE2 = new NumberValue("10"); // issue 2 is NUMBER and thus serializes with leading '=' private final String acceptstring = "{\"ElicitComparison\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"options\":[{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}]}}"; private static ElicitComparison accept1, accept1a, accept2, accept3, accept4; @Before public void before() { issuevalues.put(ISSUE1, VALUE1); issuevalues.put(ISSUE2, VALUE2); issuevaluesb.put(ISSUE1, VALUE2); bid = new Bid(issuevalues); bidb = new Bid(issuevaluesb); List opts = Arrays.asList(bid); List opts2 = Arrays.asList(bidb); accept1 = new ElicitComparison(id, bid, opts); accept1a = new ElicitComparison(id, bid, opts); accept2 = new ElicitComparison(id2, bid, opts); accept3 = new ElicitComparison(id, bidb, opts); accept4 = new ElicitComparison(id, bid, opts2); } @Override public List> getGeneralTestData() { return Arrays.asList(Arrays.asList(accept1, accept1a), Arrays.asList(accept2), Arrays.asList(accept3), Arrays.asList(accept4)); } @Override public List getGeneralTestStrings() { return Arrays.asList( "ElicitComparison.*party1.*Bid.*10.*value1.*\\[.*Bid.*10.*value1.*\\].*", "ElicitComparison.*party2.*Bid.*10.*value1.*\\[.*Bid.*10.*value1.*\\].*", "ElicitComparison.*party1.*Bid.*10.*\\[.*Bid.*10.*value1.*\\].*", "ElicitComparison.*party1.*Bid.*10.*value1.*\\[.*Bid.*10.*\\].*"); } @Test public void serializeAcceptTest() throws JsonProcessingException { System.out.println(jackson.writeValueAsString(accept1)); assertEquals(acceptstring, jackson.writeValueAsString(accept1)); } @Test public void deserializeAcceptTest() throws IOException { Action act = jackson.readValue(acceptstring, Action.class); assertEquals(accept1, act); } }