刘光辉
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package jnpf.dmsService;
 
import jnpf.dmsMapper.DmsDisableApplicationMapper;
import jnpf.dmsEntity.storage.approval.DmsDisableOccupancy;
import jnpf.exception.DataException;
import jnpf.flowable.WorkFlowApi;
import jnpf.flowable.entity.TaskEntity;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
 
class DmsDisableApplicationGuardTest {
    final DmsDisableApplicationMapper mapper = mock(DmsDisableApplicationMapper.class);
    final WorkFlowApi workflow = mock(WorkFlowApi.class);
    final DmsDisableApplicationGuard guard = new DmsDisableApplicationGuard(mapper, workflow);
 
    TaskEntity legacy(int status, boolean ended) {
        DmsDisableOccupancy application = new DmsDisableOccupancy();
        application.setTaskId("task"); application.setFlowId("template");
        when(mapper.legacyApplicationsForFile("t", "f")).thenReturn(List.of(application));
        TaskEntity task = new TaskEntity();
        task.setId("task"); task.setFlowId("flow"); task.setTemplateId("template");
        task.setStatus(status); task.setEndTime(ended ? new Date() : null);
        when(workflow.getInfoSubmit("task")).thenReturn(task);
        return task;
    }
 
    @Test void disabledCutoverNeverQueriesAbsentOccupancyTable() {
        legacy(8, false);
        assertThrows(DataException.class, () -> guard.requireFileEditable("t", "f"));
        verify(mapper, never()).pendingForFile(any(), any());
    }
    @ParameterizedTest @ValueSource(ints={3,4,7,9})
    void legacyOnlyReleasesVerifiedUnsuccessfulEnd(int status) {
        legacy(status, false);
        assertThrows(DataException.class, () -> guard.requireFileEditable("t", "f"));
        legacy(status, true);
        assertDoesNotThrow(() -> guard.requireFileEditable("t", "f"));
    }
    @Test void successfulEndKeepsFileOccupiedUntilBusinessProjection() {
        legacy(2, true);
        assertThrows(DataException.class, () -> guard.requireFileEditable("t", "f"));
    }
    @Test void missingOrMismatchedWorkflowCannotRelease() {
        TaskEntity task = legacy(3, true); task.setId("other");
        assertThrows(DataException.class, () -> guard.requireFileEditable("t", "f"));
        when(workflow.getInfoSubmit("task")).thenReturn(null);
        assertThrows(DataException.class, () -> guard.requireFileEditable("t", "f"));
    }
    @Test void enabledGuardOnlyUsesIndexedOccupancy() {
        ReflectionTestUtils.setField(guard, "occupancyEnabled", true);
        UUID doc = UUID.randomUUID();
        when(mapper.pendingForDocument("t", doc)).thenReturn(1);
        assertThrows(DataException.class, () -> guard.requireDocumentEditable("t", doc));
        verify(mapper, never()).legacyApplicationsForDocument(any(), any());
        verifyNoInteractions(workflow);
    }
}