@Before public void setup() throws IOException, InterruptedException { PropertyConfigurator.configure(getClass().getResourceAsStream("log4j.properties")); ServerConfiguration config = ServerConfiguration.defaults(); // Use any available port config.setPortSocket(0); config.setPortWebsocket(0); main = new MainServer(config); main.getMods().loadExternal(Paths.get("../extra-resources/groovy")); server = main.start(); assertTrue("Server should start correctly.", server.getClients().size() > 0); socketPort = config.getPortSocket(); client1 = createTestClient(); client1.send(new LoginMessage("Tester1")); WelcomeMessage welcome = client1.await(WelcomeMessage.class); assertEquals(200, welcome.getStatus()); System.out.println(server.getClients()); assertEquals(server.getClients().size() + 1, welcome.getUserId()); userId = welcome.getUserId(); client1.await(ChatMessage.class); mods = client1.await(AvailableModsMessage.class); assertNotEquals("No mods found in " + new File("").getAbsolutePath(), 0, mods.getMods().length); }
@Test(timeout = 10000) public void testOnlyOneInvite() throws IOException, InterruptedException { TestClient client2 = createTestClient(); client2.send(new LoginMessage("client2")); WelcomeMessage welcomeMessage = client2.await(WelcomeMessage.class); assertTrue(welcomeMessage.isOK()); int client2id = welcomeMessage.getUserId(); client1.await(UserStatusMessage.class); client1.await(ChatMessage.class); client1.send(new StartGameRequest(client2id, getTestMod())); client1.send(new StartGameRequest(client2id, getTestMod())); client1.await(ServerErrorMessage.class); }