Skip to content

Commit

Permalink
Merge branch '7.14.x' into '7.15.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
bonita-ci committed Jul 4, 2023
2 parents 456d975 + 953f19c commit a6623fb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> updateFields = new HashMap<>();
updateFields.put("content", null);
updateFields.put("hasContent", false);
recorder.recordUpdate(UpdateRecord.buildSetFields(document, updateFields),
DOCUMENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,6 +49,8 @@ public class DocumentServiceImplTest {
@Mock
private ReadPersistenceService persistenceService;
@Mock
private ReadPersistenceService definitiveArchiveReadPersistenceService;
@Mock
private SDocumentDownloadURLProvider urlProvider;
@Mock
private ArchiveService archiveService;
Expand All @@ -59,6 +59,8 @@ public class DocumentServiceImplTest {

@Before
public void setUp() {
when(archiveService.getDefinitiveArchiveReadPersistenceService())
.thenReturn(definitiveArchiveReadPersistenceService);
documentService = spy(new DocumentServiceImpl(recorder, persistenceService, urlProvider, archiveService));
}

Expand Down Expand Up @@ -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<UpdateRecord> 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<SMappedDocument> constructList(final int size) {
final ArrayList<SMappedDocument> list = new ArrayList<>();
for (int i = 0; i < size; i++) {
Expand Down

0 comments on commit a6623fb

Please sign in to comment.