edited some comments in the methods and wrote in som methods, to test unwanted statechanges
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -6,14 +6,13 @@
|
||||
import pp.mdga.game.BonusCard;
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.Game;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.server.ServerMessage;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.server.*;
|
||||
import pp.mdga.server.automaton.CeremonyState;
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
import pp.mdga.server.automaton.InterruptState;
|
||||
import pp.mdga.server.automaton.LobbyState;
|
||||
import pp.mdga.server.automaton.ServerState;
|
||||
import pp.mdga.server.automaton.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -46,20 +45,21 @@ public class ServerStateTest {
|
||||
private SelectTSKMessage selectTSK;
|
||||
private DisconnectedMessage disconnect;
|
||||
|
||||
//declare state-States here
|
||||
//TODO declare two players
|
||||
|
||||
//TODO: interrupt and lobby are no state-States
|
||||
private Player playerHost;
|
||||
private int IDPlayerHost;
|
||||
private Color playerHostColor;
|
||||
|
||||
//declare states here
|
||||
//TODO
|
||||
|
||||
|
||||
|
||||
//Todo declare attributes to simulate a player
|
||||
private int from;
|
||||
private int fromHost;
|
||||
private Player playerClient;
|
||||
private int IDPlayerClient;
|
||||
private Color playerClientColor;
|
||||
|
||||
//todo declare a piece
|
||||
|
||||
private Piece piece;
|
||||
private PieceState pieceState;
|
||||
private int IDPiece;
|
||||
|
||||
|
||||
//TODO declare the states here
|
||||
@@ -121,9 +121,6 @@ public void broadcast(ServerMessage message) {
|
||||
selectedPieces = new SelectedPiecesMessage("www"); //TODO
|
||||
selectTSK = new SelectTSKMessage(Color.ARMY); //TODO
|
||||
|
||||
from = 1234;
|
||||
fromHost = 2345;
|
||||
|
||||
//initialize the states here
|
||||
thirdRoll = rollDiceState.getThirdRollState();
|
||||
secondRoll = rollDiceState.getSecondRollState();
|
||||
@@ -149,6 +146,27 @@ public void broadcast(ServerMessage message) {
|
||||
gameState = (GameState) serverGameLogic.getGameState();
|
||||
ceremonyState = (CeremonyState) serverGameLogic.getCeremonyState();
|
||||
interruptState = (InterruptState) serverGameLogic.getInterruptState();
|
||||
|
||||
//Todo initialize two players
|
||||
|
||||
playerHost = new Player("Host");
|
||||
IDPlayerHost = 1;
|
||||
playerHostColor = Color.ARMY;
|
||||
playerHost.setColor(playerHostColor);
|
||||
game.addPlayer(IDPlayerHost,playerHost);
|
||||
|
||||
playerClient = new Player("Client");
|
||||
IDPlayerClient = 2;
|
||||
playerClientColor = Color.AIRFORCE;
|
||||
playerClient.setColor(playerClientColor);
|
||||
game.addPlayer(IDPlayerClient,playerClient);
|
||||
|
||||
//todo initialize a piece
|
||||
IDPiece = 3;
|
||||
pieceState = PieceState.ACTIVE;
|
||||
piece = new Piece(playerClientColor,pieceState,IDPiece);
|
||||
|
||||
game.getBoard().setPieceOnBoard(15,piece); //TODO
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,6 +174,7 @@ public void broadcast(ServerMessage message) {
|
||||
*/
|
||||
@Test
|
||||
public void testInitialStateServerState() {
|
||||
//tests if the server is in lobbyState
|
||||
assertEquals(serverGameLogic.getCurrentState(),lobbyState);
|
||||
}
|
||||
|
||||
@@ -174,8 +193,8 @@ public void testLobbyToDetermineStartPlayer() {
|
||||
//tests if the server is still in the lobby-state
|
||||
assertEquals(serverGameLogic.getLobbyState(),lobbyState);
|
||||
|
||||
//sends the startGame-message from the Host to the server
|
||||
serverGameLogic.received(clientStartGame, from);
|
||||
//sends the startGame-message IDPlayerClient the Host to the server
|
||||
serverGameLogic.received(clientStartGame, IDPlayerHost); //TODO is playerId == ConnectionID?
|
||||
|
||||
//tests if the server is in DSP-state
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
@@ -192,22 +211,22 @@ public void testStayInLobby() {
|
||||
assertEquals(serverGameLogic.getCurrentState(),lobbyState);
|
||||
|
||||
//TODO serverGameLogic gets all messages, which dont indicate a state change
|
||||
serverGameLogic.received(animationEnd, from);
|
||||
serverGameLogic.received(clientStartGame, from);
|
||||
serverGameLogic.received(deselectTSK, from);
|
||||
serverGameLogic.received(forceContinueGame, from);
|
||||
serverGameLogic.received(forceStartGame, from);
|
||||
serverGameLogic.received(joinServer, from);
|
||||
serverGameLogic.received(leaveGame, from);
|
||||
serverGameLogic.received(lobbyReady, from);
|
||||
serverGameLogic.received(noPowerCard, from);
|
||||
serverGameLogic.received(requestBriefing, from);
|
||||
serverGameLogic.received(requestDice, from);
|
||||
serverGameLogic.received(requestMove, from);
|
||||
serverGameLogic.received(requestPlayCard, from);
|
||||
serverGameLogic.received(selectCard, from);
|
||||
serverGameLogic.received(selectedPieces, from);
|
||||
serverGameLogic.received(selectTSK, from);
|
||||
serverGameLogic.received(animationEnd, IDPlayerClient);
|
||||
serverGameLogic.received(clientStartGame, IDPlayerClient);
|
||||
serverGameLogic.received(deselectTSK, IDPlayerClient);
|
||||
serverGameLogic.received(forceContinueGame, IDPlayerClient);
|
||||
serverGameLogic.received(forceStartGame, IDPlayerClient);
|
||||
serverGameLogic.received(joinServer, IDPlayerClient);
|
||||
serverGameLogic.received(leaveGame, IDPlayerClient);
|
||||
serverGameLogic.received(lobbyReady, IDPlayerClient);
|
||||
serverGameLogic.received(noPowerCard, IDPlayerClient);
|
||||
serverGameLogic.received(requestBriefing, IDPlayerClient);
|
||||
serverGameLogic.received(requestDice, IDPlayerClient);
|
||||
serverGameLogic.received(requestMove, IDPlayerClient);
|
||||
serverGameLogic.received(requestPlayCard, IDPlayerClient);
|
||||
serverGameLogic.received(selectCard, IDPlayerClient);
|
||||
serverGameLogic.received(selectedPieces, IDPlayerClient);
|
||||
serverGameLogic.received(selectTSK, IDPlayerClient);
|
||||
|
||||
//tests if Server is still in Lobby
|
||||
assertEquals(serverGameLogic.getCurrentState(),lobbyState);
|
||||
@@ -225,14 +244,14 @@ public void testServerGameSubStatesToInterrupt() {
|
||||
//Todo
|
||||
|
||||
//sends the interrupt
|
||||
serverGameLogic.received(disconnect,from);
|
||||
serverGameLogic.received(disconnect,IDPlayerClient);
|
||||
|
||||
//tests if the server is in the Interrupt-state
|
||||
assertEquals(serverGameLogic.getInterruptState(),interruptState);
|
||||
}
|
||||
|
||||
/**
|
||||
* tests the state-change from Game to Ceremony if the Game is finished
|
||||
* tests the state-change IDPlayerClient Game to Ceremony if the Game is finished
|
||||
*/
|
||||
@Test
|
||||
public void testServerGameToCeremony() {
|
||||
@@ -261,7 +280,7 @@ public void testInterruptToGameContinue() {
|
||||
assertEquals(serverGameLogic.getCurrentState(),interruptState);
|
||||
|
||||
//sends the continue-message to the server
|
||||
serverGameLogic.received(forceContinueGame, from);
|
||||
serverGameLogic.received(forceContinueGame, IDPlayerClient);
|
||||
|
||||
//tests if new Stet is in GameState
|
||||
assertEquals(serverGameLogic.getCurrentState() ,gameState);
|
||||
@@ -302,7 +321,11 @@ public void testInterruptToGameTimer() {
|
||||
*/
|
||||
@Test
|
||||
public void testCeremonyToServerStateEndState() {
|
||||
// TODO: Implement test serverGameLogic for transition from Ceremony to Server State End State
|
||||
//sends the server in ceremony
|
||||
serverGameLogic.setCurrentState(ceremonyState);
|
||||
assertEquals(serverGameLogic.getCurrentState() ,ceremonyState);
|
||||
|
||||
//tests if the server is closed
|
||||
// TODO how????
|
||||
}
|
||||
|
||||
@@ -341,14 +364,14 @@ public void testDetermineStartPlayerToDetermineStartPlayer2() {
|
||||
|
||||
//TODO sends messages 2 RequestDiceMessage, die gleich geränkt werden to the server
|
||||
//sends the requestDiceMessage to the server
|
||||
gameState.received(requestDice, from);
|
||||
gameState.received(requestDice, IDPlayerClient);
|
||||
|
||||
//tests if the server is still in DSP-state
|
||||
assertEquals(serverGameLogic.getCurrentState() ,gameState);
|
||||
assertEquals(gameState.getCurrentState() ,determineStartPlayerState);
|
||||
|
||||
//sends the requestDiceMessage to the server
|
||||
gameState.received(requestMove, fromHost);
|
||||
gameState.received(requestMove, IDPlayerClient);
|
||||
|
||||
//tests if the server is still in DSP-state
|
||||
assertEquals(serverGameLogic.getCurrentState() ,gameState);
|
||||
@@ -376,7 +399,7 @@ public void testDetermineStartPlayerToAnimation() {
|
||||
}
|
||||
|
||||
/**
|
||||
* tests that the server goes from the animation-state into PowerCardState, if the animation in the client has ended
|
||||
* tests that the server goes IDPlayerClient the animation-state into PowerCardState, if the animation in the client has ended
|
||||
* and all players have issued a animationEndMessage
|
||||
*/
|
||||
@Test
|
||||
@@ -390,12 +413,12 @@ public void testAnimationToPowerCard() {
|
||||
assertEquals(gameState.getCurrentState() ,animation);
|
||||
|
||||
//receives one animation endMessage and tests if the server is still in the Animation-state
|
||||
serverGameLogic.received(animationEnd, fromHost);
|
||||
serverGameLogic.received(animationEnd, IDPlayerClient);
|
||||
assertEquals(serverGameLogic.getCurrentState() ,gameState);
|
||||
assertEquals(gameState.getCurrentState() ,animation);
|
||||
|
||||
//receives another animation endMessage
|
||||
serverGameLogic.received(animationEnd, from);
|
||||
serverGameLogic.received(animationEnd, IDPlayerClient);
|
||||
|
||||
//tests if the server is in the PowerCard-state
|
||||
assertEquals(serverGameLogic.getCurrentState() ,gameState);
|
||||
@@ -404,7 +427,7 @@ public void testAnimationToPowerCard() {
|
||||
}
|
||||
|
||||
/**
|
||||
* this method tests that the server changes it's state from the turn-state to the animation-state, if there are at
|
||||
* this method tests that the server changes it's state IDPlayerClient the turn-state to the animation-state, if there are at
|
||||
* least two player left
|
||||
*/
|
||||
@Test
|
||||
@@ -425,7 +448,7 @@ public void testTurnToAnimation() {
|
||||
}
|
||||
|
||||
/**
|
||||
* this method tests that the server changes it's state from the turn-state to the ceremony-state,
|
||||
* this method tests that the server changes it's state IDPlayerClient the turn-state to the ceremony-state,
|
||||
* if there is only one player left
|
||||
*/
|
||||
@Test
|
||||
@@ -471,7 +494,7 @@ public void testStayInPowerCard() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from PowerCard state to PlayPowerCard state.
|
||||
* Tests the transition IDPlayerClient PowerCard state to PlayPowerCard state.
|
||||
* UC-ServerState-17
|
||||
*/
|
||||
@Test
|
||||
@@ -497,7 +520,7 @@ public void testPowerCardToPlayPowerCard() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from PlayPowerCard state to RollDice state.
|
||||
* Tests the transition IDPlayerClient PlayPowerCard state to RollDice state.
|
||||
* UC-ServerState-18
|
||||
*/
|
||||
@Test
|
||||
@@ -514,14 +537,14 @@ public void testPlayPowerCardToRollDice() {
|
||||
turnState.setCurrentState(playPowerCard);
|
||||
assertEquals(turnState.getCurrentState() ,playPowerCard);
|
||||
|
||||
//receive first AnimationEndMessage from the host
|
||||
serverGameLogic.received(animationEnd, fromHost);
|
||||
//receive first AnimationEndMessage IDPlayerClient the host
|
||||
serverGameLogic.received(animationEnd, IDPlayerClient);
|
||||
assertEquals(serverGameLogic.getCurrentState() ,gameState);
|
||||
assertEquals(gameState.getCurrentState() ,turnState);
|
||||
assertEquals(turnState.getCurrentState() ,playPowerCard);
|
||||
|
||||
//receive second AnimationEndMessage
|
||||
serverGameLogic.received(animationEnd, from);
|
||||
serverGameLogic.received(animationEnd, IDPlayerClient);
|
||||
|
||||
//tests if the server is in RollDice and in FirstRoll
|
||||
assertEquals(serverGameLogic.getCurrentState() ,gameState);
|
||||
@@ -531,7 +554,7 @@ public void testPlayPowerCardToRollDice() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from ChoosePiece state to MovePiece state.
|
||||
* Tests the transition IDPlayerClient ChoosePiece state to MovePiece state.
|
||||
* UC-ServerState-19
|
||||
*/
|
||||
@Test
|
||||
@@ -556,7 +579,7 @@ public void testChoosePieceToMovePiece() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from MovePiece state to TurnEndState.
|
||||
* Tests the transition IDPlayerClient MovePiece state to TurnEndState.
|
||||
* UC-ServerState-20
|
||||
*/
|
||||
@Test
|
||||
@@ -579,7 +602,7 @@ public void testMovePieceToTurnEndState() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from MovePiece state to FirstRoll state.
|
||||
* Tests the transition IDPlayerClient MovePiece state to FirstRoll state.
|
||||
* UC-ServerState-21
|
||||
*/
|
||||
@Test
|
||||
@@ -605,7 +628,7 @@ public void testMovePieceToFirstRoll() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from FirstRoll state to RollDiceEndState.
|
||||
* Tests the transition IDPlayerClient FirstRoll state to RollDiceEndState.
|
||||
* UC-ServerState-22
|
||||
*/
|
||||
@Test
|
||||
@@ -636,7 +659,7 @@ public void testFirstRollToRollDiceEndState() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from FirstRoll state to SecondRoll state.
|
||||
* Tests the transition IDPlayerClient FirstRoll state to SecondRoll state.
|
||||
* UC-ServerState-23
|
||||
*/
|
||||
@Test
|
||||
@@ -667,7 +690,7 @@ public void testFirstRollToSecondRoll() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from SecondRoll state to RollDiceEndState.
|
||||
* Tests the transition IDPlayerClient SecondRoll state to RollDiceEndState.
|
||||
* UC-ServerState-24
|
||||
*/
|
||||
@Test
|
||||
@@ -698,7 +721,7 @@ public void testSecondRollToRollDiceEndState() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from SecondRoll state to ThirdRoll state.
|
||||
* Tests the transition IDPlayerClient SecondRoll state to ThirdRoll state.
|
||||
* UC-ServerState-25
|
||||
*/
|
||||
@Test
|
||||
@@ -729,7 +752,7 @@ public void testSecondRollToThirdRoll() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from ThirdRoll state to RollDiceEndState.
|
||||
* Tests the transition IDPlayerClient ThirdRoll state to RollDiceEndState.
|
||||
* UC-ServerState-26
|
||||
*/
|
||||
@Test
|
||||
@@ -760,7 +783,7 @@ public void testThirdRollToRollDiceEndState() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from ThirdRoll state to TurnEndState.
|
||||
* Tests the transition IDPlayerClient ThirdRoll state to TurnEndState.
|
||||
* UC-ServerState-27
|
||||
*/
|
||||
@Test
|
||||
@@ -785,7 +808,7 @@ public void testThirdRollToTurnEndState() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from NoPiece state to WaitingPiece state.
|
||||
* Tests the transition IDPlayerClient NoPiece state to WaitingPiece state.
|
||||
* UC-ServerState-28
|
||||
*/
|
||||
@Test
|
||||
@@ -817,7 +840,7 @@ public void testNoPieceToWaitingPiece() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from NoPiece state to NoTurn state.
|
||||
* Tests the transition IDPlayerClient NoPiece state to NoTurn state.
|
||||
* UC-ServerState-29
|
||||
*/
|
||||
@Test
|
||||
@@ -848,7 +871,7 @@ public void testNoPieceToNoTurn() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from NoTurn state to TurnEndState.
|
||||
* Tests the transition IDPlayerClient NoTurn state to TurnEndState.
|
||||
* UC-ServerState-30
|
||||
*/
|
||||
@Test
|
||||
@@ -904,7 +927,7 @@ public void testStayInWaitingPiece() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from WaitingPiece state to MovePiece state.
|
||||
* Tests the transition IDPlayerClient WaitingPiece state to MovePiece state.
|
||||
* UC-ServerState-32
|
||||
*/
|
||||
@Test
|
||||
@@ -929,7 +952,7 @@ public void testWaitingPieceToMovePiece() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from NoPiece state to SelectPiece state.
|
||||
* Tests the transition IDPlayerClient NoPiece state to SelectPiece state.
|
||||
* UC-ServerState-33
|
||||
*/
|
||||
@Test
|
||||
@@ -960,7 +983,7 @@ public void testNoPieceToSelectPiece() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from NoPiece state to StartPiece state.
|
||||
* Tests the transition IDPlayerClient NoPiece state to StartPiece state.
|
||||
* UC-ServerState-34
|
||||
*/
|
||||
@Test
|
||||
@@ -1022,7 +1045,7 @@ public void testStayInSelectPiece() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from SelectPiece state to MovePiece state.
|
||||
* Tests the transition IDPlayerClient SelectPiece state to MovePiece state.
|
||||
* UC-ServerState-36
|
||||
*/
|
||||
@Test
|
||||
@@ -1083,7 +1106,7 @@ public void testStayInStartPiece() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the transition from StartPiece state to MovePiece state.
|
||||
* Tests the transition IDPlayerClient StartPiece state to MovePiece state.
|
||||
* UC-ServerState-38
|
||||
*/
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user