Index: protocol/src/test/java/geniusweb/protocol/session/DefaultSessionStateTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/session/DefaultSessionStateTest.java	(revision 9)
+++ protocol/src/test/java/geniusweb/protocol/session/DefaultSessionStateTest.java	(revision 10)
@@ -29,4 +29,5 @@
 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
 import geniusweb.protocol.session.saop.SAOPSettings;
+import geniusweb.protocol.session.saop.SaopPartyWithProfile;
 import geniusweb.references.Parameters;
 import geniusweb.references.PartyRef;
@@ -39,4 +40,5 @@
 	private final ObjectMapper jackson = new ObjectMapper();
 	private DefaultSessionState1 state1, state1a, stateA, stateE, stateF;
+	// The 1 is because we are testing an instance, not the abstract class
 	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\"}}}}";
 	private ProgressTime progr;
@@ -58,7 +60,7 @@
 				new PartyRef("party2"), new Parameters());
 		ProfileRef profile2 = new ProfileRef("profile2");
-		List<PartyWithProfile> participants = Arrays.asList(
-				new PartyWithProfile(party1ref, profile1),
-				new PartyWithProfile(party2ref, profile2));
+		List<SaopPartyWithProfile> participants = Arrays.asList(
+				new SaopPartyWithProfile(party1ref, profile1),
+				new SaopPartyWithProfile(party2ref, profile2));
 		SessionSettings settings = new SAOPSettings(participants, deadline);
 		ProtocolException e = new ProtocolException("test protocol error",
Index: protocol/src/test/java/geniusweb/protocol/session/saop/SAOPSettingsTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/session/saop/SAOPSettingsTest.java	(revision 9)
+++ protocol/src/test/java/geniusweb/protocol/session/saop/SAOPSettingsTest.java	(revision 10)
@@ -23,5 +23,4 @@
 import geniusweb.references.PartyRef;
 import geniusweb.references.PartyWithParameters;
-import geniusweb.references.PartyWithProfile;
 import geniusweb.references.ProfileRef;
 import tudelft.utilities.junit.GeneralTests;
@@ -30,10 +29,10 @@
 public class SAOPSettingsTest extends GeneralTests<SAOPSettings> {
 
-	private PartyWithProfile partyprof1 = mock(PartyWithProfile.class);
-	private PartyWithProfile partyprof2 = mock(PartyWithProfile.class);
-	private PartyWithProfile partyprof3 = mock(PartyWithProfile.class);
-	private List<PartyWithProfile> participants2 = Arrays.asList(partyprof1,
+	private SaopPartyWithProfile partyprof1 = mock(SaopPartyWithProfile.class);
+	private SaopPartyWithProfile partyprof2 = mock(SaopPartyWithProfile.class);
+	private SaopPartyWithProfile partyprof3 = mock(SaopPartyWithProfile.class);
+	private List<SaopPartyWithProfile> participants2 = Arrays.asList(partyprof1,
 			partyprof2);
-	private List<PartyWithProfile> participants3 = Arrays.asList(partyprof1,
+	private List<SaopPartyWithProfile> participants3 = Arrays.asList(partyprof1,
 			partyprof2, partyprof3);
 
@@ -67,9 +66,9 @@
 				new PartyRef("http://party2"), new Parameters());
 		ProfileRef profile2 = new ProfileRef("http://profile2");
-		PartyWithProfile partywithprof1 = new PartyWithProfile(party1,
+		SaopPartyWithProfile partywithprof1 = new SaopPartyWithProfile(party1,
 				profile1);
-		PartyWithProfile partywithprof2 = new PartyWithProfile(party2,
+		SaopPartyWithProfile partywithprof2 = new SaopPartyWithProfile(party2,
 				profile2);
-		List<PartyWithProfile> participants = Arrays.asList(partywithprof1,
+		List<SaopPartyWithProfile> participants = Arrays.asList(partywithprof1,
 				partywithprof2);
 
@@ -141,5 +140,5 @@
 		SAOPSettings saop = new SAOPSettings(participants2, deadline);
 		SessionSettings saop2 = saop.with(partyprof3);
-		assertEquals(3, saop2.getParticipants().size());
+		assertEquals(3, saop2.getTeams().size());
 	}
 
Index: protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java	(revision 9)
+++ protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java	(revision 10)
@@ -27,6 +27,6 @@
 import geniusweb.progress.ProgressTime;
 import geniusweb.protocol.ProtocolException;
+import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
-import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
 import geniusweb.protocol.session.SessionSettings;
 import tudelft.utilities.junit.GeneralTests;
@@ -220,22 +220,17 @@
 	}
 
-	@Test
+	@Test(expected = IllegalArgumentException.class)
 	public void withWrongActionTest() {
 		// wrong because action has actor null which does not match party1
 		SAOPState state = state1.with(party1, action);
-		assertEquals(1, state.getActions().size());
-		assertEquals(action, state.getActions().get(0));
-		assertTrue(state.isFinal(NOW));
-		assertEquals(
-				"geniusweb.protocol.ProtocolException: party1:act contains wrong credentials: act1",
-				state.getError().toString());
-	}
-
-	@Test
+//		assertEquals(1, state.getActions().size());
+//		assertEquals(action, state.getActions().get(0));
+//		assertTrue(state.isFinal(NOW));
+	}
+
+	@Test(expected = IllegalArgumentException.class)
 	public void withActionTest() {
 		when(action.getActor()).thenReturn(party1);
-		SAOPState state = state1.with(party1, action);
-		assertEquals(1, state.getActions().size());
-		assertEquals(action, state.getActions().get(0));
+		state1.with(party1, action);
 	}
 
@@ -265,15 +260,11 @@
 	}
 
-	@Test
+	@Test(expected = IllegalArgumentException.class)
 	public void RefuseImmediateAccept() {
 		Accept nullaccept = new Accept(party1, null);
 		SAOPState state = state1.with(party1, nullaccept);
-		assertTrue(state.isFinal(NOW));
-		assertEquals(
-				"geniusweb.protocol.ProtocolException: party1:Accept without a recent offer",
-				state.getError().toString());
-	}
-
-	@Test
+	}
+
+	@Test(expected = IllegalArgumentException.class)
 	public void RefuseNotMyTurn() {
 		List<Action> actions = Arrays.asList(offer1);
@@ -281,12 +272,12 @@
 				settings, null, null);
 
-		state = state.with(party1, offer1);
-		assertTrue(state.isFinal(NOW));
-		assertEquals(
-				"geniusweb.protocol.ProtocolException: party1:Party does not have the turn ",
-				state.getError().toString());
-	}
-
-	@Test
+		state.with(party1, offer1);
+//		assertTrue(state.isFinal(NOW));
+//		assertEquals(
+//				"geniusweb.protocol.ProtocolException: party1:Party does not have the turn ",
+//				state.getError().toString());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
 	public void RefuseNullAccept() {
 		List<Action> actions = Arrays.asList(offer1);
@@ -297,9 +288,7 @@
 		state = state.with(party2, nullaccept);
 		assertTrue(state.isFinal(NOW));
-		assertTrue(state.getError().toString().matches(
-				".*party2.*Party accepts a bid differing from the last offer.*"));
-	}
-
-	@Test
+	}
+
+	@Test(expected = IllegalArgumentException.class)
 	public void RefuseNullAction() {
 		List<Action> actions = Arrays.asList(offer1);
@@ -308,7 +297,4 @@
 
 		state = state.with(party2, null);
-		assertEquals(
-				"geniusweb.protocol.ProtocolException: party2:action is null",
-				state.getError().toString());
 	}
 
