1 | package geniusweb.references;
|
---|
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.List;
|
---|
10 |
|
---|
11 | import org.junit.Before;
|
---|
12 | import org.junit.Test;
|
---|
13 |
|
---|
14 | import com.fasterxml.jackson.core.JsonParseException;
|
---|
15 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
16 | import com.fasterxml.jackson.databind.JsonMappingException;
|
---|
17 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
18 |
|
---|
19 | import tudelft.utilities.junit.GeneralTests;
|
---|
20 |
|
---|
21 | public class PartyWithProfileTest extends GeneralTests<PartyWithProfile> {
|
---|
22 |
|
---|
23 | private PartyRef party1, party1a, party2, party3;
|
---|
24 | private ProfileRef profile1, profile2;
|
---|
25 | private PartyWithProfile partyprof1, partyprof1a, partyprof2, partyprof3,
|
---|
26 | partyprof4;
|
---|
27 | private final String serialized = "{\"party\":{\"partyref\":\"ws:party1\",\"parameters\":{}},\"profile\":\"ws:profile1\"}";
|
---|
28 |
|
---|
29 | @Before
|
---|
30 | public void before() throws URISyntaxException {
|
---|
31 | party1 = new PartyRef(new URI("ws:party1"));
|
---|
32 | party1a = new PartyRef(new URI("ws:party1"));
|
---|
33 | party2 = new PartyRef(new URI("ws:party2"));
|
---|
34 | party3 = new PartyRef(new URI("http:party3"));
|
---|
35 |
|
---|
36 | profile1 = new ProfileRef(new URI("ws:profile1"));
|
---|
37 | profile2 = new ProfileRef(new URI("ws:profile2"));
|
---|
38 |
|
---|
39 | Parameters settings1 = new Parameters();
|
---|
40 | Parameters settings2 = new Parameters().with("a", 1);
|
---|
41 |
|
---|
42 | PartyWithParameters party1withparams1 = new PartyWithParameters(party1,
|
---|
43 | settings1);
|
---|
44 | PartyWithParameters party1withparams2 = new PartyWithParameters(party1,
|
---|
45 | settings2);
|
---|
46 | PartyWithParameters party2withparams1 = new PartyWithParameters(party2,
|
---|
47 | settings1);
|
---|
48 |
|
---|
49 | partyprof1 = new PartyWithProfile(party1withparams1, profile1);
|
---|
50 | partyprof1a = new PartyWithProfile(party1withparams1, profile1);
|
---|
51 | partyprof2 = new PartyWithProfile(party2withparams1, profile1);
|
---|
52 | partyprof3 = new PartyWithProfile(party1withparams1, profile2);
|
---|
53 | partyprof4 = new PartyWithProfile(party1withparams2, profile1);
|
---|
54 |
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public List<List<PartyWithProfile>> getGeneralTestData() {
|
---|
59 | return Arrays.asList(Arrays.asList(partyprof1, partyprof1a),
|
---|
60 | Arrays.asList(partyprof2), Arrays.asList(partyprof3),
|
---|
61 | Arrays.asList(partyprof4));
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public List<String> getGeneralTestStrings() {
|
---|
66 | return Arrays.asList(
|
---|
67 | "PartyWithProfile.PartyRef.ws:party1.,ProfileRef.ws:profile1.*",
|
---|
68 | "PartyWithProfile.PartyRef.ws:party2.,ProfileRef.ws:profile1.*",
|
---|
69 | "PartyWithProfile.PartyRef.ws:party1.,ProfileRef.ws:profile2.*",
|
---|
70 | "PartyWithProfile.PartyRef.ws:party1.\\{a=1\\},ProfileRef.ws:profile1.*");
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Test
|
---|
74 | public void smokeTest() throws URISyntaxException {
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Test(expected = IllegalArgumentException.class)
|
---|
78 | public void nullTest() throws URISyntaxException {
|
---|
79 | new PartyWithProfile((PartyWithParameters) null, (ProfileRef) null);
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Test
|
---|
83 | public void testSerialize() throws JsonProcessingException {
|
---|
84 | ObjectMapper jackson = new ObjectMapper();
|
---|
85 |
|
---|
86 | String json = jackson.writeValueAsString(partyprof1);
|
---|
87 | System.out.println(json);
|
---|
88 | assertEquals(serialized, json);
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Test
|
---|
92 | public void testDeserialize()
|
---|
93 | throws JsonParseException, JsonMappingException, IOException {
|
---|
94 | ObjectMapper jackson = new ObjectMapper();
|
---|
95 | PartyWithProfile p = jackson.readValue(serialized,
|
---|
96 | PartyWithProfile.class);
|
---|
97 | System.out.println(p);
|
---|
98 | assertEquals(partyprof1, p);
|
---|
99 | }
|
---|
100 |
|
---|
101 | }
|
---|