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

Last change on this file since 47 was 46, checked in by ruud, 22 months ago

Fixed small issues in domaineditor.

File size: 3.2 KB
RevLine 
[46]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;
11import java.util.Set;
12
13import org.junit.Before;
14import org.junit.Test;
15
16import com.fasterxml.jackson.core.JsonProcessingException;
17import com.fasterxml.jackson.databind.ObjectMapper;
18
19import geniusweb.partiesserver.repository.GeneralPartyInfo;
20import geniusweb.party.Capabilities;
21import geniusweb.profile.Profile;
22import tudelft.utilities.junit.GeneralTests;
23
24public 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}
Note: See TracBrowser for help on using the repository browser.