use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.
the class ClansController method me.
@ApiOperation("Grab data about yourself and the clan")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success with JSON { player: {id: ?, login: ?}, clan: { id: ?, name: ?, tag: ?}}"), @ApiResponse(code = 400, message = "Bad Request") })
@RequestMapping(path = "/me", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public MeResult me(Authentication authentication) {
Player player = playerService.getPlayer(authentication);
Clan clan = player.getClan();
ClanResult clanResult = null;
if (clan != null) {
clanResult = ClanResult.of(clan);
}
return new MeResult(PlayerResult.of(player), clanResult);
}
use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.
the class GlobalControllerExceptionHandlerTest method testConstraintViolationException.
@Test
public void testConstraintViolationException() {
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
final Validator validator = vf.getValidator();
final Player player = new Player();
player.setId(1);
player.setLogin("Player");
final Clan clan = new Clan();
clan.setName("Clan");
clan.setLeader(player);
clan.setFounder(player);
clan.setMemberships(Collections.emptyList());
final Set<ConstraintViolation<Clan>> constraintViolations = validator.validate(clan);
final ConstraintViolationException ex = new ConstraintViolationException(COMMON_MESSAGE, constraintViolations);
ErrorResponse response = instance.processConstraintViolationException(ex);
assertEquals(3, response.getErrors().size());
final ErrorResult errorResult = response.getErrors().get(0);
assertEquals(ErrorCode.VALIDATION_FAILED.getTitle(), errorResult.getTitle());
assertEquals(String.valueOf(ErrorCode.VALIDATION_FAILED.getCode()), errorResult.getAppCode());
}
use of com.faforever.api.data.domain.Clan in project faf-java-api by FAForever.
the class ClanServiceTest method acceptPlayerInvitationTokenWrongPlayer.
@Test
public void acceptPlayerInvitationTokenWrongPlayer() throws IOException {
String stringToken = "1234";
Player newMember = new Player();
newMember.setId(2);
Clan clan = ClanFactory.builder().build();
Player otherPlayer = new Player();
otherPlayer.setId(3);
long expire = System.currentTimeMillis() + 1000 * 3;
Jwt jwtToken = Mockito.mock(Jwt.class);
when(jwtToken.getClaims()).thenReturn(String.format("{\"expire\":%s,\"newMember\":{\"id\":%s},\"clan\":{\"id\":%s}}", expire, newMember.getId(), clan.getId()));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);
when(clanRepository.findById(clan.getId())).thenReturn(Optional.of(clan));
when(playerRepository.findById(newMember.getId())).thenReturn(Optional.of(newMember));
when(playerService.getPlayer(any())).thenReturn(otherPlayer);
try {
instance.acceptPlayerInvitationToken(stringToken, null);
fail();
} catch (ApiException e) {
assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_ACCEPT_WRONG_PLAYER));
}
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 ClanServiceTest method createClanWithSameTag.
@Test
public void createClanWithSameTag() {
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.empty());
when(clanRepository.findOneByTag(tag)).thenReturn(Optional.of(new Clan()));
try {
instance.create(clanName, tag, description, creator);
fail();
} catch (ApiException e) {
assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_TAG_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 acceptPlayerInvitationToken.
@Test
public void acceptPlayerInvitationToken() throws IOException {
String stringToken = "1234";
Clan clan = ClanFactory.builder().build();
Player newMember = new Player();
newMember.setId(2);
long expire = System.currentTimeMillis() + 1000 * 3;
Jwt jwtToken = Mockito.mock(Jwt.class);
when(jwtToken.getClaims()).thenReturn(String.format("{\"expire\":%s,\"newMember\":{\"id\":%s},\"clan\":{\"id\":%s}}", expire, newMember.getId(), clan.getId()));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);
when(clanRepository.findById(clan.getId())).thenReturn(Optional.of(clan));
when(playerRepository.findById(newMember.getId())).thenReturn(Optional.of(newMember));
when(playerService.getPlayer(any())).thenReturn(newMember);
instance.acceptPlayerInvitationToken(stringToken, null);
ArgumentCaptor<ClanMembership> captor = ArgumentCaptor.forClass(ClanMembership.class);
verify(clanMembershipRepository, Mockito.times(1)).save(captor.capture());
assertEquals(newMember.getId(), captor.getValue().getPlayer().getId());
assertEquals(clan.getId(), captor.getValue().getClan().getId());
}
Aggregations