source: profile/src/test/java/geniusweb/profile/utilityspace/ProfileRefTest.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.profile.utilityspace;
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 geniusweb.references.ProfileRef;
20import tudelft.utilities.junit.GeneralTests;
21
22public class ProfileRefTest extends GeneralTests<ProfileRef> {
23
24 private ProfileRef profile1, profile1a, profile2, profile3;
25 private String asJson = "\"ws:localhost/profile1\"";
26
27 @Before
28 public void before() throws URISyntaxException {
29 profile1 = new ProfileRef(new URI("ws:localhost/profile1"));
30 profile1a = new ProfileRef(new URI("ws:localhost/profile1"));
31 profile2 = new ProfileRef(new URI("ws:localhost/profile2"));
32 profile3 = new ProfileRef(new URI("http:localhost/profile3"));
33
34 }
35
36 @Override
37 public List<List<ProfileRef>> getGeneralTestData() {
38 return Arrays.asList(Arrays.asList(profile1, profile1a),
39 Arrays.asList(profile2), Arrays.asList(profile3));
40 }
41
42 @Override
43 public List<String> getGeneralTestStrings() {
44 return Arrays.asList("ProfileRef.*profile1.*", "ProfileRef.*profile2.*",
45 "ProfileRef.*profile3.*");
46 }
47
48 @Test
49 public void smokeTest() throws URISyntaxException {
50 new ProfileRef(new URI("ws:localhost"));
51 }
52
53 @Test(expected = IllegalArgumentException.class)
54 public void nullTest() throws URISyntaxException {
55 new ProfileRef((URI) null);
56 }
57
58 @Test
59 public void testSerialize() throws JsonProcessingException {
60 ObjectMapper jackson = new ObjectMapper();
61
62 String json = jackson.writeValueAsString(profile1);
63 System.out.println(json);
64 assertEquals(asJson, json);
65 }
66
67 @Test
68 public void testDeserialize()
69 throws JsonParseException, JsonMappingException, IOException {
70 ObjectMapper jackson = new ObjectMapper();
71 ProfileRef p = jackson.readValue(asJson, ProfileRef.class);
72 System.out.println(p);
73 assertEquals(profile1, p);
74 }
75
76}
Note: See TracBrowser for help on using the repository browser.