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