package geniusweb.references; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Arrays; import java.util.List; import org.junit.Before; import org.junit.Test; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import geniusweb.references.PartyRef; import tudelft.utilities.junit.GeneralTests; public class PartyRefTest extends GeneralTests { private PartyRef party1, party1a, party2, party3; private String asJson = "\"ws:localhost/party1\""; @Before public void before() throws URISyntaxException { party1 = new PartyRef(new URI("ws:localhost/party1")); party1a = new PartyRef(new URI("ws:localhost/party1")); party2 = new PartyRef(new URI("ws:localhost/party2")); party3 = new PartyRef(new URI("http:localhost/party3")); } @Override public List> getGeneralTestData() { return Arrays.asList(Arrays.asList(party1, party1a), Arrays.asList(party2), Arrays.asList(party3)); } @Override public List getGeneralTestStrings() { return Arrays.asList("PartyRef.*party1.*", "PartyRef.*party2.*", "PartyRef.*party3.*"); } @Test public void smokeTest() throws URISyntaxException { new PartyRef(new URI("ws:localhost")); } @Test(expected = IllegalArgumentException.class) public void nullTest() throws URISyntaxException { new PartyRef((URI) null); } @Test public void testSerialize() throws JsonProcessingException { ObjectMapper jackson = new ObjectMapper(); String json = jackson.writeValueAsString(party1); System.out.println(json); assertEquals(asJson, json); } @Test public void testDeserialize() throws JsonParseException, JsonMappingException, IOException { ObjectMapper jackson = new ObjectMapper(); PartyRef p = jackson.readValue(asJson, PartyRef.class); System.out.println(p); assertEquals(party1, p); } }