diff --git a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/document/api/impl/DocumentServiceImpl.java b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/document/api/impl/DocumentServiceImpl.java index 2d8d5e9726b..5aad3578b91 100644 --- a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/document/api/impl/DocumentServiceImpl.java +++ b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/document/api/impl/DocumentServiceImpl.java @@ -468,7 +468,10 @@ public void deleteContentOfArchivedDocument(final long archivedDocumentId) throws SObjectNotFoundException, SBonitaReadException, SRecorderException { final SAMappedDocument archivedDocument = getArchivedDocument(archivedDocumentId); final SDocument document = getDocumentWithContent(archivedDocument.getDocumentId()); - recorder.recordUpdate(UpdateRecord.buildSetFields(document, Collections.singletonMap("content", null)), + final HashMap updateFields = new HashMap<>(); + updateFields.put("content", null); + updateFields.put("hasContent", false); + recorder.recordUpdate(UpdateRecord.buildSetFields(document, updateFields), DOCUMENT); } diff --git a/bpm/bonita-core/bonita-process-instance/src/test/java/org/bonitasoft/engine/core/document/api/impl/DocumentServiceImplTest.java b/bpm/bonita-core/bonita-process-instance/src/test/java/org/bonitasoft/engine/core/document/api/impl/DocumentServiceImplTest.java index 522d979a726..64ce0f79bcc 100644 --- a/bpm/bonita-core/bonita-process-instance/src/test/java/org/bonitasoft/engine/core/document/api/impl/DocumentServiceImplTest.java +++ b/bpm/bonita-core/bonita-process-instance/src/test/java/org/bonitasoft/engine/core/document/api/impl/DocumentServiceImplTest.java @@ -17,24 +17,22 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; import org.bonitasoft.engine.archive.ArchiveService; import org.bonitasoft.engine.commons.exceptions.SObjectNotFoundException; import org.bonitasoft.engine.core.document.model.AbstractSMappedDocument; +import org.bonitasoft.engine.core.document.model.SDocument; import org.bonitasoft.engine.core.document.model.SMappedDocument; import org.bonitasoft.engine.core.document.model.archive.SAMappedDocument; import org.bonitasoft.engine.core.document.model.recorder.SelectDescriptorBuilder; -import org.bonitasoft.engine.persistence.QueryOptions; -import org.bonitasoft.engine.persistence.ReadPersistenceService; -import org.bonitasoft.engine.persistence.SelectListDescriptor; +import org.bonitasoft.engine.persistence.*; import org.bonitasoft.engine.recorder.Recorder; +import org.bonitasoft.engine.recorder.model.UpdateRecord; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @@ -51,6 +49,8 @@ public class DocumentServiceImplTest { @Mock private ReadPersistenceService persistenceService; @Mock + private ReadPersistenceService definitiveArchiveReadPersistenceService; + @Mock private SDocumentDownloadURLProvider urlProvider; @Mock private ArchiveService archiveService; @@ -59,6 +59,8 @@ public class DocumentServiceImplTest { @Before public void setUp() { + when(archiveService.getDefinitiveArchiveReadPersistenceService()) + .thenReturn(definitiveArchiveReadPersistenceService); documentService = spy(new DocumentServiceImpl(recorder, persistenceService, urlProvider, archiveService)); } @@ -107,6 +109,27 @@ public void should_getDocumentList_return_the_list_with_100_elements() throws Ex assertThat(theList).isEqualTo(documentList1); } + @Test + public void should_call_deletion_with_right_arguments() throws Exception { + //given + Long sourceObjectId = 5L; + final SAMappedDocument mappedDocument = new SAMappedDocument(1L, sourceObjectId); + byte[] docContent = "theContent".getBytes(); + final SDocument document = new SDocument(docContent); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(UpdateRecord.class); + when(definitiveArchiveReadPersistenceService.selectById(any())) + .thenReturn(mappedDocument); + when(persistenceService.selectById(any())) + .thenReturn(document); + + //when + documentService.deleteContentOfArchivedDocument(sourceObjectId); + //then + verify(recorder).recordUpdate(argumentCaptor.capture(), any()); + UpdateRecord record = argumentCaptor.getValue(); + assertThat(record.getFields()).containsOnlyKeys("content", "hasContent"); + } + private List constructList(final int size) { final ArrayList list = new ArrayList<>(); for (int i = 0; i < size; i++) {