Package com.music.web.websocket

Examples of com.music.web.websocket.GameHandler


        return session;
    }

    @Test
    public void gameInitializedTest() throws Exception {
        GameHandler handler = new GameHandler();
        initializeGame(handler);

        GameEvent response = mapper.readValue(messages.get("1").removeLast().getPayload().toString(), GameEvent.class);
        Assert.assertEquals(GameEventType.GAME_INITIALIZED, response.getType());

        Assert.assertEquals(1, handler.getGames().size());

        Game game = handler.getGames().values().iterator().next();
        Assert.assertEquals(game.getId(), response.getGameId());
    }
View Full Code Here


    }

    @Test
    public void gameStartedTest() throws Exception {

        GameHandler handler = new GameHandler();
        handler.setPieceService(pieceServiceMock);

        initializeGame(handler);
        Game game = handler.getGames().values().iterator().next();

        GameMessage startMsg = new GameMessage();
        startMsg.setAction(GameAction.START);
        startMsg.setGameId(game.getId());

        WebSocketSession session = getSession("1");
        handler.handleMessage(session, getTextMessage(startMsg));

        GameEvent responseNewPiece = mapper.readValue(messages.get("1").removeLast().getPayload().toString(), GameEvent.class);
        GameEvent responseGameStarted = mapper.readValue(messages.get("1").removeLast().getPayload().toString(), GameEvent.class);
        Assert.assertEquals(GameEventType.GAME_STARTED, responseGameStarted.getType());
View Full Code Here

    }

    @Test
    public void playerJoinedTest() throws Exception {

        GameHandler handler = new GameHandler();
        handler.setPieceService(pieceServiceMock);

        initializeGame(handler);
        Game game = handler.getGames().values().iterator().next();

        GameMessage playerJoinMsg = new GameMessage();
        playerJoinMsg.setAction(GameAction.JOIN);
        playerJoinMsg.setPlayerName("AAA");
        playerJoinMsg.setGameId(game.getId());

        getSession("1");
        WebSocketSession player2Session = getSession("2");

        handler.afterConnectionEstablished(player2Session);

        handler.handleMessage(player2Session, getTextMessage(playerJoinMsg));

        GameEvent playerJoinedEvent = mapper.readValue(messages.get("1").removeLast().getPayload().toString(), GameEvent.class);
        Assert.assertEquals(GameEventType.PLAYER_JOINED, playerJoinedEvent.getType());
        Assert.assertEquals(playerJoinedEvent.getPlayerId(), "2");
View Full Code Here

    }

    @Test
    public void gameFinishedTest() throws Exception {
        GameHandler handler = new GameHandler();
        handler.setPieceService(pieceServiceMock);

        initializeGame(handler);
        Game game = handler.getGames().values().iterator().next();


        GameMessage playerJoinMsg = new GameMessage();
        playerJoinMsg.setAction(GameAction.JOIN);
        playerJoinMsg.setPlayerName("AAA");
        playerJoinMsg.setGameId(game.getId());
        WebSocketSession session = getSession("1");

        handler.handleMessage(session, getTextMessage(playerJoinMsg));
        game.setSecondsBeforeNextPiece(0);

        // Answer all three questions
        for (int i = 0; i < 3; i ++) {
            game.sendNextPiece();
            GameMessage answerMsg = new GameMessage();
            answerMsg.setAction(GameAction.ANSWER);
            com.music.web.websocket.dto.Answer answer = new com.music.web.websocket.dto.Answer();
            answer.setMainInstrument(0);
            answer.setMetreNumerator(2);
            answer.setMetreDenominator(4);
            answer.setTempo(80);
            answerMsg.setAnswer(answer);
            answerMsg.setGameId(game.getId());
            handler.handleMessage(session, getTextMessage(answerMsg));
        }
        Assert.assertFalse(game.isStarted());
        Assert.assertTrue(game.getResults().getRanking().contains("1"));
        Assert.assertTrue(game.getResults().getScores().containsKey(playerJoinMsg.getPlayerName()));
    }
View Full Code Here

TOP

Related Classes of com.music.web.websocket.GameHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.