1 | package geniusweb.references;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.net.MalformedURLException;
|
---|
7 | import java.net.URI;
|
---|
8 | import java.net.URISyntaxException;
|
---|
9 | import java.util.Arrays;
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | import org.junit.Before;
|
---|
13 | import org.junit.Test;
|
---|
14 |
|
---|
15 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
16 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
17 |
|
---|
18 | import geniusweb.references.DomainRef;
|
---|
19 | import tudelft.utilities.junit.GeneralTests;
|
---|
20 |
|
---|
21 | public class DomainRefTest extends GeneralTests<DomainRef> {
|
---|
22 |
|
---|
23 | private static final String HTTP_A = "http://a",
|
---|
24 | HTTP_B = "http://there/whatever";
|
---|
25 | private ObjectMapper jackson = new ObjectMapper();
|
---|
26 |
|
---|
27 | private String domainrefstring = "\"" + HTTP_B + "\"";
|
---|
28 | private DomainRef ref1, ref1a, ref2;
|
---|
29 |
|
---|
30 | @Before
|
---|
31 | public void before() throws MalformedURLException, URISyntaxException {
|
---|
32 | ref1 = new DomainRef(HTTP_A);
|
---|
33 | ref1a = new DomainRef(HTTP_A);
|
---|
34 | ref2 = new DomainRef(new URI(HTTP_B));
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Test
|
---|
38 | public void SerializeTest() throws JsonProcessingException {
|
---|
39 | System.out.println(jackson.writeValueAsString(ref2));
|
---|
40 | assertEquals(domainrefstring, jackson.writeValueAsString(ref2));
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Test
|
---|
45 | public void DeSerializeTest() throws IOException {
|
---|
46 | assertEquals(ref2, jackson.readValue(domainrefstring, DomainRef.class));
|
---|
47 |
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public List<List<DomainRef>> getGeneralTestData() {
|
---|
52 | return Arrays.asList(Arrays.asList(ref1, ref1a), Arrays.asList(ref2));
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public List<String> getGeneralTestStrings() {
|
---|
57 | return Arrays.asList("DomainRef." + HTTP_A + ".",
|
---|
58 | "DomainRef." + HTTP_B + ".");
|
---|
59 |
|
---|
60 | }
|
---|
61 | }
|
---|