Search in sources :

Example 1 with IdmProfile

use of eu.bcvsolutions.idm.core.model.entity.IdmProfile in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManagerUnitTest method testAttachmentInputStreamIsClosedAfterSave.

@Test
public void testAttachmentInputStreamIsClosedAfterSave() throws IOException {
    when(attachmentConfiguration.getStoragePath()).thenReturn("target");
    InputStream inputStreamSpy = Mockito.spy(IOUtils.toInputStream("mock"));
    // 
    IdmProfile owner = new IdmProfile(UUID.randomUUID());
    IdmAttachmentDto attachment = new IdmAttachmentDto();
    attachment.setName("mock");
    attachment.setInputData(inputStreamSpy);
    // 
    attachmentManager.saveAttachment(owner, attachment);
    // 
    Assert.assertNull(attachment.getInputData());
    Mockito.verify(inputStreamSpy).close();
    Mockito.verify(repository).saveAndFlush(Mockito.any(IdmAttachment.class));
    Mockito.verify(attachmentConfiguration, times(2)).getStoragePath();
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmProfile(eu.bcvsolutions.idm.core.model.entity.IdmProfile) InputStream(java.io.InputStream) IdmAttachment(eu.bcvsolutions.idm.core.ecm.entity.IdmAttachment) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 2 with IdmProfile

use of eu.bcvsolutions.idm.core.model.entity.IdmProfile in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManagerUnitTest method testAttachmentInputStreamIsClosedAfterUpdate.

@Test
public void testAttachmentInputStreamIsClosedAfterUpdate() throws IOException {
    when(attachmentConfiguration.getStoragePath()).thenReturn("target");
    when(repository.saveAndFlush(any())).thenReturn(new IdmAttachment());
    InputStream inputStreamSpy = Mockito.spy(IOUtils.toInputStream("mock"));
    // 
    IdmProfile owner = new IdmProfile(UUID.randomUUID());
    IdmAttachmentDto attachment = new IdmAttachmentDto();
    attachment.setId(UUID.randomUUID());
    attachment.setName("mock");
    attachment.setInputData(inputStreamSpy);
    attachment.setOwnerId(owner.getId());
    attachment.setOwnerType("mock");
    // 
    attachmentManager.updateAttachment(attachment);
    // 
    Assert.assertNull(attachment.getInputData());
    Mockito.verify(inputStreamSpy).close();
    Mockito.verify(repository).saveAndFlush(Mockito.any(IdmAttachment.class));
    Mockito.verify(repository).findById(Mockito.any(UUID.class));
    Mockito.verify(attachmentConfiguration, times(2)).getStoragePath();
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmProfile(eu.bcvsolutions.idm.core.model.entity.IdmProfile) InputStream(java.io.InputStream) UUID(java.util.UUID) IdmAttachment(eu.bcvsolutions.idm.core.ecm.entity.IdmAttachment) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Aggregations

IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)2 IdmAttachment (eu.bcvsolutions.idm.core.ecm.entity.IdmAttachment)2 IdmProfile (eu.bcvsolutions.idm.core.model.entity.IdmProfile)2 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 UUID (java.util.UUID)1