[25] | 1 | package geniusweb.partiesserver.websocket;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 |
|
---|
| 5 | import java.io.IOException;
|
---|
| 6 | import java.net.URI;
|
---|
| 7 | import java.net.URISyntaxException;
|
---|
| 8 | import java.util.Arrays;
|
---|
| 9 | import java.util.HashSet;
|
---|
| 10 | import java.util.List;
|
---|
| 11 | import java.util.Set;
|
---|
| 12 |
|
---|
| 13 | import org.junit.Before;
|
---|
| 14 | import org.junit.Test;
|
---|
| 15 |
|
---|
| 16 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
| 17 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
| 18 |
|
---|
| 19 | import geniusweb.partiesserver.repository.GeneralPartyInfo;
|
---|
| 20 | import geniusweb.party.Capabilities;
|
---|
| 21 | import geniusweb.profile.Profile;
|
---|
| 22 | import tudelft.utilities.junit.GeneralTests;
|
---|
| 23 |
|
---|
| 24 | public class GeneralPartyInfoTest extends GeneralTests<GeneralPartyInfo> {
|
---|
| 25 |
|
---|
| 26 | private URI iri1;
|
---|
| 27 | private URI iri2;
|
---|
| 28 | private HashSet<String> protocols1;
|
---|
| 29 | private HashSet<String> protocols2;
|
---|
| 30 | private Capabilities caps1;
|
---|
| 31 | private Capabilities caps2;
|
---|
| 32 | private String descr1;
|
---|
| 33 | private String descr2;
|
---|
| 34 | private GeneralPartyInfo info1;
|
---|
| 35 | private GeneralPartyInfo info1a;
|
---|
| 36 | private GeneralPartyInfo info2;
|
---|
| 37 | private GeneralPartyInfo info3;
|
---|
| 38 | private GeneralPartyInfo info4;
|
---|
| 39 | private String text1 = "GeneralPartyInfo.*iri1,Capabilities.*Behaviours=.*SAOP.*description 1.*";
|
---|
| 40 | private String text2 = "GeneralPartyInfo.*iri2,Capabilities.*Behaviours=.*SAOP.*,description 1.*";
|
---|
| 41 | private String text3 = "GeneralPartyInfo.*iri1,Capabilities.*Behaviours=.*SEB.*,description 1.*";
|
---|
| 42 | private String text4 = "GeneralPartyInfo.*iri1,Capabilities.*Behaviours=.*SAOP.*,description 2.*";
|
---|
| 43 |
|
---|
| 44 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
| 45 | private String serialized = "{\"uri\":\"http://iri1\",\"capabilities\":{\"behaviours\":[\"SAOP\"],\"profiles\":[\"geniusweb.profile.Profile\"]},\"description\":\"description 1\"}";
|
---|
| 46 |
|
---|
| 47 | @Before
|
---|
| 48 | public void before() throws URISyntaxException {
|
---|
| 49 | iri1 = new URI("http://iri1");
|
---|
| 50 | iri2 = new URI("http://iri2");
|
---|
| 51 | protocols1 = new HashSet<>(Arrays.asList("SAOP"));
|
---|
| 52 | protocols2 = new HashSet<>(Arrays.asList("SEB"));
|
---|
| 53 | Set<Class<? extends Profile>> profilesclasses = new HashSet<>(
|
---|
| 54 | Arrays.asList(Profile.class));
|
---|
| 55 | caps1 = new Capabilities(protocols1, profilesclasses);
|
---|
| 56 | caps2 = new Capabilities(protocols2, profilesclasses);
|
---|
| 57 | descr1 = "description 1";
|
---|
| 58 | descr2 = "description 2";
|
---|
| 59 | info1 = new GeneralPartyInfo(iri1, caps1, descr1);
|
---|
| 60 | info1a = new GeneralPartyInfo(iri1, caps1, descr1);
|
---|
| 61 | info2 = new GeneralPartyInfo(iri2, caps1, descr1);
|
---|
| 62 | info3 = new GeneralPartyInfo(iri1, caps2, descr1);
|
---|
| 63 | info4 = new GeneralPartyInfo(iri1, caps1, descr2);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | @Override
|
---|
| 67 | public List<List<GeneralPartyInfo>> getGeneralTestData() {
|
---|
| 68 | return Arrays.asList(Arrays.asList(info1, info1a), Arrays.asList(info2),
|
---|
| 69 | Arrays.asList(info3), Arrays.asList(info4));
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | @Override
|
---|
| 73 | public List<String> getGeneralTestStrings() {
|
---|
| 74 | return Arrays.asList(text1, text2, text3, text4);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | @Test
|
---|
| 78 | public void testDeserialize() throws IOException {
|
---|
| 79 | GeneralPartyInfo obj = jackson.readValue(serialized,
|
---|
| 80 | GeneralPartyInfo.class);
|
---|
| 81 | System.out.println(obj);
|
---|
| 82 | assertEquals(info1, obj);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | @Test
|
---|
| 86 | public void testSerialize()
|
---|
| 87 | throws JsonProcessingException, URISyntaxException {
|
---|
| 88 |
|
---|
| 89 | String string = jackson.writeValueAsString(info1);
|
---|
| 90 | System.out.println(string);
|
---|
| 91 | assertEquals(serialized, string);
|
---|
| 92 | }
|
---|
| 93 | }
|
---|