1 | package geniusweb.protocol.session.saop;
|
---|
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 geniusweb.protocol.session.OnePartyTeam;
|
---|
20 | import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
|
---|
21 | import geniusweb.references.Parameters;
|
---|
22 | import geniusweb.references.PartyRef;
|
---|
23 | import geniusweb.references.PartyWithParameters;
|
---|
24 | import geniusweb.references.ProfileRef;
|
---|
25 | import tudelft.utilities.junit.GeneralTests;
|
---|
26 |
|
---|
27 | public class SaopPartyWithProfileTest extends GeneralTests<OnePartyTeam> {
|
---|
28 |
|
---|
29 | private PartyRef party1, party1a, party2, party3;
|
---|
30 | private ProfileRef profile1, profile2;
|
---|
31 | private OnePartyTeam partyprof1, partyprof1a, partyprof2, partyprof3,
|
---|
32 | partyprof4;
|
---|
33 | private final String serialized = "{\"party\":{\"partyref\":\"ws:party1\",\"parameters\":{}},\"profile\":\"ws:profile1\"}";
|
---|
34 |
|
---|
35 | @Before
|
---|
36 | public void before() throws URISyntaxException {
|
---|
37 | party1 = new PartyRef(new URI("ws:party1"));
|
---|
38 | party1a = new PartyRef(new URI("ws:party1"));
|
---|
39 | party2 = new PartyRef(new URI("ws:party2"));
|
---|
40 | party3 = new PartyRef(new URI("http:party3"));
|
---|
41 |
|
---|
42 | profile1 = new ProfileRef(new URI("ws:profile1"));
|
---|
43 | profile2 = new ProfileRef(new URI("ws:profile2"));
|
---|
44 |
|
---|
45 | Parameters settings1 = new Parameters();
|
---|
46 | Parameters settings2 = new Parameters();
|
---|
47 | settings2.put("a", 1);
|
---|
48 |
|
---|
49 | PartyWithParameters party1withparams1 = new PartyWithParameters(party1,
|
---|
50 | settings1);
|
---|
51 | PartyWithParameters party1withparams2 = new PartyWithParameters(party1,
|
---|
52 | settings2);
|
---|
53 | PartyWithParameters party2withparams1 = new PartyWithParameters(party2,
|
---|
54 | settings1);
|
---|
55 |
|
---|
56 | partyprof1 = new OnePartyTeam(party1withparams1, profile1);
|
---|
57 | partyprof1a = new OnePartyTeam(party1withparams1, profile1);
|
---|
58 | partyprof2 = new OnePartyTeam(party2withparams1, profile1);
|
---|
59 | partyprof3 = new OnePartyTeam(party1withparams1, profile2);
|
---|
60 | partyprof4 = new OnePartyTeam(party1withparams2, profile1);
|
---|
61 |
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public List<List<OnePartyTeam>> getGeneralTestData() {
|
---|
66 | return Arrays.asList(Arrays.asList(partyprof1, partyprof1a),
|
---|
67 | Arrays.asList(partyprof2), Arrays.asList(partyprof3),
|
---|
68 | Arrays.asList(partyprof4));
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public List<String> getGeneralTestStrings() {
|
---|
73 | return Arrays.asList(
|
---|
74 | "PartyWithProfile.PartyRef.ws:party1.,ProfileRef.ws:profile1.*",
|
---|
75 | "PartyWithProfile.PartyRef.ws:party2.,ProfileRef.ws:profile1.*",
|
---|
76 | "PartyWithProfile.PartyRef.ws:party1.,ProfileRef.ws:profile2.*",
|
---|
77 | "PartyWithProfile.PartyRef.ws:party1.\\{a=1\\},ProfileRef.ws:profile1.*");
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Test
|
---|
81 | public void smokeTest() throws URISyntaxException {
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Test(expected = IllegalArgumentException.class)
|
---|
85 | public void nullTest() throws URISyntaxException {
|
---|
86 | new OnePartyTeam((PartyWithParameters) null, (ProfileRef) null);
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Test
|
---|
90 | public void testSerialize() throws JsonProcessingException {
|
---|
91 | ObjectMapper jackson = new ObjectMapper();
|
---|
92 |
|
---|
93 | String json = jackson.writeValueAsString(partyprof1);
|
---|
94 | System.out.println(json);
|
---|
95 | assertEquals(serialized, json);
|
---|
96 | }
|
---|
97 |
|
---|
98 | @Test
|
---|
99 | public void testDeserialize()
|
---|
100 | throws JsonParseException, JsonMappingException, IOException {
|
---|
101 | ObjectMapper jackson = new ObjectMapper();
|
---|
102 | // always used as part of bigger class, do not include class name
|
---|
103 | // and therfore can not serialize as TeamOfPartiesAndProfiles
|
---|
104 | TeamOfPartiesAndProfiles p = jackson.readValue(serialized,
|
---|
105 | OnePartyTeam.class);
|
---|
106 | System.out.println(p);
|
---|
107 | assertEquals(partyprof1, p);
|
---|
108 | }
|
---|
109 |
|
---|
110 | }
|
---|