1 | package geniusweb.protocol.session;
|
---|
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.Collections;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.Before;
|
---|
12 | import org.junit.Test;
|
---|
13 |
|
---|
14 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
15 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
16 |
|
---|
17 | import geniusweb.references.Parameters;
|
---|
18 | import geniusweb.references.PartyRef;
|
---|
19 | import geniusweb.references.PartyWithParameters;
|
---|
20 | import geniusweb.references.ProfileRef;
|
---|
21 | import tudelft.utilities.junit.GeneralTests;
|
---|
22 |
|
---|
23 | public class TeamInfoTest extends GeneralTests<TeamInfo> {
|
---|
24 |
|
---|
25 | private TeamInfo team1 = new TeamInfo(Collections.emptyList());
|
---|
26 | private TeamInfo team1a = new TeamInfo(Collections.emptyList());
|
---|
27 | private PartyRef partyref;
|
---|
28 | private Parameters parameters = new Parameters();;
|
---|
29 | private ProfileRef profileref;
|
---|
30 | private TeamInfo team2, team2a;
|
---|
31 | private String asString1 = "{\"TeamInfo\":{\"parties\":[{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"}]}}";
|
---|
32 |
|
---|
33 | @Before
|
---|
34 | public void before() throws URISyntaxException {
|
---|
35 | partyref = new PartyRef("party1");
|
---|
36 | profileref = new ProfileRef("profile1");
|
---|
37 | team2 = new TeamInfo(new PartyWithParameters(partyref, parameters),
|
---|
38 | profileref);
|
---|
39 | team2a = new TeamInfo(new PartyWithParameters(partyref, parameters),
|
---|
40 | profileref);
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | public List<List<TeamInfo>> getGeneralTestData() {
|
---|
46 | return Arrays.asList(Arrays.asList(team1, team1a),
|
---|
47 | Arrays.asList(team2, team2a));
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public List<String> getGeneralTestStrings() {
|
---|
52 | return Arrays.asList("TeamInfo.\\[\\].",
|
---|
53 | "TeamInfo.\\[PartyWithProfile.*party1.*profile1.*\\].*");
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Test
|
---|
57 | public void testSerialize() throws JsonProcessingException {
|
---|
58 |
|
---|
59 | ObjectMapper jackson = new ObjectMapper();
|
---|
60 | System.out.println(jackson.writeValueAsString(team2));
|
---|
61 | assertEquals(asString1, jackson.writeValueAsString(team2));
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Test
|
---|
66 | public void testDeserialize() throws IOException {
|
---|
67 |
|
---|
68 | ObjectMapper jackson = new ObjectMapper();
|
---|
69 | TeamInfo read = jackson.readValue(asString1, TeamInfo.class);
|
---|
70 | assertEquals(team2, read);
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|