Changeset 21 for protocol/src/test/java


Ignore:
Timestamp:
09/22/20 08:52:04 (4 years ago)
Author:
bart
Message:

Version 1.5.

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  
    2323import geniusweb.actions.PartyId;
    2424import geniusweb.deadline.DeadlineTime;
    25 import geniusweb.issuevalue.Bid;
     25import geniusweb.inform.Agreements;
    2626import geniusweb.progress.Progress;
    2727import geniusweb.progress.ProgressTime;
     
    2929import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    3030import geniusweb.protocol.session.saop.SAOPSettings;
    31 import geniusweb.protocol.session.saop.SaopPartyWithProfile;
    3231import geniusweb.references.Parameters;
    3332import geniusweb.references.PartyRef;
     
    6059                                new PartyRef("party2"), new Parameters());
    6160                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));
    6564                SessionSettings settings = new SAOPSettings(participants, deadline);
    6665                ProtocolException e = new ProtocolException("test protocol error",
    67                                 party1.getName());
     66                                party1);
    6867                HashMap<PartyId, PartyWithProfile> partyprofiles = new HashMap<PartyId, PartyWithProfile>();
    6968                partyprofiles.put(party1, new PartyWithProfile(party1ref, profile1));
     
    135134
    136135        @Override
    137         public Bid getAgreement() {
    138                 return null;
    139         }
    140 
    141         @Override
    142136        public SessionResult getResult() {
    143137
     
    145139                for (int n = 0; n < getConnections().size(); n++)
    146140                        emptylist.add(0d);
    147                 return new SessionResult(getSettings().getAllParties(), getAgreement(),
     141                return new SessionResult(getSettings().getAllParties(), getAgreements(),
    148142                                emptylist, getError());
    149143
    150144        }
    151145
     146        @Override
     147        public Agreements getAgreements() {
     148                return new Agreements();
     149        }
     150
    152151}
  • protocol/src/test/java/geniusweb/protocol/session/SessionResultTest.java

    r20 r21  
    77import java.util.Arrays;
    88import java.util.HashMap;
     9import java.util.HashSet;
    910import java.util.List;
    1011import java.util.Map;
     
    1617import com.fasterxml.jackson.databind.ObjectMapper;
    1718
     19import geniusweb.actions.PartyId;
     20import geniusweb.inform.Agreements;
    1821import geniusweb.issuevalue.Bid;
    1922import geniusweb.issuevalue.DiscreteValue;
     
    3235        private final String ISSUE1 = "issue1";
    3336        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}";
    3738        private List<Double> nopenalties = Arrays.asList(0d, 0d);
    3839        private List<Double> penalties = Arrays.asList(0.1d, 0.2d);
    3940
     41        private PartyId PARTY1 = new PartyId("party1");
     42        private PartyId PARTY2 = new PartyId("party2");
     43        private PartyId PARTY3 = new PartyId("party3");
     44
    4045        @Before
    4146        public void before() throws URISyntaxException, JsonProcessingException {
    42                 errorstring = "\"error\":{\"java.lang.RuntimeException\":"
     47                String errorstring = "\"error\":{\"java.lang.RuntimeException\":"
    4348                                + jackson.writeValueAsString(error) + "}";
    44                 System.out.println(errorstring);
     49                // System.out.println(errorstring);
    4550
    4651                PartyWithParameters party1 = new PartyWithParameters(
     
    5762                issuevalues1.put(ISSUE1, new DiscreteValue("a"));
    5863                Bid bid1 = new Bid(issuevalues1);
     64                Agreements agreement1 = new Agreements().with(bid1,
     65                                new HashSet<>(Arrays.asList(PARTY1, PARTY2)));
    5966
    6067                // different order but that shouldn't matter
     
    6269                issuevalues2.put(ISSUE1, new DiscreteValue("b"));
    6370                Bid bid2 = new Bid(issuevalues2);
     71                Agreements agreement2 = new Agreements().with(bid2,
     72                                new HashSet<>(Arrays.asList(PARTY1, PARTY3)));
    6473
    6574                result1 = new SessionResult(Arrays.asList(partyprofile1, partyprofile2),
    66                                 bid1, nopenalties, null);
     75                                agreement1, nopenalties, null);
    6776                result1a = new SessionResult(
    68                                 Arrays.asList(partyprofile1, partyprofile2), bid1, nopenalties,
    69                                 null);
     77                                Arrays.asList(partyprofile1, partyprofile2), agreement1,
     78                                nopenalties, null);
    7079                result2 = new SessionResult(Arrays.asList(partyprofile1, partyprofile2),
    71                                 bid2, nopenalties, null);
     80                                agreement2, nopenalties, null);
    7281                result3 = new SessionResult(Arrays.asList(partyprofile2, partyprofile1),
    73                                 bid2, nopenalties, null);
     82                                agreement1, nopenalties, null);
    7483                result4 = new SessionResult(Arrays.asList(partyprofile2, partyprofile1),
    75                                 bid2, penalties, null);
     84                                agreement1, penalties, null);
    7685
    7786                // IGNORE ERROR for now, it fails somewhere deep in maven suddenly.
     
    9099        public List<String> getGeneralTestStrings() {
    91100                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.*"
    96105
    97106                );
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPSettingsTest.java

    r10 r21  
    1919import geniusweb.deadline.DeadlineRounds;
    2020import geniusweb.deadline.DeadlineTime;
     21import geniusweb.protocol.session.OnePartyTeam;
    2122import geniusweb.protocol.session.SessionSettings;
    2223import geniusweb.references.Parameters;
     
    2930public class SAOPSettingsTest extends GeneralTests<SAOPSettings> {
    3031
    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,
    3536                        partyprof2);
    36         private List<SaopPartyWithProfile> participants3 = Arrays.asList(partyprof1,
     37        private List<OnePartyTeam> participants3 = Arrays.asList(partyprof1,
    3738                        partyprof2, partyprof3);
    3839
     
    6667                                new PartyRef("http://party2"), new Parameters());
    6768                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,
    7372                                partywithprof2);
    7473
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java

    r10 r21  
    176176                SAOPState state = new SAOPState(actions, connections3, progressrounds,
    177177                                settings, null, null);
    178                 assertNull(state.getAgreement());
     178                assertTrue(state.getAgreements().getMap().isEmpty());
    179179        }
    180180
     
    184184                SAOPState state = new SAOPState(actions, connections3, progressrounds,
    185185                                settings, null, null);
    186                 assertNull(state.getAgreement());
     186                assertTrue(state.getAgreements().getMap().isEmpty());
    187187        }
    188188
     
    192192                SAOPState state = new SAOPState(actions, connections3, progressrounds,
    193193                                settings, null, null);
    194                 assertNull(state.getAgreement());
     194                assertTrue(state.getAgreements().getMap().isEmpty());
    195195        }
    196196
     
    200200                SAOPState state = new SAOPState(actions, connections3, progressrounds,
    201201                                settings, null, null);
    202                 assertEquals(bid1, state.getAgreement());
     202                assertEquals(bid1, state.getAgreements().getMap().get(party1));
    203203                assertTrue(state.isFinal(NOW));
    204204        }
     
    209209                SAOPState state = new SAOPState(actions, connections3, progressrounds,
    210210                                settings, null, null);
    211                 assertEquals(null, state.getAgreement());
     211                assertTrue(state.getAgreements().getMap().isEmpty());
    212212        }
    213213
     
    217217                SAOPState state = new SAOPState(actions, connections3, progressrounds,
    218218                                settings, null, null);
    219                 assertEquals(null, state.getAgreement());
     219                assertTrue(state.getAgreements().getMap().isEmpty());
    220220        }
    221221
     
    246246                SAOPState state = new SAOPState(actions, connections3, progressrounds,
    247247                                settings, null, null);
    248                 assertEquals(null, state.getAgreement());
     248                assertTrue(state.getAgreements().getMap().isEmpty());
    249249                assertEquals(null, state.getError());
    250250                assertTrue(state.isFinal(NOW));
     
    255255        public void isProtocolErrorFinal() {
    256256                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")));
    258259                assertTrue(state.isFinal(NOW));
    259260                assertNotNull(state.getError());
     
    309310                assertTrue(state.isFinal(NOW));
    310311                assertNull(state.getError());
    311                 assertEquals(bid1, state.getAgreement());
     312                assertEquals(bid1, state.getAgreements().getMap().get(party1));
    312313
    313314        }
     
    325326                assertTrue(state.isFinal(NOW));
    326327                assertNull(state.getError());
    327                 assertEquals(bid2, state.getAgreement());
     328                assertEquals(bid2, state.getAgreements().getMap().get(party1));
    328329
    329330        }
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java

    r10 r21  
    3434import geniusweb.events.CurrentState;
    3535import 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;
     36import geniusweb.inform.Finished;
     37import geniusweb.inform.Inform;
     38import geniusweb.inform.Settings;
     39import geniusweb.inform.YourTurn;
    4040import geniusweb.progress.Progress;
    4141import geniusweb.protocol.ProtocolException;
     
    4343import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
    4444import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
     45import geniusweb.protocol.session.OnePartyTeam;
    4546import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
    4647import geniusweb.references.Parameters;
     
    7576        private final PartyRef party2ref = mock(PartyRef.class);
    7677        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);
    7980        private SAOP saop;
    8081        private ProtocolToPartyConnFactory factory;
     
    8283        private ProtocolToPartyConn conn1 = mock(ProtocolToPartyConn.class),
    8384                        conn2 = mock(ProtocolToPartyConn.class);
    84         private Map<PartyId, SaopPartyWithProfile> partyprofiles;
     85        private Map<PartyId, OnePartyTeam> partyprofiles;
    8586        private Progress progress = mock(Progress.class);
    8687        private ProfileRef profile1;
  • protocol/src/test/java/geniusweb/protocol/session/saop/SaopPartyWithProfileTest.java

    r10 r21  
    1717import com.fasterxml.jackson.databind.ObjectMapper;
    1818
     19import geniusweb.protocol.session.OnePartyTeam;
    1920import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
    2021import geniusweb.references.Parameters;
     
    2425import tudelft.utilities.junit.GeneralTests;
    2526
    26 public class SaopPartyWithProfileTest
    27                 extends GeneralTests<SaopPartyWithProfile> {
     27public class SaopPartyWithProfileTest extends GeneralTests<OnePartyTeam> {
    2828
    2929        private PartyRef party1, party1a, party2, party3;
    3030        private ProfileRef profile1, profile2;
    31         private SaopPartyWithProfile partyprof1, partyprof1a, partyprof2,
    32                         partyprof3, partyprof4;
     31        private OnePartyTeam partyprof1, partyprof1a, partyprof2, partyprof3,
     32                        partyprof4;
    3333        private final String serialized = "{\"party\":{\"partyref\":\"ws:party1\",\"parameters\":{}},\"profile\":\"ws:profile1\"}";
    3434
     
    5454                                settings1);
    5555
    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);
    6161
    6262        }
    6363
    6464        @Override
    65         public List<List<SaopPartyWithProfile>> getGeneralTestData() {
     65        public List<List<OnePartyTeam>> getGeneralTestData() {
    6666                return Arrays.asList(Arrays.asList(partyprof1, partyprof1a),
    6767                                Arrays.asList(partyprof2), Arrays.asList(partyprof3),
     
    8484        @Test(expected = IllegalArgumentException.class)
    8585        public void nullTest() throws URISyntaxException {
    86                 new SaopPartyWithProfile((PartyWithParameters) null, (ProfileRef) null);
     86                new OnePartyTeam((PartyWithParameters) null, (ProfileRef) null);
    8787        }
    8888
     
    103103                // and therfore can not serialize as TeamOfPartiesAndProfiles
    104104                TeamOfPartiesAndProfiles p = jackson.readValue(serialized,
    105                                 SaopPartyWithProfile.class);
     105                                OnePartyTeam.class);
    106106                System.out.println(p);
    107107                assertEquals(partyprof1, p);
  • protocol/src/test/java/geniusweb/protocol/session/shaop/SHAOPStateTest.java

    r20 r21  
    44import static org.junit.Assert.assertFalse;
    55import static org.junit.Assert.assertNotNull;
    6 import static org.junit.Assert.assertNull;
    76import static org.junit.Assert.assertTrue;
    87import static org.mockito.Mockito.mock;
     
    194193                SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
    195194                                settings, null, 0, null, null);
    196                 assertNull(state.getAgreement());
     195                assertTrue(state.getAgreements().getMap().isEmpty());
    197196        }
    198197
     
    201200                List<Action> actions = Arrays.asList(offer1, accept2);
    202201                SHAOPState state = new SHAOPState(actions, connections4, progressrounds,
    203                                 settings, null, 0, null, null);
    204                 assertNotNull(state.getAgreement());
     202                                settings, null, 0, partynrs, null);
     203                assertFalse(state.getAgreements().getMap().isEmpty());
    205204                assertTrue(state.isFinal(NOW));
    206205        }
     
    211210                SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
    212211                                settings, null, 0, null, null);
    213                 assertNull(state.getAgreement());
     212                assert (state.getAgreements().getMap().isEmpty());
    214213        }
    215214
     
    219218                SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
    220219                                settings, null, 0, null, null);
    221                 assertEquals(null, state.getAgreement());
     220                assertTrue(state.getAgreements().getMap().isEmpty());
    222221        }
    223222
     
    245244                SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
    246245                                settings, null, 0, null, null);
    247                 assertEquals(null, state.getAgreement());
     246                assertTrue(state.getAgreements().getMap().isEmpty());
    248247                assertEquals(null, state.getError());
    249248                assertTrue(state.isFinal(NOW));
     
    254253        public void isProtocolErrorFinal() {
    255254                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);
    258258                assertTrue(state.isFinal(NOW));
    259259                assertNotNull(state.getError());
  • protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsProtocolTest.java

    r20 r21  
    2020
    2121import geniusweb.events.ProtocolEvent;
    22 import geniusweb.issuevalue.Bid;
     22import geniusweb.inform.Agreements;
    2323import geniusweb.protocol.CurrentNegoState;
    2424import geniusweb.protocol.NegoState;
     
    4444        private final SessionSettings settings = mock(SessionSettings.class);
    4545        private final SessionState finalsessionstate = mock(SessionState.class);
    46         private Bid agreement = mock(Bid.class);
     46        private Agreements agreement = mock(Agreements.class);
    4747        private final long NOW = 1000;
    4848        private SessionResult finalstate = mock(SessionResult.class);
     
    5353                when(finalsessionstate.isFinal(anyLong())).thenReturn(true);
    5454                when(finalsessionstate.getSettings()).thenReturn(settings);
    55                 when(finalsessionstate.getAgreement()).thenReturn(agreement);
     55                when(finalsessionstate.getAgreements()).thenReturn(agreement);
    5656                when(finalsessionstate.getResult()).thenReturn(finalstate);
    57                 when(finalstate.getAgreement()).thenReturn(agreement);
     57                when(finalstate.getAgreements()).thenReturn(agreement);
    5858                when(state.with(any())).thenReturn(newstate);
    5959        }
     
    112112                                .forClass(SessionResult.class);
    113113                verify(state, times(1)).with(argument.capture());
    114                 assertEquals(agreement, argument.getValue().getAgreement());
     114                assertEquals(agreement, argument.getValue().getAgreements());
    115115                assertNull(argument.getValue().getError());
    116116        }
  • protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsStateTest.java

    r20 r21  
    8888                AllPermutationsState state1 = state.with(result);
    8989
    90                 assertEquals(null, state1.getError());
    9190                assertEquals(8, state1.getResults().size());
    9291                assertEquals(toursettings, state1.getSettings());
Note: See TracChangeset for help on using the changeset viewer.