刘光辉
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
package jnpf.dmsService;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import jnpf.dmsEntity.DmsDanganCundangShenqingDanganheEntity;
import jnpf.dmsEntity.DmsDanganCundangShenqingEntity;
import jnpf.dmsEntity.DmsDanganGengxinShenqingDanganheEntity;
import jnpf.dmsEntity.DmsDanganGengxinShenqingEntity;
import jnpf.dmsMapper.DmsDanganCundangShenqingDanganheMapper;
import jnpf.dmsMapper.DmsDanganCundangShenqingMapper;
import jnpf.dmsMapper.DmsDanganGengxinShenqingDanganheMapper;
import jnpf.dmsMapper.DmsDanganGengxinShenqingMapper;
import jnpf.dmsService.impl.DmsDanganGengxinShenqingTongguoServiceImpl;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
 
import java.util.Arrays;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class DmsDanganGengxinShenqingTongguoServiceTest {
 
    @BeforeEach
    void setUp() {
        initialize(DmsDanganGengxinShenqingEntity.class);
        initialize(DmsDanganGengxinShenqingDanganheEntity.class);
        initialize(DmsDanganCundangShenqingEntity.class);
        initialize(DmsDanganCundangShenqingDanganheEntity.class);
    }
 
    @Test
    void syncsMainRecordAndUpdatesEveryOriginalBoxWithTheSameNumber() throws Exception {
        DmsDanganGengxinShenqingMapper gengxinMapper = mock(DmsDanganGengxinShenqingMapper.class);
        DmsDanganGengxinShenqingDanganheMapper gengxinDanganheMapper = mock(DmsDanganGengxinShenqingDanganheMapper.class);
        DmsDanganCundangShenqingMapper cundangMapper = mock(DmsDanganCundangShenqingMapper.class);
        DmsDanganCundangShenqingDanganheMapper cundangDanganheMapper = mock(DmsDanganCundangShenqingDanganheMapper.class);
        when(gengxinMapper.selectList(any())).thenReturn(Arrays.asList(application()));
        when(cundangMapper.update(isNull(), any())).thenReturn(1);
        when(gengxinDanganheMapper.selectList(any())).thenReturn(Arrays.asList(
                danganhe("BOX-1"), danganhe("")));
        when(cundangDanganheMapper.update(isNull(), any())).thenReturn(2);
 
        service(gengxinMapper, gengxinDanganheMapper, cundangMapper, cundangDanganheMapper)
                .tongguo("flow-1", "task-1");
 
        ArgumentCaptor<Wrapper<DmsDanganCundangShenqingEntity>> mainCaptor = ArgumentCaptor.forClass(Wrapper.class);
        verify(cundangMapper).update(isNull(), mainCaptor.capture());
        String mainSql = mainCaptor.getValue().getSqlSet();
        assertTrue(mainSql.contains("dangan_mingcheng"));
        assertTrue(mainSql.contains("baocun_zhouqi_qita"));
 
        ArgumentCaptor<Wrapper<DmsDanganCundangShenqingDanganheEntity>> danganheCaptor = ArgumentCaptor.forClass(Wrapper.class);
        verify(cundangDanganheMapper, times(1)).update(isNull(), danganheCaptor.capture());
        com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<?> danganheUpdate =
                (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<?>) danganheCaptor.getValue();
        String danganheSql = danganheUpdate.getSqlSet();
        assertTrue(danganheSql.contains("danganhe_leibie"));
        assertTrue(danganheSql.contains("danganhe_weizhi"));
        String conditionSql = danganheUpdate.getSqlSegment();
        assertTrue(conditionSql.contains("f_foreign_id"));
        assertTrue(conditionSql.contains("danganhe_bianhao"));
        assertTrue(conditionSql.contains("f_delete_mark IS NULL"));
        assertEquals("cundang-1", danganheUpdate.getParamNameValuePairs().values().stream()
                .filter("cundang-1"::equals).findFirst().orElse(null));
        assertEquals("BOX-1", danganheUpdate.getParamNameValuePairs().values().stream()
                .filter("BOX-1"::equals).findFirst().orElse(null));
    }
 
    private void initialize(Class<?> entityClass) {
        if (TableInfoHelper.getTableInfo(entityClass) == null) {
            TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new Configuration(), ""), entityClass);
        }
    }
 
    private DmsDanganGengxinShenqingTongguoService service(
            DmsDanganGengxinShenqingMapper gengxinMapper,
            DmsDanganGengxinShenqingDanganheMapper gengxinDanganheMapper,
            DmsDanganCundangShenqingMapper cundangMapper,
            DmsDanganCundangShenqingDanganheMapper cundangDanganheMapper) {
        return new DmsDanganGengxinShenqingTongguoServiceImpl(
                gengxinMapper, gengxinDanganheMapper, cundangMapper, cundangDanganheMapper);
    }
 
    private DmsDanganGengxinShenqingEntity application() {
        DmsDanganGengxinShenqingEntity application = new DmsDanganGengxinShenqingEntity();
        application.setId("update-1");
        application.setFlowId("flow-1");
        application.setFlowTaskId("task-1");
        application.setCundangShenqingId("cundang-1");
        application.setDanganMingcheng("更新后档案");
        return application;
    }
 
    private DmsDanganGengxinShenqingDanganheEntity danganhe(String danganheBianhao) {
        DmsDanganGengxinShenqingDanganheEntity danganhe = new DmsDanganGengxinShenqingDanganheEntity();
        danganhe.setDanganheBianhao(danganheBianhao);
        danganhe.setDanganheLeibie("类别");
        danganhe.setDanganheMingcheng("名称");
        danganhe.setGuishuBumen("部门");
        danganhe.setDanganheWeizhi("位置");
        return danganhe;
    }
}