package geniusweb.actions; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; 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 AcceptTest 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 = "{\"accept\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}"; private static Accept accept, accept1, accept2, acceptb; static { issuevalues.put(ISSUE1, VALUE1); issuevalues.put(ISSUE2, VALUE2); bid = new Bid(issuevalues); accept = new Accept(id, bid); accept1 = new Accept(id, bid); accept2 = new Accept(id2, bid); // values swapped, so different issuevalues. issuevaluesb.put(ISSUE1, VALUE2); issuevaluesb.put(ISSUE2, VALUE2); bidb = new Bid(issuevaluesb); acceptb = new Accept(id, bidb); } @Override public List> getGeneralTestData() { List> list = new LinkedList<>(); list.add(Arrays.asList(accept, accept1)); list.add(Arrays.asList(accept2)); list.add(Arrays.asList(acceptb)); return list; } @Override public List getGeneralTestStrings() { return Arrays.asList("Accept.*" + id + ".*]", "Accept.*" + id2 + ".*]", "Accept.*" + id + ".*]"); } @Before public void before() { } @Test public void serializeAcceptTest() throws JsonProcessingException { System.out.println(jackson.writeValueAsString(accept)); assertEquals(acceptstring, jackson.writeValueAsString(accept)); } @Test public void deserializeAcceptTest() throws IOException { Action act = jackson.readValue(acceptstring, Action.class); assertEquals(accept, act); } }