Search in sources :

Example 6 with Attachment

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

the class CreateLogAttachmentServiceTest method createAttachmentPositive.

@Test
void createAttachmentPositive() {
    Log log = getLogWithoutAttachment();
    Attachment attachment = getAttachment();
    when(logRepository.findById(1L)).thenReturn(Optional.of(log));
    createLogAttachmentService.create(attachment, 1L);
    verify(logRepository, times(1)).save(log);
    assertEquals(log.getAttachment().getFileId(), attachment.getFileId());
    assertEquals(log.getAttachment().getThumbnailId(), attachment.getThumbnailId());
    assertEquals(log.getAttachment().getContentType(), attachment.getContentType());
}
Also used : Log(com.epam.ta.reportportal.entity.log.Log) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) Test(org.junit.jupiter.api.Test)

Example 7 with Attachment

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

the class AttachmentRepositoryTest method shouldNotFindByLaunchIdsWhenLessThenPeriod.

@Test
void shouldNotFindByLaunchIdsWhenLessThenPeriod() {
    Duration duration = Duration.ofDays(14).plusHours(23);
    final Long launchId = 3L;
    List<Attachment> attachments = attachmentRepository.findByLaunchIdsAndLogTimeBefore(Collections.singletonList(launchId), LocalDateTime.now(ZoneOffset.UTC).minus(duration));
    assertTrue(CollectionUtils.isEmpty(attachments), "Attachments should be empty");
}
Also used : Duration(java.time.Duration) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 8 with Attachment

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

the class AttachmentRepositoryTest method findByLaunchIdsAndPeriodTest.

@Test
void findByLaunchIdsAndPeriodTest() {
    Duration duration = Duration.ofDays(6).plusHours(23);
    final Long launchId = 3L;
    List<Attachment> attachments = attachmentRepository.findByLaunchIdsAndLogTimeBefore(Collections.singletonList(launchId), LocalDateTime.now(ZoneOffset.UTC).minus(duration));
    assertTrue(CollectionUtils.isNotEmpty(attachments), "Attachments should not be empty");
    assertEquals(1, 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 9 with Attachment

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

the class LogRepositoryTest method findAllWithAttachmentOfRetries.

@Test
void findAllWithAttachmentOfRetries() {
    Filter logWithAttachmentsFilter = Filter.builder().withTarget(Log.class).withCondition(FilterCondition.builder().withCondition(Condition.EXISTS).withSearchCriteria(CRITERIA_LOG_BINARY_CONTENT).withValue("1").build()).withCondition(new CompositeFilterCondition(Lists.newArrayList(FilterCondition.builder().eq(CRITERIA_RETRY_PARENT_LAUNCH_ID, String.valueOf(1L)).build(), FilterCondition.builder().eq(CRITERIA_ITEM_LAUNCH_ID, String.valueOf(1L)).withOperator(Operator.OR).build()))).build();
    Page<Log> logPage = logRepository.findByFilter(logWithAttachmentsFilter, PageRequest.of(0, 10));
    List<Log> logs = logPage.getContent();
    assertFalse(logs.isEmpty());
    logs.forEach(log -> {
        Attachment attachment = log.getAttachment();
        assertNotNull(attachment);
        assertNotNull(attachment.getId());
        assertNotNull(attachment.getFileId());
        assertNotNull(attachment.getContentType());
        assertNotNull(attachment.getThumbnailId());
    });
    assertEquals(7, logs.size());
}
Also used : CompositeFilterCondition(com.epam.ta.reportportal.commons.querygen.CompositeFilterCondition) Filter(com.epam.ta.reportportal.commons.querygen.Filter) Log(com.epam.ta.reportportal.entity.log.Log) IndexLog(com.epam.ta.reportportal.ws.model.analyzer.IndexLog) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 10 with Attachment

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

the class LogRepositoryTest method findAllWithAttachment.

@Test
void findAllWithAttachment() {
    Filter logWithAttachmentsFilter = Filter.builder().withTarget(Log.class).withCondition(FilterCondition.builder().withCondition(Condition.EXISTS).withSearchCriteria(CRITERIA_LOG_BINARY_CONTENT).withValue("1").build()).build();
    Page<Log> logPage = logRepository.findByFilter(logWithAttachmentsFilter, PageRequest.of(0, 10));
    List<Log> logs = logPage.getContent();
    assertFalse(logs.isEmpty());
    logs.forEach(log -> {
        Attachment attachment = log.getAttachment();
        assertNotNull(attachment);
        assertNotNull(attachment.getId());
        assertNotNull(attachment.getFileId());
        assertNotNull(attachment.getContentType());
        assertNotNull(attachment.getThumbnailId());
    });
    assertEquals(10, logs.size());
}
Also used : Filter(com.epam.ta.reportportal.commons.querygen.Filter) Log(com.epam.ta.reportportal.entity.log.Log) IndexLog(com.epam.ta.reportportal.ws.model.analyzer.IndexLog) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

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