Index: protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java	(revision 9)
+++ protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java	(revision 10)
@@ -20,4 +20,5 @@
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.junit.Test;
@@ -39,7 +40,8 @@
 import geniusweb.progress.Progress;
 import geniusweb.protocol.ProtocolException;
-import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
 import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
 import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
+import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
+import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
 import geniusweb.references.Parameters;
 import geniusweb.references.PartyRef;
@@ -73,6 +75,6 @@
 	private final PartyRef party2ref = mock(PartyRef.class);
 	private final SAOPSettings settings = mock(SAOPSettings.class);
-	private final PartyWithProfile party1 = mock(PartyWithProfile.class);
-	private final PartyWithProfile party2 = mock(PartyWithProfile.class);
+	private final SaopPartyWithProfile team1 = mock(SaopPartyWithProfile.class);
+	private final SaopPartyWithProfile team2 = mock(SaopPartyWithProfile.class);
 	private SAOP saop;
 	private ProtocolToPartyConnFactory factory;
@@ -80,5 +82,5 @@
 	private ProtocolToPartyConn conn1 = mock(ProtocolToPartyConn.class),
 			conn2 = mock(ProtocolToPartyConn.class);
-	private Map<PartyId, PartyWithProfile> partyprofiles;
+	private Map<PartyId, SaopPartyWithProfile> partyprofiles;
 	private Progress progress = mock(Progress.class);
 	private ProfileRef profile1;
