package testcode.actions; /** * Derived from AcceptTest in GeniusWeb. */ import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class ActionsTest { private final ObjectMapper jackson = new ObjectMapper(); private static final PartyId id = new PartyId("party1"); private static final PartyId id2 = new PartyId("party2"); private static Bid bid; private static Bid bidb; // issue 2 is NUMBER and thus serializes with leading '=' private final String acceptstring = "{\"Accept\":{\"actor\":\"party1\",\"bid\":\"issuevalues\"}}"; private static Accept accept, accept1, accept2, acceptb; @Before public void before() { bid = new Bid("issuevalues"); accept = new Accept(id, bid); accept1 = new Accept(id, bid); accept2 = new Accept(id2, bid); // values swapped, so different issuevalues. bidb = new Bid("issuevaluesb"); acceptb = new Accept(id, bidb); } @Test public void serializeAcceptTest() throws JsonProcessingException { System.out.println("serializeAcceptTest"); System.out.println(jackson.writeValueAsString(accept)); assertEquals(acceptstring, jackson.writeValueAsString(accept)); } @Test public void deserializeAcceptTest() throws IOException { System.out.println("deserializeAcceptTest"); Action act = jackson.readValue(acceptstring, Action.class); System.out.println(act); assertEquals(accept, act); } public static void main(String[] args) throws IOException { ActionsTest a = new ActionsTest(); a.before(); a.serializeAcceptTest(); a = new ActionsTest(); a.before(); a.deserializeAcceptTest(); } }