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 new file mode 100644 index 00000000..8d8d23c7 --- /dev/null +++ b/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/ClientStateTest.java @@ -0,0 +1,1001 @@ +package pp.mdga.client.clientState; + +import org.junit.Before; +import org.junit.Test; +import pp.mdga.client.*; +import pp.mdga.client.Ceremony; +import pp.mdga.client.StartPiece; +import pp.mdga.game.Game; +import pp.mdga.message.server.*; + + + +import static org.junit.Assert.assertTrue; + +/** + * this test-class tests the testcases T232-T239 + */ +public class ClientStateTest { + + + + //sets the variables for the states + private Animation animation; + private AudioSettings audioSettings; + private Ceremony ceremony; + private CeremonyStateMachine ceremonyStateMachine; + private ChoosePiece choosePiece; + private ChoosePieceStateMachine choosePieceStateMachine; + private ChoosePowerCard choosePowerCard; + private ClientAutomaton clientAutomaton; + private ClientGameLogic clientGameLogic; + private DetermineStartPlayer determineStartPlayer; + private DetermineStartPlayerStateMachine determineStartPlayerStateMachine; + private Dialogs dialogs; + private DialogsStateMachine dialogsStateMachine; + private GameState gameState; + private GameStateMachine gameStateMachine; + private Interrupt interrupt; + private Lobby lobby; + private MainSettings mainSettings; + private MovePiece movePiece; + private NetworkDialog networkDialog; + private NoPiece noPiece; + private PlayPowerCard playPowerCard; + private Podium podium; + private PowerCard powerCard; + private PowerCardStateMachine powerCardStateMachine; + private RollDice rollDice; + private RollRankingDice rollRankingDice; + private SelectPiece selectPiece; + private Settings settings; + private SettingsStateMachine settingsStateMachine; + private Shield shield; + private Spectator spectator; + private StartDialog startDialog; + private StartPiece startPiece; + private Statistics statistics; + private Swap swap; + private Turn turn; + private TurnStateMachine turnStateMachine; + private VideoSettings videoSettings; + private Waiting waiting; + private WaitingPiece waitingPiece; + private WaitRanking waitRanking; + + //sets the variables for the messages + private ActivePlayer activePlayer; + private AnyPiece anyPiece; + private Briefing briefing; + private Ceremony ceremonyMessage; + private Dice dice; + private DiceAgain diceAgain; + private DiceNow diceNow; + private EndOfTurn endOfTurn; + private LobbyAccept lobbyAccept; + private LobbyDeny lobbyDeny; + private LobbyPlayerJoin lobbyPlayerJoin; + private LobbyPlayerLeave lobbyPlayerLeave; + private MoveMessage moveMessage; + private NoTurn noTurn; + private PauseGame pauseGame; + private PlayCard playCard; + private PossibleCard possibleCard; + private PossiblePiece possiblePiece; + private RankingResponce rankingResponce; + private RankingRollAgain rankingRollAgain; + private ReconnectBriefing reconnectBriefing; + private ResumeGame resumeGame; + private StartPiece startPieceMessage; + private UpdateReady updateReady; + private UpdateTSK updateTSK; + private WaitPiece waitPiece; + + @Before + public void setUp() { + // This method will be executed before each test. + // Initialize common objects or setup required state for Client State transitions. + + //initialize the messages from the server + activePlayer = new ActivePlayer(); + anyPiece = new AnyPiece(); + briefing = new Briefing(); + ceremonyMessage = new Ceremony(); + dice = new Dice(); + diceAgain = new DiceAgain(); + diceNow = new DiceNow(); + endOfTurn = new EndOfTurn(); + lobbyAccept = new LobbyAccept(); + lobbyDeny = new LobbyDeny(); + lobbyPlayerJoin = new LobbyPlayerJoin(); + lobbyPlayerLeave = new LobbyPlayerLeave(); + moveMessage = new MoveMessage(); + noTurn = new NoTurn(); + pauseGame = new PauseGame(); + playCard = new PlayCard(); + possibleCard = new PossibleCard(); + possiblePiece = new PossiblePiece(); + rankingResponce = new RankingResponce(); + rankingRollAgain = new RankingRollAgain(); + reconnectBriefing = new ReconnectBriefing(); + resumeGame = new ResumeGame(); + startPieceMessage = new StartPiece(); + updateReady = new UpdateReady(); + updateTSK = new UpdateTSK(); + waitPiece = new WaitPiece(); + + //initialize the clientGameLogic + clientGameLogic = new ClientGameLogic(); + clientAutomaton = (ClientAutomaton) clientGameLogic.getState(); + + //initialize the settings + mainSettings = new MainSettings(); + videoSettings = new VideoSettings(); + audioSettings = new AudioSettings(); + settings = new Settings(); + + + //initialize the stateMachines + ceremonyStateMachine =ceremony.getCeremonyStateMachine(); + choosePieceStateMachine = choosePiece.getChoosePieceMachine(); + determineStartPlayerStateMachine = determineStartPlayer.getDetermineStartPlayerMachine(); + dialogsStateMachine = dialogs.getDialogsStateMachine(); + gameStateMachine = gameState.getGameStateMachine(); + powerCardStateMachine = powerCard.getPowerCardMachine(); + settingsStateMachine = settings.getSettingsStateMachine(); + turnStateMachine = turn.getTurnMachine(); + + + //initialize the states + dialogs = new Dialogs(clientAutomaton,clientGameLogic); + gameState = new GameState(clientAutomaton,clientGameLogic); + ceremony = new Ceremony(clientAutomaton,clientGameLogic); + interrupt = new Interrupt(clientAutomaton,clientGameLogic,gameState); + + startDialog = new StartDialog(dialogsStateMachine,clientGameLogic); + networkDialog = new NetworkDialog(dialogsStateMachine,clientGameLogic); + lobby = new Lobby(dialogsStateMachine,clientGameLogic); + + podium = new Podium(ceremonyStateMachine,clientGameLogic); + statistics = new Statistics(ceremonyStateMachine,clientGameLogic); + + determineStartPlayer = new DetermineStartPlayer(gameStateMachine,clientGameLogic); + waiting= new Waiting(gameStateMachine,clientGameLogic); + animation = new Animation(gameStateMachine,clientGameLogic); + turn = new Turn(gameStateMachine,clientGameLogic); + spectator = new Spectator(gameStateMachine,clientGameLogic); + + rollRankingDice = new RollRankingDice(determineStartPlayerStateMachine,clientGameLogic); + waitRanking = new WaitRanking(determineStartPlayerStateMachine,clientGameLogic); + + powerCard = new PowerCard(turnStateMachine,clientGameLogic); + playPowerCard = new PlayPowerCard(turnStateMachine,clientGameLogic); + rollDice= new RollDice(turnStateMachine,clientGameLogic); + choosePiece = new ChoosePiece(turnStateMachine,clientGameLogic); + movePiece = new MovePiece(turnStateMachine,clientGameLogic); + + choosePowerCard = new ChoosePowerCard(powerCardStateMachine,clientGameLogic); + shield =new Shield(powerCardStateMachine,clientGameLogic); + swap = new Swap(powerCardStateMachine,clientGameLogic); + + noPiece = new NoPiece(choosePieceStateMachine,clientGameLogic); + waitingPiece = new WaitingPiece(choosePieceStateMachine,clientGameLogic); + selectPiece = new SelectPiece(choosePieceStateMachine,clientGameLogic); + startPiece = new StartPiece(choosePieceStateMachine,clientGameLogic); + } + + /** + * UC-ClientState-01: Test the initial state of the ClientState. + */ + @Test + public void testInitialStateClientState() { + //tests if the clientAutomaton is in Dialogs + assertTrue(clientAutomaton.getState() instanceof Dialogs); + //tests if the statemachine is in StartDialog + assertTrue(dialogsStateMachine.getState() instanceof StartDialog); + } + + /** + * UC-ClientState-02: Test the transition from dialogs to the game state. + */ + @Test + public void testDialogsToGame() { + //TODO + //tests if the client is in Dialogs + assertTrue(clientAutomaton.getState() instanceof Dialogs); + + //sends the startGame-Message to the client + clientGameLogic.receive(startGame); + + //tests if the client is in the gameState after receiving the message + assertTrue(clientAutomaton.getState() instanceof GameState); + + //tests if the new State of the GameStateMachine is in DetermineStartPlayer + GameState gameState1= clientAutomaton.getState(); + GameStateMachine gameStateMachine1 = (GameStateMachine) gameState1.getState(); + assertTrue(gameStateMachine1.getState() instanceof DetermineStartPlayer); + + //tests if the new State of DetermineStartPlayer is RollRankingDice + DetermineStartPlayer determineStartPlayer1=(DetermineStartPlayer) gameStateMachine1.getState(); + DetermineStartPlayerStateMachine determineStartPlayerStateMachine1 = (DetermineStartPlayerStateMachine) determineStartPlayer1.getState(); + assertTrue(DetermineStartPlayerStateMachine.getState() instanceof RollRankingDice); + } + + /** + * UC-ClientState-03: Test the transition from dialogs to the end state of ClientState . + */ + @Test + public void testDialogsToClientStateEndState() { + //Todo Implementation goes here + } + + /** + * UC-ClientState-04: Test the transition from ClientGame to Ceremony. + */ + @Test + public void testClientGameToCeremony() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + + //tests if the client is in GameState + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the Ceremony-Message to the client + clientGameLogic.receive(ceremonyMessage); + + //tests if the client is in the ceremony after receiving the message + assertTrue(clientAutomaton.getState() instanceof Ceremony); + + //tests if the state of ceremony is Podium + Ceremony ceremony1 = (Ceremony) clientAutomaton.getState(); + CeremonyStateMachine ceremonyStateMachine1 = (CeremonyStateMachine) ceremony1.getState(); + assertTrue(ceremonyStateMachine1.getState() instanceof Podium); + } + + /** + * UC-ClientState-05: Test the transition from ClientGame substates to Interrupt. + */ + @Test + public void testClientGameSubStatesToInterrupt() { + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + + //tests if the client is in GameState + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the Ceremony-Message to the client + clientGameLogic.receive(interrupt); + + //tests if the client-automaton is in the interrupt state + assertTrue(clientAutomaton.getState() instanceof Interrupt); + } + + /** + * UC-ClientState-06: Test the transition from the game state to dialogs. + */ + @Test + public void testGameToDialogs() { + // Todo Implementation goes here + } + + /** + * UC-ClientState-07: Test remaining in the Interrupt state. + */ + @Test + public void testStayInInterrupt() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(interrupt); + + //tests if the client is in GameState + assertTrue(clientAutomaton.getState() instanceof Interrupt); + + //Todo + } + + /** + * UC-ClientState-08: Test the transition from ClientInterrupt to the game state. + */ + @Test + public void testClientInterruptToGame() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(interrupt); + + //tests if the client is in GameState + assertTrue(clientAutomaton.getState() instanceof Interrupt); + + //Todo + } + + /** + * UC-ClientState-09: Test the transition from Interrupt to dialogs. + */ + @Test + public void testInterruptToDialogs() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(interrupt); + + //tests if the client is in GameState + assertTrue(clientAutomaton.getState() instanceof Interrupt); + + //Todo + } + + /** + * UC-ClientState-10: Test the transition from Ceremony to dialogs. + */ + @Test + public void testCeremonyToDialogs() { + // Todo Implementation goes here + //send the client in the ceremony + clientAutomaton.goto(ceremony); + assertTrue(clientAutomaton.getStates() instanceof Ceremony); + + //Todo + } + + /** + * UC-ClientState-11: Test the transition from StartDialog to NetworkDialog1. + */ + @Test + public void testStartDialogToNetworkDialog1() { + // Implementation goes here + } + + /** + * UC-ClientState-12: Test the transition from StartDialog to NetworkDialog2. + */ + @Test + public void testStartDialogToNetworkDialog2() { + // Implementation goes here + } + + /** + * UC-ClientState-13: Test the transition from StartDialog to the dialogs end state. + */ + @Test + public void testStartDialogToDialogsEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-14: Test the transition from NetworkDialog to StartDialog. + */ + @Test + public void testNetworkDialogToStartDialog() { + // Implementation goes here + } + + /** + * UC-ClientState-15: Test the transition from NetworkDialog to NetworkDialog1. + */ + @Test + public void testNetworkDialogToNetworkDialog1() { + // Implementation goes here + } + + /** + * UC-ClientState-16: Test the transition from NetworkDialog to NetworkDialog2. + */ + @Test + public void testNetworkDialogToNetworkDialog2() { + // Implementation goes here + } + + /** + * UC-ClientState-17: Test the transition from NetworkDialog to Lobby. + */ + @Test + public void testNetworkDialogToLobby() { + // Implementation goes here + } + + /** + * UC-ClientState-18: Test the transition from Lobby to StartDialog. + */ + @Test + public void testLobbyToStartDialog() { + // Implementation goes here + } + + /** + * UC-ClientState-19: Test remaining in the Lobby state. + */ + @Test + public void testStayInLobby() { + // Implementation goes here + } + + /** + * UC-ClientState-20: Test the transition from Lobby to RollRankingDice. + */ + @Test + public void testLobbyToRollRankingDice() { + // Implementation goes here + } + + /** + * UC-ClientState-21: Test the transition from DetermineStartPlayer to Wait. + */ + @Test + public void testDetermineStartPlayerToWait() { + // Implementation goes here + } + + /** + * UC-ClientState-22: Test the transition from Wait to Animation. + */ + @Test + public void testWaitToAnimation() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + + //tests if the client is in GameState + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the client in WaitState + GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); + gameStateMachine1.goto(waiting); + assertTrue(gameStateMachine1.getState() instanceof Waiting); + + //tests if a piece is moved,that the client goes into Animation + clientGameLogic.receive(moveMessage); //Todo ??? richtige message + assertTrue(gameStateMachine1.getState() instanceof Animation); + + //sends the client in WaitState + gameStateMachine1.goto(waiting); + assertTrue(gameStateMachine1.getState() instanceof Waiting); + + //tests if a powerCard is played,that the client goes into Animation + clientGameLogic.receive(playCard); //Todo ??? richtige message + assertTrue(gameStateMachine1.getState() instanceof Animation); + + //sends the client in WaitState + gameStateMachine1.goto(waiting); + assertTrue(gameStateMachine1.getState() instanceof Waiting); + + //tests if a die is rolled,that the client goes into Animation + clientGameLogic.receive(dice); //Todo ??? richtige message + assertTrue(gameStateMachine1.getState() instanceof Animation); + } + + /** + * UC-ClientState-23: Test the transition from Wait to Turn. + */ + @Test + public void testWaitToTurn() { + //TODo + //sends client in gameState + clientAutomaton.goto(gameState); + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the gameStateMachine in the Turn + GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); + gameStateMachine1.goto(wait); + assertTrue(gameStateMachine1.getState() instanceof Turn); + + //the client receives the message ActivePlayer + clientGameLogic.receive(activePlayer); + + //tests if Client is in Turn + assertTrue(gameStateMachine1.getState() instanceof Turn); + + //tests if Client is in PowerCard + TurnStateMachine turnStateMachine1 = turn.getTurnStateMachine(); + assertTrue(turnStateMachine1.getState() instanceof PowerCard); + + //tests if Client is in ChoosePowerCard + PowerCardStateMachine powerCardStateMachine1 = powerCard.getPowerCardStateMachine(); + assertTrue(powerCardStateMachine1.getState() instanceof ChoosePowerCard); + } + + /** + * UC-ClientState-24: Test the transition from Wait to GameEndState. + */ + @Test + public void testWaitToGameEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-25: Test the transition from Turn substates to GameEndState. + */ + @Test + public void testTurnSubStatesToGameEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-26: Test the transition from Turn sub-states to Wait. + */ + @Test + public void testTurnSubStatesToWait() { + // Implementation goes here + } + + /** + * UC-ClientState-27: Test the transition from Turn sub-states to Spectator. + */ + @Test + public void testTurnSubStatesToSpectator() { + // Implementation goes here + } + + /** + * UC-ClientState-28: Test the transition from Spectator to GameEndState. + */ + @Test + public void testSpectatorToGameEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-29: Test the transition from PowerCard sub-states to PlayPowerCard. + */ + @Test + public void testPowerCardSubStatesToPlayPowerCard() { + // Implementation goes here + } + + /** + * UC-ClientState-30: Test the transition from PowerCard sub-states to RollDice. + */ + @Test + public void testPowerCardSubStatesToRollDice() { + // Implementation goes here + } + + /** + * UC-ClientState-31: Test staying in the PlayPowerCard state. + */ + @Test + public void testStayInPlayPowerCard() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the gameStateMachine in the Turn + GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); + gameStateMachine1.goto(turn); + assertTrue(gameStateMachine1.getState() instanceof Turn); + + //sends the turnStatemachine in PlayPowerCard + TurnStateMachine turnStateMachine1 = turn.getTurnStateMachine(); + turnStateMachine1.goto(playPowerCard); + assertTrue(turnStateMachine1.getState() instanceof PlayPowerCard); + + //Todo send messages to test to stay in playPowerCard + + } + + /** + * UC-ClientState-32: Test the transition from PlayPowerCard to RollDice. + */ + @Test + public void testPlayPowerCardToRollDice() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the gameStateMachine in the Turn + GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); + gameStateMachine1.goto(turn); + assertTrue(gameStateMachine1.getState() instanceof Turn); + + //sends the turnStatemachine in PlayPowerCard + TurnStateMachine turnStateMachine1 = turn.getTurnStateMachine(); + turnStateMachine1.goto(playPowerCard); + assertTrue(turnStateMachine1.getState() instanceof PlayPowerCard); + + //Todo send messages to test the transition in rollDice + //Todo test other messages, that there is no state change + + } + + /** + * UC-ClientState-33: Test staying in the RollDice state. + */ + @Test + public void testStayInRollDice() { + // Implementation goes here + } + + /** + * UC-ClientState-34: Test the transition from RollDice to ChoosePiece. + */ + @Test + public void testRollDiceToChoosePiece() { + // Implementation goes here + } + + /** + * UC-ClientState-35: Test the transition from RollDice to Wait. + */ + @Test + public void testRollDiceToWait() { + // Implementation goes here + } + + /** + * UC-ClientState-36: Test the transition from ChoosePiece to Wait. + */ + @Test + public void testChoosePieceToWait() { + // Implementation goes here + } + + /** + * UC-ClientState-37: Test the transition from ChoosePiece to MovePiece. + */ + @Test + public void testChoosePieceToMovePiece() { + // Implementation goes here + } + + /** + * UC-ClientState-38: Test the transition from MovePiece to Wait. + */ + @Test + public void testMovePieceToWait() { + // Implementation goes here + } + + /** + * UC-ClientState-39: Test the transition from MovePiece to Spectator. + */ + @Test + public void testMovePieceToSpectator() { + // Implementation goes here + } + + /** + * UC-ClientState-40: Test the transition from MovePiece to Ceremony. + */ + @Test + public void testMovePieceToCeremony() { + // Implementation goes here + } + + /** + * UC-ClientState-41: Test staying in the ChoosePowerCard state. + */ + @Test + public void testStayInChoosePowerCard() { + // Implementation goes here + } + + /** + * UC-ClientState-42: Test the transition from ChoosePowerCard to RollDice. + */ + @Test + public void testChoosePowerCardToRollDice() { + // Implementation goes here + } + + /** + * UC-ClientState-43: Test the transition from ChoosePowerCard to Swap. + */ + @Test + public void testChoosePowerCardToSwap() { + // Implementation goes here + } + + /** + * UC-ClientState-44: Test the transition from ChoosePowerCard to Shield. + */ + @Test + public void testChoosePowerCardToShield() { + // Implementation goes here + } + + /** + * UC-ClientState-45: Test staying in the Shield state. + */ + @Test + public void testStayInShield() { + // Implementation goes here + } + + /** + * UC-ClientState-46: Test the transition from Shield to PowerCardEndState. + */ + @Test + public void testShieldToPowerCardEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-47: Test the transition from Swap to PowerCardEndState. + */ + @Test + public void testSwapToPowerCardEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-48: Test no piece in WaitingPiece state. + */ + @Test + public void testNoPieceInWaitingPiece() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the gameStateMachine in the Turn + GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); + gameStateMachine1.goto(turn); + assertTrue(gameStateMachine1.getState() instanceof Turn); + + //sends the turnStatemachine in ChoosePiece + TurnStateMachine turnStateMachine1 = turn.getTurnStateMachine(); + turnStateMachine1.goto(choosePiece); + assertTrue(turnStateMachine1.getState() instanceof ChoosePiece); + + //sends the choosePieceStatemachine in NoPiece + ChoosePieceStateMachine choosePieceStateMachine1 = choosePiece.getChoosePieceStateMachine(); + assertTrue(choosePieceStateMachine1.getState() instanceof NoPiece); + + //Todo test other messages, that there is no state change + + //sends to the clientGameLogic the message WaitPiece + clientGameLogic.receive(waitPiece); + + assertTrue(choosePieceStateMachine1.getState() instanceof WaitingPiece); + } + + /** + * UC-ClientState-49: Test no piece in SelectedPiece state. + */ + @Test + public void testNoPieceInSelectedPiece() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the gameStateMachine in the Turn + GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); + gameStateMachine1.goto(turn); + assertTrue(gameStateMachine1.getState() instanceof Turn); + + //sends the turnStatemachine in ChoosePiece + TurnStateMachine turnStateMachine1 = turn.getTurnStateMachine(); + turnStateMachine1.goto(choosePiece); + assertTrue(turnStateMachine1.getState() instanceof ChoosePiece); + + //sends the choosePieceStatemachine in NoPiece + ChoosePieceStateMachine choosePieceStateMachine1 = choosePiece.getChoosePieceStateMachine(); + assertTrue(choosePieceStateMachine1.getState() instanceof NoPiece); + + //Todo test other messages, that there is no state change + + //sends to the clientGameLogic the message SelectPiece + clientGameLogic.receive(selectPiece); + + assertTrue(choosePieceStateMachine1.getState() instanceof SelectPiece); + } + + /** + * UC-ClientState-50: Test no piece in StartPiece state. + */ + @Test + public void testNoPieceInStartPiece() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the gameStateMachine in the Turn + GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); + gameStateMachine1.goto(turn); + assertTrue(gameStateMachine1.getState() instanceof Turn); + + //sends the turnStatemachine in ChoosePiece + TurnStateMachine turnStateMachine1 = turn.getTurnStateMachine(); + turnStateMachine1.goto(choosePiece); + assertTrue(turnStateMachine1.getState() instanceof ChoosePiece); + + //sends the choosePieceStatemachine in NoPiece + ChoosePieceStateMachine choosePieceStateMachine1 = choosePiece.getChoosePieceStateMachine(); + assertTrue(choosePieceStateMachine1.getState() instanceof NoPiece); + + //Todo test other messages, that there is no state change + + //sends to the clientGameLogic the message StartPiece + clientGameLogic.receive(startPiece); + + assertTrue(choosePieceStateMachine1.getState() instanceof StartPiece); + } + + /** + * UC-ClientState-51: Test no piece in Wait state. + */ + @Test + public void testNoPieceInWait() { + //TODO + //sends the ClientAutomaton in GameState + clientAutomaton.goto(gameState); + assertTrue(clientAutomaton.getState() instanceof GameState); + + //sends the gameStateMachine in the Turn + GameStateMachine gameStateMachine1 = gameState.getGameStateMachine(); + gameStateMachine1.goto(turn); + assertTrue(gameStateMachine1.getState() instanceof Turn); + + //sends the turnStatemachine in ChoosePiece + TurnStateMachine turnStateMachine1 = turn.getTurnStateMachine(); + turnStateMachine1.goto(choosePiece); + assertTrue(turnStateMachine1.getState() instanceof ChoosePiece); + + //sends the choosePieceStatemachine in NoPiece + ChoosePieceStateMachine choosePieceStateMachine1 = choosePiece.getChoosePieceStateMachine(); + assertTrue(choosePieceStateMachine1.getState() instanceof NoPiece); + + //Todo test other messages, that there is no state change + + //sends to the clientGameLogic the message NoTurn + clientGameLogic.receive(noTurn); + + assertTrue(turnStateMachine1.getState() instanceof Waiting); + } + + /** + * UC-ClientState-52: Test staying in the WaitingPiece state. + */ + @Test + public void testStayInWaitingPiece() { + // Implementation goes here + } + + /** + * UC-ClientState-53: Test the WaitingPiece to ChoosePiece end state. + */ + @Test + public void testWaitingPieceInChoosePieceEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-54: Test staying in the SelectedPiece state. + */ + @Test + public void testStayInSelectedPiece() { + // Implementation goes here + } + + /** + * UC-ClientState-55: Test the SelectedPiece to ChoosePiece end state. + */ + @Test + public void testSelectedPieceInChoosePieceEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-56: Test staying in the StartPiece state. + */ + @Test + public void testStayInStartPiece() { + // Implementation goes here + } + + /** + * UC-ClientState-57: Test the StartPiece to ChoosePiece end state. + */ + @Test + public void testStartPieceToChoosePieceEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-58: Test the transition from RollRankingDice to WaitRanking. + */ + @Test + public void testRollRankingDiceToWaitRanking() { + // Implementation goes here + } + + /** + * UC-ClientState-59: Test the transition from WaitRanking to RollRankingDice. + */ + @Test + public void testWaitRankingToRollRankingDice() { + // Implementation goes here + } + + /** + * UC-ClientState-60: Test the transition from WaitRanking to the EndState of determining the starting player. + */ + @Test + public void testWaitRankingToEndStateDetermineStartingPlayer() { + // Implementation goes here + } + + /** + * UC-ClientState-61: Test the transition from Podium to Statistics. + */ + @Test + public void testPodiumToStatistics() { + // Implementation goes here + } + + /** + * UC-ClientState-62: Test the transition from Statistics to the Ceremony end state. + */ + @Test + public void testStatisticsToCeremonyEndState() { + // Implementation goes here + } + + /** + * UC-ClientState-63: Test the transition from MainSettings to VideoSettings. + */ + @Test + public void testMainSettingsToVideoSettings() { + // Implementation goes here + } + + /** + * UC-ClientState-64: Test the transition from MainSettings to AudioSettings. + */ + @Test + public void testMainSettingsToAudioSettings() { + // Implementation goes here + } + + /** + * UC-ClientState-65: Test the transition from MainSettings to ClientState. + */ + @Test + public void testMainSettingsToClientState() { + // Implementation goes here + } + + /** + * UC-ClientState-66: Test staying in the VideoSettings state. + */ + @Test + public void testStayInVideoSettings() { + // Implementation goes here + } + + /** + * UC-ClientState-67: Test the transition from VideoSettings to MainSettings. + */ + @Test + public void testVideoSettingsToMainSettings() { + // Implementation goes here + } + + /** + * UC-ClientState-68: Test staying in the AudioSettings state. + */ + @Test + public void testStayInAudioSettings() { + // Implementation goes here + } + + /** + * UC-ClientState-69: Test the transition from AudioSettings to MainSettings. + */ + @Test + public void testAudioSettingsToMainSettings() { + // Implementation goes here + } + + /** + * UC-ClientState-70: Test the transition from ClientState substates to MainSettings. + */ + @Test + public void testClientStateSubStatesToMainSettings() { + // Implementation goes here + } + +} diff --git a/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/SettingsStateTest.java b/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/SettingsStateTest.java deleted file mode 100644 index 43444c3f..00000000 --- a/Projekte/mdga/model/src/test/java/pp/mdga/client/clientState/SettingsStateTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package pp.mdga.client.clientState; - -import org.junit.Before; -import org.junit.Test; - -/** - * this test-class tests the testcases T232-T239 - */ -public class SettingsStateTest { - - @Before - public void setUp() { - // This method will be executed before each test. - // Initialize common objects or setup required state for Client State transitions. - } - - // UC-ClientState-63 - @Test - public void testMainSettingsToVideoSettings() { - // TODO: Implement test logic for transitioning from Main Settings to Video Settings - } - - // UC-ClientState-64 - @Test - public void testMainSettingsToAudioSettings() { - // TODO: Implement test logic for transitioning from Main Settings to Audio Settings - } - - // UC-ClientState-65 - @Test - public void testMainSettingsToClientState() { - // TODO: Implement test logic for transitioning from Main Settings to a generic Client State - } - - // UC-ClientState-66 - @Test - public void testStayInVideoSettings() { - // TODO: Implement test logic for staying in Video Settings - } - - // UC-ClientState-67 - @Test - public void testVideoSettingsToMainSettings() { - // TODO: Implement test logic for transitioning from Video Settings to Main Settings - } - - // UC-ClientState-68 - @Test - public void testStayInAudioSettings() { - // TODO: Implement test logic for staying in Audio Settings - } - - // UC-ClientState-69 - @Test - public void testAudioSettingsToMainSettings() { - // TODO: Implement test logic for transitioning from Audio Settings to Main Settings - } - - // UC-ClientState-70 - @Test - public void testClientStateSubStatesToMainSettings() { - // TODO: Implement test logic for transitioning from any sub-state of the client to Main Settings - } -} 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 8b76956c..10bf1239 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 @@ -2,29 +2,243 @@ import org.junit.Before; import org.junit.Test; +import pp.mdga.game.Game; +import pp.mdga.message.client.AnimationEnd; +import pp.mdga.message.client.ClientMessage; +import pp.mdga.message.client.ClientStartGame; +import pp.mdga.message.client.DeselectTSK; +import pp.mdga.message.client.ForceContinueGame; +import pp.mdga.message.client.ForceStartGame; +import pp.mdga.message.client.JoinServer; +import pp.mdga.message.client.LeaveGame; +import pp.mdga.message.client.LobbyNotReady; +import pp.mdga.message.client.LobbyReady; +import pp.mdga.message.client.NoPowerCard; +import pp.mdga.message.client.RequestBriefing; +import pp.mdga.message.client.RequestDice; +import pp.mdga.message.client.RequestMove; +import pp.mdga.message.client.RequestPlayCard; +import pp.mdga.message.client.SelectCard; +import pp.mdga.message.client.SelectTSK; +import pp.mdga.message.client.SelectedPieces; +import pp.mdga.message.server.ServerMessage; +import pp.mdga.server.Animation; +import pp.mdga.server.Ceremony; +import pp.mdga.server.ChoosePiece; +import pp.mdga.server.ChoosePieceStateMachine; +import pp.mdga.server.DetermineStartPlayer; +import pp.mdga.server.FirstRoll; +import pp.mdga.server.GameState; +import pp.mdga.server.GameStateMachine; +import pp.mdga.server.Interrupt; +import pp.mdga.server.Lobby; +import pp.mdga.server.MovePiece; +import pp.mdga.server.NoPiece; +import pp.mdga.server.PlayPowerCard; +import pp.mdga.server.PowerCard; +import pp.mdga.server.RollDice; +import pp.mdga.server.RollDiceMachine; +import pp.mdga.server.SecondRoll; +import pp.mdga.server.SelectPiece; +import pp.mdga.server.ServerAutomaton; import pp.mdga.server.ServerGameLogic; +import pp.mdga.server.ServerSender; +import pp.mdga.server.NoTurn; import pp.mdga.server.ServerState; +import pp.mdga.server.StartPiece; +import pp.mdga.server.ThirdRoll; +import pp.mdga.server.Turn; +import pp.mdga.server.TurnStateMachine; +import pp.mdga.server.WaitingPiece; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; public class ServerStateTest { + private ServerGameLogic logic; + private AnimationEnd animationEnd; + private ClientStartGame clientStartGame; + private DeselectTSK deselectTSK; + private ForceContinueGame forceContinueGame; + private ForceStartGame forceStartGame; + private JoinServer joinServer; + private LeaveGame leaveGame; + private LobbyNotReady lobbyNotReady; + private LobbyReady lobbyReady; + private NoPowerCard noPowerCard; + private RequestBriefing requestBriefing; + private RequestDice requestDice; + private RequestMove requestMove; + private RequestPlayCard requestPlayCard; + private SelectCard selectCard; + private SelectedPieces selectedPieces; + private SelectTSK selectTSK; + private ClientMessage[] clientMessages; + private int from; + + private GameStateMachine gameStateMachine; + private TurnStateMachine turnStateMachine; + private RollDiceMachine rollDiceMachine; + private ChoosePieceStateMachine choosePieceStateMachine; + private ServerAutomaton serverAutomaton; + + //TODO + private Animation animation; + private Ceremony ceremony; + private ChoosePiece choosePiece; + private DetermineStartPlayer determineStartPlayer; + private FirstRoll firstRoll; + private GameState gameState; + private Interrupt interrupt; + private Lobby lobby; + private MovePiece movePiece; + private NoPiece noPiece; + private NoTurn noTurn; + private PlayPowerCard playPowerCard; + private PowerCard powerCard; + private RollDice rollDice; + private SecondRoll secondRoll; + private SelectPiece selectPiece; + private StartPiece startPiece; + private ThirdRoll thirdRoll; + private Turn turn; + private WaitingPiece waitingPiece; + @Before - public void setUp(){ - ServerGameLogic logic = new ServerGameLogic(); + public void setUp() { + + logic = new ServerGameLogic(new Game(), new ServerSender() { + @Override + public void send(int id, ServerMessage msg) { + + } + }); + animationEnd = new AnimationEnd(); + clientStartGame = new ClientStartGame(); + deselectTSK = new DeselectTSK(); + forceContinueGame = new ForceContinueGame(); + forceStartGame = new ForceStartGame(); + joinServer = new JoinServer(); + leaveGame = new LeaveGame(); + lobbyReady = new LobbyReady(); + noPowerCard = new NoPowerCard(); + requestBriefing = new RequestBriefing(); + requestDice = new RequestDice(); + requestMove = new RequestMove(); + requestPlayCard = new RequestPlayCard(); + selectCard = new SelectCard(); + selectedPieces = new SelectedPieces(); + selectTSK = new SelectTSK(); + clientMessages = new ClientMessage[]{ + animationEnd, + clientStartGame, + deselectTSK, + forceContinueGame, + forceStartGame, + joinServer, + leaveGame, + lobbyReady, + noPowerCard, + requestBriefing, + requestDice, + requestMove, + requestPlayCard, + selectCard, + selectedPieces, + selectTSK + }; + from=1234; + + choosePieceStateMachine = choosePiece.getChoosePieceMachine(); + rollDiceMachine = rollDice.getRollDicemachine(); + turnStateMachine = turn.getTurnStatemachine(); + serverAutomaton = new ServerAutomaton(logic); + gameStateMachine = gameState.getGameStatemachine(); + + thirdRoll = new ThirdRoll(rollDiceMachine,logic); + secondRoll = new SecondRoll(rollDiceMachine,logic); + firstRoll = new FirstRoll(rollDiceMachine,logic); + + noPiece = new NoPiece(choosePieceStateMachine,logic); + noTurn = new NoTurn(choosePieceStateMachine,logic); + waitingPiece = new WaitingPiece(choosePieceStateMachine,logic); + startPiece = new StartPiece(choosePieceStateMachine,logic); + selectPiece = new SelectPiece(choosePieceStateMachine,logic); + + powerCard = new PowerCard(turnStateMachine,logic); + playPowerCard = new PlayPowerCard(turnStateMachine,logic); + rollDice = new RollDice(turnStateMachine,logic); + choosePiece = new ChoosePiece(turnStateMachine,logic); + movePiece = new MovePiece(turnStateMachine,logic); + + determineStartPlayer = new DetermineStartPlayer(gameStateMachine,logic); + turn = new Turn(gameStateMachine,logic); + animation = new Animation(gameStateMachine,logic); + + lobby = new Lobby(serverAutomaton,logic); + gameState = new GameState(serverAutomaton,logic); + ceremony = new Ceremony(serverAutomaton,logic); + interrupt = new Interrupt(serverAutomaton,logic,gameState); } @Test public void testInitialStateServerState() { - + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + assertTrue(automaton.getState() instanceof Lobby); } @Test public void testLobbyToDetermineStartPlayer() { - // TODO: Implement test logic for transition from Lobby to Determine Start Player + //tests if Server is in State Lobby + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + assertTrue(automaton.getState() instanceof Lobby); + Lobby lobby = (Lobby) automaton.getState(); + //tests, when not all players are ready and the hosts send clientStartGame, that the Server stays in Lobby + //TODO set one player not ready + lobby.receivedStartGame(clientStartGame, from); + assertTrue(automaton.getState() instanceof Lobby); + //tests, when all players are ready and the hosts send clientStartGame, that the Server changes to DSP + //TODO set all player Ready + lobby.receivedStartGame(clientStartGame, from); + assertTrue(automaton.getState() instanceof GameState); + GameState gameState = (GameState) automaton.getState(); + assertTrue(gameState.getState() instanceof DetermineStartPlayer); } @Test public void testStayInLobby() { - // TODO: Implement test logic for staying in the Lobby + //tests if Server is in State Lobby + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + assertTrue(automaton.getState() instanceof Lobby); + + //lobby gets all possible messages + Lobby lobby = (Lobby) automaton.getState(); + + //logic gets all messages + logic.received(animationEnd, from); + logic.received(clientStartGame, from); + logic.received(deselectTSK, from); + logic.received(forceContinueGame, from); + logic.received(forceStartGame, from); + logic.received(joinServer, from); + logic.received(leaveGame, from); + logic.received(lobbyReady, from); + logic.received(noPowerCard, from); + logic.received(requestBriefing, from); + logic.received(requestDice, from); + logic.received(requestMove, from); + logic.received(requestPlayCard, from); + logic.received(selectCard, from); + logic.received(selectedPieces, from); + logic.received(selectTSK, from); + + //tests if Server is still in Lobby + assertTrue(automaton.getState() instanceof Lobby); } @Test @@ -35,11 +249,26 @@ public void testServerGameSubStatesToInterrupt() { @Test public void testServerGameToCeremony() { // TODO: Implement test logic for transition from Server Game to Ceremony + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + assertTrue(automaton.getState() instanceof Lobby); + Lobby lobby = (Lobby) automaton.getState(); + //Todo set all players ready + logic.received(clientStartGame, from); + assertTrue(automaton.getState() instanceof GameState); + //Todo game is finished + assertTrue(automaton.getState() instanceof Ceremony); } @Test public void testInterruptToGameContinue() { - // TODO: Implement test logic for transition from Interrupt to Game Continue + //sends the server into the interrupt + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + automaton.gotoState(interrupt); + assertTrue(automaton.getState() instanceof Interrupt); + //sends the continue-message to the server + logic.received(forceContinueGame, from); + //tests if new Stet is in GameState + assertTrue(automaton.getState() instanceof GameState); } @Test @@ -58,23 +287,71 @@ public void testCeremonyToServerStateEndState() { } @Test - public void testDeterminStartPlayerToDetermineStartPlayer1() { - // TODO: Implement test logic for Determine Start Player to Determine Start Player (Variant 1) + public void testDetermineStartPlayerToDetermineStartPlayer1() { + // Implement test logic for Determine Start Player to Determine Start Player (Variant 1) + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + assertTrue(automaton.getState() instanceof GameState); + GameState gameState = (GameState) automaton.getState(); + assertTrue(gameState.getState() instanceof GameStateMachine); + GameStateMachine gameStateMachine = (GameStateMachine) gameState.getState(); + assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayer); + + logic.received(requestDice, from); + + assertTrue(automaton.getState() instanceof DetermineStartPlayer); + } @Test - public void testDeterminStartPlayerToDetermineStartPlayer2() { - // TODO: Implement test logic for Determine Start Player to Determine Start Player (Variant 2) + public void testDetermineStartPlayerToDetermineStartPlayer2() { + // Implement test logic for Determine Start Player to Determine Start Player (Variant 2) + // sends the server in determineStartPlayer + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + assertTrue(automaton.getState() instanceof GameState); + GameState gameState = (GameState) automaton.getState(); + assertTrue(gameState.getState() instanceof GameStateMachine); + GameStateMachine gameStateMachine = (GameStateMachine) gameState.getState(); + assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayer); + //Todo: input same dices for both players + logic.received(requestDice, from); + logic.received(requestDice, 1235); + assertTrue(automaton.getState() instanceof DetermineStartPlayer); } @Test - public void testDeterminStartPlayerToAnimation() { - // TODO: Implement test logic for Determine Start Player to Animation + public void testDetermineStartPlayerToAnimation() { + // Implement test logic for Determine Start Player to Determine Start Player (Variant 2) + // sends the server in determineStartPlayer + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + assertTrue(automaton.getState() instanceof GameState); + GameState gameState = (GameState) automaton.getState(); + assertTrue(gameState.getState() instanceof GameStateMachine); + GameStateMachine gameStateMachine = (GameStateMachine) gameState.getState(); + assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayer); + //Todo: input different dices for both players + logic.received(requestDice, from); + logic.received(requestDice, 1235); + assertTrue(automaton.getState() instanceof Animation); } @Test public void testAnimationToPowerCard() { - // TODO: Implement test logic for transition from Animation to Power Card + ServerAutomaton automaton = (ServerAutomaton) logic.getState(); + assertTrue(automaton.getState() instanceof GameState); + GameState gameState = (GameState) automaton.getState(); + assertTrue(gameState.getState() instanceof GameStateMachine); + GameStateMachine gameStateMachine = (GameStateMachine) gameState.getState(); + assertTrue(gameStateMachine.getState() instanceof DetermineStartPlayer); + //Todo: input different dices for both players + logic.received(requestDice, from); + logic.received(requestDice, 1235); + assertTrue(automaton.getState() instanceof Animation); + logic.received(animationEnd, from); + assertTrue(gameStateMachine.getState() instanceof Animation); + logic.received(animationEnd, 1235); + assertTrue(gameStateMachine.getState() instanceof Turn); + TurnStateMachine turnStateMachine = (TurnStateMachine) automaton.getState(); + assertTrue(turnStateMachine.getState() instanceof PowerCard); } @Test