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

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

Update 28 jan 2020

File size: 2.9 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 tudelft.utilities.junit.GeneralTests;
21
22public class GeneralPartyInfoTest extends GeneralTests<GeneralPartyInfo> {
23
24 private URI iri1;
25 private URI iri2;
26 private HashSet<String> protocols1;
27 private HashSet<String> protocols2;
28 private Capabilities caps1;
29 private Capabilities caps2;
30 private String descr1;
31 private String descr2;
32 private GeneralPartyInfo info1;
33 private GeneralPartyInfo info1a;
34 private GeneralPartyInfo info2;
35 private GeneralPartyInfo info3;
36 private GeneralPartyInfo info4;
37 private String text1 = "GeneralPartyInfo.*iri1,Capabilities.*Behaviours=.*SAOP.*description 1.*";
38 private String text2 = "GeneralPartyInfo.*iri2,Capabilities.*Behaviours=.*SAOP.*,description 1.*";
39 private String text3 = "GeneralPartyInfo.*iri1,Capabilities.*Behaviours=.*SEB.*,description 1.*";
40 private String text4 = "GeneralPartyInfo.*iri1,Capabilities.*Behaviours=.*SAOP.*,description 2.*";
41
42 private final ObjectMapper jackson = new ObjectMapper();
43 private String serialized = "{\"uri\":\"http://iri1\",\"capabilities\":{\"behaviours\":[\"SAOP\"]},\"description\":\"description 1\"}";
44
45 @Before
46 public void before() throws URISyntaxException {
47 iri1 = new URI("http://iri1");
48 iri2 = new URI("http://iri2");
49 protocols1 = new HashSet<>(Arrays.asList("SAOP"));
50 protocols2 = new HashSet<>(Arrays.asList("SEB"));
51 caps1 = new Capabilities(protocols1);
52 caps2 = new Capabilities(protocols2);
53 descr1 = "description 1";
54 descr2 = "description 2";
55 info1 = new GeneralPartyInfo(iri1, caps1, descr1);
56 info1a = new GeneralPartyInfo(iri1, caps1, descr1);
57 info2 = new GeneralPartyInfo(iri2, caps1, descr1);
58 info3 = new GeneralPartyInfo(iri1, caps2, descr1);
59 info4 = new GeneralPartyInfo(iri1, caps1, descr2);
60 }
61
62 @Override
63 public List<List<GeneralPartyInfo>> getGeneralTestData() {
64 return Arrays.asList(Arrays.asList(info1, info1a), Arrays.asList(info2),
65 Arrays.asList(info3), Arrays.asList(info4));
66 }
67
68 @Override
69 public List<String> getGeneralTestStrings() {
70 return Arrays.asList(text1, text2, text3, text4);
71 }
72
73 @Test
74 public void testDeserialize() throws IOException {
75 GeneralPartyInfo obj = jackson.readValue(serialized,
76 GeneralPartyInfo.class);
77 System.out.println(obj);
78 assertEquals(info1, obj);
79 }
80
81 @Test
82 public void testSerialize()
83 throws JsonProcessingException, URISyntaxException {
84
85 String string = jackson.writeValueAsString(info1);
86 System.out.println(string);
87 assertEquals(serialized, string);
88 }
89}
Note: See TracBrowser for help on using the repository browser.