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

Last change on this file since 29 was 29, checked in by bart, 3 years ago

some minor fixes

File size: 3.7 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.OnePartyTeam;
20import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
21import geniusweb.references.Parameters;
22import geniusweb.references.PartyRef;
23import geniusweb.references.PartyWithParameters;
24import geniusweb.references.ProfileRef;
25import tudelft.utilities.junit.GeneralTests;
26
27public 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}
Note: See TracBrowser for help on using the repository browser.