刘光辉
119 分钟以前 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
package jnpf.elnService.template.impl;
 
import jnpf.elnEntity.template.ElnTemplateBindingEntity;
import jnpf.elnEntity.template.ElnTemplateVos;
import jnpf.elnMapper.ElnTemplateBindingMapper;
import jnpf.elnService.field.ElnTestResultFieldCatalog;
import jnpf.elnService.field.ElnTestResultFields;
import org.junit.Test;
 
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
 
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
public class ElnTestResultTemplatePublishValidatorTest {
 
    @Test
    public void requiresBothStableSystemFieldBindings() {
        ElnTemplateBindingMapper mapper = mock(ElnTemplateBindingMapper.class);
        ElnTestResultFieldCatalog catalog = mock(ElnTestResultFieldCatalog.class);
        when(mapper.selectList(any())).thenReturn(Collections.singletonList(binding(ElnTestResultFields.RESULT)));
 
        List<ElnTemplateVos.Diagnostic> diagnostics = new ElnTestResultTemplatePublishValidator(mapper, catalog)
                .validate("tenant-1", "template-1");
 
        verify(catalog).ensure("tenant-1", "system");
        assertEquals(1, diagnostics.size());
        assertEquals("TEST_CONCLUSION_BINDING_REQUIRED", diagnostics.get(0).getCode());
        assertEquals("请在文档中标注“检验结论”", diagnostics.get(0).getMessage());
    }
 
    @Test
    public void acceptsExactlyOneActivePrimaryBindingForEachSystemField() {
        ElnTemplateBindingMapper mapper = mock(ElnTemplateBindingMapper.class);
        when(mapper.selectList(any())).thenReturn(Arrays.asList(
                binding(ElnTestResultFields.RESULT), binding(ElnTestResultFields.CONCLUSION)));
 
        List<ElnTemplateVos.Diagnostic> diagnostics = new ElnTestResultTemplatePublishValidator(
                mapper, mock(ElnTestResultFieldCatalog.class)).validate("tenant-1", "template-1");
 
        assertTrue(diagnostics.isEmpty());
    }
 
    @Test
    public void explainsHowToResolveMissingAndDuplicateBindings() {
        List<ElnTemplateVos.Diagnostic> diagnostics = ElnTestResultTemplatePublishValidator.validateBindings(
                Arrays.asList(binding(ElnTestResultFields.RESULT), binding(ElnTestResultFields.RESULT)));
 
        assertEquals(2, diagnostics.size());
        assertEquals("“检验结果”存在多个标注,请只保留一个", diagnostics.get(0).getMessage());
        assertEquals("请在文档中标注“检验结论”", diagnostics.get(1).getMessage());
    }
 
    private static ElnTemplateBindingEntity binding(String code) {
        ElnTemplateBindingEntity binding = new ElnTemplateBindingEntity();
        binding.setZiduanBianma(code);
        binding.setBangdingZhuangtai("ACTIVE");
        binding.setKongjianJuese("PRIMARY");
        binding.setFDeleteMark(0);
        return binding;
    }
}