刘光辉
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
package jnpf.dmsService;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import jnpf.dmsEntity.DmsDanganCundangShenqingDanganheEntity;
import jnpf.dmsEntity.form.DmsDanganCundangDanganhePrintCallbackForm;
import jnpf.dmsMapper.DmsDanganCundangShenqingDanganheMapper;
import jnpf.dmsService.impl.DmsDanganCundangDanganhePrintCallbackServiceImpl;
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.mockito.ArgumentCaptor;
 
import java.util.Arrays;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
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.never;
import static org.mockito.Mockito.verify;
 
class DmsDanganCundangDanganhePrintCallbackServiceTest {
 
    @BeforeEach
    void setUp() {
        if (TableInfoHelper.getTableInfo(DmsDanganCundangShenqingDanganheEntity.class) == null) {
            TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new Configuration(), ""),
                    DmsDanganCundangShenqingDanganheEntity.class);
        }
    }
 
    @Test
    void marksDistinctFIdsAsPrintedInOneUpdate() throws Exception {
        DmsDanganCundangShenqingDanganheMapper mapper = mock(DmsDanganCundangShenqingDanganheMapper.class);
        DmsDanganCundangDanganhePrintCallbackService service =
                new DmsDanganCundangDanganhePrintCallbackServiceImpl(mapper);
 
        service.markPrinted(Arrays.asList(item("row-1", "box-1"), item("row-2", "box-1"), item("row-3", "box-2")));
 
        ArgumentCaptor<Wrapper<DmsDanganCundangShenqingDanganheEntity>> captor = ArgumentCaptor.forClass(Wrapper.class);
        verify(mapper).update(isNull(), captor.capture());
        com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<?> update =
                (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<?>) captor.getValue();
        assertTrue(update.getSqlSet().contains("shifou_yidayin"));
        assertTrue(update.getSqlSegment().contains("f_id"));
        assertTrue(update.getSqlSegment().contains("f_delete_mark"));
        assertTrue(update.getParamNameValuePairs().containsValue("box-1"));
        assertTrue(update.getParamNameValuePairs().containsValue("box-2"));
        assertTrue(update.getParamNameValuePairs().containsValue("yes"));
    }
 
    @Test
    void rejectsMissingFIdWithoutUpdatingAnything() {
        DmsDanganCundangShenqingDanganheMapper mapper = mock(DmsDanganCundangShenqingDanganheMapper.class);
        DmsDanganCundangDanganhePrintCallbackService service =
                new DmsDanganCundangDanganhePrintCallbackServiceImpl(mapper);
 
        DataException error = assertThrows(DataException.class,
                () -> service.markPrinted(Arrays.asList(item("row-1", " "))));
 
        assertEquals("档案盒打印回调中的f_id不能为空", error.getMessage());
        verify(mapper, never()).update(any(), any());
    }
 
    private DmsDanganCundangDanganhePrintCallbackForm item(String id, String fId) {
        DmsDanganCundangDanganhePrintCallbackForm item = new DmsDanganCundangDanganhePrintCallbackForm();
        item.setId(id);
        item.setFId(fId);
        return item;
    }
}