- Timestamp:
- 01/28/20 10:19:54 (5 years ago)
- Location:
- protocol/src
- Files:
-
- 15 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
protocol/src/main/java/geniusweb/protocol/session/DefaultSessionState.java
r9 r10 64 64 Map<PartyId, PartyWithProfile> partyprofiles, ProtocolException e) { 65 65 if (partyprofiles == null) { 66 partyprofiles = Collections. EMPTY_MAP;66 partyprofiles = Collections.emptyMap(); 67 67 } 68 68 if (conns == null) { 69 69 this.connections = new ProtocolToPartyConnections( 70 Collections. EMPTY_LIST);70 Collections.emptyList()); 71 71 } else { 72 72 this.connections = conns; … … 97 97 98 98 /** 99 * @return100 99 * @return map with {@link PartyWithProfile} for the parties. May be an 101 100 * incomplete map, as more parties with their profiles may be set -
protocol/src/main/java/geniusweb/protocol/session/SessionSettings.java
r1 r10 7 7 import geniusweb.protocol.NegoSettings; 8 8 import geniusweb.protocol.session.saop.SAOPSettings; 9 import geniusweb.protocol.session.shaop.SHAOPSettings; 9 10 import geniusweb.references.PartyWithProfile; 10 11 import tudelft.utilities.logging.Reporter; … … 13 14 * interface for settings for session protocols. Immutable. 14 15 */ 15 @JsonSubTypes({ @JsonSubTypes.Type(value = SAOPSettings.class) })16 16 @JsonSubTypes({ @JsonSubTypes.Type(value = SAOPSettings.class), 17 @JsonSubTypes.Type(value = SHAOPSettings.class) }) 17 18 public interface SessionSettings extends NegoSettings { 18 19 … … 22 23 * @return list of {@link PartyWithProfile} items. 23 24 */ 24 public List<PartyWithProfile> getParticipants();25 List<TeamOfPartiesAndProfiles> getTeams(); 25 26 26 27 /** 27 * Allows modification of SessionSettings to include a party. This is needed for28 * tournament auto-configuration of sessions.28 * Allows modification of SessionSettings to include a party. This is needed 29 * for tournament auto-configuration of sessions. 29 30 * 30 * @param partyprof the party with profileto be added31 * @param partyprofteam the {@link TeamOfPartiesAndProfiles} to be added 31 32 * @return new modified SessionSettings object 32 33 */ 33 public SessionSettings with(PartyWithProfile partyprof); 34 SessionSettings with(TeamOfPartiesAndProfiles partyprofteam); 35 36 /** 37 * 38 * @return all parties from all teams, as a flattened ordered list. The 39 * order : start with all parties from team 1, then all from team 2, 40 * etc. The specific order of the parties from a team depends on the 41 * protocol. 42 */ 43 List<PartyWithProfile> getAllParties(); 34 44 35 45 /** 36 46 * @param logger the logger where the protocol can log events to. 37 * @return the an initialized and ready to use {@link SessionProtocol} that can38 * handle this Negotiation.47 * @return the an initialized and ready to use {@link SessionProtocol} that 48 * can handle this Negotiation. 39 49 */ 40 50 @Override 41 publicSessionProtocol getProtocol(Reporter logger);51 SessionProtocol getProtocol(Reporter logger); 42 52 43 53 } -
protocol/src/main/java/geniusweb/protocol/session/saop/SAOP.java
r9 r10 65 65 public class SAOP extends DefaultListenable<ProtocolEvent> 66 66 implements SessionProtocol { 67 p rivatestatic final int TIME_MARGIN = 20;// ms extra delay after deadline68 p rivatestatic final int MINDURATION = 100;69 p rivatestatic final int MIN_SLEEP_TIME = 1000;70 p rivatestatic final int MAX_SLEEP_TIME = 60000;67 public static final int TIME_MARGIN = 20;// ms extra delay after deadline 68 public static final int MINDURATION = 100; 69 public static final int MIN_SLEEP_TIME = 1000; 70 public static final int MAX_SLEEP_TIME = 60000; 71 71 private static final ProtocolRef SAOP = new ProtocolRef("SAOP"); 72 72 private final Reporter log; … … 154 154 throws InterruptedException, IOException { 155 155 List<PartyWithProfile> participants = state.getSettings() 156 .get Participants();156 .getAllParties(); 157 157 List<Reference> parties = participants.stream() 158 158 .map(parti -> (parti.getParty().getPartyRef())) … … 319 319 setState(state.with(new ProtocolException(message, party, e))); 320 320 } 321 log.log(Level.WARNING, "SAOP protocol intercepted error due to party " 322 + party + ":" + message, e); 321 323 } 322 324 -
protocol/src/main/java/geniusweb/protocol/session/saop/SAOPSettings.java
r1 r10 4 4 import java.util.LinkedList; 5 5 import java.util.List; 6 import java.util.stream.Collectors; 6 7 7 8 import com.fasterxml.jackson.annotation.JsonCreator; … … 11 12 import geniusweb.protocol.session.SessionProtocol; 12 13 import geniusweb.protocol.session.SessionSettings; 14 import geniusweb.protocol.session.TeamOfPartiesAndProfiles; 13 15 import geniusweb.references.PartyWithProfile; 14 16 import tudelft.utilities.logging.Reporter; 15 17 16 18 public class SAOPSettings implements SessionSettings { 17 private final List< PartyWithProfile> participants;19 private final List<SaopPartyWithProfile> participants; 18 20 private final Deadline deadline; 19 21 … … 28 30 @JsonCreator 29 31 public SAOPSettings( 30 @JsonProperty("participants") List< PartyWithProfile> participants,32 @JsonProperty("participants") List<SaopPartyWithProfile> participants, 31 33 @JsonProperty("deadline") Deadline deadline) { 32 34 this.participants = participants; … … 51 53 52 54 @Override 53 public List< PartyWithProfile> getParticipants() {55 public List<TeamOfPartiesAndProfiles> getTeams() { 54 56 return Collections.unmodifiableList(participants); 55 57 } … … 60 62 public Deadline getDeadline() { 61 63 return deadline; 64 } 65 66 @Override 67 public List<PartyWithProfile> getAllParties() { 68 return participants.stream() 69 .map(particip -> particip.getAllParties().get(0)) 70 .collect(Collectors.toList()); 62 71 } 63 72 … … 101 110 102 111 @Override 103 public SessionSettings with(PartyWithProfile party) { 104 List<PartyWithProfile> newparts = new LinkedList<>(participants); 105 newparts.add(party); 112 public SessionSettings with(TeamOfPartiesAndProfiles party) { 113 if (!(party instanceof SaopPartyWithProfile)) 114 throw new IllegalArgumentException( 115 "Added party must be SaopPartyWithProfile but got " 116 + party); 117 List<SaopPartyWithProfile> newparts = new LinkedList<>(participants); 118 newparts.add((SaopPartyWithProfile) party); 106 119 return new SAOPSettings(newparts, deadline); 107 120 } -
protocol/src/main/java/geniusweb/protocol/session/saop/SAOPState.java
r9 r10 16 16 import geniusweb.progress.ProgressRounds; 17 17 import geniusweb.protocol.ProtocolException; 18 import geniusweb.protocol.partyconnection.ProtocolToPartyConn; 18 19 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections; 19 import geniusweb.protocol.partyconnection.ProtocolToPartyConn;20 20 import geniusweb.protocol.session.DefaultSessionState; 21 21 import geniusweb.protocol.session.SessionSettings; … … 61 61 62 62 /** 63 * @param actor the actor that did this action. Can be used to check64 * if action is valid. NOTICE caller has to make sure65 * the current state is not final.66 * @param action the action that was proposed by actor.67 * @param currentTimeMs the current time in ms since 1970, see68 * {@link System#currentTimeMillis()}69 * @return new SessionState with the action added as last action.70 */71 public SAOPState with(PartyId actor, Action action) {72 try {73 return with1(actor, action);74 } catch (ProtocolException e) {75 List<Action> newactions = new LinkedList<>(getActions());76 newactions.add(action);77 return new SAOPState(newactions, getConnections(), getProgress(),78 getSettings(), getPartyProfiles(), e);79 }80 }81 82 /**83 63 * 84 64 * @param connection the new {@link ProtocolToPartyConn} … … 164 144 165 145 /** 146 * @param actor the actor that did this action. Can be used to check 147 * if action is valid. NOTICE caller has to make sure 148 * the current state is not final. 149 * @param action the action that was proposed by actor. 150 * @param currentTimeMs the current time in ms since 1970, see 151 * {@link System#currentTimeMillis()} 152 * @return new SessionState with the action added as last action. 153 */ 154 155 public SAOPState with(PartyId actor, Action action) { 156 157 if (actor == null) { // this is a bug 158 throw new IllegalArgumentException("actor must not be null"); 159 } 160 if (!actor.equals(getNextActor())) { 161 throw new IllegalArgumentException("Party does not have the turn "); 162 163 } 164 if (action == null) { 165 throw new IllegalArgumentException("action is null"); 166 } 167 if (!actor.equals(action.getActor())) { 168 throw new IllegalArgumentException( 169 "act contains wrong credentials: " + action); 170 } 171 172 // check protocol is followed for specific actions 173 if (action instanceof Accept) { 174 Bid bid = getLastBid(); 175 if (bid == null) { 176 throw new IllegalArgumentException( 177 "Accept without a recent offer"); 178 } 179 if (!bid.equals(((Accept) action).getBid())) { 180 throw new IllegalArgumentException( 181 "Party accepts a bid differing from the last offer =" 182 + bid + ", action=" + action + ")"); 183 } 184 } else if (action instanceof Offer) { 185 // offer is always fine. We don't check if bid is actually in domain 186 // or complete etc. We would need domain for that 187 } else if (action instanceof EndNegotiation) { 188 // just act, we will get into the final state then. 189 } else { 190 throw new IllegalArgumentException( 191 "Action " + action + " is not allowed in SAOP"); 192 } 193 194 List<Action> newactions = new LinkedList<>(getActions()); 195 newactions.add(action); 196 return new SAOPState(newactions, getConnections(), advanceProgress(), 197 getSettings(), getPartyProfiles(), null); 198 } 199 200 /** 166 201 * Check up to nparticipants-1 steps back if there was an offer. 167 202 * … … 182 217 } 183 218 184 private SAOPState with1(PartyId actor, Action action)185 throws ProtocolException {186 187 if (actor == null) { // this is a bug188 throw new IllegalArgumentException("actor must not be null");189 }190 if (!actor.equals(getNextActor())) {191 throw new ProtocolException("Party does not have the turn ",192 actor.getName());193 194 }195 if (action == null) {196 throw new ProtocolException("action is null", actor.getName());197 }198 if (!actor.equals(action.getActor())) {199 throw new ProtocolException(200 "act contains wrong credentials: " + action,201 actor.getName());202 }203 204 // check protocol is followed for specific actions205 if (action instanceof Accept) {206 Bid bid = getLastBid();207 if (bid == null) {208 throw new ProtocolException("Accept without a recent offer",209 actor.getName());210 }211 if (!bid.equals(((Accept) action).getBid())) {212 throw new ProtocolException(213 "Party accepts a bid differing from the last offer ="214 + bid + ", action=" + action + ")",215 actor.getName());216 }217 } else if (action instanceof Offer) {218 // offer is always fine. We don't check if bid is actually in domain219 // or complete etc. We would need domain for that220 } else if (action instanceof EndNegotiation) {221 // just act, we will get into the final state then.222 } else {223 throw new ProtocolException(224 "Action " + action + " is not allowed in SAOP",225 actor.getName());226 }227 228 List<Action> newactions = new LinkedList<>(getActions());229 newactions.add(action);230 return new SAOPState(newactions, getConnections(), advanceProgress(),231 getSettings(), getPartyProfiles(), null);232 }233 234 219 /** 235 220 * -
protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsProtocol.java
r9 r10 81 81 long now = System.currentTimeMillis(); 82 82 if (sessionstate.isFinal(now)) { 83 // List<TeamOfPartiesAndProfiles> participants = 84 // sessionstate.getSettings().getParticipants() 83 85 SessionResult result = new SessionResult( 84 sessionstate.getSettings().get Participants(),86 sessionstate.getSettings().getAllParties(), 85 87 sessionstate.getAgreement(), sessionstate.getError()); 86 88 state = state.with(result); -
protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettings.java
r8 r10 1 1 package geniusweb.protocol.tournament.allpermutations; 2 2 3 import java.net.URI; 4 import java.net.URISyntaxException; 3 5 import java.util.Collections; 4 6 import java.util.List; … … 7 9 import com.fasterxml.jackson.annotation.JsonProperty; 8 10 11 import geniusweb.profile.Profile; 9 12 import geniusweb.protocol.session.SessionSettings; 13 import geniusweb.protocol.session.TeamOfPartiesAndProfiles; 14 import geniusweb.protocol.session.saop.SAOPSettings; 15 import geniusweb.protocol.session.saop.SaopPartyWithProfile; 16 import geniusweb.protocol.session.shaop.SHAOPSettings; 17 import geniusweb.protocol.session.shaop.ShaopTeam; 10 18 import geniusweb.protocol.tournament.TournamentProtocol; 11 19 import geniusweb.protocol.tournament.TournamentSettings; 20 import geniusweb.references.Parameters; 12 21 import geniusweb.references.PartyRef; 13 22 import geniusweb.references.PartyWithParameters; … … 30 39 * Takes a number of parties and profiles and makes all permutations of them 31 40 * with the given number of parties and profiles. All profiles must be in the 32 * same domain. All sessions are based on the given sessionsettings (can be any 33 * session protocol). The parties for each tournament session are added to this 34 * basic sessionsettings. 35 * 41 * same domain. 42 * <p> 43 * All sessions are based on the given {@link SessionSettings} (can be 44 * {@link SAOPSettings} or {@link SHAOPSettings}). The parties for each 45 * tournament session are added to this basic sessionsettings. sessionsettings 46 * contains basically all the normal run-sessionsettings. This is used as a 47 * "template" for all sessions of the tournament. You can put any use any 48 * session setting here, and each session will be run according to the protocol 49 * you select here. 50 * 51 * The participants list usually is empty. The AllPermutationsProtocol adds the 52 * the required parties to this list. So if you provide a non-empty list here, 53 * then these parties would be present in every session in the tournament. 54 * <p> 55 * If the tournament is used with a SHAOP sessionsettings, a number of rules are 56 * used to generate the COB party from the settings. 57 * 58 * The COB party is assumed to be the comparebids-1.0.0 party on the same server 59 * as the party you provide. So if you provide http://server/../party1-1.2.3 60 * then the cob party will be assumed to be at 61 * http://server/../comparebids-1.0.0. The provided parties that you provide are 62 * the SHAOP parties (you can also use SAOP parties). The provided profile is 63 * also given to the SHAOP party. Be aware that you typically need a parameter 64 * like partial=10. The COB party gets the profile as specified, but without the 65 * query part. The COB and SHAOP party are thus a fixed pair. 36 66 */ 37 67 public class AllPermutationsSettings implements TournamentSettings { 68 38 69 private final List<PartyWithParameters> parties; 39 70 private final List<ProfileRef> profiles; … … 49 80 * we use PermutationsWithoutReturn to create the 50 81 * parties. 51 * @param profiles 82 * @param profiles list of available {@link Profile}s to be 83 * permutated over the parties 52 84 * @param partiesPerSession number of parties per session, must be at least 53 85 * 2. … … 97 129 */ 98 130 public ImmutableList<SessionSettings> permutations() { 99 ImmutableList<ImmutableList< PartyWithProfile>> partylistlist;131 ImmutableList<ImmutableList<TeamOfPartiesAndProfiles>> partylistlist; 100 132 ImmutableList<PartyWithParameters> partieslist = new FixedList<PartyWithParameters>( 101 133 parties); … … 166 198 */ 167 199 private SessionSettings createSetting( 168 ImmutableList< PartyWithProfile> partyproflist) {200 ImmutableList<TeamOfPartiesAndProfiles> partyproflist) { 169 201 SessionSettings settings = sessionsettings; 170 for ( PartyWithProfilepartyprof : partyproflist) {202 for (TeamOfPartiesAndProfiles partyprof : partyproflist) { 171 203 settings = settings.with(partyprof); 172 204 } … … 181 213 * @param drawPartyWithPutback if parties can be drawn multiple times 182 214 * @return list of sessionsets where each sessionset contains settings for a 183 * session: a list with {@link PartyWithProfile}s. The sessionsets184 * are made by making all combinations of parties and profiles.185 * Profiles are drawn with replace.186 */ 187 private ImmutableList<ImmutableList< PartyWithProfile>> getParticipants(215 * session: a list with {@link TeamOfPartiesAndProfiles}s. The 216 * sessionsets are made by making all combinations of parties and 217 * profiles. Profiles are drawn with replace. 218 */ 219 private ImmutableList<ImmutableList<TeamOfPartiesAndProfiles>> getParticipants( 188 220 ImmutableList<PartyWithParameters> parties, 189 221 ImmutableList<ProfileRef> profiles, int n, … … 205 237 partiesPermutations, profilesPermutations); 206 238 207 return new MapList<Tuple<ImmutableList<PartyWithParameters>, ImmutableList<ProfileRef>>, ImmutableList< PartyWithProfile>>(208 tuple -> partyprofilelist(tuple), tuples);239 return new MapList<Tuple<ImmutableList<PartyWithParameters>, ImmutableList<ProfileRef>>, ImmutableList<TeamOfPartiesAndProfiles>>( 240 tuple -> teamlist(tuple), tuples); 209 241 } 210 242 … … 213 245 * @param tuple a tuple with (1) ImmutableList<PartyRef> (2) 214 246 * ImmutableList<ProfileRef> 215 * @return list of PartyWithProfile, each picked from the two lists in216 * order.217 */ 218 private ImmutableList< PartyWithProfile> partyprofilelist(247 * @return list of TeamOfPartiesAndProfiles, each picked from the two lists 248 * in order. 249 */ 250 private ImmutableList<TeamOfPartiesAndProfiles> teamlist( 219 251 Tuple<ImmutableList<PartyWithParameters>, ImmutableList<ProfileRef>> tuple) { 220 Function2<PartyWithParameters, ProfileRef, PartyWithProfile> //221 makeparty = new Function2<PartyWithParameters, ProfileRef, PartyWithProfile>() {252 Function2<PartyWithParameters, ProfileRef, TeamOfPartiesAndProfiles> // 253 makeparty = new Function2<PartyWithParameters, ProfileRef, TeamOfPartiesAndProfiles>() { 222 254 @Override 223 public PartyWithProfileapply(PartyWithParameters party,255 public TeamOfPartiesAndProfiles apply(PartyWithParameters party, 224 256 ProfileRef profile) { 225 return new PartyWithProfile(party, profile); 257 if (sessionsettings instanceof SAOPSettings) 258 return new SaopPartyWithProfile(party, profile); 259 else if (sessionsettings instanceof SHAOPSettings) { 260 return new ShaopTeam(new PartyWithProfile(party, profile), 261 makeCob(party.getPartyRef(), profile)); 262 } else 263 throw new IllegalArgumentException( 264 "Unknown/unsupported protocol " 265 + sessionsettings.getClass()); 226 266 } 267 227 268 }; 228 return new MapThreadList< PartyWithProfile, PartyWithParameters, ProfileRef>(269 return new MapThreadList<TeamOfPartiesAndProfiles, PartyWithParameters, ProfileRef>( 229 270 makeparty, tuple.get1(), tuple.get2()); 230 271 } 231 272 273 /** 274 * Extract the raw URL, without the part after the question mark 275 * 276 * @param party a party reference (for another party) 277 * @param profile a profile that may have a filter like "?partial=XX" 278 * @return profile without the filter and with a cob party on the same 279 * machine. IT IS ASSUMED that there will the default 280 * "comparebids-1.0.0" party on the same machine as where the other 281 * party is 282 */ 283 protected static PartyWithProfile makeCob(PartyRef party, 284 ProfileRef profile) { 285 try { 286 URI profileuri = profile.getURI(); 287 URI partyuri = party.getURI(); 288 ProfileRef cobprof = new ProfileRef(profileuri.getScheme() + "://" 289 + profileuri.getAuthority() + profileuri.getPath()); 290 String partypath = partyuri.getPath(); 291 partypath = partypath.substring(0, partypath.lastIndexOf('/')); 292 PartyWithParameters cobparty = new PartyWithParameters(new PartyRef( 293 partyuri.getScheme() + "://" + partyuri.getAuthority() 294 + partypath + "/comparebids-1.0.0"), 295 new Parameters()); 296 return new PartyWithProfile(cobparty, cobprof); 297 298 } catch (URISyntaxException e) { 299 throw new IllegalArgumentException( 300 "Failed making cob party with profile " + profile, e); 301 } 302 } 303 232 304 } -
protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsState.java
r1 r10 55 55 */ 56 56 public AllPermutationsState with(SessionResult result) { 57 if (!getNextSettings().get Participants()57 if (!getNextSettings().getAllParties() 58 58 .equals(result.getParticipants())) { 59 59 throw new IllegalArgumentException("Inconsistent session result"); -
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.