use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameValidityNoFogOfWar.
@Test
public void updateGameValidityNoFogOfWar() throws Exception {
Game game = hostGame(player1);
game.getOptions().put(OPTION_FOG_OF_WAR, "foo");
launchGame(game);
instance.updateGameValidity(game);
assertThat(game.getValidity(), is(Validity.NO_FOG_OF_WAR));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateGameOption.
@Test
public void updateGameOption() throws Exception {
Game game = hostGame(player1);
assertThat(game.getOptions().containsKey("GameSpeed"), is(false));
instance.updateGameOption(player1, "GameSpeed", "normal");
assertThat(game.getOptions().get("GameSpeed"), is("normal"));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method hostGame.
private Game hostGame(Player host) throws Exception {
player1.setCurrentGame(null);
CompletableFuture<Game> joinable = instance.createGame("Game title", FAF_TECHNICAL_NAME, MAP_NAME, "secret", GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, host);
assertThat(joinable.isDone(), is(false));
assertThat(joinable.isCancelled(), is(false));
assertThat(joinable.isCompletedExceptionally(), is(false));
verify(counterService, never()).decrement(String.format(Metrics.GAMES_STATE_FORMAT, GameState.CLOSED));
verify(counterService).increment(String.format(Metrics.GAMES_STATE_FORMAT, GameState.INITIALIZING));
Game game = instance.getActiveGame(1).get();
assertThat(game.getState(), is(GameState.INITIALIZING));
assertThat(player1.getCurrentGame(), is(game));
assertThat(player1.getGameState(), is(PlayerGameState.INITIALIZING));
instance.updatePlayerGameState(PlayerGameState.LOBBY, player1);
assertThat(player1.getGameState(), is(PlayerGameState.LOBBY));
game = joinable.get();
instance.updateGameOption(host, OPTION_VICTORY_CONDITION, VictoryCondition.DEMORALIZATION.getString());
instance.updateGameOption(host, OPTION_FOG_OF_WAR, "explored");
instance.updateGameOption(host, OPTION_CHEATS_ENABLED, "false");
instance.updateGameOption(host, OPTION_PREBUILT_UNITS, "Off");
instance.updateGameOption(host, OPTION_NO_RUSH, "Off");
instance.updateGameOption(host, OPTION_RESTRICTED_CATEGORIES, 0);
instance.updatePlayerOption(host, host.getId(), OPTION_ARMY, host.getId());
instance.updatePlayerOption(host, host.getId(), OPTION_FACTION, 1);
instance.updatePlayerOption(host, host.getId(), OPTION_COLOR, host.getId());
instance.updatePlayerOption(host, host.getId(), OPTION_START_SPOT, host.getId());
instance.updatePlayerOption(host, host.getId(), OPTION_TEAM, GameService.NO_TEAM_ID);
verify(counterService).increment(String.format(Metrics.GAMES_STATE_FORMAT, GameState.INITIALIZING));
verify(clientService).startGameProcess(game, player1);
assertThat(game.getTitle(), is("Game title"));
assertThat(game.getHost(), is(player1));
assertThat(game.getFeaturedMod().getTechnicalName(), is(FAF_TECHNICAL_NAME));
assertThat(game.getMapVersion(), is(notNullValue()));
assertThat(game.getMapName(), is(MAP_NAME));
assertThat(game.getPassword(), is("secret"));
assertThat(game.getState(), is(GameState.OPEN));
assertThat(game.getGameVisibility(), is(GameVisibility.PUBLIC));
assertThat(game.getMinRating(), is(GAME_MIN_RATING));
assertThat(game.getMaxRating(), is(GAME_MAX_RATING));
assertThat(player1.getCurrentGame(), is(game));
return game;
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method updateAiOptionFactionIgnored.
@Test
public void updateAiOptionFactionIgnored() throws Exception {
Game game = hostGame(player1);
assertThat(game.getAiOptions().containsKey(QAI), is(false));
instance.updateAiOption(player1, QAI, OPTION_FACTION, 2);
assertThat(game.getAiOptions().containsKey(QAI), is(false));
}
use of com.faforever.server.entity.Game in project faf-java-server by FAForever.
the class GameServiceTest method restoreGameSessionPlayingGame.
@Test
public void restoreGameSessionPlayingGame() throws Exception {
Game game = hostGame(player1);
instance.joinGame(game.getId(), game.getPassword(), player2);
assertThat(player2.getCurrentGame(), is(game));
instance.updatePlayerGameState(PlayerGameState.LOBBY, player2);
instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player2);
assertThat(player2.getGameState(), is(PlayerGameState.LAUNCHING));
instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player1);
ClientConnection clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
clientConnection.setAuthentication(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player2).setPassword("pw").setLogin("JUnit")), null));
player2.setClientConnection(clientConnection);
instance.removePlayer(player2);
assertThat(player2.getCurrentGame(), is(nullValue()));
assertThat(player2.getGameState(), is(PlayerGameState.NONE));
instance.restoreGameSession(player2, game.getId());
assertThat(player2.getCurrentGame(), is(game));
assertThat(player2.getGameState(), is(PlayerGameState.LAUNCHING));
}
Aggregations