Search in sources :

Example 11 with Avatar

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));
}
Also used : Path(java.nio.file.Path) Avatar(com.faforever.api.data.domain.Avatar) Test(org.junit.Test)

Example 12 with Avatar

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)));
}
Also used : Avatar(com.faforever.api.data.domain.Avatar) FafApiProperties(com.faforever.api.config.FafApiProperties) Before(org.junit.Before)

Aggregations

Avatar (com.faforever.api.data.domain.Avatar)12 Test (org.junit.Test)8 InputStream (java.io.InputStream)5 Path (java.nio.file.Path)5 Audit (com.faforever.api.security.Audit)3 SneakyThrows (lombok.SneakyThrows)3 Transactional (org.springframework.transaction.annotation.Transactional)3 AbstractIntegrationTest (com.faforever.api.AbstractIntegrationTest)2 ApiException (com.faforever.api.error.ApiException)2 Error (com.faforever.api.error.Error)2 NotFoundApiException (com.faforever.api.error.NotFoundApiException)2 ProgrammingError (com.faforever.api.error.ProgrammingError)2 URL (java.net.URL)2 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)2 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)2 FafApiProperties (com.faforever.api.config.FafApiProperties)1 AvatarAssignment (com.faforever.api.data.domain.AvatarAssignment)1 Before (org.junit.Before)1