Search in sources :

Example 21 with CommonsMultipartFile

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();
}
Also used : User(com.epam.ta.reportportal.entity.user.User) BinaryData(com.epam.ta.reportportal.entity.attachment.BinaryData) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 22 with CommonsMultipartFile

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);
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem) File(java.io.File) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) ClassPathResource(org.springframework.core.io.ClassPathResource) FileInputStream(java.io.FileInputStream) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile)

Example 23 with CommonsMultipartFile

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);
}
Also used : CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

CommonsMultipartFile (org.springframework.web.multipart.commons.CommonsMultipartFile)23 InputStream (java.io.InputStream)9 IOException (java.io.IOException)8 File (java.io.File)7 BaseTest (com.epam.ta.reportportal.BaseTest)5 Test (org.junit.jupiter.api.Test)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 MultipartFile (org.springframework.web.multipart.MultipartFile)4 FileItem (org.apache.commons.fileupload.FileItem)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 DiskFileItem (org.apache.commons.fileupload.disk.DiskFileItem)2 Metadata (org.apache.tika.metadata.Metadata)2 MimeTypes (org.apache.tika.mime.MimeTypes)2 LocalDate (org.joda.time.LocalDate)2 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)2 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)2 UploadedFileDto (org.mifos.dto.screen.UploadedFileDto)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2