From 0d043e4bb458c1693cad8e63e83b96f1afd9ce6f Mon Sep 17 00:00:00 2001 From: Benjamin Feyer Date: Sun, 1 Dec 2024 14:10:05 +0100 Subject: [PATCH] added some more messages to test the server --- .../client/clientState/ClientStateTest.java | 38 ++-- .../server/serverState/ServerStateTest.java | 205 ++++++++++++++---- 2 files changed, 186 insertions(+), 57 deletions(-) diff --git a/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java index 5c0db41c..cf4fd4e1 100644 --- a/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java +++ b/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java @@ -5,7 +5,6 @@ import pp.mdga.client.dialogState.*; import pp.mdga.client.ceremonyState.*; import pp.mdga.client.gameState.*; -import pp.mdga.client.settingsState.*; import pp.mdga.client.gameState.turnState.*; import pp.mdga.client.gameState.determineStartPlayerState.*; import pp.mdga.client.gameState.turnState.choosePieceState.*; @@ -33,7 +32,6 @@ public class ClientStateTest { //declare states here private AnimationState animation; - private AudioSettingsState audioSettings; private CeremonyState ceremony; private ChoosePieceState choosePiece; private ChoosePowerCardState choosePowerCard; @@ -43,7 +41,6 @@ public class ClientStateTest { private GameState gameState; private InterruptState interrupt; private LobbyState lobby; - private MainSettingsState mainSettings; private MovePieceState movePiece; private NetworkDialogState networkDialog; private NoPieceState noPiece; @@ -53,7 +50,6 @@ public class ClientStateTest { private RollDiceState rollDice; private RollRankingDiceState rollRankingDice; private SelectPieceState selectPiece; - private SettingsState settings; private ShieldState shield; private SpectatorState spectator; private StartDialogState startDialog; @@ -61,7 +57,6 @@ public class ClientStateTest { private StatisticsState statistics; private SwapState swap; private TurnState turnState; - private VideoSettingsState videoSettings; private WaitingState waiting; private WaitingPieceState waitingPiece; private WaitRankingState waitRanking; @@ -87,8 +82,8 @@ public class ClientStateTest { private PlayCardMessage playCardTurbo; private PossibleCardMessage possibleCard; private PossiblePieceMessage possiblePiece; - private PossiblePieceMessage possiblePieceSwap; //TODO - private PossiblePieceMessage possiblePieceShield;//TODO + private PossiblePieceMessage possiblePieceSwap; + private PossiblePieceMessage possiblePieceShield; private RankingResponseMessage rankingResponse; private RankingRollAgainMessage rankingRollAgain; private ReconnectBriefingMessage reconnectBriefing; @@ -141,8 +136,8 @@ public void send(ClientMessage msg) { endOfTurn = new EndOfTurnMessage(); lobbyAccept = new LobbyAcceptMessage(); lobbyDeny = new LobbyDenyMessage(); - lobbyPlayerJoin = new LobbyPlayerJoinMessage(name); - lobbyPlayerLeave = new LobbyPlayerLeaveMessage(name, color); + lobbyPlayerJoin = new LobbyPlayerJoinMessage(from,name); + lobbyPlayerLeave = new LobbyPlayerLeaveMessage(from, color); moveMessage = new MoveMessage("www",false, 20);//Todo noTurn = new NoTurnMessage(); interruptMessage = new PauseGameMessage(); @@ -468,7 +463,8 @@ public void testCeremonyToDialogs() { ceremony.setState(statistics); assertEquals(ceremony.getState(), statistics); - //Todo simulate the button next + //simulate the button next + clientGameLogic.selectNext(); assertEquals(clientGameLogic.getState(), dialogs); assertEquals(dialogs.getState(), startDialog); @@ -489,10 +485,14 @@ public void testStartDialogToNetworkDialog1() { assertEquals(dialogs.getState(), startDialog); //simulate the button-push for the join-Button - clientGameLogic.selectJoin("www");//TODO + clientGameLogic.selectJoin(name); + //tests if the client is in the network-dialog assertEquals(clientGameLogic.getState(), dialogs); assertEquals(dialogs.getState(), networkDialog); + + //tests if the client is not host + assertFalse(clientGameLogic.isHost()); } /** @@ -510,10 +510,14 @@ public void testStartDialogToNetworkDialog2() { assertEquals(dialogs.getState(), startDialog); //simulate the button-push for the host-Button - clientGameLogic.selectHost("www");//TODO + clientGameLogic.selectHost(name); + //tests if the client is in the network-dialog assertEquals(clientGameLogic.getState(), dialogs); assertEquals(dialogs.getState(), networkDialog); + + //tests if the client is host + assertTrue(clientGameLogic.isHost()); } /** @@ -868,7 +872,7 @@ public void testWaitToGameEndState() { } /** - * UC-ClientState-25: Test the transition from Turn substates to GameEndState. + * UC-ClientState-25: Test the transition from Turn sub-states to GameEndState. */ @Test public void testTurnSubStatesToGameEndState() { @@ -1940,7 +1944,7 @@ public void testStayInShield() { clientGameLogic.received(lobbyPlayerLeave); clientGameLogic.received(moveMessage); clientGameLogic.received(noTurn); - //clientGameLogic.received(interruptMessage); commented out, because it indicate a state-change to interrupt + //clientGameLogic.received(interruptMessage); commented out, because it indicates a state-change to interrupt //clientGameLogic.received(playCardSwap); //clientGameLogic.received(playCardShield); //clientGameLogic.received(playCardTurbo); @@ -2100,7 +2104,7 @@ public void testNoPieceInWaitingPiece() { clientGameLogic.received(lobbyPlayerLeave); clientGameLogic.received(moveMessage); //clientGameLogic.received(noTurn); - //clientGameLogic.received(interruptMessage); commented out, because it indicate a statechange to interrupt + //clientGameLogic.received(interruptMessage); commented out, because it indicates a statechange to interrupt clientGameLogic.received(playCardSwap); clientGameLogic.received(playCardShield); clientGameLogic.received(playCardTurbo); @@ -2431,7 +2435,7 @@ public void testStayInSelectedPiece() { choosePiece.setState(selectPiece); assertEquals(choosePiece.getState(), selectPiece); - //send all server messages which dont force a state change here + //send all server messages which don't force a state change here clientGameLogic.received(activePlayer); clientGameLogic.received(anyPiece); clientGameLogic.received(briefing); @@ -2520,7 +2524,7 @@ public void testStayInStartPiece() { choosePiece.setState(startPiece); assertEquals(choosePiece.getState(), startPiece); - //send all messages which dont force a state change + //send all messages which don't force a state change clientGameLogic.received(activePlayer); clientGameLogic.received(anyPiece); clientGameLogic.received(briefing); diff --git a/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java index 4b0b0e39..7982a128 100644 --- a/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java +++ b/Projekte/mdga/model/src/test/java/pp/mdga/server/serverState/ServerStateTest.java @@ -14,6 +14,8 @@ import pp.mdga.server.*; import pp.mdga.server.automaton.*; +import java.util.ArrayList; + import static org.junit.Assert.*; /** @@ -24,26 +26,28 @@ public class ServerStateTest { //declare game here private Game game; - //declare client-messages here + //declare serverGameLogic here private ServerGameLogic serverGameLogic; + + //declare client-messages here private AnimationEndMessage animationEnd; - private ClientStartGameMessage clientStartGame; private DeselectTSKMessage deselectTSK; + private DisconnectedMessage disconnected; private ForceContinueGameMessage forceContinueGame; - private StartGameMessage forceStartGame; private JoinServerMessage joinServer; private LeaveGameMessage leaveGame; private LobbyNotReadyMessage lobbyNotReady; private LobbyReadyMessage lobbyReady; private NoPowerCardMessage noPowerCard; private RequestBriefingMessage requestBriefing; - private RequestDieMessage requestDice; + private RequestDieMessage requestDie; private RequestMoveMessage requestMove; private RequestPlayCardMessage requestPlayCard; private SelectCardMessage selectCard; private SelectedPiecesMessage selectedPieces; private SelectTSKMessage selectTSK; - private DisconnectedMessage disconnect; + private StartGameMessage startGame; + //TODO declare two players @@ -55,12 +59,23 @@ public class ServerStateTest { private int IDPlayerClient; private Color playerClientColor; - //todo declare a piece + //declare a movable piece for client private Piece piece; private PieceState pieceState; private int IDPiece; + //declare 3 pieces in home from client + private Piece pieceHome1; + private int IDPiece1; + private Piece pieceHome2; + private int IDPiece2; + private Piece pieceHome3; + private int IDPiece3; + + //todo declare a card for client + private BonusCard bonusCardClient; + //TODO declare the states here private AnimationState animation; @@ -91,6 +106,7 @@ public class ServerStateTest { public void setUp() { game = new Game(); + game.setActiveColor(playerClientColor); serverGameLogic = new ServerGameLogic(new ServerSender() { @Override @@ -105,21 +121,23 @@ public void broadcast(ServerMessage message) { }, game); animationEnd = new AnimationEndMessage(); - clientStartGame = new ClientStartGameMessage(); - deselectTSK = new DeselectTSKMessage(Color.ARMY);//TODO + deselectTSK = new DeselectTSKMessage(playerClientColor); + disconnected = new DisconnectedMessage(); forceContinueGame = new ForceContinueGameMessage(); - forceStartGame = new StartGameMessage(); joinServer = new JoinServerMessage(); leaveGame = new LeaveGameMessage(); + lobbyNotReady = new LobbyNotReadyMessage(); lobbyReady = new LobbyReadyMessage(); noPowerCard = new NoPowerCardMessage(); requestBriefing = new RequestBriefingMessage(); - requestDice = new RequestDieMessage(); - requestMove = new RequestMoveMessage("www");//todo - requestPlayCard = new RequestPlayCardMessage(BonusCard.SHIELD,"www","www");//Todo - selectCard = new SelectCardMessage(BonusCard.SHIELD); //TODO - selectedPieces = new SelectedPiecesMessage("www"); //TODO - selectTSK = new SelectTSKMessage(Color.ARMY); //TODO + requestDie = new RequestDieMessage(); + requestMove = new RequestMoveMessage(IDPiece); + requestPlayCard = RequestPlayCardMessage.requestPlayShield(bonusCardClient); //TODO + selectCard = new SelectCardMessage(); //TODO + selectedPieces = new SelectedPiecesMessage(); + selectTSK = new SelectTSKMessage(); + startGame = new StartGameMessage(); + //initialize the states here thirdRoll = rollDiceState.getThirdRollState(); @@ -147,26 +165,40 @@ public void broadcast(ServerMessage message) { ceremonyState = (CeremonyState) serverGameLogic.getCeremonyState(); interruptState = (InterruptState) serverGameLogic.getInterruptState(); - //Todo initialize two players - + //initialize two players playerHost = new Player("Host"); IDPlayerHost = 1; - playerHostColor = Color.ARMY; + playerHostColor = Color.CYBER; playerHost.setColor(playerHostColor); game.addPlayer(IDPlayerHost,playerHost); playerClient = new Player("Client"); IDPlayerClient = 2; - playerClientColor = Color.AIRFORCE; + playerClientColor = Color.ARMY; playerClient.setColor(playerClientColor); + playerClient.addHandCards(bonusCardClient); game.addPlayer(IDPlayerClient,playerClient); - //todo initialize a piece + //initialize a piece for client IDPiece = 3; pieceState = PieceState.ACTIVE; piece = new Piece(playerClientColor,pieceState,IDPiece); + game.getBoard().setPieceOnBoard(15,piece); //sets the piece at inx 12, bc the home begins after inx 19 + + //initialize the other 3 House-Pieces + IDPiece1 =4; + IDPiece2 =5; + IDPiece3 =6; + pieceHome1 = new Piece(playerClientColor,PieceState.HOMEFINISHED,IDPiece1); + pieceHome2 = new Piece(playerClientColor,PieceState.HOMEFINISHED,IDPiece2); + pieceHome3 = new Piece(playerClientColor,PieceState.HOMEFINISHED,IDPiece3); + game.getBoard().getPlayerData().get(playerClientColor).setPieceInHome(1,pieceHome1); + game.getBoard().getPlayerData().get(playerClientColor).setPieceInHome(2,pieceHome2); + game.getBoard().getPlayerData().get(playerClientColor).setPieceInHome(3,pieceHome3); + + //initialize the powerCard + bonusCardClient = BonusCard.SHIELD; - game.getBoard().setPieceOnBoard(15,piece); //TODO } /** @@ -188,13 +220,40 @@ public void testLobbyToDetermineStartPlayer() { serverGameLogic.setCurrentState(lobbyState); assertEquals(serverGameLogic.getCurrentState(),lobbyState); - //Todo send all other messages, which dont indicate a state change + //send all other messages, which dont indicate a state change + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + serverGameLogic.received(disconnected, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + //serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + //serverGameLogic.received(startGame, IDPlayerClient); + //tests if the server is still in the lobby-state assertEquals(serverGameLogic.getLobbyState(),lobbyState); + //sets both players ready + game.setAllReady(false); + + //tests if the server is still in the lobby-state + assertEquals(serverGameLogic.getLobbyState(),lobbyState); + + //sets both players ready + game.setAllReady(true); + //sends the startGame-message IDPlayerClient the Host to the server - serverGameLogic.received(clientStartGame, IDPlayerHost); //TODO is playerId == ConnectionID? + serverGameLogic.received(startGame, IDPlayerHost); //tests if the server is in DSP-state assertEquals(serverGameLogic.getCurrentState(),gameState); @@ -210,23 +269,24 @@ public void testStayInLobby() { serverGameLogic.setCurrentState(lobbyState); assertEquals(serverGameLogic.getCurrentState(),lobbyState); - //TODO serverGameLogic gets all messages, which dont indicate a state change + //serverGameLogic gets all messages, which dont indicate a state change serverGameLogic.received(animationEnd, IDPlayerClient); - serverGameLogic.received(clientStartGame, IDPlayerClient); serverGameLogic.received(deselectTSK, IDPlayerClient); + //serverGameLogic.received(disconnected, IDPlayerClient); serverGameLogic.received(forceContinueGame, IDPlayerClient); - serverGameLogic.received(forceStartGame, IDPlayerClient); serverGameLogic.received(joinServer, IDPlayerClient); - serverGameLogic.received(leaveGame, IDPlayerClient); + //serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); serverGameLogic.received(lobbyReady, IDPlayerClient); serverGameLogic.received(noPowerCard, IDPlayerClient); serverGameLogic.received(requestBriefing, IDPlayerClient); - serverGameLogic.received(requestDice, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); serverGameLogic.received(requestMove, IDPlayerClient); serverGameLogic.received(requestPlayCard, IDPlayerClient); serverGameLogic.received(selectCard, IDPlayerClient); serverGameLogic.received(selectedPieces, IDPlayerClient); serverGameLogic.received(selectTSK, IDPlayerClient); + //serverGameLogic.received(startGame, IDPlayerClient); //tests if Server is still in Lobby assertEquals(serverGameLogic.getCurrentState(),lobbyState); @@ -241,10 +301,8 @@ public void testServerGameSubStatesToInterrupt() { serverGameLogic.setCurrentState(gameState); assertEquals(serverGameLogic.getCurrentState(),gameState); - //Todo - //sends the interrupt - serverGameLogic.received(disconnect,IDPlayerClient); + serverGameLogic.received(disconnected,IDPlayerClient); //tests if the server is in the Interrupt-state assertEquals(serverGameLogic.getInterruptState(),interruptState); @@ -274,7 +332,24 @@ public void testInterruptToGameContinue() { serverGameLogic.setCurrentState(interruptState); assertEquals(serverGameLogic.getCurrentState() ,interruptState); - //Todo send all other messages except forceContinue + //send all other messages except forceContinue + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + serverGameLogic.received(disconnected, IDPlayerClient); + //serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + serverGameLogic.received(startGame, IDPlayerClient); //tests if the server is still in Interrupt assertEquals(serverGameLogic.getCurrentState(),interruptState); @@ -342,7 +417,24 @@ public void testDetermineStartPlayerToDetermineStartPlayer1() { gameState.setCurrentState(determineStartPlayerState); assertEquals(gameState.getCurrentState() ,determineStartPlayerState); - //TODO sends messages to the server + //sends messages to the server + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + //serverGameLogic.received(disconnected, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + //serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + serverGameLogic.received(startGame, IDPlayerClient); //tests if the server is still in DSP-state assertEquals(serverGameLogic.getCurrentState() ,gameState); @@ -362,15 +454,15 @@ public void testDetermineStartPlayerToDetermineStartPlayer2() { gameState.setCurrentState(determineStartPlayerState); assertEquals(gameState.getCurrentState() ,determineStartPlayerState); - //TODO sends messages 2 RequestDiceMessage, die gleich geränkt werden to the server - //sends the requestDiceMessage to the server - gameState.received(requestDice, IDPlayerClient); + //TODO sends messages 2 requestDieMessage, die gleich geränkt werden to the server + //sends the requestDieMessage to the server + gameState.received(requestDie, IDPlayerClient); //tests if the server is still in DSP-state assertEquals(serverGameLogic.getCurrentState() ,gameState); assertEquals(gameState.getCurrentState() ,determineStartPlayerState); - //sends the requestDiceMessage to the server + //sends the requestDieMessage to the server gameState.received(requestMove, IDPlayerClient); //tests if the server is still in DSP-state @@ -391,7 +483,7 @@ public void testDetermineStartPlayerToAnimation() { gameState.setCurrentState(determineStartPlayerState); assertEquals(gameState.getCurrentState() ,determineStartPlayerState); - //TODO sends messages 2 RequestDiceMessage, die ungleich geränkt werden, sodass der server weitergeht + //TODO sends messages 2 requestDieMessage, die ungleich geränkt werden, sodass der server weitergeht //tests if the Server is in animationState assertEquals(serverGameLogic.getCurrentState() ,gameState); @@ -440,7 +532,23 @@ public void testTurnToAnimation() { gameState.setCurrentState(turnState); assertEquals(gameState.getCurrentState() ,turnState); - //todo set the turn finished and there are still two players left + //sends the server in Animation + turnState.setCurrentState(animation); + assertEquals(turnState.getState(),animation); + + //set dices-eyes in game !=6 + game.setDiceEyes(4); + + //serverGameLogic receives animationEndMessages + serverGameLogic.received(animationEnd, IDPlayerClient); + + //tests if the server is still in Animation-State + assertEquals(serverGameLogic.getCurrentState() ,gameState); + assertEquals(gameState.getCurrentState() ,turnState); + assertEquals(turnState.getState(),animation); + + //sends the second animationEndMessage + serverGameLogic.received(animationEnd, IDPlayerHost); //tests if the server is in the AnimationState assertEquals(serverGameLogic.getCurrentState() ,gameState); @@ -485,7 +593,24 @@ public void testStayInPowerCard() { turnState.setCurrentState(powerCardState); assertEquals(turnState.getCurrentState() ,powerCardState); - //Todo: receive messages which dont lead to a state change + //receive messages which don't lead to a state change todo + serverGameLogic.received(animationEnd, IDPlayerClient); + serverGameLogic.received(deselectTSK, IDPlayerClient); + //serverGameLogic.received(disconnected, IDPlayerClient); + serverGameLogic.received(forceContinueGame, IDPlayerClient); + serverGameLogic.received(joinServer, IDPlayerClient); + serverGameLogic.received(leaveGame, IDPlayerClient); + serverGameLogic.received(lobbyNotReady, IDPlayerClient); + serverGameLogic.received(lobbyReady, IDPlayerClient); + serverGameLogic.received(noPowerCard, IDPlayerClient); + serverGameLogic.received(requestBriefing, IDPlayerClient); + serverGameLogic.received(requestDie, IDPlayerClient); + serverGameLogic.received(requestMove, IDPlayerClient); + serverGameLogic.received(requestPlayCard, IDPlayerClient); + serverGameLogic.received(selectCard, IDPlayerClient); + //serverGameLogic.received(selectedPieces, IDPlayerClient); + serverGameLogic.received(selectTSK, IDPlayerClient); + serverGameLogic.received(startGame, IDPlayerClient); //tests if the server is in PowerCard assertEquals(serverGameLogic.getCurrentState() ,gameState);