source: events/src/test/java/geniusweb/actions/PartyIdTest1.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: 1.9 KB
Line 
1package geniusweb.actions;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.net.URISyntaxException;
7import java.util.Arrays;
8import java.util.List;
9
10import org.junit.Before;
11import org.junit.Test;
12
13import com.fasterxml.jackson.core.JsonParseException;
14import com.fasterxml.jackson.core.JsonProcessingException;
15import com.fasterxml.jackson.databind.JsonMappingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18import tudelft.utilities.junit.GeneralTests;
19
20public class PartyIdTest1 extends GeneralTests<PartyId> {
21
22 private PartyId party1, party1a, party2, party3;
23 private String asJson = "\"party1\"";
24
25 @Before
26 public void before() throws URISyntaxException {
27 party1 = new PartyId("party1");
28 party1a = new PartyId("party1");
29 party2 = new PartyId("party2");
30 party3 = new PartyId("party3");
31 }
32
33 @Override
34 public List<List<PartyId>> getGeneralTestData() {
35 return Arrays.asList(Arrays.asList(party1, party1a),
36 Arrays.asList(party2), Arrays.asList(party3));
37 }
38
39 @Override
40 public List<String> getGeneralTestStrings() {
41 return Arrays.asList("party1", "party2", "party3");
42 }
43
44 @SuppressWarnings("unused")
45 @Test(expected = IllegalArgumentException.class)
46 public void smokeTest() throws URISyntaxException {
47 new PartyId("*Csh789&@#^!^@^&");
48 }
49
50 @SuppressWarnings("unused")
51 @Test(expected = IllegalArgumentException.class)
52 public void nullTest() throws URISyntaxException {
53 new PartyId(null);
54 }
55
56 @Test
57 public void testSerialize() throws JsonProcessingException {
58 ObjectMapper jackson = new ObjectMapper();
59
60 String json = jackson.writeValueAsString(party1);
61 System.out.println(json);
62 assertEquals(asJson, json);
63 }
64
65 @Test
66 public void testDeserialize()
67 throws JsonParseException, JsonMappingException, IOException {
68 ObjectMapper jackson = new ObjectMapper();
69 PartyId p = jackson.readValue(asJson, PartyId.class);
70 System.out.println(p);
71 assertEquals(party1, p);
72 }
73
74}
Note: See TracBrowser for help on using the repository browser.