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