Search in sources :

Example 1 with Attachment

use of com.epam.ta.reportportal.entity.attachment.Attachment in project commons-dao by reportportal.

the class AttachmentBinaryDataServiceImpl method attachToLog.

@Override
public void attachToLog(BinaryDataMetaInfo binaryDataMetaInfo, AttachmentMetaInfo attachmentMetaInfo) {
    try {
        Attachment attachment = new Attachment();
        attachment.setFileId(binaryDataMetaInfo.getFileId());
        attachment.setThumbnailId(binaryDataMetaInfo.getThumbnailFileId());
        attachment.setContentType(binaryDataMetaInfo.getContentType());
        attachment.setFileSize(binaryDataMetaInfo.getFileSize());
        attachment.setProjectId(attachmentMetaInfo.getProjectId());
        attachment.setLaunchId(attachmentMetaInfo.getLaunchId());
        attachment.setItemId(attachmentMetaInfo.getItemId());
        attachment.setCreationDate(attachmentMetaInfo.getCreationDate());
        createLogAttachmentService.create(attachment, attachmentMetaInfo.getLogId());
    } catch (Exception exception) {
        LOGGER.error("Cannot save log to database, remove files ", exception);
        dataStoreService.delete(binaryDataMetaInfo.getFileId());
        dataStoreService.delete(binaryDataMetaInfo.getThumbnailFileId());
        throw exception;
    }
}
Also used : Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Example 2 with Attachment

use of com.epam.ta.reportportal.entity.attachment.Attachment in project commons-dao by reportportal.

the class AttachmentRepositoryTest method findByItemIdsAndPeriodTest.

@Test
void findByItemIdsAndPeriodTest() {
    Duration duration = Duration.ofDays(6).plusHours(23);
    final Long itemId = 3L;
    List<Attachment> attachments = attachmentRepository.findByItemIdsAndLogTimeBefore(Collections.singletonList(itemId), LocalDateTime.now(ZoneOffset.UTC).minus(duration));
    assertTrue(CollectionUtils.isNotEmpty(attachments), "Attachments should not be empty");
    assertEquals(3, attachments.size(), "Incorrect count of attachments");
    attachments.stream().map(it -> null != it.getFileId() || null != it.getThumbnailId()).forEach(Assertions::assertTrue);
    attachments.stream().map(Attachment::getFileSize).forEach(size -> assertEquals(1024, size));
}
Also used : Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) Arrays(java.util.Arrays) BaseTest(com.epam.ta.reportportal.BaseTest) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) PageRequest(org.springframework.data.domain.PageRequest) Sql(org.springframework.test.context.jdbc.Sql) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Test(org.junit.jupiter.api.Test) List(java.util.List) Lists(com.google.common.collect.Lists) Duration(java.time.Duration) Assertions(org.junit.jupiter.api.Assertions) ZoneOffset(java.time.ZoneOffset) Collections(java.util.Collections) Duration(java.time.Duration) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) Assertions(org.junit.jupiter.api.Assertions) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 3 with Attachment

use of com.epam.ta.reportportal.entity.attachment.Attachment in project commons-dao by reportportal.

the class AttachmentRepositoryTest method findByProjectIdsAndLogTimeBeforeTest.

@Test
void findByProjectIdsAndLogTimeBeforeTest() {
    Duration duration = Duration.ofDays(6).plusHours(23);
    final Long projectId = 1L;
    List<Attachment> attachments = attachmentRepository.findByProjectIdsAndLogTimeBefore(projectId, LocalDateTime.now(ZoneOffset.UTC).minus(duration), 3, 6);
    assertTrue(CollectionUtils.isNotEmpty(attachments), "Attachments should not be empty");
    assertEquals(3, attachments.size(), "Incorrect count of attachments");
    attachments.stream().map(it -> null != it.getFileId() || null != it.getThumbnailId()).forEach(Assertions::assertTrue);
    attachments.stream().map(Attachment::getFileSize).forEach(size -> assertEquals(1024, size));
}
Also used : Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) Arrays(java.util.Arrays) BaseTest(com.epam.ta.reportportal.BaseTest) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) PageRequest(org.springframework.data.domain.PageRequest) Sql(org.springframework.test.context.jdbc.Sql) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Test(org.junit.jupiter.api.Test) List(java.util.List) Lists(com.google.common.collect.Lists) Duration(java.time.Duration) Assertions(org.junit.jupiter.api.Assertions) ZoneOffset(java.time.ZoneOffset) Collections(java.util.Collections) Duration(java.time.Duration) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) Assertions(org.junit.jupiter.api.Assertions) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 4 with Attachment

use of com.epam.ta.reportportal.entity.attachment.Attachment 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 5 with Attachment

use of com.epam.ta.reportportal.entity.attachment.Attachment in project commons-dao by reportportal.

the class CreateLogAttachmentServiceTest method getAttachment.

private Attachment getAttachment() {
    Attachment attachment = new Attachment();
    attachment.setFileId("fileId");
    attachment.setThumbnailId("thumbnailId");
    attachment.setContentType("contentType");
    return attachment;
}
Also used : Attachment(com.epam.ta.reportportal.entity.attachment.Attachment)

Aggregations

Attachment (com.epam.ta.reportportal.entity.attachment.Attachment)11 Test (org.junit.jupiter.api.Test)8 BaseTest (com.epam.ta.reportportal.BaseTest)7 Duration (java.time.Duration)4 LocalDateTime (java.time.LocalDateTime)4 Sql (org.springframework.test.context.jdbc.Sql)4 Log (com.epam.ta.reportportal.entity.log.Log)3 Lists (com.google.common.collect.Lists)3 ZoneOffset (java.time.ZoneOffset)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 CollectionUtils (org.apache.commons.collections4.CollectionUtils)3 Assertions (org.junit.jupiter.api.Assertions)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 PageRequest (org.springframework.data.domain.PageRequest)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 IndexLog (com.epam.ta.reportportal.ws.model.analyzer.IndexLog)2