1 | package geniusweb.protocol.tournament.allpermutations;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.math.BigInteger;
|
---|
7 | import java.net.URISyntaxException;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.Collections;
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | import org.junit.Before;
|
---|
13 | import org.junit.Test;
|
---|
14 |
|
---|
15 | import com.fasterxml.jackson.core.JsonProcessingException;
|
---|
16 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
17 |
|
---|
18 | import geniusweb.deadline.DeadlineTime;
|
---|
19 | import geniusweb.protocol.NegoSettings;
|
---|
20 | import geniusweb.protocol.session.saop.SAOPSettings;
|
---|
21 | import geniusweb.protocol.tournament.ProfileList;
|
---|
22 | import geniusweb.protocol.tournament.Team;
|
---|
23 | import geniusweb.protocol.tournament.TournamentSettings;
|
---|
24 | import geniusweb.references.Parameters;
|
---|
25 | import geniusweb.references.PartyRef;
|
---|
26 | import geniusweb.references.PartyWithParameters;
|
---|
27 | import geniusweb.references.ProfileRef;
|
---|
28 | import tudelft.utilities.junit.GeneralTests;
|
---|
29 | import tudelft.utilities.logging.ReportToLogger;
|
---|
30 |
|
---|
31 | public class AllPermutationsSettingsTest
|
---|
32 | extends GeneralTests<AllPermutationsSettings> {
|
---|
33 |
|
---|
34 | private final ObjectMapper jackson = new ObjectMapper();
|
---|
35 |
|
---|
36 | private final String serialized = "{\"AllPermutationsSettings\":{\"teams\":[{\"Team\":[{\"partyref\":\"party1\",\"parameters\":{}}]},{\"Team\":[{\"partyref\":\"party2\",\"parameters\":{}}]}],\"profileslists\":[{\"ProfileList\":[\"profile1\"]},{\"ProfileList\":[\"profile2\"]},{\"ProfileList\":[\"profile3\"]}],\"reuseTeams\":false,\"teamsPerSession\":2,\"sessionsettings\":{\"SAOPSettings\":{\"participants\":[],\"deadline\":{\"DeadlineTime\":{\"durationms\":10000}}}},\"numberTournaments\":1}}";
|
---|
37 | private AllPermutationsSettings settings, settings1a, settings2, settings3,
|
---|
38 | settings4, settings5;
|
---|
39 |
|
---|
40 | // use directly because there is some hard coding currently.
|
---|
41 | private SAOPSettings saopsettings;
|
---|
42 |
|
---|
43 | private ProfileRef profile1, profile2, profile3;
|
---|
44 | private ProfileList profiles1, profiles2, profiles3;
|
---|
45 | private List<Team> parties;
|
---|
46 |
|
---|
47 | @Before
|
---|
48 | public void before() throws URISyntaxException {
|
---|
49 | PartyRef partyref1 = new PartyRef("party1");
|
---|
50 | PartyRef partyref2 = new PartyRef("party2");
|
---|
51 | PartyRef partyref3 = new PartyRef("party3");
|
---|
52 |
|
---|
53 | Parameters params1 = new Parameters();
|
---|
54 | Parameters params2 = new Parameters();
|
---|
55 | Parameters params3 = new Parameters();
|
---|
56 |
|
---|
57 | Team partywithparams1 = new Team(
|
---|
58 | Arrays.asList(new PartyWithParameters(partyref1, params1)));
|
---|
59 | Team partywithparams2 = new Team(
|
---|
60 | Arrays.asList(new PartyWithParameters(partyref2, params2)));
|
---|
61 | Team partywithparams3 = new Team(
|
---|
62 | Arrays.asList(new PartyWithParameters(partyref3, params3)));
|
---|
63 |
|
---|
64 | parties = Arrays.asList(partywithparams1, partywithparams2);
|
---|
65 | DeadlineTime deadline = new DeadlineTime(10000);
|
---|
66 |
|
---|
67 | saopsettings = new SAOPSettings(Collections.emptyList(), deadline);
|
---|
68 |
|
---|
69 | profile1 = new ProfileRef("profile1");
|
---|
70 | profile2 = new ProfileRef("profile2");
|
---|
71 | profile3 = new ProfileRef("profile3");
|
---|
72 | profiles1 = new ProfileList(Arrays.asList(profile1));
|
---|
73 | profiles2 = new ProfileList(Arrays.asList(profile2));
|
---|
74 | profiles3 = new ProfileList(Arrays.asList(profile3));
|
---|
75 |
|
---|
76 | List<ProfileList> profiles = Arrays.asList(profiles1, profiles2,
|
---|
77 | profiles3);
|
---|
78 |
|
---|
79 | settings = new AllPermutationsSettings(parties, profiles, false, 2,
|
---|
80 | saopsettings, 1);
|
---|
81 |
|
---|
82 | settings1a = new AllPermutationsSettings(parties, profiles, false, 2,
|
---|
83 | saopsettings, 1);
|
---|
84 |
|
---|
85 | settings2 = new AllPermutationsSettings(Arrays.asList(partywithparams1,
|
---|
86 | partywithparams2, partywithparams3), profiles, false, 2,
|
---|
87 | saopsettings, 1);
|
---|
88 |
|
---|
89 | settings3 = new AllPermutationsSettings(parties, profiles, true, 2,
|
---|
90 | saopsettings, 1);
|
---|
91 |
|
---|
92 | settings4 = new AllPermutationsSettings(parties,
|
---|
93 | Arrays.asList(profiles1, profiles2, profiles3, profiles1),
|
---|
94 | false, 2, saopsettings, 1);
|
---|
95 |
|
---|
96 | settings5 = new AllPermutationsSettings(parties, profiles, false, 2,
|
---|
97 | saopsettings, 2);
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|
101 | @Override
|
---|
102 | public List<List<AllPermutationsSettings>> getGeneralTestData() {
|
---|
103 | return Arrays.asList(Arrays.asList(settings, settings1a),
|
---|
104 | Arrays.asList(settings2), Arrays.asList(settings3),
|
---|
105 | Arrays.asList(settings4), Arrays.asList(settings5));
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Override
|
---|
109 | public List<String> getGeneralTestStrings() {
|
---|
110 | return Arrays.asList(
|
---|
111 | "AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
|
---|
112 | "AllPermutationsSettings.*party1.*party2.*party3.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
|
---|
113 | "AllPermutationsSettings.*party1.*party2.*,true,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
|
---|
114 | "AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*profile1.*,2,SAOPSettings.*1.*",
|
---|
115 | "AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*2.*");
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Test
|
---|
119 | public void getProtocolTest() {
|
---|
120 | assertEquals("APP", settings.getProtocol(new ReportToLogger("test"))
|
---|
121 | .getRef().getURI().toString());
|
---|
122 | }
|
---|
123 |
|
---|
124 | @Test
|
---|
125 | public void testDeserialize() throws IOException {
|
---|
126 | TournamentSettings obj = (TournamentSettings) jackson
|
---|
127 | .readValue(serialized, NegoSettings.class);
|
---|
128 | System.out.println(obj);
|
---|
129 | assertEquals(settings, obj);
|
---|
130 | }
|
---|
131 |
|
---|
132 | @Test
|
---|
133 | public void testSerialize()
|
---|
134 | throws JsonProcessingException, URISyntaxException {
|
---|
135 |
|
---|
136 | String string = jackson.writeValueAsString(settings);
|
---|
137 | System.out.println(string);
|
---|
138 | assertEquals(serialized, string);
|
---|
139 | }
|
---|
140 |
|
---|
141 | @SuppressWarnings("unused")
|
---|
142 | @Test(expected = IllegalArgumentException.class)
|
---|
143 | public void testNullParties() {
|
---|
144 | new AllPermutationsSettings(null,
|
---|
145 | Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
|
---|
146 | 2, saopsettings, 1);
|
---|
147 |
|
---|
148 | }
|
---|
149 |
|
---|
150 | @SuppressWarnings("unused")
|
---|
151 | @Test(expected = IllegalArgumentException.class)
|
---|
152 | public void testNoParties() {
|
---|
153 | new AllPermutationsSettings(Collections.emptyList(),
|
---|
154 | Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
|
---|
155 | 2, saopsettings, 1);
|
---|
156 |
|
---|
157 | }
|
---|
158 |
|
---|
159 | @SuppressWarnings("unused")
|
---|
160 | @Test(expected = IllegalArgumentException.class)
|
---|
161 | public void testNullProfiles() {
|
---|
162 | new AllPermutationsSettings(parties, null, true, 2, saopsettings, 1);
|
---|
163 |
|
---|
164 | }
|
---|
165 |
|
---|
166 | @SuppressWarnings("unused")
|
---|
167 | @Test(expected = IllegalArgumentException.class)
|
---|
168 | public void testInsufficientProfiles() {
|
---|
169 | new AllPermutationsSettings(parties,
|
---|
170 | Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
|
---|
171 | 4, saopsettings, 1);
|
---|
172 |
|
---|
173 | }
|
---|
174 |
|
---|
175 | @SuppressWarnings("unused")
|
---|
176 | @Test(expected = IllegalArgumentException.class)
|
---|
177 | public void testNullSessionSettings() {
|
---|
178 | new AllPermutationsSettings(parties,
|
---|
179 | Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
|
---|
180 | 4, null, 1);
|
---|
181 |
|
---|
182 | }
|
---|
183 |
|
---|
184 | @SuppressWarnings("unused")
|
---|
185 | @Test(expected = IllegalArgumentException.class)
|
---|
186 | public void testOnePartyPerSession() {
|
---|
187 | new AllPermutationsSettings(parties,
|
---|
188 | Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
|
---|
189 | 1, saopsettings, 1);
|
---|
190 |
|
---|
191 | }
|
---|
192 |
|
---|
193 | @Test
|
---|
194 | public void getMaxRuntimeTest() {
|
---|
195 | assertEquals(BigInteger.valueOf(6), settings.permutations().size());
|
---|
196 | assertEquals((Double) (6d * 12), settings.getMaxRunTime());
|
---|
197 | }
|
---|
198 |
|
---|
199 | }
|
---|