Search in sources :

Example 6 with Clan

use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.

the class ClanServiceTest method createClanWhereLeaderIsAlreadyInAClan.

@Test
public void createClanWhereLeaderIsAlreadyInAClan() {
    String clanName = "My cool Clan";
    String tag = "123";
    String description = "A cool clan for testing";
    Player creator = new Player();
    creator.setId(1);
    creator.getClanMemberships().add(new ClanMembership());
    try {
        instance.create(clanName, tag, description, creator);
        fail();
    } catch (ApiException e) {
        assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_CREATE_CREATOR_IS_IN_A_CLAN));
    }
    verify(clanRepository, Mockito.never()).save(any(Clan.class));
}
Also used : Player(com.faforever.api.data.domain.Player) Clan(com.faforever.api.data.domain.Clan) ClanMembership(com.faforever.api.data.domain.ClanMembership) ApiException(com.faforever.api.error.ApiException) Test(org.junit.Test)

Example 7 with Clan

use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.

the class ClanServiceTest method createClanWithSameName.

@Test
public void createClanWithSameName() {
    String clanName = "My cool Clan";
    String tag = "123";
    String description = "A cool clan for testing";
    Player creator = new Player();
    creator.setId(1);
    when(clanRepository.findOneByName(clanName)).thenReturn(Optional.of(new Clan()));
    try {
        instance.create(clanName, tag, description, creator);
        fail();
    } catch (ApiException e) {
        assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_NAME_EXISTS));
    }
    ArgumentCaptor<Clan> clanCaptor = ArgumentCaptor.forClass(Clan.class);
    verify(clanRepository, Mockito.times(0)).save(clanCaptor.capture());
}
Also used : Player(com.faforever.api.data.domain.Player) Clan(com.faforever.api.data.domain.Clan) ApiException(com.faforever.api.error.ApiException) Test(org.junit.Test)

Example 8 with Clan

use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.

the class ClanServiceTest method acceptPlayerInvitationTokenInvalidPlayer.

@Test
public void acceptPlayerInvitationTokenInvalidPlayer() throws IOException {
    String stringToken = "1234";
    Clan clan = ClanFactory.builder().build();
    long expire = System.currentTimeMillis() + 1000 * 3;
    Jwt jwtToken = Mockito.mock(Jwt.class);
    when(jwtToken.getClaims()).thenReturn(String.format("{\"expire\":%s,\"newMember\":{\"id\":2},\"clan\":{\"id\":%s}}", expire, clan.getId()));
    when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);
    when(clanRepository.findById(clan.getId())).thenReturn(Optional.of(clan));
    try {
        instance.acceptPlayerInvitationToken(stringToken, null);
        fail();
    } catch (ProgrammingError e) {
        assertEquals("ClanMember does not exist: 2", e.getMessage());
    }
    verify(clanMembershipRepository, Mockito.never()).save(any(ClanMembership.class));
}
Also used : Clan(com.faforever.api.data.domain.Clan) Jwt(org.springframework.security.jwt.Jwt) ProgrammingError(com.faforever.api.error.ProgrammingError) ClanMembership(com.faforever.api.data.domain.ClanMembership) Test(org.junit.Test)

Example 9 with Clan

use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.

the class ClanEnricherListenerTest method enrich.

@Test
public void enrich() throws Exception {
    Clan clan = ClanFactory.builder().id(54).build();
    instance.enrich(clan);
    assertThat(clan.getWebsiteUrl(), is("http://example.com/54"));
}
Also used : Clan(com.faforever.api.data.domain.Clan) Test(org.junit.Test)

Example 10 with Clan

use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.

the class ClanControllerTest method createClanWithSuccess.

@Test
@WithUserDetails(AUTH_USER)
public void createClanWithSuccess() throws Exception {
    Player player = getPlayer();
    assertNull(player.getClan());
    assertFalse(clanRepository.findOneByName(NEW_CLAN_NAME).isPresent());
    MultiValueMap<String, String> params = new HttpHeaders();
    params.add("name", NEW_CLAN_NAME);
    params.add("tag", NEW_CLAN_TAG);
    params.add("description", NEW_CLAN_DESCRIPTION);
    ResultActions action = mockMvc.perform(post("/clans/create").params(params));
    Clan clan = clanRepository.findOneByName(NEW_CLAN_NAME).orElseThrow(() -> new IllegalStateException("Clan not found - but should be created"));
    action.andExpect(status().isOk()).andExpect(jsonPath("$.id", is(clan.getId()))).andExpect(jsonPath("$.type", is("clan")));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Player(com.faforever.api.data.domain.Player) Clan(com.faforever.api.data.domain.Clan) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractIntegrationTest(com.faforever.api.AbstractIntegrationTest) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Aggregations

Clan (com.faforever.api.data.domain.Clan)20 Player (com.faforever.api.data.domain.Player)17 Test (org.junit.Test)15 ApiException (com.faforever.api.error.ApiException)10 ClanMembership (com.faforever.api.data.domain.ClanMembership)7 Jwt (org.springframework.security.jwt.Jwt)5 ProgrammingError (com.faforever.api.error.ProgrammingError)4 InvitationResult (com.faforever.api.clan.result.InvitationResult)3 Error (com.faforever.api.error.Error)3 SneakyThrows (lombok.SneakyThrows)3 AbstractIntegrationTest (com.faforever.api.AbstractIntegrationTest)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ClanResult (com.faforever.api.clan.result.ClanResult)1 MeResult (com.faforever.api.clan.result.MeResult)1 FafApiProperties (com.faforever.api.config.FafApiProperties)1 HttpHeaders (org.springframework.http.HttpHeaders)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1