Search in sources :

Example 6 with GameInfoMessage

use of com.faforever.client.remote.domain.GameInfoMessage in project downlords-faf-client by FAForever.

the class GameServiceImplTest method testOnGameInfoMessageSetsCurrentGameIfUserIsInAndStatusOpen.

@Test
public void testOnGameInfoMessageSetsCurrentGameIfUserIsInAndStatusOpen() throws Exception {
    assertThat(instance.getCurrentGame(), nullValue());
    when(playerService.getCurrentPlayer()).thenReturn(Optional.ofNullable(PlayerBuilder.create("PlayerName").get()));
    GameInfoMessage gameInfoMessage = GameInfoMessageBuilder.create(1234).defaultValues().state(OPEN).addTeamMember("1", "PlayerName").get();
    gameInfoMessageListenerCaptor.getValue().accept(gameInfoMessage);
    WaitForAsyncUtils.waitForFxEvents();
    assertThat(instance.getCurrentGame(), notNullValue());
    assertThat(instance.getCurrentGame().getId(), is(1234));
}
Also used : GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 7 with GameInfoMessage

use of com.faforever.client.remote.domain.GameInfoMessage in project downlords-faf-client by FAForever.

the class GameServiceImplTest method testOnGameInfoAdd.

@Test
public void testOnGameInfoAdd() {
    assertThat(instance.getGames(), empty());
    GameInfoMessage gameInfoMessage1 = GameInfoMessageBuilder.create(1).defaultValues().title("Game 1").get();
    gameInfoMessageListenerCaptor.getValue().accept(gameInfoMessage1);
    GameInfoMessage gameInfoMessage2 = GameInfoMessageBuilder.create(2).defaultValues().title("Game 2").get();
    gameInfoMessageListenerCaptor.getValue().accept(gameInfoMessage2);
    WaitForAsyncUtils.waitForFxEvents();
    Game game1 = new Game(gameInfoMessage1);
    Game game2 = new Game(gameInfoMessage2);
    assertThat(instance.getGames(), containsInAnyOrder(game1, game2));
}
Also used : GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 8 with GameInfoMessage

use of com.faforever.client.remote.domain.GameInfoMessage in project downlords-faf-client by FAForever.

the class GameServiceImplTest method testOnGameInfoMessageDoesntSetCurrentGameIfUserIsInAndStatusNotOpen.

@Test
public void testOnGameInfoMessageDoesntSetCurrentGameIfUserIsInAndStatusNotOpen() throws Exception {
    assertThat(instance.getCurrentGame(), nullValue());
    when(playerService.getCurrentPlayer()).thenReturn(Optional.ofNullable(PlayerBuilder.create("PlayerName").get()));
    GameInfoMessage gameInfoMessage = GameInfoMessageBuilder.create(1234).defaultValues().state(PLAYING).addTeamMember("1", "PlayerName").get();
    gameInfoMessageListenerCaptor.getValue().accept(gameInfoMessage);
    assertThat(instance.getCurrentGame(), nullValue());
}
Also used : GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 9 with GameInfoMessage

use of com.faforever.client.remote.domain.GameInfoMessage in project downlords-faf-client by FAForever.

the class MockFafServerAccessor method connectAndLogIn.

