package 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.Test; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import geniusweb.actions.Action; import geniusweb.actions.Offer; import geniusweb.actions.PartyId; import geniusweb.issuevalue.Bid; import geniusweb.issuevalue.DiscreteValue; import geniusweb.issuevalue.NumberValue; import geniusweb.issuevalue.Value; import tudelft.utilities.junit.GeneralTests; public class OfferTest extends GeneralTests { private final ObjectMapper jackson = new ObjectMapper(); private static final PartyId id = new PartyId("party1"); private static final Map issuevalues = new HashMap(); private static final Map issuevaluesb = new HashMap(); private static Bid bid; private static Bid bidb; private static final String ISSUE1 = "issue1"; private static final Value VALUE1 = new DiscreteValue("value1"); private static final String ISSUE2 = "issue2"; private static final Value VALUE2 = new NumberValue("10"); private static final String acceptstring = "{\"offer\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}"; private static Offer offer; private static Offer offer1; private static Offer offerb; static { issuevalues.put(ISSUE1, VALUE1); issuevalues.put(ISSUE2, VALUE2); bid = new Bid(issuevalues); offer = new Offer(id, bid); offer1 = new Offer(id, bid); // values swapped, so different issuevalues. issuevaluesb.put(ISSUE1, VALUE2); issuevaluesb.put(ISSUE2, VALUE2); bidb = new Bid(issuevaluesb); offerb = new Offer(id, bidb); } @Override public List> getGeneralTestData() { return Arrays.asList(Arrays.asList(offer, offer1), Arrays.asList(offerb)); } @Override public List getGeneralTestStrings() { return Arrays.asList("Offer\\[.*" + id + ".*Bid.*\\]", "Offer\\[.*" + id + ".*Bid.*\\]"); } @Test public void serializeAcceptTest() throws JsonProcessingException { System.out.println(jackson.writeValueAsString(offer)); assertEquals(acceptstring, jackson.writeValueAsString(offer)); } @Test public void deserializeAcceptTest() throws IOException { Action act = jackson.readValue(acceptstring, Action.class); assertEquals(offer, act); } }