1 | package geniusweb.references;
|
---|
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 tudelft.utilities.junit.GeneralTests;
|
---|
20 |
|
---|
21 | public 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 | }
|
---|