package geniusweb.partiesserver.websocket; 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.HashSet; import java.util.List; import org.junit.Before; import org.junit.Test; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import geniusweb.partiesserver.repository.GeneralPartyInfo; import geniusweb.party.Capabilities; import geniusweb.references.ProtocolRef; import tudelft.utilities.junit.GeneralTests; public class GeneralPartyInfoTest extends GeneralTests { private URI iri1; private URI iri2; private HashSet protocols1; private HashSet protocols2; private Capabilities caps1; private Capabilities caps2; private String descr1; private String descr2; private GeneralPartyInfo info1; private GeneralPartyInfo info1a; private GeneralPartyInfo info2; private GeneralPartyInfo info3; private GeneralPartyInfo info4; private String text1 = "GeneralPartyInfo.*iri1,Capabilities.*Protocols=.*ProtocolRef.*protocol1.*,description 1.*"; private String text2 = "GeneralPartyInfo.*iri2,Capabilities.*Protocols=.*ProtocolRef.*protocol1.*,description 1.*"; private String text3 = "GeneralPartyInfo.*iri1,Capabilities.*Protocols=.*ProtocolRef.*protocol2.*,description 1.*"; private String text4 = "GeneralPartyInfo.*iri1,Capabilities.*Protocols=.*ProtocolRef.*protocol1.*,description 2.*"; private final ObjectMapper jackson = new ObjectMapper(); private String serialized = "{\"uri\":\"http://iri1\",\"capabilities\":{\"protocols\":[\"http://protocol1\"]},\"description\":\"description 1\"}"; @Before public void before() throws URISyntaxException { iri1 = new URI("http://iri1"); iri2 = new URI("http://iri2"); protocols1 = new HashSet<>( Arrays.asList(new ProtocolRef("http://protocol1"))); protocols2 = new HashSet<>( Arrays.asList(new ProtocolRef("http://protocol2"))); caps1 = new Capabilities(protocols1); caps2 = new Capabilities(protocols2); descr1 = "description 1"; descr2 = "description 2"; info1 = new GeneralPartyInfo(iri1, caps1, descr1); info1a = new GeneralPartyInfo(iri1, caps1, descr1); info2 = new GeneralPartyInfo(iri2, caps1, descr1); info3 = new GeneralPartyInfo(iri1, caps2, descr1); info4 = new GeneralPartyInfo(iri1, caps1, descr2); } @Override public List> getGeneralTestData() { return Arrays.asList(Arrays.asList(info1, info1a), Arrays.asList(info2), Arrays.asList(info3), Arrays.asList(info4)); } @Override public List getGeneralTestStrings() { return Arrays.asList(text1, text2, text3, text4); } @Test public void testDeserialize() throws IOException { GeneralPartyInfo obj = jackson.readValue(serialized, GeneralPartyInfo.class); System.out.println(obj); assertEquals(info1, obj); } @Test public void testSerialize() throws JsonProcessingException, URISyntaxException { String string = jackson.writeValueAsString(info1); System.out.println(string); assertEquals(serialized, string); } }