use of eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto in project CzechIdMng by bcvsolutions.
the class DefaultAttachmentManagerIntegrationTest method prepareAttachment.
private IdmAttachmentDto prepareAttachment(String content) {
IdmAttachmentDto attachment = new IdmAttachmentDto();
attachment.setName("test.txt");
attachment.setMimetype("text/plain");
attachment.setInputData(IOUtils.toInputStream(content));
//
return attachment;
}
use of eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto in project CzechIdMng by bcvsolutions.
the class DefaultAttachmentManagerIntegrationTest method testUpdateAttachment.
@Test
@Transactional
public void testUpdateAttachment() {
Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
String contentOne = "test data 1";
IdmAttachmentDto attachment = prepareAttachment(contentOne);
attachment = attachmentManager.saveAttachment(owner, attachment);
//
String updatedContent = "update";
attachment.setInputData(IOUtils.toInputStream(updatedContent));
attachment.setDescription(updatedContent);
attachment = attachmentManager.updateAttachment(attachment);
//
List<IdmAttachmentDto> attachments = attachmentManager.getAttachmentVersions(attachment.getId());
//
Assert.assertEquals(1, attachments.size());
IdmAttachmentDto createdAttachment = attachments.get(0);
Assert.assertEquals(attachment.getName(), createdAttachment.getName());
Assert.assertEquals(attachment.getMimetype(), createdAttachment.getMimetype());
Assert.assertEquals(owner.getClass().getCanonicalName(), createdAttachment.getOwnerType());
Assert.assertEquals(owner.getId(), createdAttachment.getOwnerId());
Assert.assertNotNull(createdAttachment.getContentId());
Assert.assertNotNull(createdAttachment.getContentPath());
Assert.assertNull(createdAttachment.getParent());
Assert.assertNull(createdAttachment.getNextVersion());
Assert.assertEquals(Integer.valueOf(1), createdAttachment.getVersionNumber());
Assert.assertEquals("1.0", createdAttachment.getVersionLabel());
Assert.assertEquals(AttachableEntity.DEFAULT_ENCODING, createdAttachment.getEncoding());
Assert.assertEquals(Long.valueOf(updatedContent.getBytes(AttachableEntity.DEFAULT_CHARSET).length), createdAttachment.getFilesize());
Assert.assertEquals(updatedContent, createdAttachment.getDescription());
//
attachmentManager.deleteAttachment(attachment);
//
Assert.assertEquals(0, attachmentManager.getAttachmentVersions(attachment.getId()).size());
}
use of eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto in project CzechIdMng by bcvsolutions.
the class DefaultAttachmentManagerIntegrationTest method testAttachmentVersions.
@Test
@Transactional
public void testAttachmentVersions() throws IOException {
Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
String contentOne = "test data 1";
IdmAttachmentDto attachmentOne = prepareAttachment(contentOne);
attachmentOne = attachmentManager.saveAttachment(owner, attachmentOne);
String contentTwo = "test data 2";
IdmAttachmentDto attachmentTwo = prepareAttachment(contentTwo);
attachmentTwo = attachmentManager.saveAttachmentVersion(owner, attachmentTwo, attachmentOne);
String contentThree = "test data 3";
IdmAttachmentDto attachmentThree = prepareAttachment(contentThree);
attachmentThree = attachmentManager.saveAttachmentVersion(owner, attachmentThree, attachmentTwo);
//
Assert.assertNotNull(attachmentManager.get(attachmentOne));
Assert.assertNotNull(attachmentManager.get(attachmentTwo));
Assert.assertNotNull(attachmentManager.get(attachmentThree));
//
// last version only
List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(owner, null).getContent();
Assert.assertEquals(1, attachments.size());
Assert.assertEquals(contentThree, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(0).getId())));
//
attachments = attachmentManager.getAttachmentVersions(attachmentOne.getId());
Assert.assertEquals(3, attachments.size());
// three
Assert.assertEquals(Integer.valueOf(3), attachments.get(0).getVersionNumber());
Assert.assertEquals("3.0", attachments.get(0).getVersionLabel());
Assert.assertNull(attachments.get(0).getNextVersion());
Assert.assertEquals(attachmentOne.getId(), attachments.get(0).getParent());
Assert.assertEquals(contentThree, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(0).getId())));
// two
Assert.assertEquals(Integer.valueOf(2), attachments.get(1).getVersionNumber());
Assert.assertEquals("2.0", attachments.get(1).getVersionLabel());
Assert.assertEquals(attachmentThree.getId(), attachments.get(1).getNextVersion());
Assert.assertEquals(attachmentOne.getId(), attachments.get(1).getParent());
Assert.assertEquals(contentTwo, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(1).getId())));
// one
Assert.assertEquals(Integer.valueOf(1), attachments.get(2).getVersionNumber());
Assert.assertEquals("1.0", attachments.get(2).getVersionLabel());
Assert.assertEquals(attachmentTwo.getId(), attachments.get(2).getNextVersion());
Assert.assertNull(attachments.get(2).getParent());
Assert.assertEquals(contentOne, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(2).getId())));
//
attachmentManager.deleteAttachment(attachmentThree);
//
Assert.assertNull(attachmentManager.get(attachmentOne));
Assert.assertNull(attachmentManager.get(attachmentTwo));
Assert.assertNull(attachmentManager.get(attachmentThree));
}
Aggregations