Search in sources :

Example 1 with Rating

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

the class LoginDetailsServerMessageTransformerTest method transformHandleAvatarNull.

@Test
@SuppressWarnings("unchecked")
public void transformHandleAvatarNull() throws Exception {
    Map<String, Serializable> result = LoginDetailsResponseTransformer.INSTANCE.transform(new LoginDetailsResponse(new PlayerResponse(1, TEST_USERNAME, "CH", new PlayerResponse.Player(new Rating(1200d, 200d), new Rating(900d, 100d), 12, null, "FOO"))));
    Map<String, Object> me = (Map<String, Object>) result.get("me");
    assertThat(me.get("avatar"), is(nullValue()));
}
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) Test(org.junit.Test)

Example 2 with Rating

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

the class LoginDetailsServerMessageTransformerTest method transformHandleCountryNull.

@Test
@SuppressWarnings("unchecked")
public void transformHandleCountryNull() throws Exception {
    Map<String, Serializable> result = LoginDetailsResponseTransformer.INSTANCE.transform(new LoginDetailsResponse(new PlayerResponse(1, TEST_USERNAME, null, new PlayerResponse.Player(new Rating(1200d, 200d), new Rating(900d, 100d), 12, null, "FOO"))));
    Map<String, Object> me = (Map<String, Object>) result.get("me");
    assertThat(me.get("country"), is(""));
}
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) Test(org.junit.Test)

Example 3 with Rating

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

the class PlayerResponsesTransformerTest method transformHandleAvatarNull.

@Test
@SuppressWarnings("unchecked")
public void transformHandleAvatarNull() 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, null, "FOO")))));
    List<Map<String, Object>> players = (List<Map<String, Object>>) result.get("players");
    assertThat(players.get(0).get("avatar"), is(nullValue()));
}
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) Test(org.junit.Test)

Example 4 with Rating

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

the class PlayerResponsesTransformerTest method transformHandleCountryNull.

@Test
@SuppressWarnings("unchecked")
public void transformHandleCountryNull() throws Exception {
    Map<String, Serializable> result = PlayerResponsesTransformer.INSTANCE.transform(new PlayerResponses(Collections.singletonList(new PlayerResponse(1, TEST_USERNAME, null, new PlayerResponse.Player(new Rating(1200d, 200d), new Rating(900d, 100d), 12, null, "FOO")))));
    List<Map<String, Object>> players = (List<Map<String, Object>>) result.get("players");
    assertThat(players.get(0).get("country"), is(""));
}
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) Test(org.junit.Test)

Example 5 with Rating

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

the class ClientService method toPlayerInformationResponse.

private PlayerResponse toPlayerInformationResponse(Player player) {
    Optional<PlayerResponse.Player.Avatar> avatar = player.getAvailableAvatars().stream().filter(AvatarAssociation::isSelected).findFirst().map(association -> {
        com.faforever.server.entity.Avatar avatarEntity = association.getAvatar();
        return new PlayerResponse.Player.Avatar(avatarEntity.getUrl(), avatarEntity.getDescription());
    });
    Optional<Rating> globalRating = Optional.ofNullable(player.getGlobalRating()).map(rating -> new Rating(rating.getMean(), rating.getDeviation()));
    Optional<Rating> ladder1v1Rating = Optional.ofNullable(player.getLadder1v1Rating()).map(rating -> new Rating(rating.getMean(), rating.getDeviation()));
    return new PlayerResponse(player.getId(), player.getLogin(), player.getCountry(), new PlayerResponse.Player(globalRating.orElse(null), ladder1v1Rating.orElse(null), Optional.ofNullable(player.getGlobalRating()).map(GlobalRating::getNumGames).orElse(0), avatar.orElse(null), Optional.ofNullable(player.getClan()).map(Clan::getTag).orElse(null)));
}
Also used : PlayerResponse(com.faforever.server.player.PlayerResponse) Rating(com.faforever.server.player.PlayerResponse.Player.Rating) GlobalRating(com.faforever.server.entity.GlobalRating) AvatarAssociation(com.faforever.server.entity.AvatarAssociation)

Aggregations

PlayerResponse (com.faforever.server.player.PlayerResponse)13 Rating (com.faforever.server.player.PlayerResponse.Player.Rating)13 Test (org.junit.Test)12 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)1 GlobalRating (com.faforever.server.entity.GlobalRating)1 Player (com.faforever.server.game.GameResponse.Player)1