merge tests into development #25

Closed
j23f0712 wants to merge 24 commits from dev/test into development
2 changed files with 353 additions and 315 deletions
Showing only changes of commit 56f32c5c0b - Show all commits

View File

@@ -6,14 +6,13 @@
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import pp.mdga.game.Color; import pp.mdga.game.Color;
import pp.mdga.game.Game; 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.server.ServerMessage;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.server.*; import pp.mdga.server.*;
import pp.mdga.server.automaton.CeremonyState; import pp.mdga.server.automaton.*;
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 static org.junit.Assert.*; import static org.junit.Assert.*;
@@ -46,20 +45,21 @@ public class ServerStateTest {
private SelectTSKMessage selectTSK; private SelectTSKMessage selectTSK;
private DisconnectedMessage disconnect; 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 private Player playerClient;
//TODO private int IDPlayerClient;
private Color playerClientColor;
//Todo declare attributes to simulate a player
private int from;
private int fromHost;
//todo declare a piece
private Piece piece;
private PieceState pieceState;
private int IDPiece;
//TODO declare the states here //TODO declare the states here
@@ -121,9 +121,6 @@ public void broadcast(ServerMessage message) {
selectedPieces = new SelectedPiecesMessage("www"); //TODO selectedPieces = new SelectedPiecesMessage("www"); //TODO
selectTSK = new SelectTSKMessage(Color.ARMY); //TODO selectTSK = new SelectTSKMessage(Color.ARMY); //TODO
from = 1234;
fromHost = 2345;
//initialize the states here //initialize the states here
thirdRoll = rollDiceState.getThirdRollState(); thirdRoll = rollDiceState.getThirdRollState();
secondRoll = rollDiceState.getSecondRollState(); secondRoll = rollDiceState.getSecondRollState();
@@ -149,6 +146,27 @@ public void broadcast(ServerMessage message) {
gameState = (GameState) serverGameLogic.getGameState(); gameState = (GameState) serverGameLogic.getGameState();
ceremonyState = (CeremonyState) serverGameLogic.getCeremonyState(); ceremonyState = (CeremonyState) serverGameLogic.getCeremonyState();
interruptState = (InterruptState) serverGameLogic.getInterruptState(); 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 @Test
public void testInitialStateServerState() { public void testInitialStateServerState() {
//tests if the server is in lobbyState
assertEquals(serverGameLogic.getCurrentState(),lobbyState); assertEquals(serverGameLogic.getCurrentState(),lobbyState);
} }
@@ -174,8 +193,8 @@ public void testLobbyToDetermineStartPlayer() {
//tests if the server is still in the lobby-state //tests if the server is still in the lobby-state
assertEquals(serverGameLogic.getLobbyState(),lobbyState); assertEquals(serverGameLogic.getLobbyState(),lobbyState);
//sends the startGame-message from the Host to the server //sends the startGame-message IDPlayerClient the Host to the server
serverGameLogic.received(clientStartGame, from); serverGameLogic.received(clientStartGame, IDPlayerHost); //TODO is playerId == ConnectionID?
//tests if the server is in DSP-state //tests if the server is in DSP-state
assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(serverGameLogic.getCurrentState(),gameState);
@@ -192,22 +211,22 @@ public void testStayInLobby() {
assertEquals(serverGameLogic.getCurrentState(),lobbyState); assertEquals(serverGameLogic.getCurrentState(),lobbyState);
//TODO serverGameLogic gets all messages, which dont indicate a state change //TODO serverGameLogic gets all messages, which dont indicate a state change
serverGameLogic.received(animationEnd, from); serverGameLogic.received(animationEnd, IDPlayerClient);
serverGameLogic.received(clientStartGame, from); serverGameLogic.received(clientStartGame, IDPlayerClient);
serverGameLogic.received(deselectTSK, from); serverGameLogic.received(deselectTSK, IDPlayerClient);
serverGameLogic.received(forceContinueGame, from); serverGameLogic.received(forceContinueGame, IDPlayerClient);
serverGameLogic.received(forceStartGame, from); serverGameLogic.received(forceStartGame, IDPlayerClient);
serverGameLogic.received(joinServer, from); serverGameLogic.received(joinServer, IDPlayerClient);
serverGameLogic.received(leaveGame, from); serverGameLogic.received(leaveGame, IDPlayerClient);
serverGameLogic.received(lobbyReady, from); serverGameLogic.received(lobbyReady, IDPlayerClient);
serverGameLogic.received(noPowerCard, from); serverGameLogic.received(noPowerCard, IDPlayerClient);
serverGameLogic.received(requestBriefing, from); serverGameLogic.received(requestBriefing, IDPlayerClient);
serverGameLogic.received(requestDice, from); serverGameLogic.received(requestDice, IDPlayerClient);
serverGameLogic.received(requestMove, from); serverGameLogic.received(requestMove, IDPlayerClient);
serverGameLogic.received(requestPlayCard, from); serverGameLogic.received(requestPlayCard, IDPlayerClient);
serverGameLogic.received(selectCard, from); serverGameLogic.received(selectCard, IDPlayerClient);
serverGameLogic.received(selectedPieces, from); serverGameLogic.received(selectedPieces, IDPlayerClient);
serverGameLogic.received(selectTSK, from); serverGameLogic.received(selectTSK, IDPlayerClient);
//tests if Server is still in Lobby //tests if Server is still in Lobby
assertEquals(serverGameLogic.getCurrentState(),lobbyState); assertEquals(serverGameLogic.getCurrentState(),lobbyState);
@@ -225,14 +244,14 @@ public void testServerGameSubStatesToInterrupt() {
//Todo //Todo
//sends the interrupt //sends the interrupt
serverGameLogic.received(disconnect,from); serverGameLogic.received(disconnect,IDPlayerClient);
//tests if the server is in the Interrupt-state //tests if the server is in the Interrupt-state
assertEquals(serverGameLogic.getInterruptState(),interruptState); 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 @Test
public void testServerGameToCeremony() { public void testServerGameToCeremony() {
@@ -261,7 +280,7 @@ public void testInterruptToGameContinue() {
assertEquals(serverGameLogic.getCurrentState(),interruptState); assertEquals(serverGameLogic.getCurrentState(),interruptState);
//sends the continue-message to the server //sends the continue-message to the server
serverGameLogic.received(forceContinueGame, from); serverGameLogic.received(forceContinueGame, IDPlayerClient);
//tests if new Stet is in GameState //tests if new Stet is in GameState
assertEquals(serverGameLogic.getCurrentState() ,gameState); assertEquals(serverGameLogic.getCurrentState() ,gameState);
@@ -302,7 +321,11 @@ public void testInterruptToGameTimer() {
*/ */
@Test @Test
public void testCeremonyToServerStateEndState() { 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???? // TODO how????
} }
@@ -341,14 +364,14 @@ public void testDetermineStartPlayerToDetermineStartPlayer2() {
//TODO sends messages 2 RequestDiceMessage, die gleich geränkt werden to the server //TODO sends messages 2 RequestDiceMessage, die gleich geränkt werden to the server
//sends the requestDiceMessage 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 //tests if the server is still in DSP-state
assertEquals(serverGameLogic.getCurrentState() ,gameState); assertEquals(serverGameLogic.getCurrentState() ,gameState);
assertEquals(gameState.getCurrentState() ,determineStartPlayerState); assertEquals(gameState.getCurrentState() ,determineStartPlayerState);
//sends the requestDiceMessage to the server //sends the requestDiceMessage to the server
gameState.received(requestMove, fromHost); gameState.received(requestMove, IDPlayerClient);
//tests if the server is still in DSP-state //tests if the server is still in DSP-state
assertEquals(serverGameLogic.getCurrentState() ,gameState); 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 * and all players have issued a animationEndMessage
*/ */
@Test @Test
@@ -390,12 +413,12 @@ public void testAnimationToPowerCard() {
assertEquals(gameState.getCurrentState() ,animation); assertEquals(gameState.getCurrentState() ,animation);
//receives one animation endMessage and tests if the server is still in the Animation-state //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(serverGameLogic.getCurrentState() ,gameState);
assertEquals(gameState.getCurrentState() ,animation); assertEquals(gameState.getCurrentState() ,animation);
//receives another animation endMessage //receives another animation endMessage
serverGameLogic.received(animationEnd, from); serverGameLogic.received(animationEnd, IDPlayerClient);
//tests if the server is in the PowerCard-state //tests if the server is in the PowerCard-state
assertEquals(serverGameLogic.getCurrentState() ,gameState); 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 * least two player left
*/ */
@Test @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 * if there is only one player left
*/ */
@Test @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 * UC-ServerState-17
*/ */
@Test @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 * UC-ServerState-18
*/ */
@Test @Test
@@ -514,14 +537,14 @@ public void testPlayPowerCardToRollDice() {
turnState.setCurrentState(playPowerCard); turnState.setCurrentState(playPowerCard);
assertEquals(turnState.getCurrentState() ,playPowerCard); assertEquals(turnState.getCurrentState() ,playPowerCard);
//receive first AnimationEndMessage from the host //receive first AnimationEndMessage IDPlayerClient the host
serverGameLogic.received(animationEnd, fromHost); serverGameLogic.received(animationEnd, IDPlayerClient);
assertEquals(serverGameLogic.getCurrentState() ,gameState); assertEquals(serverGameLogic.getCurrentState() ,gameState);
assertEquals(gameState.getCurrentState() ,turnState); assertEquals(gameState.getCurrentState() ,turnState);
assertEquals(turnState.getCurrentState() ,playPowerCard); assertEquals(turnState.getCurrentState() ,playPowerCard);
//receive second AnimationEndMessage //receive second AnimationEndMessage
serverGameLogic.received(animationEnd, from); serverGameLogic.received(animationEnd, IDPlayerClient);
//tests if the server is in RollDice and in FirstRoll //tests if the server is in RollDice and in FirstRoll
assertEquals(serverGameLogic.getCurrentState() ,gameState); 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 * UC-ServerState-19
*/ */
@Test @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 * UC-ServerState-20
*/ */
@Test @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 * UC-ServerState-21
*/ */
@Test @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 * UC-ServerState-22
*/ */
@Test @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 * UC-ServerState-23
*/ */
@Test @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 * UC-ServerState-24
*/ */
@Test @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 * UC-ServerState-25
*/ */
@Test @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 * UC-ServerState-26
*/ */
@Test @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 * UC-ServerState-27
*/ */
@Test @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 * UC-ServerState-28
*/ */
@Test @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 * UC-ServerState-29
*/ */
@Test @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 * UC-ServerState-30
*/ */
@Test @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 * UC-ServerState-32
*/ */
@Test @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 * UC-ServerState-33
*/ */
@Test @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 * UC-ServerState-34
*/ */
@Test @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 * UC-ServerState-36
*/ */
@Test @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 * UC-ServerState-38
*/ */
@Test @Test