@@ -101,17 +103,20 @@
 			throws URISyntaxException, IOException, NoResourcesNowException {
 		SAOP = new ProtocolRef("SAOP");
-		when(party1.getParty()).thenReturn(partywithparam1);
-		when(party2.getParty()).thenReturn(partywithparam2);
+		when(team1.getParty()).thenReturn(partywithparam1);
+		when(team2.getParty()).thenReturn(partywithparam2);
+		when(team1.getAllParties()).thenReturn(Arrays.asList(team1));
+		when(team2.getAllParties()).thenReturn(Arrays.asList(team2));
 
 		partyprofiles = new HashMap<>();
-		partyprofiles.put(PARTY1ID, party1);
-		partyprofiles.put(PARTY2ID, party2);
+		partyprofiles.put(PARTY1ID, team1);
+		partyprofiles.put(PARTY2ID, team2);
 
 		when(deadlinetime.getDuration()).thenReturn(1000l);
 
-		List<PartyWithProfile> participants = new ArrayList<>();
-		participants.add(party1);
-		participants.add(party2);
-		when(settings.getParticipants()).thenReturn(participants);
+		List<TeamOfPartiesAndProfiles> teams = new ArrayList<>();
+		teams.add(team1);
+		teams.add(team2);
+		when(settings.getTeams()).thenReturn(teams);
+		when(settings.getAllParties()).thenReturn(Arrays.asList(team1, team2));
 		when(settings.getDeadline()).thenReturn(deadlinetime);
 
@@ -126,7 +131,7 @@
 
 		profile1 = mock(ProfileRef.class);
-		when(party1.getProfile()).thenReturn(profile1);
+		when(team1.getProfile()).thenReturn(profile1);
 		profile2 = mock(ProfileRef.class);
-		when(party2.getProfile()).thenReturn(profile2);
+		when(team2.getProfile()).thenReturn(profile2);
 
 		mockState(connectedstate, "connected state");
@@ -157,5 +162,7 @@
 		when(state.getSettings()).thenReturn(settings);
 		when(state.getConnections()).thenReturn(connectionswithparties);
-		when(state.getPartyProfiles()).thenReturn(partyprofiles);
+		when(state.getPartyProfiles())
+				.thenReturn(partyprofiles.entrySet().stream().collect(
+						Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
 		when(state.getProgress()).thenReturn(progress);
 		when(state.with(any(ProtocolToPartyConn.class),
Index: protocol/src/test/java/geniusweb/protocol/session/saop/SaopPartyWithProfileTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/session/saop/SaopPartyWithProfileTest.java	(revision 10)
+++ protocol/src/test/java/geniusweb/protocol/session/saop/SaopPartyWithProfileTest.java	(revision 10)
@@ -0,0 +1,110 @@
+package geniusweb.protocol.session.saop;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
+import geniusweb.references.Parameters;
+import geniusweb.references.PartyRef;
+import geniusweb.references.PartyWithParameters;
+import geniusweb.references.ProfileRef;
+import tudelft.utilities.junit.GeneralTests;
+
+public class SaopPartyWithProfileTest
+		extends GeneralTests<SaopPartyWithProfile> {
+
+	private PartyRef party1, party1a, party2, party3;
+	private ProfileRef profile1, profile2;
+	private SaopPartyWithProfile partyprof1, partyprof1a, partyprof2,
+			partyprof3, partyprof4;
+	private final String serialized = "{\"party\":{\"partyref\":\"ws:party1\",\"parameters\":{}},\"profile\":\"ws:profile1\"}";
+
+	@Before
+	public void before() throws URISyntaxException {
+		party1 = new PartyRef(new URI("ws:party1"));
+		party1a = new PartyRef(new URI("ws:party1"));
+		party2 = new PartyRef(new URI("ws:party2"));
+		party3 = new PartyRef(new URI("http:party3"));
+
+		profile1 = new ProfileRef(new URI("ws:profile1"));
+		profile2 = new ProfileRef(new URI("ws:profile2"));
+
+		Parameters settings1 = new Parameters();
+		Parameters settings2 = new Parameters();
+		settings2.put("a", 1);
+
+		PartyWithParameters party1withparams1 = new PartyWithParameters(party1,
+				settings1);
+		PartyWithParameters party1withparams2 = new PartyWithParameters(party1,
+				settings2);
+		PartyWithParameters party2withparams1 = new PartyWithParameters(party2,
+				settings1);
+
+		partyprof1 = new SaopPartyWithProfile(party1withparams1, profile1);
+		partyprof1a = new SaopPartyWithProfile(party1withparams1, profile1);
+		partyprof2 = new SaopPartyWithProfile(party2withparams1, profile1);
+		partyprof3 = new SaopPartyWithProfile(party1withparams1, profile2);
+		partyprof4 = new SaopPartyWithProfile(party1withparams2, profile1);
+
+	}
+
+	@Override
+	public List<List<SaopPartyWithProfile>> getGeneralTestData() {
+		return Arrays.asList(Arrays.asList(partyprof1, partyprof1a),
+				Arrays.asList(partyprof2), Arrays.asList(partyprof3),
+				Arrays.asList(partyprof4));
+	}
+
+	@Override
+	public List<String> getGeneralTestStrings() {
+		return Arrays.asList(
+				"PartyWithProfile.PartyRef.ws:party1.,ProfileRef.ws:profile1.*",
+				"PartyWithProfile.PartyRef.ws:party2.,ProfileRef.ws:profile1.*",
+				"PartyWithProfile.PartyRef.ws:party1.,ProfileRef.ws:profile2.*",
+				"PartyWithProfile.PartyRef.ws:party1.\\{a=1\\},ProfileRef.ws:profile1.*");
+	}
+
+	@Test
+	public void smokeTest() throws URISyntaxException {
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void nullTest() throws URISyntaxException {
+		new SaopPartyWithProfile((PartyWithParameters) null, (ProfileRef) null);
+	}
+
+	@Test
+	public void testSerialize() throws JsonProcessingException {
+		ObjectMapper jackson = new ObjectMapper();
+
+		String json = jackson.writeValueAsString(partyprof1);
+		System.out.println(json);
+		assertEquals(serialized, json);
+	}
+
+	@Test
+	public void testDeserialize()
+			throws JsonParseException, JsonMappingException, IOException {
+		ObjectMapper jackson = new ObjectMapper();
+		// always used as part of bigger class, do not include class name
+		// and therfore can not serialize as TeamOfPartiesAndProfiles
+		TeamOfPartiesAndProfiles p = jackson.readValue(serialized,
+				SaopPartyWithProfile.class);
+		System.out.println(p);
+		assertEquals(partyprof1, p);
+	}
+
+}
Index: protocol/src/test/java/geniusweb/protocol/session/shaop/SHAOPSettingsTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/session/shaop/SHAOPSettingsTest.java	(revision 10)
+++ protocol/src/test/java/geniusweb/protocol/session/shaop/SHAOPSettingsTest.java	(revision 10)
@@ -0,0 +1,116 @@
+package geniusweb.protocol.session.shaop;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import geniusweb.deadline.DeadlineTime;
+import geniusweb.protocol.session.SessionSettings;
+import geniusweb.references.Parameters;
+import geniusweb.references.PartyRef;
+import geniusweb.references.PartyWithParameters;
+import geniusweb.references.PartyWithProfile;
+import geniusweb.references.ProfileRef;
+import tudelft.utilities.junit.GeneralTests;
+import tudelft.utilities.logging.ReportToLogger;
+
+public class SHAOPSettingsTest extends GeneralTests<SHAOPSettings> {
+
+	private final ObjectMapper jackson = new ObjectMapper();
+	private Parameters params = new Parameters();
+	private final String serialized = "{\"SHAOPSettings\":{\"participants\":[{\"cob\":{\"party\":{\"partyref\":\"party2\",\"parameters\":{}},\"profile\":\"profile1\"},\"shaop\":{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"}},{\"cob\":{\"party\":{\"partyref\":\"party4\",\"parameters\":{}},\"profile\":\"profile1\"},\"shaop\":{\"party\":{\"partyref\":\"party3\",\"parameters\":{}},\"profile\":\"profile1\"}}],\"deadline\":{\"deadlinetime\":{\"durationms\":1000}}}}";
+	private SHAOPSettings settings1, settings1a, settings2, settings3;
+	private ShaopTeam pair1, pair2, pair3;
+
+	@Before
+	public void before() throws URISyntaxException {
+		ProfileRef profile1 = new ProfileRef("profile1");
+		PartyWithParameters party1 = new PartyWithParameters(
+				new PartyRef("party1"), params);
+		PartyWithParameters party2 = new PartyWithParameters(
+				new PartyRef("party2"), params);
+		PartyWithParameters party3 = new PartyWithParameters(
+				new PartyRef("party3"), params);
+		PartyWithParameters party4 = new PartyWithParameters(
+				new PartyRef("party4"), params);
+		PartyWithParameters party5 = new PartyWithParameters(
+				new PartyRef("party5"), params);
+		PartyWithParameters party6 = new PartyWithParameters(
+				new PartyRef("party6"), params);
+
+		PartyWithProfile partyprof1 = new PartyWithProfile(party1, profile1);
+		PartyWithProfile partyprof2 = new PartyWithProfile(party2, profile1);
+		PartyWithProfile partyprof3 = new PartyWithProfile(party3, profile1);
+		PartyWithProfile partyprof4 = new PartyWithProfile(party4, profile1);
+		PartyWithProfile partyprof5 = new PartyWithProfile(party5, profile1);
+		PartyWithProfile partyprof6 = new PartyWithProfile(party6, profile1);
+
+		DeadlineTime deadline = new DeadlineTime(1000);
+		DeadlineTime deadline2 = new DeadlineTime(2000);
+		pair1 = new ShaopTeam(partyprof1, partyprof2);
+		pair2 = new ShaopTeam(partyprof3, partyprof4);
+		pair3 = new ShaopTeam(partyprof5, partyprof6);
+
+		settings1 = new SHAOPSettings(Arrays.asList(pair1, pair2), deadline);
+		settings1a = new SHAOPSettings(Arrays.asList(pair1, pair2), deadline);
+		settings2 = new SHAOPSettings(Arrays.asList(pair1, pair3), deadline);
+		settings3 = new SHAOPSettings(Arrays.asList(pair1, pair2), deadline2);
+	}
+
+	@Override
+	public List<List<SHAOPSettings>> getGeneralTestData() {
+		return Arrays.asList(Arrays.asList(settings1, settings1a),
+				Arrays.asList(settings2), Arrays.asList(settings3));
+	}
+
+	@Override
+	public List<String> getGeneralTestStrings() {
+		return Arrays.asList(
+				"SHAOPSettings.*Parties.*PartyWithProfile.*party1.*party2.*Parties.*party3.*party4.*DeadlineTime.*1000.*",
+				"SHAOPSettings.*Parties.*PartyWithProfile.*party1.*party2.*Parties.*party5.*party6.*DeadlineTime.*1000.*",
+				"SHAOPSettings.*Parties.*PartyWithProfile.*party1.*party2.*Parties.*party3.*party4.*DeadlineTime.*2000.*");
+	}
+
+	@Test
+	public void getProtocolTest() {
+		assertEquals("SHAOP", settings1.getProtocol(new ReportToLogger("test"))
+				.getRef().getURI().toString());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void constructorNoDeadlineTest() {
+		new SHAOPSettings(Arrays.asList(pair1, pair2), null);
+	}
+
+	@Test
+	public void testMaxRuntime() {
+		assertEquals((Double) 1.000, settings1.getMaxRunTime());
+	}
+
+	@Test
+	public void testDeserialize() throws IOException {
+		SessionSettings obj = jackson.readValue(serialized,
+				SessionSettings.class);
+		System.out.println(obj);
+		assertEquals(settings1, obj);
+	}
+
+	@Test
+	public void testSerialize()
+			throws JsonProcessingException, URISyntaxException {
+
+		String string = jackson.writeValueAsString(settings1);
+		System.out.println(string);
+		assertEquals(serialized, string);
+	}
+
+}
Index: protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsProtocolTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsProtocolTest.java	(revision 10)
+++ protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsProtocolTest.java	(revision 10)
@@ -0,0 +1,179 @@
+package geniusweb.protocol.tournament.allpermutations;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.math.BigInteger;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+import geniusweb.events.ProtocolEvent;
+import geniusweb.issuevalue.Bid;
+import geniusweb.protocol.CurrentNegoState;
+import geniusweb.protocol.NegoState;
+import geniusweb.protocol.SessionResult;
+import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
+import geniusweb.protocol.session.SessionProtocol;
+import geniusweb.protocol.session.SessionSettings;
+import geniusweb.protocol.session.SessionState;
+import geniusweb.references.PartyWithProfile;
+import geniusweb.references.ProtocolRef;
+import tudelft.utilities.listener.Listener;
+import tudelft.utilities.logging.ReportToLogger;
+
+public class AllPermutationsProtocolTest {
+
+	private final AllPermutationsState state = mock(AllPermutationsState.class),
+			newstate = mock(AllPermutationsState.class);
+	private final ReportToLogger log = new ReportToLogger("test");
+	private final AllPermutationsProtocol app = new AllPermutationsProtocol(
+			state, log);
+	private final ProtocolToPartyConnFactory factory = mock(
+			ProtocolToPartyConnFactory.class);
+	private final SessionSettings settings = mock(SessionSettings.class);
+	private final SessionState finalsessionstate = mock(SessionState.class);
+	private Bid agreement = mock(Bid.class);
+	private final long NOW = 1000;
+
+	@Before
+	public void before() {
+		when(state.getSize()).thenReturn(BigInteger.ZERO);
+		when(finalsessionstate.isFinal(anyLong())).thenReturn(true);
+		when(finalsessionstate.getSettings()).thenReturn(settings);
+		when(finalsessionstate.getAgreement()).thenReturn(agreement);
+		when(state.with(any())).thenReturn(newstate);
+	}
+
+	@Test
+	public void smokeTest() {
+	}
+
+	@Test
+	public void startTestNoSessions() {
+		AllPermutationsProtocol app = new AllPermutationsProtocol(state, log);
+		app.start(factory);
+
+	}
+
+	@Test
+	public void getDescrTest() {
+		assertNotNull(app.getDescription());
+	}
+
+	@Test
+	public void getStateTest() {
+		assertEquals(state, app.getState());
+	}
+
+	@Test
+	public void getRefTest() {
+		assertEquals("APP", app.getRef().getURI().toString());
+	}
+
+	@Test
+	public void runOneSessionTest() throws InterruptedException {
+		MockSessionProtocol sessionprotocol = startSession();
+		sessionprotocol.getListener();
+	}
+
+	@Test
+	public void runOneSessionAndUnhandledEvent() throws InterruptedException {
+		MockSessionProtocol sessionprotocol = startSession();
+		sessionprotocol.getListener().notifyChange(mock(ProtocolEvent.class));
+		verify(state, times(0)).with(any());
+	}
+
+	/**
+	 * Check that a started session correctly handles a session event.
+	 */
+	@Test
+	public void CurrentNegoStateEventTest() throws InterruptedException {
+		MockSessionProtocol sessionprotocol = startSession();
+
+		CurrentNegoState evt = mock(CurrentNegoState.class);
+		when(evt.getState()).thenReturn(finalsessionstate);
+		sessionprotocol.getListener().notifyChange(evt);
+
+		ArgumentCaptor<SessionResult> argument = ArgumentCaptor
+				.forClass(SessionResult.class);
+		verify(state, times(1)).with(argument.capture());
+		assertEquals(agreement, argument.getValue().getAgreement());
+		assertNull(argument.getValue().getError());
+	}
+
+	private MockSessionProtocol startSession() throws InterruptedException {
+		SessionSettings setting = mock(SessionSettings.class);
+		MockSessionProtocol sessionprotocol = new MockSessionProtocol();
+		when(setting.getProtocol(log)).thenReturn(sessionprotocol);
+		when(state.getNextSettings()).thenReturn(setting);
+
+		app.start(factory);
+		Thread.sleep(500); // allow app to start session
+		// this call should return fine, and have listener registered to our
+		// protocol. app now waits for a notification
+		return sessionprotocol;
+	}
+
+}
+
+/**
+ * 
+ * The protocol needs to record the listners, we need a listener to trigger
+ * further protocol actions. Mockito can't handle this, we mneed our own mock...
+ *
+ */
+class MockSessionProtocol implements SessionProtocol {
+	private final List<Listener<ProtocolEvent>> listeners = new LinkedList<>();
+
+	@Override
+	public void start(ProtocolToPartyConnFactory connectionfactory) {
+
+	}
+
+	@Override
+	public String getDescription() {
+		return null;
+	}
+
+	@Override
+	public NegoState getState() {
+		return null;
+	}
+
+	@Override
+	public ProtocolRef getRef() {
+		return null;
+	}
+
+	@Override
+	public void addParticipant(PartyWithProfile party) {
+	}
+
+	@Override
+	public void addListener(Listener<ProtocolEvent> l) {
+		listeners.add(l);
+	}
+
+	@Override
+	public void removeListener(Listener<ProtocolEvent> l) {
+	}
+
+	public Listener<ProtocolEvent> getListener() {
+		if (listeners.size() != 1) {
+			throw new IllegalStateException("Not having exactly 1 listener");
+		}
+		return listeners.get(0);
+	}
+
+}
Index: protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java	(revision 10)
+++ protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java	(revision 10)
@@ -0,0 +1,197 @@
+package geniusweb.protocol.tournament.allpermutations;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import geniusweb.deadline.DeadlineTime;
+import geniusweb.protocol.NegoSettings;
+import geniusweb.protocol.session.saop.SAOPSettings;
+import geniusweb.protocol.tournament.TournamentSettings;
+import geniusweb.references.Parameters;
+import geniusweb.references.PartyRef;
+import geniusweb.references.PartyWithParameters;
+import geniusweb.references.PartyWithProfile;
+import geniusweb.references.ProfileRef;
+import tudelft.utilities.junit.GeneralTests;
+import tudelft.utilities.logging.ReportToLogger;
+
+public class AllPermutationsSettingsTest
+		extends GeneralTests<AllPermutationsSettings> {
+
+	private final ObjectMapper jackson = new ObjectMapper();
+
+	private final String serialized = "{\"AllPermutationsSettings\":{\"parties\":[{\"partyref\":\"party1\",\"parameters\":{}},{\"partyref\":\"party2\",\"parameters\":{}}],\"reuseParties\":false,\"profiles\":[\"profile1\",\"profile2\",\"profile3\"],\"partiesPerSession\":2,\"sessionsettings\":{\"SAOPSettings\":{\"participants\":[],\"deadline\":{\"deadlinetime\":{\"durationms\":10000}}}}}}";
+	private AllPermutationsSettings settings, settings1a, settings2, settings3,
+			settings4;
+
+	private SAOPSettings saopsettings;
+
+	private ProfileRef profile1, profile2, profile3;
+
+	private List<PartyWithParameters> parties;
+
+	@Before
+	public void before() throws URISyntaxException {
+		PartyRef partyref1 = new PartyRef("party1");
+		PartyRef partyref2 = new PartyRef("party2");
+		PartyRef partyref3 = new PartyRef("party3");
+
+		Parameters params1 = new Parameters();
+		Parameters params2 = new Parameters();
+		Parameters params3 = new Parameters();
+
+		PartyWithParameters partywithparams1 = new PartyWithParameters(
+				partyref1, params1);
+		PartyWithParameters partywithparams2 = new PartyWithParameters(
+				partyref2, params2);
+		PartyWithParameters partywithparams3 = new PartyWithParameters(
+				partyref3, params3);
+
+		parties = Arrays.asList(partywithparams1, partywithparams2);
+		DeadlineTime deadline = new DeadlineTime(10000);
+
+		saopsettings = new SAOPSettings(Collections.emptyList(), deadline);
+
+		profile1 = new ProfileRef("profile1");
+		profile2 = new ProfileRef("profile2");
+		profile3 = new ProfileRef("profile3");
+
+		List<ProfileRef> profiles = Arrays.asList(profile1, profile2, profile3);
+
+		settings = new AllPermutationsSettings(parties, false, profiles, 2,
+				saopsettings);
+
+		settings1a = new AllPermutationsSettings(parties, false, profiles, 2,
+				saopsettings);
+
+		settings2 = new AllPermutationsSettings(Arrays.asList(partywithparams1,
+				partywithparams2, partywithparams3), false, profiles, 2,
+				saopsettings);
+
+		settings3 = new AllPermutationsSettings(parties, true, profiles, 2,
+				saopsettings);
+
+		settings4 = new AllPermutationsSettings(parties, false,
+				Arrays.asList(profile1, profile2, profile3, profile1), 2,
+				saopsettings);
+
+	}
+
+	@Override
+	public List<List<AllPermutationsSettings>> getGeneralTestData() {
+		return Arrays.asList(Arrays.asList(settings, settings1a),
+				Arrays.asList(settings2), Arrays.asList(settings3),
+				Arrays.asList(settings4));
+	}
+
+	@Override
+	public List<String> getGeneralTestStrings() {
+		return Arrays.asList(
+				"AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
+				"AllPermutationsSettings.*party1.*party2.*party3.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
+				"AllPermutationsSettings.*party1.*party2.*,true,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
+				"AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*profile1.*,2,SAOPSettings.*");
+	}
+
+	@Test
+	public void getProtocolTest() {
+		assertEquals("APP", settings.getProtocol(new ReportToLogger("test"))
+				.getRef().getURI().toString());
+	}
+
+	@Test
+	public void testDeserialize() throws IOException {
+		TournamentSettings obj = (TournamentSettings) jackson
+				.readValue(serialized, NegoSettings.class);
+		System.out.println(obj);
+		assertEquals(settings, obj);
+	}
+
+	@Test
+	public void testSerialize()
+			throws JsonProcessingException, URISyntaxException {
+
+		String string = jackson.writeValueAsString(settings);
+		System.out.println(string);
+		assertEquals(serialized, string);
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testNullParties() {
+		new AllPermutationsSettings(null, true,
+				Arrays.asList(profile1, profile2, profile3, profile1), 2,
+				saopsettings);
+
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testNoParties() {
+		new AllPermutationsSettings(Collections.emptyList(), true,
+				Arrays.asList(profile1, profile2, profile3, profile1), 2,
+				saopsettings);
+
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testNullProfiles() {
+		new AllPermutationsSettings(parties, true, null, 2, saopsettings);
+
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testInsufficientProfiles() {
+		new AllPermutationsSettings(parties, true,
+				Arrays.asList(profile1, profile2, profile3, profile1), 4,
+				saopsettings);
+
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testNullSessionSettings() {
+		new AllPermutationsSettings(parties, true,
+				Arrays.asList(profile1, profile2, profile3, profile1), 4, null);
+
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testOnePartyPerSession() {
+		new AllPermutationsSettings(parties, true,
+				Arrays.asList(profile1, profile2, profile3, profile1), 1,
+				saopsettings);
+
+	}
+
+	@Test
+	public void getMaxRuntimeTest() {
+		assertEquals(BigInteger.valueOf(6), settings.permutations().size());
+		assertEquals((Double) (6d * 12), settings.getMaxRunTime());
+	}
+
+	@Test
+	public void makeCobTest() throws URISyntaxException {
+		// Check that the cob party gets profile without the query part
+		String profilebase = "ws://1.2.3.4:8080/profilesserver-a.b.c/websocket/get/someprofile";
+		String partybase = "http://131.180.202.213:8080/partiesserver/run/";
+		String query = "?a=2&partial=4";
+		PartyWithProfile partyprofile = AllPermutationsSettings.makeCob(
+				new PartyRef(partybase + "simpleshaop-1.0.0"),
+				new ProfileRef(profilebase + query));
+		assertEquals(profilebase,
+				partyprofile.getProfile().getURI().toString());
+		assertEquals(partybase + "comparebids-1.0.0",
+				partyprofile.getParty().getPartyRef().getURI().toString());
+	}
+
+}
Index: protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsStateTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsStateTest.java	(revision 10)
+++ protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsStateTest.java	(revision 10)
@@ -0,0 +1,95 @@
+package geniusweb.protocol.tournament.allpermutations;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+import geniusweb.protocol.SessionResult;
+import geniusweb.protocol.session.SessionSettings;
+import geniusweb.references.PartyWithProfile;
+import tudelft.utilities.immutablelist.ImmutableList;
+
+public class AllPermutationsStateTest {
+
+	private final AllPermutationsSettings toursettings = mock(
+			AllPermutationsSettings.class);;
+	@SuppressWarnings("unchecked")
+	private final List<SessionResult> results = mock(List.class);
+	@SuppressWarnings("unchecked")
+	private final ImmutableList<SessionSettings> settings = mock(
+			ImmutableList.class);
+	private final AllPermutationsState state = new AllPermutationsState(
+			toursettings, settings, results);
+	private final SessionSettings session7settings = mock(
+			SessionSettings.class);
+	private final long NOW = 1000;
+
+	@SuppressWarnings("unchecked")
+	private final List<PartyWithProfile> participants = mock(List.class);
+
+	@Test
+	public void getResultsTest() {
+		assertEquals(results, state.getResults());
+	}
+
+	@Test
+	public void isFinalTestFalse() {
+		when(settings.size()).thenReturn(BigInteger.TEN);
+		when(results.size()).thenReturn(11);
+		assertFalse(state.isFinal(NOW));
+	}
+
+	@Test
+	public void isFinalTestTrue() {
+		when(settings.size()).thenReturn(BigInteger.TEN);
+		when(results.size()).thenReturn(10);
+		assertTrue(state.isFinal(NOW));
+	}
+
+	@Test
+	public void getNextSetting() {
+		prepareNextSettings();
+		assertEquals(session7settings, state.getNextSettings());
+	}
+
+	private void prepareNextSettings() {
+		when(results.size()).thenReturn(7); // result 0..6
+		when(settings.size()).thenReturn(BigInteger.TEN);
+		// when(session7settings.getTeams()).thenReturn(participants);
+		when(session7settings.getAllParties()).thenReturn(participants);
+		when(settings.get(BigInteger.valueOf(7))).thenReturn(session7settings);
+
+	}
+
+	@Test
+	public void withTest() {
+		prepareNextSettings();
+		ArrayList<SessionResult> results1 = new ArrayList<>();
+		for (int n = 0; n < 7; n++) {
+			results1.add(mock(SessionResult.class));
+		}
+		// use state with "real" results... to allow array copy in with
+		AllPermutationsState state = new AllPermutationsState(toursettings,
+				settings, results1);
+
+		when(settings.size()).thenReturn(BigInteger.TEN);
+		when(settings.get(BigInteger.valueOf(7))).thenReturn(session7settings);
+
+		SessionResult result = mock(SessionResult.class);
+		when(result.getParticipants()).thenReturn(participants);
+		AllPermutationsState state1 = state.with(result);
+
+		assertEquals(null, state1.getError());
+		assertEquals(8, state1.getResults().size());
+		assertEquals(toursettings, state1.getSettings());
+
+	}
+}
