Search in sources :

Example 1 with SocialRelationResponse

use of com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse in project faf-java-server by FAForever.

the class SocialRelationResponseListResponseTransformerTest method transform.

@Test
public void transform() throws Exception {
    Map<String, Serializable> result = SocialRelationListResponseTransformer.INSTANCE.transform(new SocialRelationListResponse(Arrays.asList(new SocialRelationResponse(1, RelationType.FRIEND), new SocialRelationResponse(2, RelationType.FOE), new SocialRelationResponse(3, RelationType.FOE), new SocialRelationResponse(4, RelationType.FRIEND))));
    assertThat(result, is(ImmutableMap.of("command", "social", "friends", Arrays.asList(1, 4), "foes", Arrays.asList(2, 3))));
}
Also used : Serializable(java.io.Serializable) SocialRelationListResponse(com.faforever.server.social.SocialRelationListResponse) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Test(org.junit.Test)

Example 2 with SocialRelationResponse

use of com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse in project faf-java-server by FAForever.

the class SocialService method onPlayerOnlineEvent.

@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
    Player player = event.getPlayer();
    List<SocialRelation> socialRelations = player.getSocialRelations();
    if (socialRelations == null) {
        return;
    }
    clientService.sendSocialRelations(new SocialRelationListResponse(socialRelations.stream().map(socialRelation -> new SocialRelationResponse(socialRelation.getSubjectId(), RelationType.valueOf(socialRelation.getStatus().toString()))).collect(Collectors.toList())), player);
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) SocialRelationStatus(com.faforever.server.entity.SocialRelationStatus) EventListener(org.springframework.context.event.EventListener) RelationType(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse.RelationType) Collectors(java.util.stream.Collectors) Player(com.faforever.server.entity.Player) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SocialRelation(com.faforever.server.entity.SocialRelation) Service(org.springframework.stereotype.Service) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) ClientService(com.faforever.server.client.ClientService) Transactional(org.springframework.transaction.annotation.Transactional) Player(com.faforever.server.entity.Player) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) EventListener(org.springframework.context.event.EventListener)

Example 3 with SocialRelationResponse

use of com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse in project faf-java-server by FAForever.

the class V2ServerMessageTransformerTest method socialRelationList.

@Test
public void socialRelationList() throws Exception {
    String response = instance.transform(new SocialRelationListResponse(Arrays.asList(new SocialRelationResponse(1, RelationType.FRIEND), new SocialRelationResponse(2, RelationType.FOE))));
    assertThat(response, is("{\"data\":{\"socialRelations\":[{\"playerId\":1,\"type\":\"FRIEND\"},{\"playerId\":2,\"type\":\"FOE\"}]},\"type\":\"socialRelations\"}"));
}
Also used : SocialRelationListResponse(com.faforever.server.social.SocialRelationListResponse) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Test(org.junit.Test)

Example 4 with SocialRelationResponse

use of com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse in project faf-java-server by FAForever.

the class SocialServiceTest method onAuthenticationSuccess.

@Test
public void onAuthenticationSuccess() throws Exception {
    User user = (User) new User().setPlayer(new Player().setSocialRelations(Arrays.asList(new SocialRelation(1, null, 10, SocialRelationStatus.FRIEND), new SocialRelation(2, null, 11, SocialRelationStatus.FOE)))).setPassword("pw").setLogin("junit");
    FafUserDetails userDetails = new FafUserDetails(user);
    instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, userDetails.getPlayer()));
    ArgumentCaptor<SocialRelationListResponse> captor = ArgumentCaptor.forClass(SocialRelationListResponse.class);
    verify(clientService).sendSocialRelations(captor.capture(), any());
    SocialRelationListResponse response = captor.getValue();
    assertThat(response, instanceOf(SocialRelationListResponse.class));
    assertThat(response.getSocialRelations(), hasSize(2));
    assertThat(response.getSocialRelations().get(0), is(new SocialRelationResponse(10, RelationType.FRIEND)));
    assertThat(response.getSocialRelations().get(1), is(new SocialRelationResponse(11, RelationType.FOE)));
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) FafUserDetails(com.faforever.server.security.FafUserDetails) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Test(org.junit.Test)

Aggregations

SocialRelationResponse (com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse)4 Test (org.junit.Test)3 Player (com.faforever.server.entity.Player)2 SocialRelation (com.faforever.server.entity.SocialRelation)2 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)2 SocialRelationListResponse (com.faforever.server.social.SocialRelationListResponse)2 ClientService (com.faforever.server.client.ClientService)1 SocialRelationStatus (com.faforever.server.entity.SocialRelationStatus)1 User (com.faforever.server.entity.User)1 FafUserDetails (com.faforever.server.security.FafUserDetails)1 RelationType (com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse.RelationType)1 Serializable (java.io.Serializable)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 EventListener (org.springframework.context.event.EventListener)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1