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

Last change on this file since 27 was 27, checked in by bart, 4 years ago

some minor fixes

File size: 3.1 KB
RevLine 
[27]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.*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}
Note: See TracBrowser for help on using the repository browser.