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 ProtocolRefTest extends GeneralTests<ProtocolRef> {
|
---|
22 |
|
---|
23 | private ProtocolRef protocol1, protocol1a, protocol2, protocol3;
|
---|
24 | private String asJson = "\"file:StackedAlternatingOffersProtocol\"";
|
---|
25 |
|
---|
26 | @Before
|
---|
27 | public void before() throws URISyntaxException {
|
---|
28 | protocol1 = new ProtocolRef(
|
---|
29 | new URI("file:StackedAlternatingOffersProtocol"));
|
---|
30 | protocol1a = new ProtocolRef(
|
---|
31 | new URI("file:StackedAlternatingOffersProtocol"));
|
---|
32 | protocol2 = new ProtocolRef(new URI("ws:localhost/protocol2"));
|
---|
33 | protocol3 = new ProtocolRef(new URI("http:localhost/protocol3"));
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public List<List<ProtocolRef>> getGeneralTestData() {
|
---|
38 | return Arrays.asList(Arrays.asList(protocol1, protocol1a),
|
---|
39 | Arrays.asList(protocol2), Arrays.asList(protocol3));
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public List<String> getGeneralTestStrings() {
|
---|
44 | return Arrays.asList("ProtocolRef.*StackedAlternatingOffersProtocol.*",
|
---|
45 | "ProtocolRef.*protocol2.*", "ProtocolRef.*protocol3.*");
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Test
|
---|
49 | public void smokeTest() throws URISyntaxException {
|
---|
50 | new ProtocolRef(new URI("ws:localhost"));
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Test(expected = IllegalArgumentException.class)
|
---|
54 | public void nullTest() throws URISyntaxException {
|
---|
55 | new ProtocolRef((URI) null);
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Test
|
---|
59 | public void testSaop() {
|
---|
60 | ProtocolRef saop = new ProtocolRef("SAOP");
|
---|
61 | System.out.println(saop.getURI());
|
---|
62 | assertEquals("SAOP", saop.getURI().getPath());
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Test
|
---|
66 | public void testSerialize() throws JsonProcessingException {
|
---|
67 | ObjectMapper jackson = new ObjectMapper();
|
---|
68 |
|
---|
69 | String json = jackson.writeValueAsString(protocol1);
|
---|
70 | System.out.println(json);
|
---|
71 | assertEquals(asJson, json);
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Test
|
---|
75 | public void testDeserialize()
|
---|
76 | throws JsonParseException, JsonMappingException, IOException {
|
---|
77 | ObjectMapper jackson = new ObjectMapper();
|
---|
78 | ProtocolRef p = jackson.readValue(asJson, ProtocolRef.class);
|
---|
79 | System.out.println(p);
|
---|
80 | assertEquals(protocol1, p);
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|