Ignore:
Timestamp:
01/28/20 10:19:54 (4 years ago)
Author:
bart
Message:

Update 28 jan 2020

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  
    2929import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    3030import geniusweb.protocol.session.saop.SAOPSettings;
     31import geniusweb.protocol.session.saop.SaopPartyWithProfile;
    3132import geniusweb.references.Parameters;
    3233import geniusweb.references.PartyRef;
     
    3940        private final ObjectMapper jackson = new ObjectMapper();
    4041        private DefaultSessionState1 state1, state1a, stateA, stateE, stateF;
     42        // The 1 is because we are testing an instance, not the abstract class
    4143        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\"}}}}";
    4244        private ProgressTime progr;
     
    5860                                new PartyRef("party2"), new Parameters());
    5961                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));
    6365                SessionSettings settings = new SAOPSettings(participants, deadline);
    6466                ProtocolException e = new ProtocolException("test protocol error",
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPSettingsTest.java

    r8 r10  
    2323import geniusweb.references.PartyRef;
    2424import geniusweb.references.PartyWithParameters;
    25 import geniusweb.references.PartyWithProfile;
    2625import geniusweb.references.ProfileRef;
    2726import tudelft.utilities.junit.GeneralTests;
     
    3029public class SAOPSettingsTest extends GeneralTests<SAOPSettings> {
    3130
    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,
    3635                        partyprof2);
    37         private List<PartyWithProfile> participants3 = Arrays.asList(partyprof1,
     36        private List<SaopPartyWithProfile> participants3 = Arrays.asList(partyprof1,
    3837                        partyprof2, partyprof3);
    3938
     
    6766                                new PartyRef("http://party2"), new Parameters());
    6867                ProfileRef profile2 = new ProfileRef("http://profile2");
    69                 PartyWithProfile partywithprof1 = new PartyWithProfile(party1,
     68                SaopPartyWithProfile partywithprof1 = new SaopPartyWithProfile(party1,
    7069                                profile1);
    71                 PartyWithProfile partywithprof2 = new PartyWithProfile(party2,
     70                SaopPartyWithProfile partywithprof2 = new SaopPartyWithProfile(party2,
    7271                                profile2);
    73                 List<PartyWithProfile> participants = Arrays.asList(partywithprof1,
     72                List<SaopPartyWithProfile> participants = Arrays.asList(partywithprof1,
    7473                                partywithprof2);
    7574
     
    141140                SAOPSettings saop = new SAOPSettings(participants2, deadline);
    142141                SessionSettings saop2 = saop.with(partyprof3);
    143                 assertEquals(3, saop2.getParticipants().size());
     142                assertEquals(3, saop2.getTeams().size());
    144143        }
    145144
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java

    r9 r10  
    2727import geniusweb.progress.ProgressTime;
    2828import geniusweb.protocol.ProtocolException;
     29import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    2930import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    30 import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    3131import geniusweb.protocol.session.SessionSettings;
    3232import tudelft.utilities.junit.GeneralTests;
     
    220220        }
    221221
    222         @Test
     222        @Test(expected = IllegalArgumentException.class)
    223223        public void withWrongActionTest() {
    224224                // wrong because action has actor null which does not match party1
    225225                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)
    235232        public void withActionTest() {
    236233                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);
    240235        }
    241236
     
    265260        }
    266261
    267         @Test
     262        @Test(expected = IllegalArgumentException.class)
    268263        public void RefuseImmediateAccept() {
    269264                Accept nullaccept = new Accept(party1, null);
    270265                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)
    278269        public void RefuseNotMyTurn() {
    279270                List<Action> actions = Arrays.asList(offer1);
     
    281272                                settings, null, null);
    282273
    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)
    291282        public void RefuseNullAccept() {
    292283                List<Action> actions = Arrays.asList(offer1);
     
    297288                state = state.with(party2, nullaccept);
    298289                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)
    304293        public void RefuseNullAction() {
    305294                List<Action> actions = Arrays.asList(offer1);
     
    308297
    309298                state = state.with(party2, null);
    310                 assertEquals(
    311                                 "geniusweb.protocol.ProtocolException: party2:action is null",
    312                                 state.getError().toString());
    313299        }
    314300
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java

    r9 r10  
    2020import java.util.List;
    2121import java.util.Map;
     22import java.util.stream.Collectors;
    2223
    2324import org.junit.Test;
     
    3940import geniusweb.progress.Progress;
    4041import geniusweb.protocol.ProtocolException;
    41 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    4242import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    4343import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
     44import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
     45import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
    4446import geniusweb.references.Parameters;
    4547import geniusweb.references.PartyRef;
     
    7375        private final PartyRef party2ref = mock(PartyRef.class);
    7476        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);
    7779        private SAOP saop;
    7880        private ProtocolToPartyConnFactory factory;
     
    8082        private ProtocolToPartyConn conn1 = mock(ProtocolToPartyConn.class),
    8183                        conn2 = mock(ProtocolToPartyConn.class);
    82         private Map<PartyId, PartyWithProfile> partyprofiles;
     84        private Map<PartyId, SaopPartyWithProfile> partyprofiles;
    8385        private Progress progress = mock(Progress.class);
    8486        private ProfileRef profile1;
     
    101103                        throws URISyntaxException, IOException, NoResourcesNowException {
    102104                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));
    105109
    106110                partyprofiles = new HashMap<>();
    107                 partyprofiles.put(PARTY1ID, party1);
    108                 partyprofiles.put(PARTY2ID, party2);
     111                partyprofiles.put(PARTY1ID, team1);
     112                partyprofiles.put(PARTY2ID, team2);
    109113
    110114                when(deadlinetime.getDuration()).thenReturn(1000l);
    111115
    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));
    116121                when(settings.getDeadline()).thenReturn(deadlinetime);
    117122
     
    126131
    127132                profile1 = mock(ProfileRef.class);
    128                 when(party1.getProfile()).thenReturn(profile1);
     133                when(team1.getProfile()).thenReturn(profile1);
    129134                profile2 = mock(ProfileRef.class);
    130                 when(party2.getProfile()).thenReturn(profile2);
     135                when(team2.getProfile()).thenReturn(profile2);
    131136
    132137                mockState(connectedstate, "connected state");
     
    157162                when(state.getSettings()).thenReturn(settings);
    158163                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())));
    160167                when(state.getProgress()).thenReturn(progress);
    161168                when(state.with(any(ProtocolToPartyConn.class),
Note: See TracChangeset for help on using the changeset viewer.