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;
}
}
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));
}
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));
}
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());
}
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;
}
Aggregations