source: src/test/java/geniusweb/partiesserver/websocket/GeneralPartyInfoTest.java@ 1

Last change on this file since 1 was 1, checked in by bart, 5 years ago

Initial Release

File size: 3.1 KB
Line 
1package geniusweb.partiesserver.websocket;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.net.URI;
7import java.net.URISyntaxException;
8import java.util.Arrays;
9import java.util.HashSet;
10import java.util.List;
11
12import org.junit.Before;
13import org.junit.Test;
14
15import com.fasterxml.jackson.core.JsonProcessingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18import geniusweb.partiesserver.repository.GeneralPartyInfo;
19import geniusweb.party.Capabilities;
20import geniusweb.references.ProtocolRef;
21import tudelft.utilities.junit.GeneralTests;
22
23public 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}
Note: See TracBrowser for help on using the repository browser.