@Override
public CompletableFuture<LoginMessage> connectAndLogIn(String username, String password) {
    return taskService.submitTask(new CompletableTask<LoginMessage>(HIGH) {

        @Override
        protected LoginMessage call() throws Exception {
            updateTitle(i18n.get("login.progress.message"));
            Player player = new Player();
            player.setId(4812);
            player.setLogin(USER_NAME);
            player.setClan("ABC");
            player.setCountry("A1");
            player.setGlobalRating(new float[] { 1500, 220 });
            player.setLadderRating(new float[] { 1500, 220 });
            player.setNumberOfGames(330);
            PlayersMessage playersMessage = new PlayersMessage();
            playersMessage.setPlayers(singletonList(player));
            eventBus.post(new LoginSuccessEvent(username, password, player.getId()));
            messageListeners.getOrDefault(playersMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(playersMessage));
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    UpdatedAchievementsMessage updatedAchievementsMessage = new UpdatedAchievementsMessage();
                    UpdatedAchievement updatedAchievement = new UpdatedAchievement();
                    updatedAchievement.setAchievementId("50260d04-90ff-45c8-816b-4ad8d7b97ecd");
                    updatedAchievement.setNewlyUnlocked(true);
                    updatedAchievementsMessage.setUpdatedAchievements(Arrays.asList(updatedAchievement));
                    messageListeners.getOrDefault(updatedAchievementsMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(updatedAchievementsMessage));
                }
            }, 7000);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    MatchmakerMessage matchmakerServerMessage = new MatchmakerMessage();
                    matchmakerServerMessage.setQueues(singletonList(new MatchmakerQueue("ladder1v1", singletonList(new RatingRange(100, 200)), singletonList(new RatingRange(100, 200)))));
                    messageListeners.getOrDefault(matchmakerServerMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(matchmakerServerMessage));
                }
            }, 7000);
            List<GameInfoMessage> gameInfoMessages = Arrays.asList(createGameInfo(1, "Mock game 500 - 800", PUBLIC, "faf", "scmp_010", 1, 6, "Mock user"), createGameInfo(2, "Mock game 500+", PUBLIC, "faf", "scmp_011", 2, 6, "Mock user"), createGameInfo(3, "Mock game +500", PUBLIC, "faf", "scmp_012", 3, 6, "Mock user"), createGameInfo(4, "Mock game <1000", PUBLIC, "faf", "scmp_013", 4, 6, "Mock user"), createGameInfo(5, "Mock game >1000", PUBLIC, "faf", "scmp_014", 5, 6, "Mock user"), createGameInfo(6, "Mock game ~600", PASSWORD, "faf", "scmp_015", 6, 6, "Mock user"), createGameInfo(7, "Mock game 7", PASSWORD, "faf", "scmp_016", 7, 6, "Mock user"));
            gameInfoMessages.forEach(gameInfoMessage -> messageListeners.getOrDefault(gameInfoMessage.getClass(), Collections.emptyList()).forEach(consumer -> consumer.accept(gameInfoMessage)));
            notificationService.addNotification(new PersistentNotification("How about a long-running (7s) mock task?", Severity.INFO, Arrays.asList(new Action("Execute", event -> taskService.submitTask(new CompletableTask<Void>(HIGH) {

                @Override
                protected Void call() throws Exception {
                    updateTitle("Mock task");
                    Thread.sleep(2000);
                    for (int i = 0; i < 5; i++) {
                        updateProgress(i, 5);
                        Thread.sleep(1000);
                    }
                    return null;
                }
            })), new Action("Nope"))));
            LoginMessage sessionInfo = new LoginMessage();
            sessionInfo.setId(123);
            sessionInfo.setLogin(USER_NAME);
            return sessionInfo;
        }
    }).getFuture();
}
Also used : NewGameInfo(com.faforever.client.game.NewGameInfo) Arrays(java.util.Arrays) PUBLIC(com.faforever.client.remote.domain.GameAccess.PUBLIC) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) Timer(java.util.Timer) Faction(com.faforever.client.game.Faction) ConnectionState(com.faforever.client.net.ConnectionState) GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) Collections.singletonList(java.util.Collections.singletonList) HIGH(com.faforever.client.task.CompletableTask.Priority.HIGH) IceServer(com.faforever.client.remote.domain.IceServersServerMessage.IceServer) GameStatus(com.faforever.client.remote.domain.GameStatus) TimerTask(java.util.TimerTask) FafClientApplication(com.faforever.client.FafClientApplication) Collections.emptyList(java.util.Collections.emptyList) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) PASSWORD(com.faforever.client.remote.domain.GameAccess.PASSWORD) PlayersMessage(com.faforever.client.remote.domain.PlayersMessage) List(java.util.List) Lazy(org.springframework.context.annotation.Lazy) TaskService(com.faforever.client.task.TaskService) Player(com.faforever.client.remote.domain.Player) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) MatchmakerQueue(com.faforever.client.rankedmatch.MatchmakerMessage.MatchmakerQueue) GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage) Avatar(com.faforever.client.remote.domain.Avatar) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) CompletableTask(com.faforever.client.task.CompletableTask) LoginMessage(com.faforever.client.remote.domain.LoginMessage) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) GameAccess(com.faforever.client.remote.domain.GameAccess) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) KnownFeaturedMod(com.faforever.client.game.KnownFeaturedMod) LinkedList(java.util.LinkedList) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Action(com.faforever.client.notification.Action) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) Profile(org.springframework.context.annotation.Profile) PersistentNotification(com.faforever.client.notification.PersistentNotification) Consumer(java.util.function.Consumer) ServerMessage(com.faforever.client.remote.domain.ServerMessage) Component(org.springframework.stereotype.Component) RatingRange(com.faforever.client.remote.domain.RatingRange) Severity(com.faforever.client.notification.Severity) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) I18n(com.faforever.client.i18n.I18n) Collections(java.util.Collections) GpgGameMessage(com.faforever.client.fa.relay.GpgGameMessage) Player(com.faforever.client.remote.domain.Player) Action(com.faforever.client.notification.Action) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) CompletableTask(com.faforever.client.task.CompletableTask) PlayersMessage(com.faforever.client.remote.domain.PlayersMessage) MatchmakerQueue(com.faforever.client.rankedmatch.MatchmakerMessage.MatchmakerQueue) TimerTask(java.util.TimerTask) RatingRange(com.faforever.client.remote.domain.RatingRange) GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) LoginMessage(com.faforever.client.remote.domain.LoginMessage) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) PersistentNotification(com.faforever.client.notification.PersistentNotification)

Aggregations

GameInfoMessage (com.faforever.client.remote.domain.GameInfoMessage)9 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)7 Test (org.junit.Test)7 FafClientApplication (com.faforever.client.FafClientApplication)1 GpgGameMessage (com.faforever.client.fa.relay.GpgGameMessage)1 Faction (com.faforever.client.game.Faction)1 KnownFeaturedMod (com.faforever.client.game.KnownFeaturedMod)1 NewGameInfo (com.faforever.client.game.NewGameInfo)1 I18n (com.faforever.client.i18n.I18n)1 ConnectionState (com.faforever.client.net.ConnectionState)1 Action (com.faforever.client.notification.Action)1 NotificationService (com.faforever.client.notification.NotificationService)1 PersistentNotification (com.faforever.client.notification.PersistentNotification)1 Severity (com.faforever.client.notification.Severity)1 MatchmakerMessage (com.faforever.client.rankedmatch.MatchmakerMessage)1 MatchmakerQueue (com.faforever.client.rankedmatch.MatchmakerMessage.MatchmakerQueue)1 Avatar (com.faforever.client.remote.domain.Avatar)1 GameAccess (com.faforever.client.remote.domain.GameAccess)1 PASSWORD (com.faforever.client.remote.domain.GameAccess.PASSWORD)1 PUBLIC (com.faforever.client.remote.domain.GameAccess.PUBLIC)1