source: protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java@ 14

Last change on this file since 14 was 14, checked in by bart, 4 years ago

Release 1.4.0

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