use of com.faforever.api.data.domain.Avatar in project faf-java-api by FAForever.
the class AvatarServiceTest method deleteAvatarWithAssignments.
@Test
public void deleteAvatarWithAssignments() throws Exception {
when(avatarRepository.findById(AVATAR_ID)).thenReturn(Optional.of(new Avatar().setAssignments(Collections.singletonList(new AvatarAssignment()))));
expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.AVATAR_IN_USE));
avatarService.deleteAvatar(AVATAR_ID);
verify(avatarRepository, never()).delete(new Avatar());
}
use of com.faforever.api.data.domain.Avatar in project faf-java-api by FAForever.
the class AvatarServiceTest method existingAvatarReuploadWithDifferentValidName.
@Test
public void existingAvatarReuploadWithDifferentValidName() throws Exception {
final Path avatarFilePath = avatarsPath.resolve(EXISTING_VALID_AVATAR_FILENAME);
Files.copy(loadResource(BIG_AVATAR_FILENAME).openStream(), avatarFilePath);
final String avatarFileName = VALID_AVATAR_FILENAME;
final URL imageResource = loadResource(avatarFileName);
try (final InputStream imageInputStream = imageResource.openStream()) {
avatarService.updateAvatar(1, AVATAR_METADATA, "[./><" + avatarFileName, imageInputStream, VALID_FILE_SIZE);
ArgumentCaptor<Avatar> avatarCaptor = ArgumentCaptor.forClass(Avatar.class);
verify(avatarRepository, times(1)).save(avatarCaptor.capture());
final Avatar storedAvatar = avatarCaptor.getValue();
assertEquals(String.format(DOWNLOAD_URL_FORMAT, EXISTING_VALID_AVATAR_FILENAME), storedAvatar.getUrl());
assertEquals(AVATAR_NAME, storedAvatar.getTooltip());
assertThat(avatarsPath.resolve(EXISTING_VALID_AVATAR_FILENAME).toFile().length(), is(imageResource.openConnection().getContentLengthLong()));
}
}
use of com.faforever.api.data.domain.Avatar in project faf-java-api by FAForever.
the class AvatarServiceTest method deleteNotExistingAvatar.
@Test
public void deleteNotExistingAvatar() throws Exception {
when(avatarRepository.findById(AVATAR_ID)).thenReturn(Optional.empty());
expectedException.expect(NotFoundApiException.class);
avatarService.deleteAvatar(AVATAR_ID);
verify(avatarRepository, never()).delete(new Avatar());
}
use of com.faforever.api.data.domain.Avatar in project faf-java-api by FAForever.
the class AvatarControllerTest method moderatorCanReupload.
@Test
@WithUserDetails(AUTH_MODERATOR)
public void moderatorCanReupload() throws Exception {
Files.copy(FileHandlingHelper.loadResourceAsStream("/avatars/donator.png"), Paths.get("build/cache/avatars/avatar1.png"));
mockMvc.perform(createAvatarReuploadRequest(1).with(getOAuthToken(OAuthScope._UPLOAD_AVATAR))).andExpect(status().isOk()).andExpect(content().string(""));
final Avatar avatar = avatarRepository.findOneByUrl("http://localhost/faf/avatars/avatar1.png").get();
assertThat(avatar.getUrl(), is("http://localhost/faf/avatars/avatar1.png"));
assertThat(avatar.getTooltip(), is("Best avatar"));
verify(auditServiceSpy, times(1)).logMessage(any());
}
use of com.faforever.api.data.domain.Avatar in project faf-java-api by FAForever.
the class AvatarControllerTest method moderatorCanUpload.
@Test
@WithUserDetails(AUTH_MODERATOR)
public void moderatorCanUpload() throws Exception {
mockMvc.perform(createAvatarUploadRequest().with(getOAuthToken(OAuthScope._UPLOAD_AVATAR))).andExpect(status().isCreated()).andExpect(content().string(""));
final Avatar avatar = avatarRepository.findOneByUrl("http://localhost/faf/avatars/avatar3.png").get();
assertThat(avatar.getUrl(), is("http://localhost/faf/avatars/avatar3.png"));
assertThat(avatar.getTooltip(), is("Best avatar"));
verify(auditServiceSpy, times(1)).logMessage(any());
}
Aggregations