Search in sources :

Example 71 with Game

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

the class GameServiceTest method onGameLaunching.

@Test
public void onGameLaunching() throws Exception {
    Game game = hostGame(player1);
    instance.updatePlayerOption(player1, player1.getId(), OPTION_FACTION, 1);
    instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player1);
    assertThat(game.getState(), is(GameState.PLAYING));
    assertThat(game.getStartTime(), is(lessThan(Instant.now().plusSeconds(1))));
    assertThat(game.getStartTime(), is(greaterThan(Instant.now().minusSeconds(10))));
    verify(entityManager).persist(game);
    verify(clientService, atLeastOnce()).broadcastDelayed(any(GameResponse.class), any(), any(), any(), any());
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 72 with Game

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

the class GameServiceTest method updateGameValiditySinglePlayer.

@Test
public void updateGameValiditySinglePlayer() throws Exception {
    Game game = hostGame(player1);
    launchGame(game);
    instance.updateGameValidity(game);
    assertThat(game.getValidity(), is(Validity.SINGLE_PLAYER));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 73 with Game

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

the class GameServiceTest method simpleValidGameWithEnded.

@Test
public void simpleValidGameWithEnded() throws Exception {
    Game game = hostGame(player1);
    addPlayer(game, player2);
    launchGame(game);
    Stream.of(player1, player2).forEach(player -> {
        instance.reportArmyOutcome(player, 1, Outcome.VICTORY);
        instance.reportArmyScore(player, 1, 10);
        instance.reportArmyOutcome(player, 2, Outcome.DEFEAT);
        instance.reportArmyScore(player, 2, -1);
    });
    assertThat(game.getValidity(), is(Validity.VALID));
}
Also used : Game(com.faforever.server.entity.Game) Test(org.junit.Test)

Example 74 with Game

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

the class GameServiceTest method disconnectFromGame.

/**
 * Tests whether all but the affected player are informed to drop someone.
 */
@Test
@SuppressWarnings("unchecked")
public void disconnectFromGame() throws Exception {
    Game game = hostGame(player1);
    Player player3 = (Player) new Player().setId(3);
    Player player4 = (Player) new Player().setId(4);
    addPlayer(game, player2);
    addPlayer(game, player3);
    addPlayer(game, player4);
    when(playerService.getOnlinePlayer(3)).thenReturn(Optional.of(player3));
    instance.disconnectPlayerFromGame(player1, 3);
    ArgumentCaptor<List<ConnectionAware>> captor = ArgumentCaptor.forClass((Class) List.class);
    verify(clientService).disconnectPlayerFromGame(eq(3), captor.capture());
    List<ConnectionAware> recipients = captor.getValue();
    assertThat(recipients, hasSize(3));
    assertThat(recipients, hasItems(player1, player2, player4));
}
Also used : Player(com.faforever.server.entity.Player) Game(com.faforever.server.entity.Game) List(java.util.List) ConnectionAware(com.faforever.server.client.ConnectionAware) Test(org.junit.Test)

Example 75 with Game

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

the class GameServiceTest method onGameClosedSavesGameIfGameStarted.

@Test
public void onGameClosedSavesGameIfGameStarted() throws Exception {
    Game game = hostGame(player1);
    launchGame(game);
    instance.updatePlayerGameState(PlayerGameState.CLOSED, player1);
    assertThat(game.getState(), is(GameState.CLOSED));
    verify(gameRepository).save(game);
    verify(mapService).incrementTimesPlayed(game.getMapVersion().getMap());
    verifyZeroInteractions(divisionService);
    assertThat(player1.getCurrentGame(), is(nullValue()));
    assertThat(player1.getGameState(), is(PlayerGameState.NONE));
}
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