diff --git a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/data/StudentsStoreImpl.java b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/data/StudentsStoreImpl.java index ee9b2da..6e27ea3 100644 --- a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/data/StudentsStoreImpl.java +++ b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/data/StudentsStoreImpl.java @@ -59,7 +59,7 @@ public void importData(BufferedReader reader) throws IOException { boolean endReached = false; while (!endReached && (record = reader.readLine()) != null) { if (record.equalsIgnoreCase(RouletteV1Protocol.CMD_LOAD_ENDOFDATA_MARKER)) { - LOG.log(Level.INFO, "End of stream reached. New students have been added to the store. How many? We'll tell you when the lab is complete..."); + LOG.log(Level.INFO, "End of stream reached. {0} New students have been added to the store.", studentsToAdd.size()); endReached = true; } else { LOG.log(Level.INFO, "Adding student {0} to the store.", record); diff --git a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/IRouletteV2Client.java b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/IRouletteV2Client.java index 5020d64..2f9f1dd 100644 --- a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/IRouletteV2Client.java +++ b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/IRouletteV2Client.java @@ -7,6 +7,7 @@ /** * * @author Olivier Liechti + * @author Max Caduff */ public interface IRouletteV2Client extends IRouletteV1Client { @@ -28,4 +29,22 @@ public interface IRouletteV2Client extends IRouletteV1Client { */ public List listStudents() throws IOException; + /** + * + * @return the number of students added in the last batch. + */ + public int getNumberOfStudentAdded(); + + /** + * + * @return the number of commands sent to the server. + */ + public int getNumberOfCommands(); + + /** + * + * @return if the last command has succeeded or not. + */ + public boolean checkSuccessOfCommand(); + } diff --git a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/RouletteV1ClientImpl.java b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/RouletteV1ClientImpl.java index f2df5cd..5c7e19c 100644 --- a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/RouletteV1ClientImpl.java +++ b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/RouletteV1ClientImpl.java @@ -20,51 +20,98 @@ * This class implements the client side of the protocol specification (version 1). * * @author Olivier Liechti + * @author Max Caduff */ public class RouletteV1ClientImpl implements IRouletteV1Client { - private static final Logger LOG = Logger.getLogger(RouletteV1ClientImpl.class.getName()); + protected static final Logger LOG = Logger.getLogger(RouletteV1ClientImpl.class.getName()); + private Socket clientSocket ; + protected BufferedReader reader; + protected PrintWriter writer; + @Override public void connect(String server, int port) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + + clientSocket = new Socket(server, port) ; + + reader = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()) ); + writer = new PrintWriter( new OutputStreamWriter(clientSocket.getOutputStream()) ); + LOG.log(Level.INFO, "Connection. Server says: {0}", reader.readLine()); } @Override public void disconnect() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + + if (isConnected()) { + writer.println(RouletteV1Protocol.CMD_BYE); + writer.flush(); + clientSocket.close(); + } } + @Override public boolean isConnected() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return clientSocket != null && !clientSocket.isClosed() && clientSocket.isConnected() ; } @Override public void loadStudent(String fullname) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + + writer.println(RouletteV1Protocol.CMD_LOAD); + writer.flush(); + LOG.log(Level.INFO, "Begin loading. Server says: {0}", reader.readLine()); + + + writer.println(fullname); + writer.println(RouletteV1Protocol.CMD_LOAD_ENDOFDATA_MARKER); + writer.flush(); + LOG.log(Level.INFO, "End of loading. Server says: {0}", reader.readLine()); + } @Override public void loadStudents(List students) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + + writer.println(RouletteV1Protocol.CMD_LOAD); + writer.flush(); + LOG.log(Level.INFO, "Begin loading. Server says: {0}", reader.readLine()); + + for (Student s : students) { + writer.println(s.getFullname()); + } + writer.println(RouletteV1Protocol.CMD_LOAD_ENDOFDATA_MARKER); + writer.flush(); + LOG.log(Level.INFO, "End of loading. Server says: {0}", reader.readLine()); + } @Override public Student pickRandomStudent() throws EmptyStoreException, IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + + writer.println(RouletteV1Protocol.CMD_RANDOM); + writer.flush(); + RandomCommandResponse parsedAnswer = JsonObjectMapper.parseJson(reader.readLine(), RandomCommandResponse.class); + + if (parsedAnswer.getError() != null ) + throw new EmptyStoreException(); + + return new Student(parsedAnswer.getFullname()); } @Override public int getNumberOfStudents() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + writer.println(RouletteV1Protocol.CMD_INFO); + writer.flush(); + return JsonObjectMapper.parseJson(reader.readLine(), InfoCommandResponse.class).getNumberOfStudents(); } @Override public String getProtocolVersion() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + writer.println(RouletteV1Protocol.CMD_INFO); + writer.flush(); + return JsonObjectMapper.parseJson(reader.readLine(), InfoCommandResponse.class).getProtocolVersion(); } - - } diff --git a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2ClientImpl.java b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2ClientImpl.java index 784db93..702031d 100644 --- a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2ClientImpl.java +++ b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2ClientImpl.java @@ -1,27 +1,113 @@ package ch.heigvd.res.labs.roulette.net.client; +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; import ch.heigvd.res.labs.roulette.data.JsonObjectMapper; import ch.heigvd.res.labs.roulette.data.Student; import ch.heigvd.res.labs.roulette.data.StudentsList; import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; import java.io.IOException; import java.util.List; +import java.util.logging.Level; /** * This class implements the client side of the protocol specification (version 2). * * @author Olivier Liechti + * @author Max Caduff */ public class RouletteV2ClientImpl extends RouletteV1ClientImpl implements IRouletteV2Client { + private int cmdCounter = 0; + private int lastNbOfStudentsAdded = 0; + private boolean cmdSuccess = false; + @Override public void clearDataStore() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + cmdSuccess = false; + writer.println(RouletteV2Protocol.CMD_CLEAR); + writer.flush(); + LOG.log(Level.INFO, "Data erased. Server says: {0}", reader.readLine()); + cmdCounter++; + cmdSuccess = true; } @Override public List listStudents() throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + cmdSuccess = false; + writer.println(RouletteV2Protocol.CMD_LIST); + writer.flush(); + cmdCounter++; + List lst = JsonObjectMapper.parseJson(reader.readLine(), StudentsList.class ).getStudents(); + cmdSuccess = true; + return lst; + } + + + @Override + public void loadStudent(String fullname) throws IOException { + + cmdSuccess = false; + super.loadStudent(fullname); + cmdSuccess = true; + cmdCounter++; + lastNbOfStudentsAdded = 1; + } + + @Override + public void loadStudents(List students) throws IOException { + + cmdSuccess = false; + super.loadStudents(students); + cmdSuccess = true; + cmdCounter++; + lastNbOfStudentsAdded = students.size(); + } + + @Override + public Student pickRandomStudent() throws EmptyStoreException, IOException { + cmdSuccess = false; + cmdCounter++; + Student rnd = super.pickRandomStudent(); + cmdSuccess = true; + return rnd; + } + + @Override + public int getNumberOfStudents() throws IOException { + cmdCounter++; + cmdSuccess = false; + int nb = super.getNumberOfStudents(); + cmdSuccess = true; + return nb; + } + + @Override + public String getProtocolVersion() throws IOException { + cmdCounter++; + cmdSuccess = false; + String v = super.getProtocolVersion(); + cmdSuccess = true; + return v; + } + + @Override + public int getNumberOfStudentAdded() { + return lastNbOfStudentsAdded; + } + + @Override + public int getNumberOfCommands() { + return cmdCounter; + } + public boolean checkSuccessOfCommand() { + return cmdSuccess; + } + + @Override + public void disconnect() throws IOException { + cmdCounter++; + cmdSuccess = false; + super.disconnect(); + cmdSuccess = true; } - } diff --git a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/ByeCommandResponse.java b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/ByeCommandResponse.java new file mode 100644 index 0000000..9537883 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/ByeCommandResponse.java @@ -0,0 +1,26 @@ +package ch.heigvd.res.labs.roulette.net.protocol; + +/** + * Created on 05.04.18. + * This class is used to serialize/deserialize the response sent by the server + * when processing the "BYE" command defined in the protocol specification. + * @author Max Caduff + */ +public class ByeCommandResponse { + private String status = "failed"; + private int numberOfCommands = 0; + + public ByeCommandResponse(int nbCommands) { + numberOfCommands = nbCommands; + status = "success"; + } + + public String getStatus() { + return status; + } + + public int getNumberOfCommands() { + return numberOfCommands; + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/LoadCommandResponse.java b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/LoadCommandResponse.java new file mode 100644 index 0000000..28a0831 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/LoadCommandResponse.java @@ -0,0 +1,31 @@ +package ch.heigvd.res.labs.roulette.net.protocol; + +/** + * Created on 05.04.18. + * This class is used to serialize/deserialize the response sent by the server + * when processing the "LOAD" command defined in the protocol specification. + * + * @author Max Caduff + */ +public class LoadCommandResponse { + private String status = "new"; + private int numberOfNewStudents = -1; + + public void setNumberOfNewStudents(int numberOfNewStudents) { + this.numberOfNewStudents = numberOfNewStudents; + status = "success"; + } + + public void setError() { + status = "error"; + } + + public String getStatus() { + return status; + } + + public int getNumberOfNewStudents() { + return numberOfNewStudents; + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/RouletteV2Protocol.java b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/RouletteV2Protocol.java index f63e81d..82d182e 100644 --- a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/RouletteV2Protocol.java +++ b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/protocol/RouletteV2Protocol.java @@ -4,9 +4,11 @@ * This class defines constants for the Roulette Protocol (version 2) * * @author Olivier Liechti + * @author Max Caduff */ public class RouletteV2Protocol extends RouletteV1Protocol { + public final static int DEFAULT_PORT = 2613; public final static String VERSION = "2.0"; public final static String CMD_CLEAR = "CLEAR"; @@ -16,4 +18,7 @@ public class RouletteV2Protocol extends RouletteV1Protocol { public final static String[] SUPPORTED_COMMANDS = new String[]{CMD_HELP, CMD_RANDOM, CMD_LOAD, CMD_INFO, CMD_BYE, CMD_CLEAR, CMD_LIST}; + // easter egg + public final static String FRENCHIE = "BAILLE"; + } diff --git a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/server/RouletteV2ClientHandler.java b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/server/RouletteV2ClientHandler.java index b858dcd..04a2582 100644 --- a/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/server/RouletteV2ClientHandler.java +++ b/QuizRouletteServer-build/QuizRouletteServer-code/src/main/java/ch/heigvd/res/labs/roulette/net/server/RouletteV2ClientHandler.java @@ -1,24 +1,120 @@ package ch.heigvd.res.labs.roulette.net.server; -import ch.heigvd.res.labs.roulette.data.IStudentsStore; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import ch.heigvd.res.labs.roulette.data.*; +import ch.heigvd.res.labs.roulette.net.protocol.*; + +import java.io.*; +import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; /** * This class implements the Roulette protocol (version 2). * * @author Olivier Liechti + * @author Max Caduff */ public class RouletteV2ClientHandler implements IClientHandler { + final static Logger LOG = Logger.getLogger(RouletteV2ClientHandler.class.getName()); + private IStudentsStore store; + + public RouletteV2ClientHandler(IStudentsStore store) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of gen + this.store = store; } @Override public void handleClientConnection(InputStream is, OutputStream os) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(os)); + + writer.println("Hello! Type HELP to get the available commands"); + writer.flush(); + + String command; + boolean done = false; + int commandCounter = 0; + + while (!done && ((command = reader.readLine()) != null)) { + LOG.log(Level.INFO, "COMMAND: {0}", command); + switch (command.toUpperCase()) { + + case RouletteV2Protocol.CMD_RANDOM: + RandomCommandResponse rcResponse = new RandomCommandResponse(); + try { + rcResponse.setFullname(store.pickRandomStudent().getFullname()); + } catch (EmptyStoreException ex) { + rcResponse.setError("There is no student, you cannot pick a random one"); + } + writer.println(JsonObjectMapper.toJson(rcResponse)); + writer.flush(); + commandCounter++; + break; + + case RouletteV2Protocol.CMD_HELP: + writer.println("Commands: " + Arrays.toString(RouletteV2Protocol.SUPPORTED_COMMANDS)); + commandCounter++; + break; + case RouletteV2Protocol.CMD_INFO: + InfoCommandResponse response = new InfoCommandResponse(RouletteV2Protocol.VERSION, store.getNumberOfStudents()); + writer.println(JsonObjectMapper.toJson(response)); + writer.flush(); + commandCounter++; + break; + + case RouletteV2Protocol.CMD_LOAD: + LoadCommandResponse loadAnswer = new LoadCommandResponse(); + writer.println(RouletteV2Protocol.RESPONSE_LOAD_START); + writer.flush(); + try { + int actualSize = store.getNumberOfStudents(); + store.importData(reader); + loadAnswer.setNumberOfNewStudents(store.getNumberOfStudents() - actualSize); + } + catch (IOException e) { + loadAnswer.setError(); + } + writer.println(JsonObjectMapper.toJson(loadAnswer)); + writer.flush(); + commandCounter++; + break; + + case RouletteV2Protocol.CMD_LIST: + StudentsList listAnswer = new StudentsList(); + listAnswer.addAll( store.listStudents()); + writer.println(JsonObjectMapper.toJson( listAnswer)); + writer.flush(); + commandCounter++; + break; + + case RouletteV2Protocol.CMD_CLEAR: + store.clear(); + writer.println(RouletteV2Protocol.RESPONSE_CLEAR_DONE); + writer.flush(); + commandCounter++; + break; + + case RouletteV2Protocol.CMD_BYE: + commandCounter++; + ByeCommandResponse byeAnswer = new ByeCommandResponse(commandCounter); + writer.println(JsonObjectMapper.toJson(byeAnswer)); + done = true; + break; + + case RouletteV2Protocol.FRENCHIE: + writer.println("Are you french?"); + break; + + default: + writer.println("Huh? please use HELP if you don't know what commands are available."); + writer.flush(); + break; + } + writer.flush(); + } + } } + + diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/FabriceMbassiRouletteV2Test.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/FabriceMbassiRouletteV2Test.java new file mode 100644 index 0000000..83259ca --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/FabriceMbassiRouletteV2Test.java @@ -0,0 +1,74 @@ +package ch.heigvd.res.labs.roulette.net.client; + + import ch.heigvd.res.labs.roulette.data.EmptyStoreException; + import ch.heigvd.res.labs.roulette.data.Student; + import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; + import ch.heigvd.schoolpulse.TestAuthor; + import org.junit.Rule; + import org.junit.Test; + import org.junit.rules.ExpectedException; + + import java.io.*; + import java.net.Socket; + import java.util.LinkedList; + + import static org.junit.Assert.assertEquals; + import static org.junit.Assert.assertTrue; + import static org.junit.Assert.assertFalse; + + public class FabriceMbassiRouletteV2Test { + + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + public void clearServerAfterClearCommand() throws IOException, EmptyStoreException{ + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("Fabrice"); + client.loadStudent("Mbassi"); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + /* + public void ServerListStudents() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + + Student fa = new Student("Fabrice"); + Student mb = new Student ("Mbassi"); + + client.loadStudent("Fabrice"); + client.loadStudent("Mbassi"); + + List expectedList = new ArrayList<> (); + expectedList.add(Fabrice); + expectedList.add(Mbassi); + + assertEquals(expectedList, client.listStudents()); + + expectedList.add(erica); + + assertNotEquals(expectedList, client.listStudents()); + + } + */ + public void ConnectedClientTestStart() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + + public void ConnectToARouletteServerOk() throws IOException{ + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + public void NumberOfVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + } \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AdamZouariTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AdamZouariTest.java new file mode 100644 index 0000000..b320338 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AdamZouariTest.java @@ -0,0 +1,97 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Adam Zouari + * @author Nair Alic + */ +public class RouletteV2AdamZouariTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "AdamZouari") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + @Test + @TestAuthor(githubId = "AdamZouari") + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + @Test + @TestAuthor(githubId = "AdamZouari") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "AdamZouari") + public void theServerShouldHaveZeroStudentsAfterClear() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.loadStudent("Adam"); + client.loadStudent("Nair"); + client.clearDataStore(); + int numberOfStudents = client.getNumberOfStudents(); + assertEquals(0, numberOfStudents); + } + + @Test + @TestAuthor(githubId = "AdamZouari") + public void theServerShouldStillHaveZeroStudentsAfterClear() throws IOException { + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + + + @Test + @TestAuthor(githubId = "AdamZouari") + public void theServerShouldListStudents() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + + Student adam = new Student("Adam"); + Student nair = new Student ("Nair"); + Student olivier = new Student ("Olivier"); + + client.loadStudent("Adam"); + client.loadStudent("Nair"); + + List expectedList = new ArrayList<> (); + expectedList.add(adam); + expectedList.add(nair); + + assertEquals(expectedList, client.listStudents()); + + expectedList.add(olivier); + + assertNotEquals(expectedList, client.listStudents()); + + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AmadeousTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AmadeousTest.java new file mode 100644 index 0000000..02aad6f --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AmadeousTest.java @@ -0,0 +1,114 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; + +import static org.junit.Assert.*; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 1) + * + * @author Julien Biefer (Amadeous) et Léo Cortès (Schnoudli) + */ +public class RouletteV2AmadeousTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "amadeous") + public void sendingClearCommandShouldClearTheServer() throws IOException { + // As IRouletteV2Client extedns IRouletteV1Client, we can simply cast it + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.loadStudent("Test"); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "amadeous") + public void askingListOfStudentShouldReturnACorrectList() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.loadStudent("Test1"); + client.loadStudent("Test2"); + client.loadStudent("Test3"); + + assertEquals("Test1", client.listStudents().get(0).getFullname()); + assertEquals("Test2", client.listStudents().get(1).getFullname()); + assertEquals("Test3", client.listStudents().get(2).getFullname()); + } + + @Test + @TestAuthor(githubId = "amadeous") + public void askingListOfStudentWhenThereIsNoStudentShouldReturnAnEmptyList() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + assertEquals(0, client.getNumberOfStudents()); + assertEquals(0, client.listStudents().size()); + } + + @Test + @TestAuthor(githubId = "amadeous") + public void loadingAStudentShouldBeSuccessful() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + int actualNb = client.getNumberOfStudents(); + client.loadStudent("Test"); + + assertEquals("Test", client.listStudents().get(actualNb).getFullname()); + } + + @Test + @TestAuthor(githubId = "amadeous") + public void loadingAStudentShouldIncreaseTheNumberOfStudentStored() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + int beforeLoad = client.getNumberOfStudents(); + client.loadStudent("Test"); + int afterLoad = client.getNumberOfStudents(); + assertTrue(beforeLoad < afterLoad); + } + + @Test + @TestAuthor(githubId = "amadeous") + public void sendingByeShouldReturnTheCorrectNumberOfSendCommands() throws IOException, EmptyStoreException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.getNumberOfStudents(); + client.getProtocolVersion(); + boolean exceptionThrown = false; + try { + client.pickRandomStudent(); + } catch (EmptyStoreException e) { + exceptionThrown = true; + } + client.disconnect(); + + assertTrue(exceptionThrown); + // Uses the additional method getNumberOfCommands as suggested in the RES 2018 - Annonces Telegram Channel + assertEquals(4, client.getNumberOfCommands()); + } + + @Test + @TestAuthor(githubId = "amadeous") + // This is an adaptation of the same test for v1 + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + /* + @Test + @TestAuthor(githubId = "amadeous") + public void theServerShouldReturnTheCorrectDefaultPort() throws IOException { + // Not for the ephemeral pair!! + assertEquals(roulettePair.getServer().getPort(), RouletteV2Protocol.DEFAULT_PORT); + } + */ + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AngoranceTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AngoranceTest.java new file mode 100644 index 0000000..03d85ec --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2AngoranceTest.java @@ -0,0 +1,146 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Olivier Liechti + * + * @modifiedBy Daniel Gonzalez Lopez, Héléna Line Reymond + */ +public class RouletteV2AngoranceTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = {"Angorance", "LNAline"}) + public void theServerShouldClearStudents() throws IOException { + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + // Add students on the server + List serverStudents = new ArrayList<>(); + + serverStudents.add(new Student("Sacha")); + serverStudents.add(new Student("Olivier")); + serverStudents.add(new Student("Fabienne")); + + client.loadStudents(serverStudents); + + // Clear the list of students from the client + assertEquals(serverStudents.size(), client.getNumberOfStudents()); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = {"Angorance", "LNAline"}) + public void theServerShouldListStudents() throws IOException { + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + // Add students on the server + List serverStudents = new ArrayList<>(); + + serverStudents.add(new Student("Sacha")); + serverStudents.add(new Student("Olivier")); + serverStudents.add(new Student("Fabienne")); + + client.loadStudents(serverStudents); + + // Get the list of students from the client + List clientStudents = client.listStudents(); + + // Check if the list of student is the same on client and server + assertEquals(serverStudents.size(), client.getNumberOfStudents()); + + assertTrue(clientStudents.containsAll(serverStudents)); + } + + @Test + @TestAuthor(githubId = {"Angorance", "LNAline"}) + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = {"Angorance", "LNAline"}) + public void theServerShouldReturnTheCorrectNumberOfNewStudents() throws IOException { + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + // Add students on the server + List serverStudents = new ArrayList<>(); + + serverStudents.add(new Student("Sacha")); + serverStudents.add(new Student("Olivier")); + serverStudents.add(new Student("Fabienne")); + + client.loadStudents(serverStudents); + + assertEquals(3, client.getNumberOfStudentAdded()); + + client.loadStudent("Lastone"); + + assertEquals(1, client.getNumberOfStudentAdded()); + } + + @Test + @TestAuthor(githubId = {"Angorance", "LNAline"}) + public void theServerShouldReturnTheCorrectNumberOfCommandsExecuted() throws IOException, EmptyStoreException { + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + client.getProtocolVersion(); // 1 + + // Add students on the server + List serverStudents = new ArrayList<>(); + + serverStudents.add(new Student("Sacha")); + serverStudents.add(new Student("Olivier")); + serverStudents.add(new Student("Fabienne")); + + client.loadStudents(serverStudents); // 2 + + client.getNumberOfStudents(); // 3 + + client.pickRandomStudent(); // 4 + + client.listStudents(); // 5 + + client.clearDataStore(); // 6 + + client.disconnect(); // 7 + + assertEquals(7, client.getNumberOfCommands()); + } + + @Test + @TestAuthor(githubId = {"Angorance", "LNAline"}) + public void theServerShouldReturnTheStatusOfTheExecutedCommand() throws IOException { + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + client.loadStudent("Hilarb"); + + assertTrue(client.checkSuccessOfCommand()); + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2DumoriaTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2DumoriaTest.java new file mode 100644 index 0000000..60059bf --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2DumoriaTest.java @@ -0,0 +1,172 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.res.labs.roulette.net.server.RouletteServer; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.IOException; +import java.util.List; + +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Benjamin Thomas + */ +public class RouletteV2DumoriaTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "Dumoria") + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldHaveZeroStudentsAtStart() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + int numberOfStudents = client.getNumberOfStudents(); + assertEquals(0, numberOfStudents); + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldStillHaveZeroStudentsAtStart() throws IOException { + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + + //------------------------------------ + + /* + @Test + @TestAuthor(githubId = "Dumoria") + public void theClientShouldBeConnectedToTheRightPort() { + int port = roulettePair.getServer().getPort(); + assertEquals(RouletteV2Protocol.DEFAULT_PORT, port); + // Not for the ephemeral server! + } + */ + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldBeAbleToClearAnEmptyList() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldClearAllTheData() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + + client.loadStudent("Chris"); + client.loadStudent("Ben"); + assertEquals(2, client.getNumberOfStudents()); + + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldReturnAnEmptyList() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + + List students = client.listStudents(); + + assertTrue(students.isEmpty()); + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldListAllTheStudent() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.loadStudent("Chris"); + client.loadStudent("Ben"); + + List students = client.listStudents(); + + assertEquals("Chris", students.get(0).getFullname()); + assertEquals("Ben", students.get(1).getFullname()); + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldReturnTheRightNumberOfNewStudents() throws IOException, EmptyStoreException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("Chris"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("Ben"); + assertEquals(2, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "Dumoria") + public void theServerShouldReturnTheRightNumberOfCommands() throws IOException, EmptyStoreException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.loadStudent("Chris"); + client.loadStudent("Ben"); + client.listStudents(); + client.clearDataStore(); + client.disconnect(); + + int nbrCmd = client.getNumberOfCommands(); + assertEquals(5, nbrCmd); + } + + +} + diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2GZeedTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2GZeedTest.java new file mode 100644 index 0000000..3f36d1a --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2GZeedTest.java @@ -0,0 +1,71 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV1Protocol; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author GZeed + */ +public class RouletteV2GZeedTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "GZeed") + public void itShouldBePossibleListStudentToARouletteServer() throws Exception { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.client; + client.clearDataStore(); + assertTrue(client.listStudents().isEmpty()); + List sts = new ArrayList(); + sts.add(new Student("pier")); + sts.add(new Student("paul")); + sts.add(new Student("jack")); + + client.loadStudents(sts); + + assertEquals(sts, client.listStudents()); + + } + + @Test + @TestAuthor(githubId = "GZeed") + public void itShouldBePossibleListAnyStudentToARouletteServer() throws Exception { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.client; + client.clearDataStore(); + assertTrue(client.listStudents().isEmpty()); + } + + @Test + @TestAuthor(githubId = "GZeed") + public void theServerShouldCountStudentsAndClearAllStudents() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.client; + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("sacha"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("olivier"); + assertEquals(2, client.getNumberOfStudents()); + client.loadStudent("fabienne"); + assertEquals(3, client.getNumberOfStudents()); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + + } +} \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2JokauTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2JokauTest.java new file mode 100644 index 0000000..851e6f7 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2JokauTest.java @@ -0,0 +1,153 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +public class RouletteV2JokauTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "wasadigi") + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + + @Test + @TestAuthor(githubId = "wasadigi") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + // Adapted from wasadigi + @Test + @TestAuthor(githubId = "jokau, loic-schurch") + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV1Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + @Test + @TestAuthor(githubId = "jokau, loic-schurch") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + + @Test + @TestAuthor(githubId = "jokau, loic-schurch") + public void theServerShouldHaveZeroStudentsAtStart() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + int numberOfStudents = client.getNumberOfStudents(); + assertEquals(0, numberOfStudents); + } + + @Test + @TestAuthor(githubId = {"wasadigi", "SoftEng-HEIGVD"}) + public void theServerShouldStillHaveZeroStudentsAtStart() throws IOException { + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "wasadigi, jokau, loic-schurch") + public void theServerShouldSendAnErrorResponseWhenRandomIsCalledAndThereIsNoStudent() throws IOException, EmptyStoreException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + exception.expect(EmptyStoreException.class); + client.pickRandomStudent(); + } + + @Test + @TestAuthor(githubId = "SoftEng-HEIGVD") + public void theServerShouldCountStudents() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("sacha"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("olivier"); + assertEquals(2, client.getNumberOfStudents()); + client.loadStudent("fabienne"); + assertEquals(3, client.getNumberOfStudents()); + } + + // new V2 specific tests + @Test + @TestAuthor(githubId = "jokau, loic-schurch") + public void theServerShouldAddStudentsInList() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + ArrayList a = new ArrayList<>(); + a.add(new Student("a")); + a.add(new Student("b")); + a.add(new Student("c")); + client.loadStudents(a); + assertEquals(3, client.getNumberOfStudents()); + } + @Test + @TestAuthor(githubId = "jokau, loic-schurch") + public void theServerShouldClearDataStore() throws IOException{ + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient();; + client.loadStudent("sacha"); + client.loadStudent("olivier"); + client.loadStudent("fabienne"); + assertEquals(3, client.getNumberOfStudents()); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "jokau, loic-schurch") + public void theServerShouldListStudents() throws IOException{ + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.loadStudent("sacha"); + client.loadStudent("olivier"); + client.loadStudent("fabienne"); + List student = client.listStudents(); + assertEquals("sacha", student.get(0).getFullname()); + assertEquals("olivier", student.get(1).getFullname()); + assertEquals("fabienne", student.get(2).getFullname()); + } + + @Test + @TestAuthor(githubId = "jokau, loic-schurch") + public void theServerShouldCountStudentsAdded() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + ArrayList a = new ArrayList<>(); + a.add(new Student("a")); + a.add(new Student("b")); + a.add(new Student("c")); + client.loadStudents(a); + assertEquals(3, client.getNumberOfStudents()); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + assertEquals(3, client.getNumberOfStudentAdded()); + } + + @Test + @TestAuthor(githubId = "jokau, loic-schurch") + public void theServerShouldCountTheNumberOfCommands() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.loadStudent("a"); + client.listStudents(); + client.clearDataStore(); + assertEquals(3, client.getNumberOfCommands()); + } +} \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2LionelNanchenTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2LionelNanchenTest.java new file mode 100644 index 0000000..06611e3 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2LionelNanchenTest.java @@ -0,0 +1,97 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.*; +import java.net.Socket; +import java.util.LinkedList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class RouletteV2LionelNanchenTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "LionelNanchen") + public void theServerShouldBeEmptyAfterClearCommand() throws IOException, EmptyStoreException{ + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("sacha"); + client.loadStudent("olivier"); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "LionelNanchen") + public void theServerShouldFetchTheListOfStudents() throws IOException, EmptyStoreException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + LinkedList students = new LinkedList<>(); + students.add(new Student("sacha")); + students.add(new Student("olivier")); + students.add(new Student("fabienne")); + client.loadStudents(students); + assertEquals(students, client.listStudents()); + } + + @Test + @TestAuthor(githubId = "LionelNanchen") + public void theServerShouldCountNumberOfStudentCreated() throws IOException { + Socket clientSocket = new Socket("localhost", roulettePair.getServer().getPort()); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream()), true); + + bufferedReader.readLine(); + printWriter.println(RouletteV2Protocol.CMD_LOAD); + bufferedReader.readLine(); + printWriter.println("sacha"); + printWriter.println("olivier"); + printWriter.println("fabienne"); + printWriter.println(RouletteV2Protocol.CMD_LOAD_ENDOFDATA_MARKER); + String status = bufferedReader.readLine(); + boolean b = false; + if (status.contains("3")) { + b = true; + } + assertTrue(b); + } + + @Test + @TestAuthor(githubId = "LionelNanchen") + public void theServerShouldCountAllCommmands() throws IOException { + Socket clientSocket = new Socket("localhost", roulettePair.getServer().getPort()); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream()), true); + + bufferedReader.readLine(); + printWriter.println(RouletteV2Protocol.CMD_LOAD); + bufferedReader.readLine(); + printWriter.println("sacha"); + printWriter.println(RouletteV2Protocol.CMD_LOAD_ENDOFDATA_MARKER); + bufferedReader.readLine(); + printWriter.println(RouletteV2Protocol.CMD_RANDOM); + bufferedReader.readLine(); + printWriter.println(RouletteV2Protocol.CMD_INFO); + bufferedReader.readLine(); + printWriter.println(RouletteV2Protocol.CMD_BYE); + + String status = bufferedReader.readLine(); + boolean b = false; + if (status.contains("4")) { + b = true; + } + assertTrue(b); + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2LoyseKrugTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2LoyseKrugTest.java new file mode 100644 index 0000000..ab04ed9 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2LoyseKrugTest.java @@ -0,0 +1,141 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.*; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.Socket; +import java.util.LinkedList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/* + Test class for the protovol V2 + Authors : Adrien Allemand, Loyse Krug + */ +public class RouletteV2LoyseKrugTest { + + @Rule + public EphemeralClientServerPair ephemeralClientServerPair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + //test CLEAR + @Test + @TestAuthor(githubId = {"LoyseKrug", "AdrienAllemand"}) + public void ClearCommandEmptiesStudentList() throws IOException { + + IRouletteV2Client client = (IRouletteV2Client)ephemeralClientServerPair.getClient(); + + client.loadStudent("Loyse Krug"); + + //now clear students + client.clearDataStore(); + + //check that studentlist is empty + assertEquals(client.getNumberOfStudents(),0); + } + + //test Liste + @Test + @TestAuthor(githubId = {"LoyseKrug", "AdrienAllemand"}) + public void ListStudentsReturnsAllStudentsPreviouslyAdded() throws IOException { + + IRouletteV2Client client = (IRouletteV2Client)ephemeralClientServerPair.getClient(); + + // a few students + LinkedList studentList = new LinkedList(); + studentList.add(new Student("Adrien Allemand")); + studentList.add(new Student("Loyse Krug")); + studentList.add(new Student("Olivier Liechti")); + + // add the students to the server list + client.loadStudents(studentList); + + // fetch the list of students that are loaded on the server + List studentLoadedList = client.listStudents(); + + // check that all students added to the server are in the list we just got + for (Student s : studentList) { + assertTrue(studentLoadedList.contains(s)); + } + } + + //test Load response + @Test + @TestAuthor(githubId = {"LoyseKrug", "AdrienAllemand"}) + public void ClientLoadGetsCorrectAnswerFromServer() throws IOException { + + // we make custom client to test the server answer for Load Command + Socket client = new Socket("localhost",ephemeralClientServerPair.getServer().getPort()); + BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); + PrintWriter out = new PrintWriter(client.getOutputStream()); + + in.readLine(); + + // manually insert a new student + out.println(RouletteV2Protocol.CMD_LOAD); + out.flush(); + in.readLine(); + out.println("Adrien Allemand"); + out.flush(); + out.println(RouletteV2Protocol.CMD_LOAD_ENDOFDATA_MARKER); + out.flush(); + + // read the server answer and check it + String s = in.readLine(); + assertEquals("{\"status\":\"success\",\"numberOfNewStudents\":1}", s); + } + + + //test BYE response + @Test + @TestAuthor(githubId = {"LoyseKrug", "AdrienAllemand"}) + public void ClientByeGetsCorrectAnswerFromServer() throws IOException { + + // we make custom client to test the server answer for bye command + Socket client = new Socket("localhost",ephemeralClientServerPair.getServer().getPort()); + BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); + PrintWriter out = new PrintWriter(client.getOutputStream()); + + in.readLine(); + + // manually say bye + out.println(RouletteV2Protocol.CMD_BYE); + out.flush(); + + // read the server answer and check it + String s = in.readLine(); + assertEquals(s, "{\"status\":\"success\",\"numberOfCommands\":1}"); + } + + //test INFO response + @Test + @TestAuthor(githubId = {"LoyseKrug", "AdrienAllemand"}) + public void ClientInfoGetsCorrectAnswerFromServer() throws IOException { + + //first clear server as we don't want any students in it + IRouletteV2Client client2 = (IRouletteV2Client)ephemeralClientServerPair.getClient(); + client2.clearDataStore(); + + // next we make custom client to test the server answer for INFO command + Socket client = new Socket("localhost",ephemeralClientServerPair.getServer().getPort()); + BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); + PrintWriter out = new PrintWriter(client.getOutputStream()); + + in.readLine(); + + // manually say bye + out.println(RouletteV2Protocol.CMD_INFO); + out.flush(); + + // read the server answer and check it + String s = in.readLine(); + assertEquals(s, "{\"protocolVersion\":\"2.0\",\"numberOfStudents\":0}"); + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2Ludwig9392Test.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2Ludwig9392Test.java new file mode 100644 index 0000000..fcc8579 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2Ludwig9392Test.java @@ -0,0 +1,102 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV1Protocol; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Loic Frueh + * @author Dejvid Muaremi + */ +public class RouletteV2Ludwig9392Test { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + /* + @Test + @TestAuthor(githubId = "Ludwig9392") + public void theTestRouletteServerShouldListenOnTheCorrectPort(){ + int port = roulettePair.getServer().getPort(); + assertEquals(2613,port); + } + */ + + @Test + @TestAuthor(githubId = "Ludwig9392") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "Ludwig9392") + public void theServerShouldBeAbleToClearTheData() throws IOException { + roulettePair.getClient().loadStudent("Loic"); + roulettePair.getClient().loadStudent("Dejvid"); + roulettePair.getClient().loadStudent("Adam"); + assertEquals(3, roulettePair.getClient().getNumberOfStudents()); + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.clearDataStore(); + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "Ludwig9392") + public void theClientShouldBeAbleToReturnTheCorrectNumberOfStudentAdded() throws IOException{ + roulettePair.getClient().loadStudent("Michel"); + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + assertEquals(1, client.getNumberOfStudentAdded()); + + List students = new ArrayList(); + students.add(new Student("Dejvid")); + students.add(new Student("Loic")); + students.add(new Student("Adam")); + roulettePair.getClient().loadStudents(students); + assertEquals(3, client.getNumberOfStudentAdded()); + + } + + @Test + @TestAuthor(githubId = "Ludwig9392") + public void theClientShouldBeAbleToReturnTheCorrectNumberOfCommandsSent() throws IOException{ + roulettePair.getClient().loadStudent("Jean"); + roulettePair.getClient().loadStudent("Pierre"); + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.clearDataStore(); + client.listStudents(); + assertEquals(4, client.getNumberOfCommands()); + } + + @Test + @TestAuthor(githubId = "Ludwig9392") + public void theServerShouldBeAbleToReturnTheListOfStudent() throws IOException{ + roulettePair.getClient().loadStudent("Michel"); + roulettePair.getClient().loadStudent("Dejvid"); + roulettePair.getClient().loadStudent("Loic"); + roulettePair.getClient().loadStudent("Adam"); + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + List students = client.listStudents(); + assertEquals("Michel", students.get(0).getFullname()); + assertEquals("Dejvid", students.get(1).getFullname()); + assertEquals("Loic", students.get(2).getFullname()); + assertEquals("Adam", students.get(3).getFullname()); + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2ManalitoTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2ManalitoTest.java new file mode 100644 index 0000000..ce70ef8 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2ManalitoTest.java @@ -0,0 +1,106 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.schoolpulse.TestAuthor; +import static org.junit.Assert.*; +import org.junit.Test; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import java.io.IOException; +import java.util.LinkedList; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Olivier Liechti + */ +public class RouletteV2ManalitoTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = {"manalito", "nfluckiger"}) + public void ClearShouldEraseAllStudents() throws IOException{ + + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + + client.loadStudent("Fluckiger"); + client.loadStudent("Siu"); + client.loadStudent("LastOfTheStudents"); + + assertEquals(3, client.getNumberOfStudents()); + + client.clearDataStore(); + + assertTrue(client.listStudents().isEmpty()); + + } + + @Test + @TestAuthor(githubId = {"manalito", "nfluckiger"}) + public void ServerShouldGiveRightVersion() throws IOException{ + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = {"manalito", "nfluckiger"}) + public void ServersShouldReturnTheRightListOfStudents() throws IOException{ + + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + + LinkedList students = new LinkedList<>(); + + students.add(new Student("Nathan")); + students.add(new Student("Aurelien")); + students.add(new Student("TheLastOfTheStudents")); + + + client.loadStudents(students); + + assertEquals(students, client.listStudents()); + assertEquals(students.size(), client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = {"manalito", "nfluckiger"}) + public void ServersShouldReturnNumberOfStudentAdded() throws IOException{ + + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + + LinkedList students = new LinkedList<>(); + + students.add(new Student("Nathan")); + students.add(new Student("Aurelien")); + students.add(new Student("TheLastOfTheStudents")); + client.loadStudents(students); + + int numberOfNewStuddents = client.getNumberOfStudentAdded(); + + assertEquals(3, numberOfNewStuddents); + } + + @Test + @TestAuthor(githubId = {"manalito", "nfluckiger"}) + public void ServersShouldReturnNumberOfCommandsTyped() throws IOException{ + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + + client.loadStudent("Nathan"); + client.getProtocolVersion(); + client.getNumberOfStudents(); + + assertEquals(client.getNumberOfCommands(), 3); + } + + + + + +} \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2Mantha32Test.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2Mantha32Test.java new file mode 100644 index 0000000..3a95cea --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2Mantha32Test.java @@ -0,0 +1,131 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.Socket; +import java.util.Arrays; +import java.util.List; +import org.junit.Assert; +import static org.junit.Assert.assertEquals; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 1) + * + * @author Olivier Liechti + */ + +public class RouletteV2Mantha32Test { + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "Mantha32") + public void theServerShouldReturnTheCorrectProtocolVersion() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "Mantha32") + public void theServerShouldHaveNoStudentsAfterClear() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("Mantha32"); + client.loadStudent("Iando Rafid"); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + + @Test + @TestAuthor(githubId = "Mantha32") + public void theServerShouldHaveReturnListOfStudent() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.clearDataStore(); + + List students; + students = Arrays.asList(new Student("Mantha32"), + new Student("Iando Rafid")); + client.loadStudents(students); + + List StudentsInStore = client.listStudents(); + assertEquals(students.size(), StudentsInStore.size()); + + for(Student st : StudentsInStore){ + Assert.assertTrue(students.contains(st)); + } + + } + + @Test + @TestAuthor(githubId = "Mantha32") + public void theServerShouldReturnTheNumberOfStudentAdded() throws IOException{ + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.clearDataStore(); + Socket socket = new Socket("localhost", roulettePair.getServer().getPort()); + BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); + PrintWriter output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); + + input.readLine(); + + output.println(RouletteV2Protocol.CMD_LOAD); + output.flush(); + input.readLine(); + output.println("Mantha32"); + output.println("Iando Rafid"); + output.println(RouletteV2Protocol.CMD_LOAD_ENDOFDATA_MARKER); + output.flush(); + + String result = input.readLine(); + + assertEquals("{\"status\":\"success\",\"numberOfNewStudents\":2}", result); + } + + + + @Test + @TestAuthor(githubId = "Mantha32") + public void theServerShouldReturnTheNumberOfCommands() throws IOException{ + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.clearDataStore(); + + Socket socket = new Socket("localhost", roulettePair.getServer().getPort()); + BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); + PrintWriter output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); + + input.readLine(); + + output.println(RouletteV2Protocol.CMD_LOAD); + output.flush(); + input.readLine(); + + output.println("Mantha 32"); + output.println("Iando Rafid"); + output.println(RouletteV2Protocol.CMD_LOAD_ENDOFDATA_MARKER); + output.flush(); + input.readLine(); + + output.println(RouletteV2Protocol.CMD_INFO); + output.flush(); + input.readLine(); + + output.println(RouletteV2Protocol.CMD_BYE); + output.flush(); + String result = input.readLine(); + + assertEquals("{\"status\":\"success\",\"numberOfCommands\":3}", result); + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2NortalleTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2NortalleTest.java new file mode 100644 index 0000000..56ebef8 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2NortalleTest.java @@ -0,0 +1,91 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author David Jaquet + * @author Vincent Guidoux + * + * @remark We don't test the command tested in the version 1 + */ +public class RouletteV2NortalleTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "Nortalle") + public void theServerShouldBeAbleToClearTheStudents() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + roulettePair.getClient().loadStudent("David Jaquet"); + + client.clearDataStore(); + + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "Nortalle") + public void theServerShouldBeAbleToListTheStudents() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + // To be sure to not have data of previous tests + client.clearDataStore(); + + List studentsSended = new ArrayList<>(); + studentsSended.add(new Student("Mar Labie")); + studentsSended.add(new Student("David Jaquet")); + studentsSended.add(new Student("Samuel Mayor")); + studentsSended.add(new Student("Vincent Guidoux")); + studentsSended.add(new Student("Guillaume Hochet")); + client.loadStudents(studentsSended); + + List studentsReceived = client.listStudents(); + + assertEquals(studentsReceived.size(), studentsSended.size()); + + for(Student student : studentsReceived) + assertNotEquals(-1, studentsSended.indexOf(student)); + } + + @Test + @TestAuthor(githubId = "Nortalle") + public void theServerShouldReturnTheNumberOfNewStudents() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + client.loadStudent("Julien Biefer"); + client.loadStudent("Johanna Melly"); + + assertEquals(2, client.getNumberOfStudents()); // clients on the server + assertEquals(1, client.getNumberOfStudentAdded()); // clients added in the last LOAD command + } + + @Test + @TestAuthor(githubId = "Nortalle") + public void theServerShouldReturnTheNumberOfCommandsSent() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + client.loadStudent("Yann Lederrey"); + client.loadStudent("Leo Cortes"); + client.getNumberOfStudents(); + client.getProtocolVersion(); + + assertEquals(4, client.getNumberOfCommands()); + } +} \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2OuzgagaTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2OuzgagaTest.java new file mode 100644 index 0000000..75d1a40 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2OuzgagaTest.java @@ -0,0 +1,145 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * This class contains automated tests to validate the client and the server implementation of the Roulette Protocol (version 2) + * + * @author Rochat Antoine & Schopfer Benoit + */ +public class RouletteV2OuzgagaTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = {"Nooka10", "ouzgaga"}) + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = {"Nooka10", "ouzgaga"}) + public void theServerShouldHaveZeroStudentsAfterClear() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("benoit"); + client.loadStudent("antoine"); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + + @Test + @TestAuthor(githubId = {"Nooka10", "ouzgaga"}) + public void theServerShouldSendTheCorrectResponseWhenLoadListAndByeAreCalled() throws IOException { + + Socket client = new Socket("localhost", roulettePair.getServer().getPort()); + + BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); + PrintWriter out = new PrintWriter(client.getOutputStream()); + + String responsesFromServer; + + in.readLine(); // welcome message from the server + + out.println("LOAD"); + out.flush(); + in.readLine(); // Send your data [end with ENDOFDATA] + + out.println("john doe"); + out.flush(); + + out.println("bill smith"); + out.flush(); + + out.println("ENDOFDATA"); + out.flush(); + responsesFromServer = in.readLine(); // check the load command response from the server + assertEquals("{\"status\":\"success\",\"numberOfNewStudents\":2}", responsesFromServer); + + out.println("LIST"); + out.flush(); + responsesFromServer = in.readLine(); // check the list commmand response from the server + assertEquals("{\"students\":[{\"fullname\":\"john doe\"},{\"fullname\":\"bill smith\"}]}", responsesFromServer); + + out.println("BYE"); + out.flush(); + responsesFromServer = in.readLine(); // check the bye command response from the server + assertEquals("{\"status\":\"success\",\"numberOfCommands\":3}", responsesFromServer); + } + + + @Test + @TestAuthor(githubId = {"Nooka10", "ouzgaga"}) + public void theServerShouldSendTheCorrectNumberOfNewStudentsAdded() throws IOException { + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + List serverStudents = new ArrayList<>(); + + serverStudents.add(new Student("Antoine Rochat")); + serverStudents.add(new Student("Benoit Schopfer")); + + client.loadStudents(serverStudents); + + assertEquals(2, client.getNumberOfStudentAdded()); + + client.loadStudent("Chuck Norris"); + + assertEquals(1, client.getNumberOfStudentAdded()); + } + + @Test + @TestAuthor(githubId = {"Nooka10", "ouzgaga"}) + public void theServerShouldSendTheCorrectNumberOfCommands() throws IOException, EmptyStoreException { + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + client.loadStudent("Chuck Norris"); // command #1 + + List serverStudents = new ArrayList<>(); + + serverStudents.add(new Student("Antoine Rochat")); + serverStudents.add(new Student("Benoit Schopfer")); + + client.loadStudents(serverStudents); // command #2 + + client.pickRandomStudent(); // command #3 + + client.getProtocolVersion(); // command #4 + + client.getNumberOfStudents(); // command #5 + + client.pickRandomStudent(); // command #6 + + client.listStudents(); // command #7 + + client.clearDataStore(); // command #8 + + client.listStudents(); // command #9 + + client.disconnect(); // command #10 + + assertEquals(10, client.getNumberOfCommands()); + + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2PstackouseTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2PstackouseTest.java new file mode 100644 index 0000000..f0528f2 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2PstackouseTest.java @@ -0,0 +1,99 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV1Protocol; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 1) + * + * @author Patrick Neto + */ +public class RouletteV2PstackouseTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "p-stackouse") + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + + @Test + @TestAuthor(githubId = "p-stackouse") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + @Test + @TestAuthor(githubId = "p-stackouse") + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + /* + @Test + @TestAuthor(githubId = "p-stackouse") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV1Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + */ + + @Test + @TestAuthor(githubId = "p-stackouse") + public void theServerShouldHaveZeroStudentsAtStart() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + int numberOfStudents = client.getNumberOfStudents(); + assertEquals(0, numberOfStudents); + } + + @Test + @TestAuthor(githubId = {"p-stackouse", "SoftEng-HEIGVD"}) + public void theServerShouldStillHaveZeroStudentsAtStart() throws IOException { + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "SoftEng-HEIGVD") + public void theServerShouldCountStudents() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("Patrick"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("Guillaume"); + assertEquals(2, client.getNumberOfStudents()); + client.loadStudent("Toto"); + assertEquals(3, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "p-stackouse") + public void theServerShouldSendAnErrorResponseWhenRandomIsCalledAndThereIsNoStudent() throws IOException, EmptyStoreException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + exception.expect(EmptyStoreException.class); + client.pickRandomStudent(); + } + + +} \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SachaKorTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SachaKorTest.java new file mode 100644 index 0000000..2e21844 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SachaKorTest.java @@ -0,0 +1,94 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.QuizRouletteServer; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.res.labs.roulette.net.server.RouletteServer; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 1) + * + * @author Olivier Liechti + */ +public class RouletteV2SachaKorTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "sachakor") + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + + @Test + @TestAuthor(githubId = "sachakor") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + @Test + @TestAuthor(githubId = "sachakor") + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + @Test + @TestAuthor(githubId = "sachakor") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "sachakor") + public void theServerShouldHaveZeroStudentsAfterClearingDataStore() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.loadStudent("sacha"); + client.loadStudent("steven"); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "sachakor") + public void theServerShouldSendTheListOfStudents() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + List studentList = new LinkedList<>(); + studentList.add(new Student("sasha")); + studentList.add(new Student("sam")); + client.loadStudents(studentList); + List actual = client.listStudents(); + assertEquals(studentList, actual); + } + + @Test + @TestAuthor(githubId = "Etnarion") + public void itShouldBePossibleToConnectToTheServerWithTheDefaultPort() throws IOException { + RouletteServer server = new RouletteServer(RouletteV2Protocol.DEFAULT_PORT, RouletteV2Protocol.VERSION); + server.startServer(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", server.getPort()); + assertTrue(client.isConnected()); + server.stopServer(); + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SmithHeigTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SmithHeigTest.java new file mode 100644 index 0000000..c88434b --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SmithHeigTest.java @@ -0,0 +1,73 @@ +package ch.heigvd.res.labs.roulette.net.client; + + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.*; +import org.junit.rules.ExpectedException; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.Socket; + +import static org.junit.Assert.*; + +public class RouletteV2SmithHeigTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + /** + * When the server clear, should have 0 students after that + * @throws IOException + */ + @Test + @TestAuthor(githubId = "smithheig") + public void theServerShouldHaveZeroStudentAfterClear() throws IOException { + roulettePair.getClient().loadStudent("bob"); + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.clearDataStore(); // test clear data + assertEquals(0,roulettePair.getClient().getNumberOfStudents()); + } + + /** + * Test if the client revieved the list of the current students on the server + * @throws IOException + */ + @Test + @TestAuthor(githubId = "smithheig") + public void testClientReceivedCorrectListOfStudentFromServer() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + client.loadStudent("bob"); + client.loadStudent("john"); + + assertTrue(client.listStudents().contains(new Student("bob"))); + assertTrue(client.listStudents().contains(new Student("john"))); + } + + /** + * Test if the server give you a Bye message correct + * @throws IOException + */ + @Test + @TestAuthor(githubId = "smithheig") + public void testResponseFromServerWhenExitWithBye() throws IOException{ + Socket client = new Socket("localhost",roulettePair.getServer().getPort()); + BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); + PrintWriter out = new PrintWriter(client.getOutputStream()); + + in.readLine(); + + out.println("BYE"); + out.flush(); + + String s = in.readLine(); + assertEquals(s, "{\"status\":\"success\",\"numberOfCommands\":1}"); + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SysmohTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SysmohTest.java new file mode 100644 index 0000000..76af164 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2SysmohTest.java @@ -0,0 +1,126 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +public class RouletteV2SysmohTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "sysmoh") + public void serverShouldReturnCorrectProtocolVersion() throws IOException { + + assertEquals(RouletteV2Protocol.VERSION, getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "sysmoh") + public void clientShouldBeAbleToConnectToRouletteServerV2() throws IOException { + + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + + client.connect("localhost", roulettePair.getServer().getPort()); + assertTrue(client.isConnected()); + + client.disconnect(); + assertFalse(client.isConnected()); + } + + @Test + @TestAuthor(githubId = "sysmoh") + public void clientShouldBeAbleToClearStudentsList() throws IOException { + + IRouletteV2Client client = getClient(); + client.connect("localhost", roulettePair.getServer().getPort()); + + client.loadStudent("Sisi la famille"); + client.loadStudent("Himotep Asterix"); + + assertEquals(2, client.getNumberOfStudents()); + + client.clearDataStore(); + + assertEquals(0, client.getNumberOfStudents()); + assertTrue(client.listStudents().isEmpty()); + } + + @Test + @TestAuthor(githubId = "sysmoh") + public void clientShouldBeAbleToListPerformedCommands() throws IOException { + + IRouletteV2Client client = getClient(); + client.connect("localhost", roulettePair.getServer().getPort()); + + assertEquals(client.getNumberOfCommands(), 0); + + client.loadStudent("wallah"); + client.loadStudent("habdoulilah"); + client.getProtocolVersion(); + client.getNumberOfStudents(); + client.disconnect(); + + assertEquals(client.getNumberOfCommands(), 5); + } + + @Test + @TestAuthor(githubId = "sysmoh") + public void clientShouldBeAbleToListStudents() throws IOException { + + IRouletteV2Client client = getClient(); + client.connect("localhost", roulettePair.getServer().getPort()); + + ArrayList students = new ArrayList<>(); + students.add("Jean Dujardin"); + students.add("Mark Ronson"); + students.add("Sacha Grey"); + + for(String student : students) + client.loadStudent(student); + + List studentList = client.listStudents(); + + for(Student student : studentList) + assertTrue(students.contains(student.getFullname())); + } + + @Test + @TestAuthor(githubId = "sysmoh") + public void clientShouldBeAbleToSayNumberOfStudentsAdded() throws IOException { + + IRouletteV2Client client = getClient(); + client.connect("localhost", roulettePair.getServer().getPort()); + + String students [] = { + "a", + "b", + "c" + }; + + for(String student : students) + client.loadStudent(student); + + assertEquals(client.getNumberOfStudents(), 3); + } + + + private IRouletteV2Client getClient() { + + return (IRouletteV2Client) roulettePair.getClient(); + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2YannledTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2YannledTest.java new file mode 100644 index 0000000..ee84d9a --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2YannledTest.java @@ -0,0 +1,84 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.*; + +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Lederrey Yann, Schar Joel + */ +public class RouletteV2YannledTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "wasadigi") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + @Test + @TestAuthor(githubId = "wasadigi") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "yannled") + public void theServerShouldBeAbleToClearDataStore() throws IOException { + List students = new ArrayList<>(); + students.add(new Student("Olivier Liechti")); + students.add(new Student("Olivier Kopp")); + students.add(new Student("Olivier De Benoist")); + roulettePair.getClient().loadStudents(students); + assertEquals(3, roulettePair.getClient().getNumberOfStudents()); + ((IRouletteV2Client) roulettePair.getClient()).clearDataStore(); + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "yannled") + public void theServerShouldBeAbleToListStoredStudents() throws IOException { + List students = new ArrayList<>(); + Student olivier1 = new Student("Olivier Liechti"); + Student olivier2 = new Student("Olivier Kopp"); + Student olivier3 = new Student("Olivier De Benoist"); + students.add(olivier1); + students.add(olivier2); + students.add(olivier3); + roulettePair.getClient().loadStudents(students); + assertEquals(3, roulettePair.getClient().getNumberOfStudents()); + List listedStudents = ((IRouletteV2Client) roulettePair.getClient()).listStudents(); + for (int i = 0; i < 3; ++i) + assertEquals(students.get(i).getFullname(), listedStudents.get(i).getFullname()); + } + + @Test + @TestAuthor(githubId = "yannled") + public void theServerShouldKeepTheNumberOfUsedCommands() throws IOException, EmptyStoreException { + roulettePair.getClient().loadStudent("Olivier Liechti"); + roulettePair.getClient().loadStudent("Olivier Koop"); + roulettePair.getClient().loadStudent("Olivier De Benoist"); + assertEquals(3, roulettePair.getClient().getNumberOfStudents()); + assertEquals(4, ((IRouletteV2Client) roulettePair.getClient()).getNumberOfCommands()); + } +} \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2christophejoyetTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2christophejoyetTest.java new file mode 100644 index 0000000..4c65c8b --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2christophejoyetTest.java @@ -0,0 +1,133 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV1Protocol; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.*; +import java.net.Socket; +import java.util.LinkedList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Christophe Joyet + */ +public class RouletteV2christophejoyetTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + //tests from RouletteV1WasadigiTest not necessary + /* + @Test + @TestAuthor(githubId = "christophe-joyet") + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + @Test + @TestAuthor(githubId = "christophe-joyet") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + @Test + @TestAuthor(githubId = "christophe-joyet") + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + @Test + @TestAuthor(githubId = "christophe-joyet") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV1Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + @Test + @TestAuthor(githubId = "christophe-joyet") + public void theServerShouldHaveZeroStudentsAtStart() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + int numberOfStudents = client.getNumberOfStudents(); + assertEquals(0, numberOfStudents); + } + @Test + @TestAuthor(githubId = {"christophe-joyet", "SoftEng-HEIGVD"}) + public void theServerShouldStillHaveZeroStudentsAtStart() throws IOException { + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + @Test + @TestAuthor(githubId = "christophe-joyet") + public void theNumberOfStudentSentByTheClient() throws IOException{ + IRouletteV2Client client; + }*/ + + @Test + @TestAuthor(githubId = "christophe-joyet") + public void serverMustBeClearedAfterCleared() throws IOException { + IRouletteV2Client client; + client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("olivier"); + client.loadStudent("ambert"); + client.loadStudent("nicole"); + client.loadStudent("georges"); + client.clearDataStore(); + assertTrue(client.getNumberOfStudents() == 0); + + } + + @Test + @TestAuthor(githubId = "christophe-joyet") + public void numberOfTheStudentLinesSentByTheClientWithLoadCommand() throws IOException { + Socket clientSocket; + clientSocket = new Socket("localhost", roulettePair.server.getPort()); + BufferedReader br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + PrintWriter pw = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream())); + + br.readLine(); + pw.println(RouletteV2Protocol.CMD_LOAD); + pw.flush(); + pw.println("olivier"); + pw.println("ambert"); + pw.println("nicole"); + pw.println(RouletteV2Protocol.CMD_LOAD_ENDOFDATA_MARKER); + pw.flush(); + + br.readLine(); //to read the end of the data answer + String numberOfLines = br.readLine(); + assertEquals(numberOfLines, "{\"status\":\"success\",\"numberOfNewStudents\":3}"); + + + } + + @Test + @TestAuthor(githubId = "christophe-joyet") + public void listOfStudentShouldBeCorrect() throws IOException { + IRouletteV2Client client; + client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("olivier"); + client.loadStudent("ambert"); + LinkedList listOfStudent = new LinkedList(); + listOfStudent.add(new Student("olivier")); + listOfStudent.add(new Student("ambert")); + assertEquals(listOfStudent, client.listStudents()); + } + + +} \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2dorianekaffoTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2dorianekaffoTest.java new file mode 100644 index 0000000..fecc39a --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2dorianekaffoTest.java @@ -0,0 +1,68 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.IOException; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Doriane Kaffo + */ +public class RouletteV2dorianekaffoTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + /* + @Test + @TestAuthor(githubId = "dorianekaffo") + public void theServerShouldListenToTheCorrectPort() { + assertEquals(RouletteV2Protocol.DEFAULT_PORT, roulettePair.getServer().getPort()); + } + */ + + @Test + @TestAuthor(githubId = "dorianekaffo") + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + + @Test + @TestAuthor(githubId = "dorianekaffo") + public void theServerShouldNotHaveStudentsAfterClear() throws IOException { + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("dodo"); + client.loadStudent("doriane"); + client.loadStudent("kaffo"); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "dorianekaffo") + public void ClientV2ShouldConnectToRouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + client.disconnect(); + } + + @Test + @TestAuthor(githubId = "dorianekaffo") + public void theServerShouldReturnTheGoodNumberOfVersion() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2francoisburgenerTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2francoisburgenerTest.java new file mode 100644 index 0000000..2c92517 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2francoisburgenerTest.java @@ -0,0 +1,167 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV1Protocol; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 1) + * + * @author Bryan Curchod, François Burgener + */ +public class RouletteV2francoisburgenerTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + + /*The same tests as the v1 but adapt for v2*/ + @Test + @TestAuthor(githubId = "wasadigi") + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + + @Test + @TestAuthor(githubId = "wasadigi") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + @Test + @TestAuthor(githubId = {"wasadigi", "francoisburgener", "BryCur"}) + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + @Test + @TestAuthor(githubId = {"wasadigi", "francoisburgener", "BryCur"}) + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + RouletteV2ClientImpl client = (RouletteV2ClientImpl) roulettePair.getClient(); + assertEquals(RouletteV2Protocol.VERSION, client.getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = {"wasadigi", "francoisburgener", "BryCur"}) + public void theServerShouldHaveZeroStudentsAtStart() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + int numberOfStudents = client.getNumberOfStudents(); + assertEquals(0, numberOfStudents); + } + + @Test + @TestAuthor(githubId = {"wasadigi", "SoftEng-HEIGVD"}) + public void theServerShouldStillHaveZeroStudentsAtStart() throws IOException { + assertEquals(0, roulettePair.getClient().getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = {"SoftEng-HEIGVD", "francoisburgener", "BryCur"}) + public void theServerShouldCountStudents() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("François"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("Bryan"); + assertEquals(2, client.getNumberOfStudents()); + client.loadStudent("Olivier"); + assertEquals(3, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = {"francoisburgener", "BryCur"}) + public void theServerShouldSendAnErrorResponseWhenRandomIsCalledAndThereIsNoStudent() throws IOException, EmptyStoreException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + exception.expect(EmptyStoreException.class); + client.pickRandomStudent(); + } + + /*The beginning of the tests of the v2*/ + @Test + @TestAuthor(githubId = {"francoisburgener", "BryCur"}) + public void theServerShouldClearData() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("François"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("Bryan"); + assertEquals(2, client.getNumberOfStudents()); + client.loadStudent("Olivier"); + assertEquals(3, client.getNumberOfStudents()); + + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = {"francoisburgener", "BryCur"}) + public void theServerShouldListData() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("François"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("Bryan"); + assertEquals(2, client.getNumberOfStudents()); + client.loadStudent("Olivier"); + assertEquals(3, client.getNumberOfStudents()); + + List students = client.listStudents(); + assertEquals("François", students.get(0).getFullname()); + assertEquals("Bryan", students.get(1).getFullname()); + assertEquals("Olivier", students.get(2).getFullname()); + } + + @Test + @TestAuthor(githubId = {"francoisburgener", "BryCur"}) + public void theDefaultPortShouldBe2613() throws IOException { + assertEquals(RouletteV2Protocol.DEFAULT_PORT, 2613); + } + + @Test + @TestAuthor(githubId = {"francoisburgener", "BryCur"}) + public void theServerShouldReturnTheNumberOfCommand() throws IOException { + RouletteV2ClientImpl client = (RouletteV2ClientImpl) roulettePair.getClient(); + client.loadStudent("Romain"); + client.listStudents(); + client.disconnect(); + + int numberOfCommands = client.getNumberOfCommands(); + assertEquals(3, numberOfCommands); + + } + + @Test + @TestAuthor(githubId = {"francoisburgener", "BryCur"}) + public void theServerShouldReturnTheNumberOfAddedStudents() throws IOException { + RouletteV2ClientImpl client = (RouletteV2ClientImpl) roulettePair.getClient(); + client.loadStudent("test"); + assertEquals(1, client.getNumberOfStudentAdded()); + LinkedList students = new LinkedList<>(); + students.add(new Student("Romain")); + students.add(new Student("Joel")); + client.loadStudents(students); + assertEquals(2, client.getNumberOfStudentAdded()); + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2mathieujeeTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2mathieujeeTest.java new file mode 100644 index 0000000..6aed3b1 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2mathieujeeTest.java @@ -0,0 +1,91 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Mathieu Jee + * @author Lionel Burgbacher + * + */ +public class RouletteV2mathieujeeTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "mathieujee") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "mathieujee") + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + @Test + @TestAuthor(githubId = "mathieujee") + public void theServerShouldHaveZeroStudentsAfterClear() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.loadStudent("student n1"); + client.loadStudent("student n2"); + client.loadStudent("student n3"); + assertEquals(3, client.getNumberOfStudents()); + client.clearDataStore(); + assertTrue(client.listStudents().isEmpty()); + } + + @Test + @TestAuthor(githubId = "mathieujee") + public void ClearAnEmptyServerShouldNotProvokeAnError() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + assertEquals(0, client.getNumberOfStudents()); + client.clearDataStore(); + assertTrue(client.listStudents().isEmpty()); + } + + @Test + @TestAuthor(githubId = "mathieujee") + public void theServerShouldReturnTheCorrectListOfStudentsAfterList() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.loadStudent("student n1"); + client.loadStudent("student n2"); + client.loadStudent("student n3"); + assertEquals(3, client.getNumberOfStudents()); + List students = client.listStudents(); + assertEquals("student n1", students.get(0).getFullname()); + assertEquals("student n2", students.get(1).getFullname()); + assertEquals("student n3", students.get(2).getFullname()); + } + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2maxcaduffTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2maxcaduffTest.java new file mode 100644 index 0000000..68f2f11 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2maxcaduffTest.java @@ -0,0 +1,60 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.res.labs.roulette.net.server.RouletteServer; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.IOException; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Max Caduff + */ +public class RouletteV2maxcaduffTest { + + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + + @Test + @TestAuthor(githubId = "maxcaduff") + public void theClientShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "maxcaduff") + public void theServerShouldListAndClearCorrectly() throws IOException { + + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = (RouletteV2ClientImpl)roulettePair.getClient(); + client.connect("localhost", port); + client.loadStudent("Pierre"); + client.loadStudent("Paul"); + client.loadStudent("Jaques"); + assertEquals(3, client.getNumberOfStudents()); + String listOfStudents = client.listStudents().toString(); + assertTrue( listOfStudents.contains("Pierre") && listOfStudents.contains("Paul") && listOfStudents.contains("Jaques")); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "maxcaduff") + public void theServerAndClientShouldWorkWithTheDefaultPort() throws Exception { + RouletteServer server = new RouletteServer(RouletteV2Protocol.DEFAULT_PORT, RouletteV2Protocol.VERSION); + server.startServer(); + RouletteV2ClientImpl client = new RouletteV2ClientImpl(); + client.connect("localhost", RouletteV2Protocol.DEFAULT_PORT ); + assertTrue(client.isConnected()); + server.stopServer(); + } + + + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2mlabieTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2mlabieTest.java new file mode 100644 index 0000000..977e21f --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2mlabieTest.java @@ -0,0 +1,134 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.JsonObjectMapper; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Marc Labie + */ +public class RouletteV2mlabieTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + + // Reprise des 4 tests implémenter dans RouletteV1WasadigiTest pour s'assurer que le le serveur + // et le client fonctionne, et que la version a bien changé. + @Test + @TestAuthor(githubId = "wasadigi") + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + + @Test + @TestAuthor(githubId = "wasadigi") + public void theTestRouletteClientShouldBeConnectedWhenATestStarts() throws IOException { + assertTrue(roulettePair.getClient().isConnected()); + } + + @Test + @TestAuthor(githubId = {"wasadigi", "mlabie"}) + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws Exception { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + @Test + @TestAuthor(githubId = {"wasadigi", "mlabie"}) + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + + + @Test + @TestAuthor(githubId = "mlabie") + public void theServerShouldHaveZeroStudentsAfterClear() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("sacha"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("olivier"); + assertEquals(2, client.getNumberOfStudents()); + client.loadStudent("fabienne"); + assertEquals(3, client.getNumberOfStudents()); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "mlabie") + public void theServerShouldReturnAListWithStudents() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + List students = client.listStudents(); + assertEquals(0, students.size()); + client.loadStudent("sacha"); + client.loadStudent("olivier"); + client.loadStudent("fabienne"); + students = client.listStudents(); + assertEquals(3, students.size()); + assertEquals("[{\"fullname\":\"sacha\"},{\"fullname\":\"olivier\"},{\"fullname\":\"fabienne\"}]", + JsonObjectMapper.toJson(students)); + } + + @Test + @TestAuthor(githubId = "mlabie") + public void theServerShouldReturnTheNumberOfEntriesAfterLoad() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + List students = client.listStudents(); + students.add(new Student("sacha")); + students.add(new Student("olivier")); + students.add(new Student("fabienne")); + //int nbrOfLoad = client.loadStudents(students); + client.loadStudents(students); + int nbrOfLoad = client.getNumberOfStudentAdded(); + assertEquals(3, nbrOfLoad); + } + + @Test + @TestAuthor(githubId = "mlabie") + public void theServerShouldReturnTheNumberOfCommandAfterEndingConnection() throws IOException, EmptyStoreException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.loadStudent("sacha"); + client.listStudents(); + client.getNumberOfStudents(); + + client.clearDataStore(); + exception.expect(EmptyStoreException.class); + client.pickRandomStudent(); + //int nbrOfCommand = client.disconnect(); + client.disconnect(); + int nbrOfCommand = client.getNumberOfCommands(); + assertEquals(5, nbrOfCommand); + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2olivierKoppTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2olivierKoppTest.java new file mode 100644 index 0000000..e9eef33 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2olivierKoppTest.java @@ -0,0 +1,81 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.List; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Olivier Kopp + */ +public class RouletteV2olivierKoppTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = {"olivierKopp"}) + public void clientShouldBeAbleToConnectToRouletteV2() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } + + @Test + @TestAuthor(githubId = {"olivierKopp"}) + public void studentListShouldBeEmptyAfterClear() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.loadStudent("student1"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("student2"); + assertEquals(2, client.getNumberOfStudents()); + client.clearDataStore(); + assertTrue(client.listStudents().isEmpty()); + } + + @Test + @TestAuthor(githubId = {"olivierKopp"}) + public void serverShouldReturnAllStudentsAfterList() throws IOException { + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + client.loadStudent("student1"); + client.loadStudent("student2"); + client.loadStudent("student3"); + assertEquals(3, client.getNumberOfStudents()); + List students = client.listStudents(); + assertEquals(students.get(0).getFullname(), "student1"); + assertEquals(students.get(1).getFullname(), "student2"); + assertEquals(students.get(2).getFullname(), "student3"); + } + + @Test + @TestAuthor(githubId = {"olivierKopp"}) + public void serverShouldReturnCorrectVersionInfo() throws IOException{ + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + client.connect("localhost", port); + assertEquals(roulettePair.getClient().getProtocolVersion(), RouletteV2Protocol.VERSION); + } + + +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2onicoleheigTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2onicoleheigTest.java new file mode 100644 index 0000000..6edb4c4 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2onicoleheigTest.java @@ -0,0 +1,95 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.data.StudentsList; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.*; +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Olivier Nicole + */ +public class RouletteV2onicoleheigTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "onicoleheig") + public void dataStoreShouldBeCleared() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("jean"); + client.loadStudent("peuplu"); + assertEquals(2, client.getNumberOfStudents()); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "onicoleheig") + public void studentsShouldBeInTheList() throws IOException { + ArrayList students = new ArrayList(); + students.add(new Student("jean")); + students.add(new Student("peuplu")); + + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + + for(Student s : students){ + client.loadStudent(s.getFullname()); + } + + ArrayList response = (ArrayList) client.listStudents(); + + for(int i = 0; i < students.size(); ++i){ + assertEquals(students.get(i), response.get(i)); + } + } + + @Test + @TestAuthor(githubId = "onicoleheig") + public void serverVersionShouldBeCorrect() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "onicoleheig") + public void loadStudentsShouldReturnTheCorrectNumberOfNewStudents() throws IOException { + Socket socket = new Socket("localhost", roulettePair.getServer().getPort()); + + //create the writer and the reader + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "utf-8")); + PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "utf-8")); + + bufferedReader.readLine(); + + printWriter.println(RouletteV2Protocol.CMD_LOAD); + printWriter.flush(); + + printWriter.println("jean"); + printWriter.println("peuplu"); + + printWriter.println(RouletteV2Protocol.CMD_LOAD_ENDOFDATA_MARKER); + printWriter.flush(); + + //read end of data response + bufferedReader.readLine(); + + assertEquals("{\"status\":\"success\",\"numberOfNewStudents\":2}", bufferedReader.readLine()); + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2rlabinotTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2rlabinotTest.java new file mode 100644 index 0000000..fe1976b --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2rlabinotTest.java @@ -0,0 +1,96 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 1) + * + * @author Labinot Rashiti + * @author Romain Gallay + */ + +public class RouletteV2rlabinotTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "rlabinot") + public void theServerShouldReturnCorrectProtocolVersion() throws IOException { + String version = roulettePair.getClient().getProtocolVersion(); + assertEquals("2.0", version); + } + + @Test + @TestAuthor(githubId = "rlabinot") + public void theServerShouldHaveZeroStudentAfterClear() throws IOException, EmptyStoreException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + + client.loadStudent("Pierre"); + client.loadStudent("Paul"); + client.loadStudent("Jacques"); + + assertEquals(3, client.getNumberOfStudents()); + + client.clearDataStore(); + + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "rlabinot") + public void theServerShouldReturnTheStudentList() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + + String pierre = "Pierre"; + String paul = "Paul"; + + client.loadStudent(pierre); + client.loadStudent(paul); + + assertEquals(pierre, client.listStudents().get(0).getFullname()); + assertEquals(paul, client.listStudents().get(1).getFullname()); + + } + + @Test + @TestAuthor(githubId = "rlabinot") + public void theClientShouldReturnTheNumberOfStudentsAdded() throws IOException, EmptyStoreException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + + client.loadStudent("Pierre"); + client.loadStudent("Paul"); + client.loadStudent("Jacques"); + + assertEquals(1, client.getNumberOfStudentAdded()); + } + + @Test + @TestAuthor(githubId = "rlabinot") + public void theClientShouldReturnTheNumberOfCommandsSent() throws IOException { + IRouletteV2Client client = (IRouletteV2Client)roulettePair.getClient(); + + String pierre = "Pierre"; + + client.loadStudent(pierre); + client.clearDataStore(); + client.getProtocolVersion(); + + assertEquals(3, client.getNumberOfCommands()); + + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2romainSilvestriTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2romainSilvestriTest.java new file mode 100644 index 0000000..fa8d122 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2romainSilvestriTest.java @@ -0,0 +1,63 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.IOException; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 1) + * + * @author Romain Silvestri + */ +public class RouletteV2romainSilvestriTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "romainSilvestri") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "romainSilvestri") + public void theServerShouldReturnTheCorrectNumberOfStudents() throws IOException{ + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + assertEquals(0, client.getNumberOfStudents()); + client.loadStudent("romain"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("florent"); + client.loadStudent("loic"); + assertEquals(3, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "romainSilvestri") + public void theServerShouldBeAbleToClearAllHisData() throws IOException{ + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("romain"); + client.loadStudent("florent"); + assertEquals(2, client.getNumberOfStudents()); + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "romainSilvestri") + public void itShouldBePossibleForARouletteClientToConnectToARouletteServer() throws IOException{ + int port = roulettePair.getServer().getPort(); + IRouletteV2Client client = new RouletteV2ClientImpl(); + assertFalse(client.isConnected()); + client.connect("localhost", port); + assertTrue(client.isConnected()); + } +} \ No newline at end of file diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2shinopillTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2shinopillTest.java new file mode 100644 index 0000000..fd06fa4 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2shinopillTest.java @@ -0,0 +1,63 @@ + +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.Student; + +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +public class RouletteV2shinopillTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "shinopill") + public void theServerShoudReturnTheGoodProtocol() throws IOException{ + assertEquals(roulettePair.client.getProtocolVersion(),"2.0"); + } + + @Test + @TestAuthor(githubId = "shinopill") + public void theServerShouldBeEmptyAfterClear() throws IOException{ + roulettePair.client.loadStudent("Florent"); + roulettePair.client.loadStudent("Olivier"); + assertEquals(roulettePair.client.getNumberOfStudents(),2); + ((IRouletteV2Client)roulettePair.client).clearDataStore(); + assertEquals(roulettePair.client.getNumberOfStudents(),0); + + } + + @Test + @TestAuthor(githubId = "shinopill") + public void theServerShoudReturnTheSameListOfStudent() throws IOException{ + Student a = new Student("a"); + Student b = new Student("b"); + Student c = new Student("c"); + List studentList = new ArrayList<>(); + studentList.add(a); + studentList.add(b); + studentList.add(c); + + roulettePair.client.loadStudents(studentList); + + List severList = ((IRouletteV2Client)roulettePair.client).listStudents(); + + for(int i = 0 ; i < studentList.size(); i++){ + assertEquals(severList.get(i),studentList.get(i)); + } + + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2tranqui793Test.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2tranqui793Test.java new file mode 100644 index 0000000..366f008 --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2tranqui793Test.java @@ -0,0 +1,82 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.data.EmptyStoreException; +import ch.heigvd.res.labs.roulette.data.Student; +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import ch.heigvd.schoolpulse.TestAuthor; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Olivier Liechti + */ +public class RouletteV2tranqui793Test { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + @TestAuthor(githubId = "tranqui793") + public void theServerShouldHaveZeroStudentsAfterDataHasBeenCleared() throws IOException { + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + //test if at start he has 0 students + assertEquals(0, client.getNumberOfStudents()); + //we load some students and test if they have been loaded successfully + client.loadStudent("sacha"); + assertEquals(1, client.getNumberOfStudents()); + client.loadStudent("olivier"); + assertEquals(2, client.getNumberOfStudents()); + client.loadStudent("fabienne"); + assertEquals(3, client.getNumberOfStudents()); + //we clear data and test if the data has been cleared + client.clearDataStore(); + assertEquals(0, client.getNumberOfStudents()); + } + + @Test + @TestAuthor(githubId = "tranqui793") + public void theServerShouldReturnTheCorrectVersionNumber() throws IOException { + assertEquals(RouletteV2Protocol.VERSION, roulettePair.getClient().getProtocolVersion()); + } + + @Test + @TestAuthor(githubId = "tranqui793") + public void theServerShouldReturnTheCorrectNamesOfStudents() throws IOException { + List studentsList = new LinkedList(); + studentsList.add(new Student("sacha")); + studentsList.add(new Student("fabienne")); + studentsList.add(new Student("olivier")); + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("sacha"); + client.loadStudent("olivier"); + client.loadStudent("fabienne"); + List studentServerList = client.listStudents(); + assertTrue(studentServerList.containsAll(studentsList)); + } + + @Test + @TestAuthor(githubId = "tranqui793") + public void theServerShouldHasTheCorrectNumberOfStudents() throws IOException { + List studentsList = new LinkedList(); + studentsList.add(new Student("sacha")); + studentsList.add(new Student("fabienne")); + studentsList.add(new Student("olivier")); + IRouletteV2Client client = (IRouletteV2Client) roulettePair.getClient(); + client.loadStudent("sacha"); + client.loadStudent("olivier"); + client.loadStudent("fabienne"); + List studentServerList = client.listStudents(); + assertTrue(studentsList.size()==studentServerList.size()); + } +} diff --git a/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2yosraharbaouiTest.java b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2yosraharbaouiTest.java new file mode 100644 index 0000000..e925abb --- /dev/null +++ b/QuizRouletteServer-build/QuizRouletteServer-test/src/test/java/ch/heigvd/res/labs/roulette/net/client/RouletteV2yosraharbaouiTest.java @@ -0,0 +1,54 @@ +package ch.heigvd.res.labs.roulette.net.client; + +import ch.heigvd.res.labs.roulette.net.protocol.RouletteV2Protocol; +import java.io.IOException; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +/** + * This class contains automated tests to validate the client and the server + * implementation of the Roulette Protocol (version 2) + * + * @author Yosra Harbaoui + */ +public class RouletteV2yosraharbaouiTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Rule + public EphemeralClientServerPair roulettePair = new EphemeralClientServerPair(RouletteV2Protocol.VERSION); + + @Test + public void theTestRouletteServerShouldRunDuringTests() throws IOException { + assertTrue(roulettePair.getServer().isRunning()); + } + + @Test + public void theServerListSouldBeEmptyAtSetup() throws IOException { + IRouletteV2Client clientV2 = (IRouletteV2Client) roulettePair.getClient(); + assertTrue(clientV2.listStudents().isEmpty()); + } + + @Test + public void theServerShouldGetTheNumberOfStudentsInTheStore() throws IOException { + IRouletteV2Client clientV2 = (IRouletteV2Client) roulettePair.getClient(); + clientV2.loadStudent("Yosra"); + clientV2.loadStudent("Olivier"); + clientV2.loadStudent("Miguel"); + assertEquals(3 , clientV2.getNumberOfStudents()); + } + + @Test + public void theServerListShouldBeEmptyAfterClearDataStore() throws IOException { + IRouletteV2Client clientV2 = (IRouletteV2Client) roulettePair.getClient(); + clientV2.loadStudent("Yosra"); + clientV2.loadStudent("Olivier"); + clientV2.loadStudent("Miguel"); + assertEquals(3, clientV2.getNumberOfStudents()); + clientV2.clearDataStore(); + assertEquals(0, clientV2.getNumberOfStudents()); + + } +}