刘光辉
5 小时以前 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package jnpf.dmsService;
 
import jnpf.base.ActionResult;
import jnpf.dms.DmsResourceApi;
import jnpf.dmsEntity.DmsWenjianBanbenEntity;
import jnpf.dmsEntity.print.form.DmsWorkflowPrintFilesGrantForm;
import jnpf.dmsEntity.print.vo.DmsWorkflowPrintFilesGrantResultVO;
import jnpf.dmsEntity.waifa.DmsWenjianWaifaShenqingDetailEntity;
import jnpf.dmsEntity.waifa.DmsWenjianWaifaShenqingEntity;
import jnpf.dmsMapper.DmsWenjianBanbenMapper;
import jnpf.dmsMapper.DmsWenjianWaifaShenqingDetailMapper;
import jnpf.dmsMapper.DmsWenjianWaifaShenqingMapper;
import jnpf.exception.DataException;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
 
import java.util.Arrays;
import java.util.Collections;
import java.util.UUID;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class DmsWenjianFuzhuGuanliWaifaServiceTest {
 
    private static final UUID DOCUMENT_ID =
            UUID.fromString("018f0000-0000-7000-8000-000000000911");
    private static final UUID FILE_VERSION_ID =
            UUID.fromString("018f0000-0000-7000-8000-000000000912");
 
    @Test
    void grantsPermanentPrintPermissionToExternalRequestApplicant() {
        Fixture fixture = new Fixture();
        when(fixture.shenqingMapper.selectList(any()))
                .thenReturn(Collections.singletonList(application()));
        when(fixture.zixiangMapper.selectList(any()))
                .thenReturn(Arrays.asList(detail("version-1"), detail("version-1")));
        when(fixture.banbenMapper.selectList(any()))
                .thenReturn(Collections.singletonList(banben("version-1")));
        DmsWorkflowPrintFilesGrantResultVO expected =
                new DmsWorkflowPrintFilesGrantResultVO(1, 1);
        when(fixture.dmsResourceApi.grantWorkflowPrintFiles(
                eq("jnpf-flowable"), any())).thenReturn(ActionResult.success("success", expected));
 
        DmsWorkflowPrintFilesGrantResultVO result = fixture.service.waifaWenjianShouquan(
                " flow-1 ", " task-1 ");
 
        assertSame(expected, result);
        ArgumentCaptor<DmsWorkflowPrintFilesGrantForm> formCaptor =
                ArgumentCaptor.forClass(DmsWorkflowPrintFilesGrantForm.class);
        verify(fixture.dmsResourceApi).grantWorkflowPrintFiles(
                eq("jnpf-flowable"), formCaptor.capture());
        DmsWorkflowPrintFilesGrantForm form = formCaptor.getValue();
        assertEquals("applicant-1", form.getUserId());
        assertEquals(1, form.getFiles().size());
        assertEquals(DOCUMENT_ID, form.getFiles().get(0).getDocumentId());
        assertEquals(FILE_VERSION_ID, form.getFiles().get(0).getFileVersionId());
        assertNull(form.getFiles().get(0).getValidTo());
    }
 
    @Test
    void rejectsPartialBusinessVersionMatchesBeforeCallingAuthorizationApi() {
        Fixture fixture = new Fixture();
        when(fixture.shenqingMapper.selectList(any()))
                .thenReturn(Collections.singletonList(application()));
        when(fixture.zixiangMapper.selectList(any()))
                .thenReturn(Arrays.asList(detail("version-1"), detail("version-2")));
        when(fixture.banbenMapper.selectList(any()))
                .thenReturn(Collections.singletonList(banben("version-1")));
 
        assertThrows(DataException.class,
                () -> fixture.service.waifaWenjianShouquan("flow-1", "task-1"));
 
        verify(fixture.dmsResourceApi, never()).grantWorkflowPrintFiles(any(), any());
    }
 
    @Test
    void rejectsFailedAuthorizationResponse() {
        Fixture fixture = new Fixture();
        when(fixture.shenqingMapper.selectList(any()))
                .thenReturn(Collections.singletonList(application()));
        when(fixture.zixiangMapper.selectList(any()))
                .thenReturn(Collections.singletonList(detail("version-1")));
        when(fixture.banbenMapper.selectList(any()))
                .thenReturn(Collections.singletonList(banben("version-1")));
        when(fixture.dmsResourceApi.grantWorkflowPrintFiles(any(), any()))
                .thenReturn(ActionResult.fail("授权被拒绝"));
 
        DataException exception = assertThrows(DataException.class,
                () -> fixture.service.waifaWenjianShouquan("flow-1", "task-1"));
 
        assertEquals("授权被拒绝", exception.getMessage());
    }
 
    private static DmsWenjianWaifaShenqingEntity application() {
        DmsWenjianWaifaShenqingEntity entity = new DmsWenjianWaifaShenqingEntity();
        entity.setId("application-1");
        entity.setTenantId("tenant-1");
        entity.setApplicantUserId(" applicant-1 ");
        return entity;
    }
 
    private static DmsWenjianWaifaShenqingDetailEntity detail(String banbenId) {
        DmsWenjianWaifaShenqingDetailEntity entity =
                new DmsWenjianWaifaShenqingDetailEntity();
        entity.setId("detail-" + banbenId);
        entity.setRequestId("application-1");
        entity.setTenantId("tenant-1");
        entity.setBanbenId(banbenId);
        return entity;
    }
 
    private static DmsWenjianBanbenEntity banben(String banbenId) {
        DmsWenjianBanbenEntity entity = new DmsWenjianBanbenEntity();
        entity.setId(banbenId);
        entity.setTenantId("tenant-1");
        entity.setWenjianZhongxinWenjianId(DOCUMENT_ID.toString());
        entity.setWenjianZhongxinBanbenId(FILE_VERSION_ID.toString());
        return entity;
    }
 
    private static class Fixture {
        private final DmsWenjianWaifaShenqingMapper shenqingMapper =
                mock(DmsWenjianWaifaShenqingMapper.class);
        private final DmsWenjianWaifaShenqingDetailMapper zixiangMapper =
                mock(DmsWenjianWaifaShenqingDetailMapper.class);
        private final DmsWenjianBanbenMapper banbenMapper = mock(DmsWenjianBanbenMapper.class);
        private final DmsResourceApi dmsResourceApi = mock(DmsResourceApi.class);
        private final DmsWenjianFuzhuGuanliWaifaService service =
                new DmsWenjianFuzhuGuanliWaifaService(
                        shenqingMapper, zixiangMapper, banbenMapper, dmsResourceApi);
    }
}