Search in sources :

Example 21 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method mutualDrawRequestedByAllPlayers.

@Test
public void mutualDrawRequestedByAllPlayers() throws Exception {
    Game game = hostGame(player1);
    instance.updatePlayerOption(player1, player1.getId(), OPTION_TEAM, 2);
    instance.joinGame(game.getId(), game.getPassword(), player2);
    instance.updatePlayerGameState(PlayerGameState.LOBBY, player2);
    instance.updatePlayerOption(player1, player2.getId(), OPTION_TEAM, 3);
    Player player3 = new Player();
    player3.setId(3);
    instance.joinGame(game.getId(), game.getPassword(), player3);
    instance.updatePlayerGameState(PlayerGameState.LOBBY, player3);
    instance.updatePlayerOption(player1, player3.getId(), OPTION_TEAM, GameService.OBSERVERS_TEAM_ID);
    launchGame(game);
    instance.mutuallyAgreeDraw(player1);
    assertThat(game.isMutuallyAgreedDraw(), is(false));
    instance.mutuallyAgreeDraw(player2);
    assertThat(game.isMutuallyAgreedDraw(), is(true));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 22 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method endGameIfNoPlayerConnected.

@Test
public void endGameIfNoPlayerConnected() throws Exception {
    Game game = hostGame(player1);
    assertThat(game.getState(), is(GameState.OPEN));
    addPlayer(game, player2);
    assertThat(game.getState(), is(GameState.OPEN));
    instance.updatePlayerGameState(PlayerGameState.CLOSED, player1);
    assertThat(game.getState(), is(GameState.OPEN));
    instance.updatePlayerGameState(PlayerGameState.CLOSED, player2);
    assertThat(game.getState(), is(GameState.CLOSED));
    assertThat(player1.getCurrentGame(), is(nullValue()));
    assertThat(player1.getGameState(), is(PlayerGameState.NONE));
    assertThat(player2.getCurrentGame(), is(nullValue()));
    assertThat(player2.getGameState(), is(PlayerGameState.NONE));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 23 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method mutualDrawRequestedByPlayerWithoutGame.

@Test
public void mutualDrawRequestedByPlayerWithoutGame() throws Exception {
    Game game = hostGame(player1);
    launchGame(game);
    expectedException.expect(requestExceptionWithCode(ErrorCode.NOT_IN_A_GAME));
    instance.mutuallyAgreeDraw(player2);
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 24 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method simpleTwoPlayerGame.

@Test
@SuppressWarnings("unchecked")
public void simpleTwoPlayerGame() throws Exception {
    Game game = hostGame(player1);
    addPlayer(game, player2);
    instance.updatePlayerOption(player1, player1.getId(), OPTION_ARMY, 1);
    instance.updatePlayerOption(player1, player2.getId(), OPTION_ARMY, 2);
    launchGame(game);
    instance.reportArmyScore(player1, 1, 10);
    instance.reportArmyScore(player1, 2, -1);
    instance.reportArmyOutcome(player1, 1, Outcome.VICTORY);
    instance.reportArmyOutcome(player1, 2, Outcome.DEFEAT);
    instance.reportArmyScore(player2, 1, 10);
    instance.reportArmyScore(player2, 2, -1);
    instance.reportArmyOutcome(player2, 1, Outcome.VICTORY);
    instance.reportArmyOutcome(player2, 2, Outcome.DEFEAT);
    instance.updatePlayerGameState(PlayerGameState.ENDED, player1);
    instance.updatePlayerGameState(PlayerGameState.ENDED, player2);
    instance.updatePlayerGameState(PlayerGameState.CLOSED, player1);
    verify(clientService).disconnectPlayerFromGame(eq(player1.getId()), (Collection<? extends ConnectionAware>) argThat(Matchers.contains(player2)));
    instance.updatePlayerGameState(PlayerGameState.CLOSED, player2);
    verify(clientService).disconnectPlayerFromGame(eq(player2.getId()), argThat(Matchers.empty()));
    assertThat(game.getPlayerStats().values(), hasSize(2));
    assertThat(game.getPlayerStats().get(player1.getId()).getScore(), is(10));
    assertThat(game.getPlayerStats().get(player2.getId()).getScore(), is(-1));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 25 with Game

use of com.faforever.server.entity.Game in project faf-java-server by FAForever.

the class GameServiceTest method onGameEndedProcessesStatsIfGameStarted.

@Test
public void onGameEndedProcessesStatsIfGameStarted() throws Exception {
    Game game = hostGame(player1);
    launchGame(game);
    instance.updatePlayerGameState(PlayerGameState.ENDED, player1);
    assertThat(game.getState(), is(GameState.ENDED));
    verify(armyStatisticsService).process(any(), eq(game), any());
    verifyZeroInteractions(divisionService);
    assertThat(player1.getCurrentGame(), is(game));
    assertThat(player1.getGameState(), is(PlayerGameState.ENDED));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Aggregations

Game (com.faforever.server.entity.Game)96 Test (org.junit.Test)71 Player (com.faforever.server.entity.Player)26 FeaturedMod (com.faforever.server.entity.FeaturedMod)15 ModVersion (com.faforever.server.entity.ModVersion)12 ConnectionAware (com.faforever.server.client.ConnectionAware)11 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)11 List (java.util.List)11 ClientService (com.faforever.server.client.ClientService)10 ServerProperties (com.faforever.server.config.ServerProperties)10 RequestException (com.faforever.server.error.RequestException)10 ModService (com.faforever.server.mod.ModService)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)10 Duration (java.time.Duration)10 Map (java.util.Map)10 Optional (java.util.Optional)10 Slf4j (lombok.extern.slf4j.Slf4j)10 Service (org.springframework.stereotype.Service)10 ArmyResult (com.faforever.server.entity.ArmyResult)9 GamePlayerStats (com.faforever.server.entity.GamePlayerStats)9