use of com.epam.ta.reportportal.entity.attachment.AttachmentMetaInfo in project commons-dao by reportportal.
the class FilePathGeneratorTest method generate_different_even_for_same_date.
@Test
void generate_different_even_for_same_date() {
// given:
AttachmentMetaInfo metaInfo = AttachmentMetaInfo.builder().withProjectId(1L).withLaunchUuid("271b5881-9a62-4df4-b477-335a96acbe14").build();
LocalDateTime date = LocalDateTime.of(2018, 5, 28, 3, 3);
when(dateTimeProvider.localDateTimeNow()).thenReturn(date);
//
// when:
String pathOne = new FilePathGenerator(dateTimeProvider).generate(metaInfo);
Assertions.assertThat(pathOne).isEqualTo("1/2018-5/271b5881-9a62-4df4-b477-335a96acbe14");
}
use of com.epam.ta.reportportal.entity.attachment.AttachmentMetaInfo in project commons-dao by reportportal.
the class AttachmentCommonDataStoreServiceTest method AttachFileToExistingLogTest.
@Test
@Sql("/db/fill/data-store/data-store-fill.sql")
void AttachFileToExistingLogTest() {
String fileID = "fileID";
String thumbnailID = "thumbnailID";
String contentType = "content-type";
long fileSize = 1024;
final LocalDateTime creationDate = LocalDateTime.of(2020, Month.JANUARY, 1, 1, 1);
BinaryDataMetaInfo binaryDataMetaInfo = new BinaryDataMetaInfo();
binaryDataMetaInfo.setFileId(fileID);
binaryDataMetaInfo.setThumbnailFileId(thumbnailID);
binaryDataMetaInfo.setContentType(contentType);
binaryDataMetaInfo.setFileSize(fileSize);
Long projectId = 1L;
Long itemId = 1L;
AttachmentMetaInfo attachmentMetaInfo = AttachmentMetaInfo.builder().withProjectId(projectId).withLaunchId(1L).withItemId(itemId).withLogId(1L).withCreationDate(creationDate).build();
attachmentBinaryDataService.attachToLog(binaryDataMetaInfo, attachmentMetaInfo);
Optional<Attachment> attachment = attachmentRepository.findByFileId(fileID);
assertTrue(attachment.isPresent());
assertEquals(projectId, attachment.get().getProjectId());
assertEquals(itemId, attachment.get().getItemId());
assertEquals(fileID, attachment.get().getFileId());
assertEquals(thumbnailID, attachment.get().getThumbnailId());
assertEquals(contentType, attachment.get().getContentType());
assertEquals(fileSize, attachment.get().getFileSize());
assertEquals(creationDate, attachment.get().getCreationDate());
}
use of com.epam.ta.reportportal.entity.attachment.AttachmentMetaInfo in project commons-dao by reportportal.
the class LocalDataStoreTest method save_load_delete.
@Test
void save_load_delete() throws Exception {
// given:
AttachmentMetaInfo attachmentMetaInfo = AttachmentMetaInfo.builder().withProjectId(1L).withLaunchId(2L).withItemId(3L).withLogId(4L).build();
String generatedDirectory = "/test";
when(fileNameGenerator.generate(attachmentMetaInfo)).thenReturn(generatedDirectory);
FileUtils.deleteDirectory(new File(Paths.get(ROOT_PATH, generatedDirectory).toUri()));
// when: save new file
String savedFilePath = localDataStore.save(TEST_FILE, new ByteArrayInputStream("test text".getBytes(Charsets.UTF_8)));
// and: load it back
InputStream loaded = localDataStore.load(savedFilePath);
// then: saved and loaded files should be the same
byte[] bytes = IOUtils.toByteArray(loaded);
String result = new String(bytes, Charsets.UTF_8);
assertEquals("test text", result, "saved and loaded files should be the same");
// when: delete saved file
localDataStore.delete(savedFilePath);
// and: load file again
boolean isNotFound = false;
try {
localDataStore.load(savedFilePath);
} catch (ReportPortalException e) {
isNotFound = true;
}
// then: deleted file should not be found
assertTrue("deleted file should not be found", isNotFound);
}
Aggregations