use of org.springframework.web.multipart.commons.CommonsMultipartFile in project commons-dao by reportportal.
the class UserCommonDataStoreServiceTest method saveUserPhoto.
@Test
void saveUserPhoto() throws IOException {
CommonsMultipartFile multipartFile = getMultipartFile("meh.jpg");
User user = userRepository.findByLogin("default").get();
userDataStoreService.saveUserPhoto(user, multipartFile);
user = userRepository.findByLogin("default").get();
BinaryData binaryData = userDataStoreService.loadUserPhoto(user, false);
assertThat(IOUtils.contentEquals(multipartFile.getInputStream(), binaryData.getInputStream())).isTrue();
BinaryData binaryDataThumbnail = userDataStoreService.loadUserPhoto(user, true);
assertThat(IOUtils.contentEquals(thumbnailator.createThumbnail(multipartFile.getInputStream()), binaryDataThumbnail.getInputStream())).isTrue();
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project commons-dao by reportportal.
the class CommonDataStoreServiceTest method getMultipartFile.
public static CommonsMultipartFile getMultipartFile(String path) throws IOException {
File file = new ClassPathResource(path).getFile();
FileItem fileItem = new DiskFileItem("mainFile", Files.probeContentType(file.toPath()), false, file.getName(), (int) file.length(), file.getParentFile());
IOUtils.copy(new FileInputStream(file), fileItem.getOutputStream());
return new CommonsMultipartFile(fileItem);
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project commons-dao by reportportal.
the class CommonDataStoreServiceTest method saveThumbnailTest.
@Test
void saveThumbnailTest() throws IOException {
CommonsMultipartFile multipartFile = getMultipartFile("meh.jpg");
String fileId = dataStoreService.saveThumbnail(multipartFile.getOriginalFilename(), multipartFile.getInputStream());
assertNotNull(fileId);
assertTrue(Files.exists(Paths.get(storageRootPath, dataEncoder.decode(fileId))));
dataStoreService.delete(fileId);
}
Aggregations