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 java.util.Set; 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.profile.Profile; 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.*Profile.*SAOP.*description 1.*"; private String text2 = "GeneralPartyInfo.*iri2,Capabilities.*Profile.*SAOP.*,description 1.*"; private String text3 = "GeneralPartyInfo.*iri1,Capabilities.*Profile.*SEB.*,description 1.*"; private String text4 = "GeneralPartyInfo.*iri1,Capabilities.*Profile.*SAOP.*,description 2.*"; private final ObjectMapper jackson = new ObjectMapper(); private String serialized = "{\"uri\":\"http://iri1\",\"capabilities\":{\"behaviours\":[\"SAOP\"],\"profiles\":[\"geniusweb.profile.Profile\"]},\"description\":\"description 1\"}"; @SuppressWarnings("rawtypes") public void test() { Object a = 1; List l = (List) a; } @Before public void before() throws URISyntaxException { iri1 = new URI("http://iri1"); iri2 = new URI("http://iri2"); protocols1 = new HashSet<>(Arrays.asList("SAOP")); protocols2 = new HashSet<>(Arrays.asList("SEB")); Set> profilesclasses = new HashSet<>( Arrays.asList(Profile.class)); caps1 = new Capabilities(protocols1, profilesclasses); caps2 = new Capabilities(protocols2, profilesclasses); 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); } }