1 | package geniusweb.protocol.session.shaop;
|
---|
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.JsonProcessingException;
|
---|
14 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
15 |
|
---|
16 | import geniusweb.deadline.DeadlineTime;
|
---|
17 | import geniusweb.protocol.session.SessionSettings;
|
---|
18 | import geniusweb.protocol.session.TeamInfo;
|
---|
19 | import geniusweb.references.Parameters;
|
---|
20 | import geniusweb.references.PartyRef;
|
---|
21 | import geniusweb.references.PartyWithParameters;
|
---|
22 | import geniusweb.references.PartyWithProfile;
|
---|
23 | import geniusweb.references.ProfileRef;
|
---|
24 | import tudelft.utilities.junit.GeneralTests;
|
---|
25 | import tudelft.utilities.logging.ReportToLogger;
|
---|
26 |
|
---|
27 | public class SHAOPSettingsTest extends GeneralTests<SHAOPSettings> {
|
---|
28 |
|
---|
29 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
30 | private Parameters params = new Parameters();
|
---|
31 | private final String serialized = "{\"SHAOPSettings\":{\"participants\":[{\"TeamInfo\":{\"parties\":[{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"},{\"party\":{\"partyref\":\"party2\",\"parameters\":{}},\"profile\":\"profile1\"}]}},{\"TeamInfo\":{\"parties\":[{\"party\":{\"partyref\":\"party3\",\"parameters\":{}},\"profile\":\"profile1\"},{\"party\":{\"partyref\":\"party4\",\"parameters\":{}},\"profile\":\"profile1\"}]}}],\"deadline\":{\"DeadlineTime\":{\"durationms\":1000}}}}";
|
---|
32 | private SHAOPSettings settings1, settings1a, settings2, settings3;
|
---|
33 | private TeamInfo pair1, pair2, pair3;
|
---|
34 |
|
---|
35 | @Before
|
---|
36 | public void before() throws URISyntaxException {
|
---|
37 | ProfileRef profile1 = new ProfileRef("profile1");
|
---|
38 | PartyWithParameters party1 = new PartyWithParameters(
|
---|
39 | new PartyRef("party1"), params);
|
---|
40 | PartyWithParameters party2 = new PartyWithParameters(
|
---|
41 | new PartyRef("party2"), params);
|
---|
42 | PartyWithParameters party3 = new PartyWithParameters(
|
---|
43 | new PartyRef("party3"), params);
|
---|
44 | PartyWithParameters party4 = new PartyWithParameters(
|
---|
45 | new PartyRef("party4"), params);
|
---|
46 | PartyWithParameters party5 = new PartyWithParameters(
|
---|
47 | new PartyRef("party5"), params);
|
---|
48 | PartyWithParameters party6 = new PartyWithParameters(
|
---|
49 | new PartyRef("party6"), params);
|
---|
50 |
|
---|
51 | PartyWithProfile partyprof1 = new PartyWithProfile(party1, profile1);
|
---|
52 | PartyWithProfile partyprof2 = new PartyWithProfile(party2, profile1);
|
---|
53 | PartyWithProfile partyprof3 = new PartyWithProfile(party3, profile1);
|
---|
54 | PartyWithProfile partyprof4 = new PartyWithProfile(party4, profile1);
|
---|
55 | PartyWithProfile partyprof5 = new PartyWithProfile(party5, profile1);
|
---|
56 | PartyWithProfile partyprof6 = new PartyWithProfile(party6, profile1);
|
---|
57 |
|
---|
58 | DeadlineTime deadline = new DeadlineTime(1000);
|
---|
59 | DeadlineTime deadline2 = new DeadlineTime(2000);
|
---|
60 | pair1 = new TeamInfo(Arrays.asList(partyprof1, partyprof2));
|
---|
61 | pair2 = new TeamInfo(Arrays.asList(partyprof3, partyprof4));
|
---|
62 | pair3 = new TeamInfo(Arrays.asList(partyprof5, partyprof6));
|
---|
63 |
|
---|
64 | settings1 = new SHAOPSettings(Arrays.asList(pair1, pair2), deadline);
|
---|
65 | settings1a = new SHAOPSettings(Arrays.asList(pair1, pair2), deadline);
|
---|
66 | settings2 = new SHAOPSettings(Arrays.asList(pair1, pair3), deadline);
|
---|
67 | settings3 = new SHAOPSettings(Arrays.asList(pair1, pair2), deadline2);
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public List<List<SHAOPSettings>> getGeneralTestData() {
|
---|
72 | return Arrays.asList(Arrays.asList(settings1, settings1a),
|
---|
73 | Arrays.asList(settings2), Arrays.asList(settings3));
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public List<String> getGeneralTestStrings() {
|
---|
78 | return Arrays.asList(
|
---|
79 | "SHAOPSettings.*TeamInfo.*PartyWithProfile.*party1.*party2.*TeamInfo.*party3.*party4.*DeadlineTime.*1000.*",
|
---|
80 | "SHAOPSettings.*TeamInfo.*PartyWithProfile.*party1.*party2.*TeamInfo.*party5.*party6.*DeadlineTime.*1000.*",
|
---|
81 | "SHAOPSettings.*TeamInfo.*PartyWithProfile.*party1.*party2.*TeamInfo.*party3.*party4.*DeadlineTime.*2000.*");
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Test
|
---|
85 | public void getProtocolTest() {
|
---|
86 | assertEquals("SHAOP", settings1.getProtocol(new ReportToLogger("test"))
|
---|
87 | .getRef().getURI().toString());
|
---|
88 | }
|
---|
89 |
|
---|
90 | @Test(expected = IllegalArgumentException.class)
|
---|
91 | public void constructorNoDeadlineTest() {
|
---|
92 | new SHAOPSettings(Arrays.asList(pair1, pair2), null);
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Test
|
---|
96 | public void testMaxRuntime() {
|
---|
97 | assertEquals((Double) 1.000, settings1.getMaxRunTime());
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Test
|
---|
101 | public void testDeserialize() throws IOException {
|
---|
102 | SessionSettings obj = jackson.readValue(serialized,
|
---|
103 | SessionSettings.class);
|
---|
104 | System.out.println(obj);
|
---|
105 | assertEquals(settings1, obj);
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Test
|
---|
109 | public void testSerialize()
|
---|
110 | throws JsonProcessingException, URISyntaxException {
|
---|
111 |
|
---|
112 | String string = jackson.writeValueAsString(settings1);
|
---|
113 | System.out.println(string);
|
---|
114 | assertEquals(serialized, string);
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|