source: references/src/test/java/geniusweb/references/PartyWithProfileTest.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.3 KB
Line 
1package geniusweb.references;
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 tudelft.utilities.junit.GeneralTests;
20
21public 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}
Note: See TracBrowser for help on using the repository browser.