刘光辉
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package jnpf.dmsController;
 
import jnpf.dmsEntity.wenjianbianhao.DmsFlowEventType;
import jnpf.dmsEntity.wenjianbianhao.form.DmsFlowEventForm;
import jnpf.dmsEntity.banben.form.DmsWenjianBanbenQueryForm;
import jnpf.dmsEntity.banben.vo.DmsWenjianBanbenQueryVO;
import jnpf.dmsEntity.banben.vo.DmsWenjianZhongxinBanbenVO;
import jnpf.dmsService.DmsWenjianBanbenService;
import jnpf.exception.DataException;
import jnpf.flowable.WorkFlowApi;
import jnpf.flowable.entity.TaskEntity;
import jnpf.util.context.SpringContext;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.StaticApplicationContext;
 
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class DmsWenjianBanbenControllerTest {
 
    @BeforeAll
    static void setUpSpringContext() {
        SpringContext.setApplicationContext(new StaticApplicationContext());
    }
 
    private final DmsWenjianBanbenService service = mock(DmsWenjianBanbenService.class);
    private final jnpf.dmsService.DmsApprovedFlowService approvedFlow = mock(jnpf.dmsService.DmsApprovedFlowService.class);
    private final DmsWenjianBanbenController controller =
            new DmsWenjianBanbenController(service, approvedFlow);
 
    @Test
    void queryByFileAndVersionDelegatesRequestValues() throws DataException {
        DmsWenjianBanbenQueryForm form = new DmsWenjianBanbenQueryForm();
        form.setWenjianId("file-1");
        form.setBanbenhao("D(01)");
        when(service.getByWenjianIdAndBanbenhao("file-1", "D(01)"))
                .thenReturn(new DmsWenjianBanbenQueryVO());
 
        controller.getByWenjianIdAndBanbenhao(form);
 
        verify(service).getByWenjianIdAndBanbenhao("file-1", "D(01)");
    }
 
    @Test
    void fileCenterVersionDelegatesBusinessVersionId() throws DataException {
        DmsWenjianZhongxinBanbenVO result = new DmsWenjianZhongxinBanbenVO();
        result.setWenjianZhongxinBanbenId("file-center-version-1");
        when(service.getWenjianZhongxinBanben("version-1")).thenReturn(result);
 
        controller.getWenjianZhongxinBanben("version-1");
 
        verify(service).getWenjianZhongxinBanben("version-1");
    }
 
    @Test
    void revisionEventUsesApprovedFlowOrchestrator() throws DataException {
        DmsFlowEventForm form = form(DmsFlowEventType.END);
        controller.syncRevisionAuditFlowEvent(form);
        verify(approvedFlow).sync(form, "xiuding_shenhe");
    }
 
    @Test
    void newEventUsesApprovedFlowOrchestrator() throws DataException {
        DmsFlowEventForm form = form(DmsFlowEventType.START);
        controller.syncNewAuditFlowEvent(form);
        verify(approvedFlow).sync(form, "xinzeng_shenhe");
    }
 
    private DmsFlowEventForm form(DmsFlowEventType eventType) {
        DmsFlowEventForm form = new DmsFlowEventForm();
        form.setFlowId("flow-1");
        form.setTaskId("task-1");
        form.setEventType(eventType);
        return form;
    }
}