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));
}
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());
}
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));
}
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"));
}
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")));
}
Aggregations