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