Changeset 21 for protocol/src/test
- Timestamp:
- 09/22/20 08:52:04 (4 years ago)
- Location:
- protocol/src/test/java/geniusweb/protocol
- Files:
-
- 11 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
protocol/src/test/java/geniusweb/protocol/session/DefaultSessionStateTest.java
r20 r21 23 23 import geniusweb.actions.PartyId; 24 24 import geniusweb.deadline.DeadlineTime; 25 import geniusweb.i ssuevalue.Bid;25 import geniusweb.inform.Agreements; 26 26 import geniusweb.progress.Progress; 27 27 import geniusweb.progress.ProgressTime; … … 29 29 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections; 30 30 import geniusweb.protocol.session.saop.SAOPSettings; 31 import geniusweb.protocol.session.saop.SaopPartyWithProfile;32 31 import geniusweb.references.Parameters; 33 32 import geniusweb.references.PartyRef; … … 60 59 new PartyRef("party2"), new Parameters()); 61 60 ProfileRef profile2 = new ProfileRef("profile2"); 62 List< SaopPartyWithProfile> participants = Arrays.asList(63 new SaopPartyWithProfile(party1ref, profile1),64 new SaopPartyWithProfile(party2ref, profile2));61 List<OnePartyTeam> participants = Arrays.asList( 62 new OnePartyTeam(party1ref, profile1), 63 new OnePartyTeam(party2ref, profile2)); 65 64 SessionSettings settings = new SAOPSettings(participants, deadline); 66 65 ProtocolException e = new ProtocolException("test protocol error", 67 party1 .getName());66 party1); 68 67 HashMap<PartyId, PartyWithProfile> partyprofiles = new HashMap<PartyId, PartyWithProfile>(); 69 68 partyprofiles.put(party1, new PartyWithProfile(party1ref, profile1)); … … 135 134 136 135 @Override 137 public Bid getAgreement() {138 return null;139 }140 141 @Override142 136 public SessionResult getResult() { 143 137 … … 145 139 for (int n = 0; n < getConnections().size(); n++) 146 140 emptylist.add(0d); 147 return new SessionResult(getSettings().getAllParties(), getAgreement (),141 return new SessionResult(getSettings().getAllParties(), getAgreements(), 148 142 emptylist, getError()); 149 143 150 144 } 151 145 146 @Override 147 public Agreements getAgreements() { 148 return new Agreements(); 149 } 150 152 151 } -
protocol/src/test/java/geniusweb/protocol/session/SessionResultTest.java
r20 r21 7 7 import java.util.Arrays; 8 8 import java.util.HashMap; 9 import java.util.HashSet; 9 10 import java.util.List; 10 11 import java.util.Map; … … 16 17 import com.fasterxml.jackson.databind.ObjectMapper; 17 18 19 import geniusweb.actions.PartyId; 20 import geniusweb.inform.Agreements; 18 21 import geniusweb.issuevalue.Bid; 19 22 import geniusweb.issuevalue.DiscreteValue; … … 32 35 private final String ISSUE1 = "issue1"; 33 36 private SessionResult result1, result1a, result2, result3, result4; 34 private String errorstring; // created dynamically: eclipse and maven 35 // generate different stacktrace. 36 private String jsonstring = "{\"participants\":[{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"},{\"party\":{\"partyref\":\"party2\",\"parameters\":{}},\"profile\":\"profile2\"}],\"agreement\":{\"issuevalues\":{\"issue1\":\"a\"}},\"penalties\":[0.0,0.0],\"error\":null}"; 37 private String jsonstring = "{\"participants\":[{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"},{\"party\":{\"partyref\":\"party2\",\"parameters\":{}},\"profile\":\"profile2\"}],\"agreements\":{\"party2\":{\"issuevalues\":{\"issue1\":\"a\"}},\"party1\":{\"issuevalues\":{\"issue1\":\"a\"}}},\"penalties\":[0.0,0.0],\"error\":null}"; 37 38 private List<Double> nopenalties = Arrays.asList(0d, 0d); 38 39 private List<Double> penalties = Arrays.asList(0.1d, 0.2d); 39 40 41 private PartyId PARTY1 = new PartyId("party1"); 42 private PartyId PARTY2 = new PartyId("party2"); 43 private PartyId PARTY3 = new PartyId("party3"); 44 40 45 @Before 41 46 public void before() throws URISyntaxException, JsonProcessingException { 42 errorstring = "\"error\":{\"java.lang.RuntimeException\":"47 String errorstring = "\"error\":{\"java.lang.RuntimeException\":" 43 48 + jackson.writeValueAsString(error) + "}"; 44 System.out.println(errorstring);49 // System.out.println(errorstring); 45 50 46 51 PartyWithParameters party1 = new PartyWithParameters( … … 57 62 issuevalues1.put(ISSUE1, new DiscreteValue("a")); 58 63 Bid bid1 = new Bid(issuevalues1); 64 Agreements agreement1 = new Agreements().with(bid1, 65 new HashSet<>(Arrays.asList(PARTY1, PARTY2))); 59 66 60 67 // different order but that shouldn't matter … … 62 69 issuevalues2.put(ISSUE1, new DiscreteValue("b")); 63 70 Bid bid2 = new Bid(issuevalues2); 71 Agreements agreement2 = new Agreements().with(bid2, 72 new HashSet<>(Arrays.asList(PARTY1, PARTY3))); 64 73 65 74 result1 = new SessionResult(Arrays.asList(partyprofile1, partyprofile2), 66 bid1, nopenalties, null);75 agreement1, nopenalties, null); 67 76 result1a = new SessionResult( 68 Arrays.asList(partyprofile1, partyprofile2), bid1, nopenalties,69 n ull);77 Arrays.asList(partyprofile1, partyprofile2), agreement1, 78 nopenalties, null); 70 79 result2 = new SessionResult(Arrays.asList(partyprofile1, partyprofile2), 71 bid2, nopenalties, null);80 agreement2, nopenalties, null); 72 81 result3 = new SessionResult(Arrays.asList(partyprofile2, partyprofile1), 73 bid2, nopenalties, null);82 agreement1, nopenalties, null); 74 83 result4 = new SessionResult(Arrays.asList(partyprofile2, partyprofile1), 75 bid2, penalties, null);84 agreement1, penalties, null); 76 85 77 86 // IGNORE ERROR for now, it fails somewhere deep in maven suddenly. … … 90 99 public List<String> getGeneralTestStrings() { 91 100 return Arrays.asList( 92 "SessionResult.*party1.*profile1.*,.*party2.*profile2.* Bid.*issue1=\"a\".*0\\.0.*0\\.0.*null.*",93 "SessionResult.*party1.*profile1.*,.*party2.*profile2.* Bid.*issue1=\"b\".*0\\.0.*0\\.0.*null.*",94 "SessionResult.*party2.*profile2.*,.*party1.*profile1.* Bid.*issue1=\"b\".*0\\.0.*0\\.0.*null.*",95 "SessionResult.*party2.*profile2.*,.*party1.*profile1.* Bid.*issue1=\"b\".*0\\.1.*0\\.2.*null.*"101 "SessionResult.*party1.*profile1.*,.*party2.*profile2.*Agreements.*Bid.*issue1=\"a\".*0\\.0.*0\\.0.*null.*", 102 "SessionResult.*party1.*profile1.*,.*party2.*profile2.*Agreements.*Bid.*issue1=\"b\".*0\\.0.*0\\.0.*null.*", 103 "SessionResult.*party2.*profile2.*,.*party1.*profile1.*Agreements.*Bid.*issue1=\"a\".*0\\.0.*0\\.0.*null.*", 104 "SessionResult.*party2.*profile2.*,.*party1.*profile1.*Agreements.*Bid.*issue1=\"a\".*0\\.1.*0\\.2.*null.*" 96 105 97 106 ); -
protocol/src/test/java/geniusweb/protocol/session/saop/SAOPSettingsTest.java
r10 r21 19 19 import geniusweb.deadline.DeadlineRounds; 20 20 import geniusweb.deadline.DeadlineTime; 21 import geniusweb.protocol.session.OnePartyTeam; 21 22 import geniusweb.protocol.session.SessionSettings; 22 23 import geniusweb.references.Parameters; … … 29 30 public class SAOPSettingsTest extends GeneralTests<SAOPSettings> { 30 31 31 private SaopPartyWithProfile partyprof1 = mock(SaopPartyWithProfile.class);32 private SaopPartyWithProfile partyprof2 = mock(SaopPartyWithProfile.class);33 private SaopPartyWithProfile partyprof3 = mock(SaopPartyWithProfile.class);34 private List< SaopPartyWithProfile> participants2 = Arrays.asList(partyprof1,32 private OnePartyTeam partyprof1 = mock(OnePartyTeam.class); 33 private OnePartyTeam partyprof2 = mock(OnePartyTeam.class); 34 private OnePartyTeam partyprof3 = mock(OnePartyTeam.class); 35 private List<OnePartyTeam> participants2 = Arrays.asList(partyprof1, 35 36 partyprof2); 36 private List< SaopPartyWithProfile> participants3 = Arrays.asList(partyprof1,37 private List<OnePartyTeam> participants3 = Arrays.asList(partyprof1, 37 38 partyprof2, partyprof3); 38 39 … … 66 67 new PartyRef("http://party2"), new Parameters()); 67 68 ProfileRef profile2 = new ProfileRef("http://profile2"); 68 SaopPartyWithProfile partywithprof1 = new SaopPartyWithProfile(party1, 69 profile1); 70 SaopPartyWithProfile partywithprof2 = new SaopPartyWithProfile(party2, 71 profile2); 72 List<SaopPartyWithProfile> participants = Arrays.asList(partywithprof1, 69 OnePartyTeam partywithprof1 = new OnePartyTeam(party1, profile1); 70 OnePartyTeam partywithprof2 = new OnePartyTeam(party2, profile2); 71 List<OnePartyTeam> participants = Arrays.asList(partywithprof1, 73 72 partywithprof2); 74 73 -
protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java
r10 r21 176 176 SAOPState state = new SAOPState(actions, connections3, progressrounds, 177 177 settings, null, null); 178 assert Null(state.getAgreement());178 assertTrue(state.getAgreements().getMap().isEmpty()); 179 179 } 180 180 … … 184 184 SAOPState state = new SAOPState(actions, connections3, progressrounds, 185 185 settings, null, null); 186 assert Null(state.getAgreement());186 assertTrue(state.getAgreements().getMap().isEmpty()); 187 187 } 188 188 … … 192 192 SAOPState state = new SAOPState(actions, connections3, progressrounds, 193 193 settings, null, null); 194 assert Null(state.getAgreement());194 assertTrue(state.getAgreements().getMap().isEmpty()); 195 195 } 196 196 … … 200 200 SAOPState state = new SAOPState(actions, connections3, progressrounds, 201 201 settings, null, null); 202 assertEquals(bid1, state.getAgreement ());202 assertEquals(bid1, state.getAgreements().getMap().get(party1)); 203 203 assertTrue(state.isFinal(NOW)); 204 204 } … … 209 209 SAOPState state = new SAOPState(actions, connections3, progressrounds, 210 210 settings, null, null); 211 assert Equals(null, state.getAgreement());211 assertTrue(state.getAgreements().getMap().isEmpty()); 212 212 } 213 213 … … 217 217 SAOPState state = new SAOPState(actions, connections3, progressrounds, 218 218 settings, null, null); 219 assert Equals(null, state.getAgreement());219 assertTrue(state.getAgreements().getMap().isEmpty()); 220 220 } 221 221 … … 246 246 SAOPState state = new SAOPState(actions, connections3, progressrounds, 247 247 settings, null, null); 248 assert Equals(null, state.getAgreement());248 assertTrue(state.getAgreements().getMap().isEmpty()); 249 249 assertEquals(null, state.getError()); 250 250 assertTrue(state.isFinal(NOW)); … … 255 255 public void isProtocolErrorFinal() { 256 256 SAOPState state = new SAOPState(actions, connections3, progressrounds, 257 settings, null, new ProtocolException("test error", "test")); 257 settings, null, 258 new ProtocolException("test error", new PartyId("test"))); 258 259 assertTrue(state.isFinal(NOW)); 259 260 assertNotNull(state.getError()); … … 309 310 assertTrue(state.isFinal(NOW)); 310 311 assertNull(state.getError()); 311 assertEquals(bid1, state.getAgreement ());312 assertEquals(bid1, state.getAgreements().getMap().get(party1)); 312 313 313 314 } … … 325 326 assertTrue(state.isFinal(NOW)); 326 327 assertNull(state.getError()); 327 assertEquals(bid2, state.getAgreement ());328 assertEquals(bid2, state.getAgreements().getMap().get(party1)); 328 329 329 330 } -
protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java
r10 r21 34 34 import geniusweb.events.CurrentState; 35 35 import geniusweb.events.ProtocolEvent; 36 import geniusweb. party.inform.Finished;37 import geniusweb. party.inform.Inform;38 import geniusweb. party.inform.Settings;39 import geniusweb. party.inform.YourTurn;36 import geniusweb.inform.Finished; 37 import geniusweb.inform.Inform; 38 import geniusweb.inform.Settings; 39 import geniusweb.inform.YourTurn; 40 40 import geniusweb.progress.Progress; 41 41 import geniusweb.protocol.ProtocolException; … … 43 43 import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory; 44 44 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections; 45 import geniusweb.protocol.session.OnePartyTeam; 45 46 import geniusweb.protocol.session.TeamOfPartiesAndProfiles; 46 47 import geniusweb.references.Parameters; … … 75 76 private final PartyRef party2ref = mock(PartyRef.class); 76 77 private final SAOPSettings settings = mock(SAOPSettings.class); 77 private final SaopPartyWithProfile team1 = mock(SaopPartyWithProfile.class);78 private final SaopPartyWithProfile team2 = mock(SaopPartyWithProfile.class);78 private final OnePartyTeam team1 = mock(OnePartyTeam.class); 79 private final OnePartyTeam team2 = mock(OnePartyTeam.class); 79 80 private SAOP saop; 80 81 private ProtocolToPartyConnFactory factory; … … 82 83 private ProtocolToPartyConn conn1 = mock(ProtocolToPartyConn.class), 83 84 conn2 = mock(ProtocolToPartyConn.class); 84 private Map<PartyId, SaopPartyWithProfile> partyprofiles;85 private Map<PartyId, OnePartyTeam> partyprofiles; 85 86 private Progress progress = mock(Progress.class); 86 87 private ProfileRef profile1; -
protocol/src/test/java/geniusweb/protocol/session/saop/SaopPartyWithProfileTest.java
r10 r21 17 17 import com.fasterxml.jackson.databind.ObjectMapper; 18 18 19 import geniusweb.protocol.session.OnePartyTeam; 19 20 import geniusweb.protocol.session.TeamOfPartiesAndProfiles; 20 21 import geniusweb.references.Parameters; … … 24 25 import tudelft.utilities.junit.GeneralTests; 25 26 26 public class SaopPartyWithProfileTest 27 extends GeneralTests<SaopPartyWithProfile> { 27 public class SaopPartyWithProfileTest extends GeneralTests<OnePartyTeam> { 28 28 29 29 private PartyRef party1, party1a, party2, party3; 30 30 private ProfileRef profile1, profile2; 31 private SaopPartyWithProfile partyprof1, partyprof1a, partyprof2,32 partyprof 3, partyprof4;31 private OnePartyTeam partyprof1, partyprof1a, partyprof2, partyprof3, 32 partyprof4; 33 33 private final String serialized = "{\"party\":{\"partyref\":\"ws:party1\",\"parameters\":{}},\"profile\":\"ws:profile1\"}"; 34 34 … … 54 54 settings1); 55 55 56 partyprof1 = new SaopPartyWithProfile(party1withparams1, profile1);57 partyprof1a = new SaopPartyWithProfile(party1withparams1, profile1);58 partyprof2 = new SaopPartyWithProfile(party2withparams1, profile1);59 partyprof3 = new SaopPartyWithProfile(party1withparams1, profile2);60 partyprof4 = new SaopPartyWithProfile(party1withparams2, profile1);56 partyprof1 = new OnePartyTeam(party1withparams1, profile1); 57 partyprof1a = new OnePartyTeam(party1withparams1, profile1); 58 partyprof2 = new OnePartyTeam(party2withparams1, profile1); 59 partyprof3 = new OnePartyTeam(party1withparams1, profile2); 60 partyprof4 = new OnePartyTeam(party1withparams2, profile1); 61 61 62 62 } 63 63 64 64 @Override 65 public List<List< SaopPartyWithProfile>> getGeneralTestData() {65 public List<List<OnePartyTeam>> getGeneralTestData() { 66 66 return Arrays.asList(Arrays.asList(partyprof1, partyprof1a), 67 67 Arrays.asList(partyprof2), Arrays.asList(partyprof3), … … 84 84 @Test(expected = IllegalArgumentException.class) 85 85 public void nullTest() throws URISyntaxException { 86 new SaopPartyWithProfile((PartyWithParameters) null, (ProfileRef) null);86 new OnePartyTeam((PartyWithParameters) null, (ProfileRef) null); 87 87 } 88 88 … … 103 103 // and therfore can not serialize as TeamOfPartiesAndProfiles 104 104 TeamOfPartiesAndProfiles p = jackson.readValue(serialized, 105 SaopPartyWithProfile.class);105 OnePartyTeam.class); 106 106 System.out.println(p); 107 107 assertEquals(partyprof1, p); -
protocol/src/test/java/geniusweb/protocol/session/shaop/SHAOPStateTest.java
r20 r21 4 4 import static org.junit.Assert.assertFalse; 5 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertNull;7 6 import static org.junit.Assert.assertTrue; 8 7 import static org.mockito.Mockito.mock; … … 194 193 SHAOPState state = new SHAOPState(actions, connections3, progressrounds, 195 194 settings, null, 0, null, null); 196 assert Null(state.getAgreement());195 assertTrue(state.getAgreements().getMap().isEmpty()); 197 196 } 198 197 … … 201 200 List<Action> actions = Arrays.asList(offer1, accept2); 202 201 SHAOPState state = new SHAOPState(actions, connections4, progressrounds, 203 settings, null, 0, null, null);204 assert NotNull(state.getAgreement());202 settings, null, 0, partynrs, null); 203 assertFalse(state.getAgreements().getMap().isEmpty()); 205 204 assertTrue(state.isFinal(NOW)); 206 205 } … … 211 210 SHAOPState state = new SHAOPState(actions, connections3, progressrounds, 212 211 settings, null, 0, null, null); 213 assert Null(state.getAgreement());212 assert (state.getAgreements().getMap().isEmpty()); 214 213 } 215 214 … … 219 218 SHAOPState state = new SHAOPState(actions, connections3, progressrounds, 220 219 settings, null, 0, null, null); 221 assert Equals(null, state.getAgreement());220 assertTrue(state.getAgreements().getMap().isEmpty()); 222 221 } 223 222 … … 245 244 SHAOPState state = new SHAOPState(actions, connections3, progressrounds, 246 245 settings, null, 0, null, null); 247 assert Equals(null, state.getAgreement());246 assertTrue(state.getAgreements().getMap().isEmpty()); 248 247 assertEquals(null, state.getError()); 249 248 assertTrue(state.isFinal(NOW)); … … 254 253 public void isProtocolErrorFinal() { 255 254 SHAOPState state = new SHAOPState(actions, connections3, progressrounds, 256 settings, new ProtocolException("test error", "test"), 0, null, 257 null); 255 settings, 256 new ProtocolException("test error", new PartyId("test")), 0, 257 null, null); 258 258 assertTrue(state.isFinal(NOW)); 259 259 assertNotNull(state.getError()); -
protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsProtocolTest.java
r20 r21 20 20 21 21 import geniusweb.events.ProtocolEvent; 22 import geniusweb.i ssuevalue.Bid;22 import geniusweb.inform.Agreements; 23 23 import geniusweb.protocol.CurrentNegoState; 24 24 import geniusweb.protocol.NegoState; … … 44 44 private final SessionSettings settings = mock(SessionSettings.class); 45 45 private final SessionState finalsessionstate = mock(SessionState.class); 46 private Bid agreement = mock(Bid.class);46 private Agreements agreement = mock(Agreements.class); 47 47 private final long NOW = 1000; 48 48 private SessionResult finalstate = mock(SessionResult.class); … … 53 53 when(finalsessionstate.isFinal(anyLong())).thenReturn(true); 54 54 when(finalsessionstate.getSettings()).thenReturn(settings); 55 when(finalsessionstate.getAgreement ()).thenReturn(agreement);55 when(finalsessionstate.getAgreements()).thenReturn(agreement); 56 56 when(finalsessionstate.getResult()).thenReturn(finalstate); 57 when(finalstate.getAgreement ()).thenReturn(agreement);57 when(finalstate.getAgreements()).thenReturn(agreement); 58 58 when(state.with(any())).thenReturn(newstate); 59 59 } … … 112 112 .forClass(SessionResult.class); 113 113 verify(state, times(1)).with(argument.capture()); 114 assertEquals(agreement, argument.getValue().getAgreement ());114 assertEquals(agreement, argument.getValue().getAgreements()); 115 115 assertNull(argument.getValue().getError()); 116 116 } -
protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsStateTest.java
r20 r21 88 88 AllPermutationsState state1 = state.with(result); 89 89 90 assertEquals(null, state1.getError());91 90 assertEquals(8, state1.getResults().size()); 92 91 assertEquals(toursettings, state1.getSettings());
Note:
See TracChangeset
for help on using the changeset viewer.