From e9e81f5a1375731433dcf7dfb50ef784f03c74a7 Mon Sep 17 00:00:00 2001 From: Dumitru Corini Date: Mon, 3 Jul 2023 10:46:28 +0200 Subject: [PATCH] fix(document service): manage hasContent to false after deleting content (#2617) covers [RUNTIME-38](https://bonitasoft.atlassian.net/browse/RUNTIME-38) --- .../api/impl/DocumentServiceImpl.java | 5 ++- .../api/impl/DocumentServiceImplTest.java | 37 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) 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++) {