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.*Profile.*SAOP.*description 1.*";
|
---|
40 | private String text2 = "GeneralPartyInfo.*iri2,Capabilities.*Profile.*SAOP.*,description 1.*";
|
---|
41 | private String text3 = "GeneralPartyInfo.*iri1,Capabilities.*Profile.*SEB.*,description 1.*";
|
---|
42 | private String text4 = "GeneralPartyInfo.*iri1,Capabilities.*Profile.*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 | @SuppressWarnings("rawtypes")
|
---|
48 | public void test() {
|
---|
49 | Object a = 1;
|
---|
50 | List l = (List) a;
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Before
|
---|
54 | public void before() throws URISyntaxException {
|
---|
55 | iri1 = new URI("http://iri1");
|
---|
56 | iri2 = new URI("http://iri2");
|
---|
57 | protocols1 = new HashSet<>(Arrays.asList("SAOP"));
|
---|
58 | protocols2 = new HashSet<>(Arrays.asList("SEB"));
|
---|
59 | Set<Class<? extends Profile>> profilesclasses = new HashSet<>(
|
---|
60 | Arrays.asList(Profile.class));
|
---|
61 | caps1 = new Capabilities(protocols1, profilesclasses);
|
---|
62 | caps2 = new Capabilities(protocols2, profilesclasses);
|
---|
63 | descr1 = "description 1";
|
---|
64 | descr2 = "description 2";
|
---|
65 | info1 = new GeneralPartyInfo(iri1, caps1, descr1);
|
---|
66 | info1a = new GeneralPartyInfo(iri1, caps1, descr1);
|
---|
67 | info2 = new GeneralPartyInfo(iri2, caps1, descr1);
|
---|
68 | info3 = new GeneralPartyInfo(iri1, caps2, descr1);
|
---|
69 | info4 = new GeneralPartyInfo(iri1, caps1, descr2);
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Override
|
---|
73 | public List<List<GeneralPartyInfo>> getGeneralTestData() {
|
---|
74 | return Arrays.asList(Arrays.asList(info1, info1a), Arrays.asList(info2),
|
---|
75 | Arrays.asList(info3), Arrays.asList(info4));
|
---|
76 | }
|
---|
77 |
|
---|
78 | @Override
|
---|
79 | public List<String> getGeneralTestStrings() {
|
---|
80 | return Arrays.asList(text1, text2, text3, text4);
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Test
|
---|
84 | public void testDeserialize() throws IOException {
|
---|
85 | GeneralPartyInfo obj = jackson.readValue(serialized,
|
---|
86 | GeneralPartyInfo.class);
|
---|
87 | System.out.println(obj);
|
---|
88 | assertEquals(info1, obj);
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Test
|
---|
92 | public void testSerialize()
|
---|
93 | throws JsonProcessingException, URISyntaxException {
|
---|
94 |
|
---|
95 | String string = jackson.writeValueAsString(info1);
|
---|
96 | System.out.println(string);
|
---|
97 | assertEquals(serialized, string);
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|