Search in sources :

Example 1 with AttachmentMetaInfo

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");
}
Also used : LocalDateTime(java.time.LocalDateTime) AttachmentMetaInfo(com.epam.ta.reportportal.entity.attachment.AttachmentMetaInfo) Test(org.junit.jupiter.api.Test)

Example 2 with AttachmentMetaInfo

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());
}
Also used : LocalDateTime(java.time.LocalDateTime) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) BinaryDataMetaInfo(com.epam.ta.reportportal.commons.BinaryDataMetaInfo) AttachmentMetaInfo(com.epam.ta.reportportal.entity.attachment.AttachmentMetaInfo) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 3 with AttachmentMetaInfo

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) File(java.io.File) AttachmentMetaInfo(com.epam.ta.reportportal.entity.attachment.AttachmentMetaInfo) Test(org.junit.jupiter.api.Test)

Aggregations

AttachmentMetaInfo (com.epam.ta.reportportal.entity.attachment.AttachmentMetaInfo)3 Test (org.junit.jupiter.api.Test)3 LocalDateTime (java.time.LocalDateTime)2 BaseTest (com.epam.ta.reportportal.BaseTest)1 BinaryDataMetaInfo (com.epam.ta.reportportal.commons.BinaryDataMetaInfo)1 Attachment (com.epam.ta.reportportal.entity.attachment.Attachment)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Sql (org.springframework.test.context.jdbc.Sql)1