source: protocol/src/test/java/geniusweb/protocol/session/saop/SaopPartyWithProfileTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

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