刘光辉
4 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package jnpf.dmsService;
 
import jnpf.dmsIntegration.audit.DmsBusinessChangeAudit;
import jnpf.dmsEntity.permission.entity.DmsDocumentEntity;
import jnpf.dmsMapper.DmsDocumentMapper;
import jnpf.dmsService.center.DmsCenterDirectoryService;
import jnpf.exception.DataException;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
 
class DmsCenterDirectoryAuditTest {
    final DmsDocumentMapper documents = mock(DmsDocumentMapper.class);
    final DmsBusinessChangeAudit audit = mock(DmsBusinessChangeAudit.class);
    final DmsCenterDirectoryService service = new DmsCenterDirectoryService(audit, documents);
    final UUID mainId = UUID.randomUUID(), recordId = UUID.randomUUID();
    final DmsDocumentEntity record = new DmsDocumentEntity();
    void arrange() {
        when(documents.selectByTenantAndIdForUpdate("tenant", mainId)).thenReturn(new DmsDocumentEntity());
        when(documents.selectByTenantAndIdForUpdate("tenant", recordId)).thenReturn(record);
    }
    @Test void bindingRecordsOldAndNewOwnershipAndRetryDoesNotDuplicate() {
        arrange(); when(documents.bindMainDocument("tenant", recordId, mainId)).thenReturn(1);
        service.bind("tenant", mainId, List.of(recordId));
        verify(audit).record(eq("tenant"), eq("DMS_CENTER_BIND_DIRECTORY"), anyString(), eq("dms_documents"),
                eq(recordId.toString()), argThat(m -> m.containsKey("main_document_id") && m.get("main_document_id") == null),
                argThat(m -> mainId.equals(m.get("main_document_id"))), isNull(), anyMap());
        record.setMainDocumentId(mainId);
        service.bind("tenant", mainId, List.of(recordId));
        verifyNoMoreInteractions(audit);
    }
    @Test void failedWriteProducesNoSuccessEvent() {
        arrange(); assertThrows(DataException.class, () -> service.bind("tenant", mainId, List.of(recordId)));
        verifyNoInteractions(audit);
    }
}