Changeset 10 for protocol/src/test/java
- Timestamp:
- 01/28/20 10:19:54 (5 years ago)
- Location:
- protocol/src/test/java/geniusweb/protocol
- Files:
-
- 7 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocol/src/test/java/geniusweb/protocol/session/DefaultSessionStateTest.java
r9 r10 29 29 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections; 30 30 import geniusweb.protocol.session.saop.SAOPSettings; 31 import geniusweb.protocol.session.saop.SaopPartyWithProfile; 31 32 import geniusweb.references.Parameters; 32 33 import geniusweb.references.PartyRef; … … 39 40 private final ObjectMapper jackson = new ObjectMapper(); 40 41 private DefaultSessionState1 state1, state1a, stateA, stateE, stateF; 42 // The 1 is because we are testing an instance, not the abstract class 41 43 private String state1string = "{\"DefaultSessionState1\":{\"actions\":[],\"progress\":{\"time\":{\"duration\":1000,\"start\":1000}},\"settings\":{\"SAOPSettings\":{\"participants\":[{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"},{\"party\":{\"partyref\":\"party2\",\"parameters\":{}},\"profile\":\"profile2\"}],\"deadline\":{\"deadlinetime\":{\"durationms\":1000}}}},\"error\":null,\"partyprofiles\":{\"party1\":{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"}}}}"; 42 44 private ProgressTime progr; … … 58 60 new PartyRef("party2"), new Parameters()); 59 61 ProfileRef profile2 = new ProfileRef("profile2"); 60 List< PartyWithProfile> participants = Arrays.asList(61 new PartyWithProfile(party1ref, profile1),62 new PartyWithProfile(party2ref, profile2));62 List<SaopPartyWithProfile> participants = Arrays.asList( 63 new SaopPartyWithProfile(party1ref, profile1), 64 new SaopPartyWithProfile(party2ref, profile2)); 63 65 SessionSettings settings = new SAOPSettings(participants, deadline); 64 66 ProtocolException e = new ProtocolException("test protocol error", -
protocol/src/test/java/geniusweb/protocol/session/saop/SAOPSettingsTest.java
r8 r10 23 23 import geniusweb.references.PartyRef; 24 24 import geniusweb.references.PartyWithParameters; 25 import geniusweb.references.PartyWithProfile;26 25 import geniusweb.references.ProfileRef; 27 26 import tudelft.utilities.junit.GeneralTests; … … 30 29 public class SAOPSettingsTest extends GeneralTests<SAOPSettings> { 31 30 32 private PartyWithProfile partyprof1 = mock(PartyWithProfile.class);33 private PartyWithProfile partyprof2 = mock(PartyWithProfile.class);34 private PartyWithProfile partyprof3 = mock(PartyWithProfile.class);35 private List< PartyWithProfile> participants2 = Arrays.asList(partyprof1,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, 36 35 partyprof2); 37 private List< PartyWithProfile> participants3 = Arrays.asList(partyprof1,36 private List<SaopPartyWithProfile> participants3 = Arrays.asList(partyprof1, 38 37 partyprof2, partyprof3); 39 38 … … 67 66 new PartyRef("http://party2"), new Parameters()); 68 67 ProfileRef profile2 = new ProfileRef("http://profile2"); 69 PartyWithProfile partywithprof1 = newPartyWithProfile(party1,68 SaopPartyWithProfile partywithprof1 = new SaopPartyWithProfile(party1, 70 69 profile1); 71 PartyWithProfile partywithprof2 = newPartyWithProfile(party2,70 SaopPartyWithProfile partywithprof2 = new SaopPartyWithProfile(party2, 72 71 profile2); 73 List< PartyWithProfile> participants = Arrays.asList(partywithprof1,72 List<SaopPartyWithProfile> participants = Arrays.asList(partywithprof1, 74 73 partywithprof2); 75 74 … … 141 140 SAOPSettings saop = new SAOPSettings(participants2, deadline); 142 141 SessionSettings saop2 = saop.with(partyprof3); 143 assertEquals(3, saop2.get Participants().size());142 assertEquals(3, saop2.getTeams().size()); 144 143 } 145 144 -
protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java
r9 r10 27 27 import geniusweb.progress.ProgressTime; 28 28 import geniusweb.protocol.ProtocolException; 29 import geniusweb.protocol.partyconnection.ProtocolToPartyConn; 29 30 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections; 30 import geniusweb.protocol.partyconnection.ProtocolToPartyConn;31 31 import geniusweb.protocol.session.SessionSettings; 32 32 import tudelft.utilities.junit.GeneralTests; … … 220 220 } 221 221 222 @Test 222 @Test(expected = IllegalArgumentException.class) 223 223 public void withWrongActionTest() { 224 224 // wrong because action has actor null which does not match party1 225 225 SAOPState state = state1.with(party1, action); 226 assertEquals(1, state.getActions().size()); 227 assertEquals(action, state.getActions().get(0)); 228 assertTrue(state.isFinal(NOW)); 229 assertEquals( 230 "geniusweb.protocol.ProtocolException: party1:act contains wrong credentials: act1", 231 state.getError().toString()); 232 } 233 234 @Test 226 // assertEquals(1, state.getActions().size()); 227 // assertEquals(action, state.getActions().get(0)); 228 // assertTrue(state.isFinal(NOW)); 229 } 230 231 @Test(expected = IllegalArgumentException.class) 235 232 public void withActionTest() { 236 233 when(action.getActor()).thenReturn(party1); 237 SAOPState state = state1.with(party1, action); 238 assertEquals(1, state.getActions().size()); 239 assertEquals(action, state.getActions().get(0)); 234 state1.with(party1, action); 240 235 } 241 236 … … 265 260 } 266 261 267 @Test 262 @Test(expected = IllegalArgumentException.class) 268 263 public void RefuseImmediateAccept() { 269 264 Accept nullaccept = new Accept(party1, null); 270 265 SAOPState state = state1.with(party1, nullaccept); 271 assertTrue(state.isFinal(NOW)); 272 assertEquals( 273 "geniusweb.protocol.ProtocolException: party1:Accept without a recent offer", 274 state.getError().toString()); 275 } 276 277 @Test 266 } 267 268 @Test(expected = IllegalArgumentException.class) 278 269 public void RefuseNotMyTurn() { 279 270 List<Action> actions = Arrays.asList(offer1); … … 281 272 settings, null, null); 282 273 283 state = state.with(party1, offer1);284 assertTrue(state.isFinal(NOW));285 assertEquals(286 "geniusweb.protocol.ProtocolException: party1:Party does not have the turn ",287 state.getError().toString());288 } 289 290 @Test 274 state.with(party1, offer1); 275 // assertTrue(state.isFinal(NOW)); 276 // assertEquals( 277 // "geniusweb.protocol.ProtocolException: party1:Party does not have the turn ", 278 // state.getError().toString()); 279 } 280 281 @Test(expected = IllegalArgumentException.class) 291 282 public void RefuseNullAccept() { 292 283 List<Action> actions = Arrays.asList(offer1); … … 297 288 state = state.with(party2, nullaccept); 298 289 assertTrue(state.isFinal(NOW)); 299 assertTrue(state.getError().toString().matches( 300 ".*party2.*Party accepts a bid differing from the last offer.*")); 301 } 302 303 @Test 290 } 291 292 @Test(expected = IllegalArgumentException.class) 304 293 public void RefuseNullAction() { 305 294 List<Action> actions = Arrays.asList(offer1); … … 308 297 309 298 state = state.with(party2, null); 310 assertEquals(311 "geniusweb.protocol.ProtocolException: party2:action is null",312 state.getError().toString());313 299 } 314 300 -
protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java
r9 r10 20 20 import java.util.List; 21 21 import java.util.Map; 22 import java.util.stream.Collectors; 22 23 23 24 import org.junit.Test; … … 39 40 import geniusweb.progress.Progress; 40 41 import geniusweb.protocol.ProtocolException; 41 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;42 42 import geniusweb.protocol.partyconnection.ProtocolToPartyConn; 43 43 import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory; 44 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections; 45 import geniusweb.protocol.session.TeamOfPartiesAndProfiles; 44 46 import geniusweb.references.Parameters; 45 47 import geniusweb.references.PartyRef; … … 73 75 private final PartyRef party2ref = mock(PartyRef.class); 74 76 private final SAOPSettings settings = mock(SAOPSettings.class); 75 private final PartyWithProfile party1 = mock(PartyWithProfile.class);76 private final PartyWithProfile party2 = mock(PartyWithProfile.class);77 private final SaopPartyWithProfile team1 = mock(SaopPartyWithProfile.class); 78 private final SaopPartyWithProfile team2 = mock(SaopPartyWithProfile.class); 77 79 private SAOP saop; 78 80 private ProtocolToPartyConnFactory factory; … … 80 82 private ProtocolToPartyConn conn1 = mock(ProtocolToPartyConn.class), 81 83 conn2 = mock(ProtocolToPartyConn.class); 82 private Map<PartyId, PartyWithProfile> partyprofiles;84 private Map<PartyId, SaopPartyWithProfile> partyprofiles; 83 85 private Progress progress = mock(Progress.class); 84 86 private ProfileRef profile1; … … 101 103 throws URISyntaxException, IOException, NoResourcesNowException { 102 104 SAOP = new ProtocolRef("SAOP"); 103 when(party1.getParty()).thenReturn(partywithparam1); 104 when(party2.getParty()).thenReturn(partywithparam2); 105 when(team1.getParty()).thenReturn(partywithparam1); 106 when(team2.getParty()).thenReturn(partywithparam2); 107 when(team1.getAllParties()).thenReturn(Arrays.asList(team1)); 108 when(team2.getAllParties()).thenReturn(Arrays.asList(team2)); 105 109 106 110 partyprofiles = new HashMap<>(); 107 partyprofiles.put(PARTY1ID, party1);108 partyprofiles.put(PARTY2ID, party2);111 partyprofiles.put(PARTY1ID, team1); 112 partyprofiles.put(PARTY2ID, team2); 109 113 110 114 when(deadlinetime.getDuration()).thenReturn(1000l); 111 115 112 List<PartyWithProfile> participants = new ArrayList<>(); 113 participants.add(party1); 114 participants.add(party2); 115 when(settings.getParticipants()).thenReturn(participants); 116 List<TeamOfPartiesAndProfiles> teams = new ArrayList<>(); 117 teams.add(team1); 118 teams.add(team2); 119 when(settings.getTeams()).thenReturn(teams); 120 when(settings.getAllParties()).thenReturn(Arrays.asList(team1, team2)); 116 121 when(settings.getDeadline()).thenReturn(deadlinetime); 117 122 … … 126 131 127 132 profile1 = mock(ProfileRef.class); 128 when( party1.getProfile()).thenReturn(profile1);133 when(team1.getProfile()).thenReturn(profile1); 129 134 profile2 = mock(ProfileRef.class); 130 when( party2.getProfile()).thenReturn(profile2);135 when(team2.getProfile()).thenReturn(profile2); 131 136 132 137 mockState(connectedstate, "connected state"); … … 157 162 when(state.getSettings()).thenReturn(settings); 158 163 when(state.getConnections()).thenReturn(connectionswithparties); 159 when(state.getPartyProfiles()).thenReturn(partyprofiles); 164 when(state.getPartyProfiles()) 165 .thenReturn(partyprofiles.entrySet().stream().collect( 166 Collectors.toMap(e -> e.getKey(), e -> e.getValue()))); 160 167 when(state.getProgress()).thenReturn(progress); 161 168 when(state.with(any(ProtocolToPartyConn.class),
Note:
See TracChangeset
for help on using the changeset viewer.