source: references/src/test/java/geniusweb/references/PartiWithParamsTest.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: 2.1 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 PartiWithParamsTest extends GeneralTests<PartyWithParameters> {
22
23 private PartyRef party1, party2;
24 private Parameters param1, param2;
25 private PartyWithParameters party1param1, party1param1a;
26 private PartyWithParameters party1param2;
27 private final String serialized = "{\"partyref\":\"ws:party1\",\"parameters\":{\"a\":1}}";
28
29 @Before
30 public void before() throws URISyntaxException {
31 party1 = new PartyRef(new URI("ws:party1"));
32 party2 = new PartyRef(new URI("ws:party2"));
33 param1 = new Parameters();
34 param2 = new Parameters().with("a", 1);
35 party1param1 = new PartyWithParameters(party1, param1);
36 party1param1a = new PartyWithParameters(party1, param1);
37 party1param2 = new PartyWithParameters(party1, param2);
38 }
39
40 @Override
41 public List<List<PartyWithParameters>> getGeneralTestData() {
42 return Arrays.asList(
43 Arrays.asList(party1param1, party1param1a, party1param1a),
44 Arrays.asList(party1param2));
45 }
46
47 @Override
48 public List<String> getGeneralTestStrings() {
49 return Arrays.asList("PartyRef.ws:party1.",
50 "PartyRef.ws:party1.\\{a=1\\}");
51 }
52
53 @Test
54 public void testSerialize() throws JsonProcessingException {
55 ObjectMapper jackson = new ObjectMapper();
56
57 String json = jackson.writeValueAsString(party1param2);
58 System.out.println(json);
59 assertEquals(serialized, json);
60 }
61
62 @Test
63 public void testDeserialize()
64 throws JsonParseException, JsonMappingException, IOException {
65 ObjectMapper jackson = new ObjectMapper();
66 PartyWithParameters p = jackson.readValue(serialized,
67 PartyWithParameters.class);
68 System.out.println(p);
69 assertEquals(party1param2, p);
70 }
71
72}
Note: See TracBrowser for help on using the repository browser.