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