刘光辉
3 小时以前 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
package jnpf.dmsService.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import jnpf.dmsEntity.DmsWenjianBianhaoGuizeEntity;
import jnpf.dmsMapper.DmsWenjianBianhaoGuizeMapper;
import jnpf.exception.DataException;
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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
 
import java.util.Collections;
 
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.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
@ExtendWith(MockitoExtension.class)
class DmsWenjianBianhaoGuizeTongguoServiceImplTest {
 
    @Mock private DmsWenjianBianhaoGuizeMapper guizeMapper;
 
    @InjectMocks
    private DmsWenjianBianhaoGuizeTongguoServiceImpl service;
 
    @BeforeEach
    void initTableInfo() {
        if (TableInfoHelper.getTableInfo(DmsWenjianBianhaoGuizeEntity.class) == null) {
            TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new Configuration(), ""),
                    DmsWenjianBianhaoGuizeEntity.class);
        }
    }
 
    @Test
    void disablesOnlyOtherRulesWithTheSameSerialNumber() throws DataException {
        DmsWenjianBianhaoGuizeEntity currentRule = new DmsWenjianBianhaoGuizeEntity();
        currentRule.setId("rule-current");
        currentRule.setFlowId("flow-1");
        currentRule.setFlowTaskId("task-1");
        currentRule.setGuizeLiushuihao("serial-001");
        when(guizeMapper.selectList(any())).thenReturn(Collections.singletonList(currentRule));
 
        service.tongguo("flow-1", "task-1");
 
        ArgumentCaptor<LambdaUpdateWrapper> captor = ArgumentCaptor.forClass(LambdaUpdateWrapper.class);
        verify(guizeMapper).update(isNull(), captor.capture());
        ArgumentCaptor<LambdaQueryWrapper> queryCaptor = ArgumentCaptor.forClass(LambdaQueryWrapper.class);
        verify(guizeMapper).selectList(queryCaptor.capture());
        assertTrue(queryCaptor.getValue().getCustomSqlSegment().contains("f_flow_id"));
        assertTrue(queryCaptor.getValue().getCustomSqlSegment().contains("f_flow_task_id"));
        String condition = captor.getValue().getCustomSqlSegment();
        assertTrue(condition.contains("guize_liushuihao"));
        assertTrue(condition.contains("f_id NOT IN"));
        assertTrue(captor.getValue().getSqlSet().contains("biz_enabled"));
    }
 
    @Test
    void doesNotDisableRulesWhenTheCurrentRuleHasNoSerialNumber() throws DataException {
        DmsWenjianBianhaoGuizeEntity currentRule = new DmsWenjianBianhaoGuizeEntity();
        currentRule.setId("rule-current");
        currentRule.setFlowId("flow-1");
        currentRule.setFlowTaskId("task-1");
        currentRule.setGuizeLiushuihao(" ");
        when(guizeMapper.selectList(any())).thenReturn(Collections.singletonList(currentRule));
 
        service.tongguo("flow-1", "task-1");
 
        verify(guizeMapper, never()).update(isNull(), any());
    }
}