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;
|
}
|
}
|