Search in sources :

Example 11 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class LoginDetailsServerMessageTransformerTest method transformHandleGlobalRatingNull.

@Test
@SuppressWarnings("unchecked")
public void transformHandleGlobalRatingNull() throws Exception {
    Map<String, Serializable> result = LoginDetailsResponseTransformer.INSTANCE.transform(new LoginDetailsResponse(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(null, new Rating(900d, 100d), 12, new Avatar("http://example.com", "Tooltip"), "FOO"))));
    Map<String, Object> me = (Map<String, Object>) result.get("me");
    assertThat(me.get("global_rating"), is(new double[2]));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Serializable(java.io.Serializable) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) LoginDetailsResponse(com.faforever.server.player.LoginDetailsResponse) Map(java.util.Map) Avatar(com.faforever.server.player.PlayerResponse.Player.Avatar) Test(org.junit.Test)

Example 12 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class PlayerResponsesTransformerTest method transformFull.

@Test
@SuppressWarnings("unchecked")
public void transformFull() throws Exception {
    Map<String, Serializable> result = PlayerResponsesTransformer.INSTANCE.transform(new PlayerResponses(Collections.singletonList(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(new Rating(1200d, 200d), new Rating(900d, 100d), 12, new Avatar("http://example.com", "Tooltip"), "FOO")))));
    assertThat(result.get("command"), is("player_info"));
    List<Map<String, Serializable>> players = (List<Map<String, Serializable>>) result.get("players");
    assertThat(players.size(), is(1));
    Map<String, Serializable> player = players.get(0);
    assertThat(player.get("id"), is(1));
    assertThat(player.get("login"), is(TEST_USERNAME));
    assertThat(player.get("login"), is(TEST_USERNAME));
    assertThat(player.get("global_rating"), is(new double[] { 1200, 200 }));
    assertThat(player.get("ladder_rating"), is(new double[] { 900, 100 }));
    assertThat(player.get("number_of_games"), is(12));
    Map<String, Serializable> avatarMap = (Map<String, Serializable>) player.get("avatar");
    assertThat(avatarMap.get("url"), is("http://example.com"));
    assertThat(avatarMap.get("tooltip"), is("Tooltip"));
    assertThat(player.get("country"), is("CH"));
    assertThat(player.get("clan"), is("FOO"));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Serializable(java.io.Serializable) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) PlayerResponses(com.faforever.server.client.PlayerResponses) List(java.util.List) Map(java.util.Map) Avatar(com.faforever.server.player.PlayerResponse.Player.Avatar) Test(org.junit.Test)

Example 13 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class PlayerResponsesTransformerTest method transformHandleLadder1v1RatingNull.

@Test
@SuppressWarnings("unchecked")
public void transformHandleLadder1v1RatingNull() throws Exception {
    Map<String, Serializable> result = PlayerResponsesTransformer.INSTANCE.transform(new PlayerResponses(Collections.singletonList(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(new Rating(900d, 100d), null, 12, new Avatar("http://example.com", "Tooltip"), "FOO")))));
    List<Map<String, Object>> players = (List<Map<String, Object>>) result.get("players");
    assertThat(players.get(0).get("ladder_rating"), is(new double[2]));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Serializable(java.io.Serializable) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) PlayerResponses(com.faforever.server.client.PlayerResponses) List(java.util.List) Map(java.util.Map) Avatar(com.faforever.server.player.PlayerResponse.Player.Avatar) Test(org.junit.Test)

Example 14 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class PlayerResponsesTransformerTest method transformHandleGlobalRatingNull.

@Test
@SuppressWarnings("unchecked")
public void transformHandleGlobalRatingNull() throws Exception {
    Map<String, Serializable> result = PlayerResponsesTransformer.INSTANCE.transform(new PlayerResponses(Collections.singletonList(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(null, new Rating(900d, 100d), 12, new Avatar("http://example.com", "Tooltip"), "FOO")))));
    List<Map<String, Object>> players = (List<Map<String, Object>>) result.get("players");
    assertThat(players.get(0).get("global_rating"), is(new double[2]));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Serializable(java.io.Serializable) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) PlayerResponses(com.faforever.server.client.PlayerResponses) List(java.util.List) Map(java.util.Map) Avatar(com.faforever.server.player.PlayerResponse.Player.Avatar) Test(org.junit.Test)

Example 15 with PlayerResponse

use of com.faforever.server.player.PlayerResponse in project faf-java-server by FAForever.

the class ClientServiceTest method sendOnlinePlayerList.

@Test
public void sendOnlinePlayerList() throws Exception {
    List<Player> players = Arrays.asList((Player) new Player().setAvailableAvatars(emptyList()).setId(1).setLogin("JUnit").setCountry("CH"), (Player) new Player().setAvailableAvatars(emptyList()).setId(2).setLogin("JUnit").setCountry("CH"));
    ConnectionAware connectionAware = new Player().setClientConnection(clientConnection);
    CompletableFuture<PlayerResponses> sent = new CompletableFuture<>();
    doAnswer(invocation -> sent.complete(invocation.getArgumentAt(0, PlayerResponses.class))).when(clientGateway).send(any(PlayerResponses.class), eq(clientConnection));
    instance.sendPlayerInformation(players, connectionAware);
    PlayerResponses responses = sent.get(10, TimeUnit.SECONDS);
    assertThat(responses.getResponses(), hasSize(2));
    Iterator<PlayerResponse> iterator = responses.getResponses().iterator();
    assertThat(iterator.next().getPlayerId(), is(1));
    assertThat(iterator.next().getPlayerId(), is(2));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Player(com.faforever.server.entity.Player) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Aggregations

PlayerResponse (com.faforever.server.player.PlayerResponse)15 Test (org.junit.Test)14 Rating (com.faforever.server.player.PlayerResponse.Player.Rating)13 Serializable (java.io.Serializable)10 Map (java.util.Map)10 Avatar (com.faforever.server.player.PlayerResponse.Player.Avatar)8 LoginDetailsResponse (com.faforever.server.player.LoginDetailsResponse)6 PlayerResponses (com.faforever.server.client.PlayerResponses)5 List (java.util.List)5 AvatarAssociation (com.faforever.server.entity.AvatarAssociation)2 GlobalRating (com.faforever.server.entity.GlobalRating)2 Avatar (com.faforever.server.entity.Avatar)1 Clan (com.faforever.server.entity.Clan)1 ClanMembership (com.faforever.server.entity.ClanMembership)1 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)1 Player (com.faforever.server.entity.Player)1 Player (com.faforever.server.game.GameResponse.Player)1 CompletableFuture (java.util.concurrent.CompletableFuture)1