source: references/src/test/java/geniusweb/references/ProtocolRefTest.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.4 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 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}
Note: See TracBrowser for help on using the repository browser.