use of com.faforever.api.data.domain.Avatar in project faf-java-api by FAForever.
the class AvatarServiceTest method deleteAvatar.
@Test
public void deleteAvatar() throws Exception {
final Avatar avatarToDelete = new Avatar().setUrl(VALID_AVATAR_FILENAME).setAssignments(Collections.emptyList());
when(avatarRepository.findById(AVATAR_ID)).thenReturn(Optional.of(avatarToDelete));
final Path avatarFilePath = temporaryFolder.getRoot().toPath().resolve(AVATARS_FOLDER).resolve(VALID_AVATAR_FILENAME);
Files.copy(loadResource(VALID_AVATAR_FILENAME).openStream(), avatarFilePath);
avatarService.deleteAvatar(AVATAR_ID);
verify(avatarRepository, times(1)).delete(avatarToDelete);
assertThat(avatarFilePath.toFile().exists(), is(false));
}
use of com.faforever.api.data.domain.Avatar in project faf-java-api by FAForever.
the class AvatarServiceTest method setUp.
@Before
public void setUp() throws Exception {
FafApiProperties properties = new FafApiProperties();
avatarsPath = temporaryFolder.getRoot().toPath().resolve(AVATARS_FOLDER);
Files.createDirectories(avatarsPath);
properties.getAvatar().setTargetDirectory(avatarsPath).setDownloadUrlFormat(DOWNLOAD_URL_FORMAT).setAllowedExtensions(Collections.singleton("png")).setMaxSizeBytes(1536).setMaxNameLength(15);
avatarService = new AvatarService(avatarRepository, properties);
when(avatarRepository.findOneByUrl(any())).thenReturn(Optional.empty());
when(avatarRepository.findById(EXISTING_AVATAR_ID)).thenReturn(Optional.of(new Avatar().setUrl(String.format(DOWNLOAD_URL_FORMAT, EXISTING_VALID_AVATAR_FILENAME)).setTooltip(EXISTING_AVATAR_NAME)));
}
Aggregations