自动化立体仓库 - WMS系统
zwl
3 天以前 2acfc2d2a0e956910c51bd996f443b3cb9bd3dc9
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.zy.asrs.service.impl;
 
import com.zy.asrs.entity.BasCrnDepthRule;
import com.zy.asrs.entity.RowLastno;
import com.zy.asrs.entity.param.BasCrnDepthRuleTemplateParam;
import com.zy.asrs.service.RowLastnoService;
import com.zy.common.model.CrnDepthRuleProfile;
import com.zy.common.properties.SlaveProperties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
 
import java.util.Arrays;
import java.util.List;
 
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.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
 
@ExtendWith(MockitoExtension.class)
class BasCrnDepthRuleServiceImplTest {
 
    @Mock
    private RowLastnoService rowLastnoService;
 
    private BasCrnDepthRuleServiceImpl service;
 
    @BeforeEach
    void setUp() {
        service = spy(new BasCrnDepthRuleServiceImpl());
        ReflectionTestUtils.setField(service, "rowLastnoService", rowLastnoService);
        ReflectionTestUtils.setField(service, "slaveProperties", buildSlaveProperties());
    }
 
    @Test
    void validateRule_forSingleExtension_fillsShallowRowsAndNormalizesCsv() {
        BasCrnDepthRule rule = new BasCrnDepthRule();
        rule.setWhsType(1);
        rule.setCrnNo(1);
        rule.setLayoutType(1);
        rule.setSearchRowsCsv("1, 2,2");
 
        service.validateRule(rule);
 
        assertEquals("1,2", rule.getSearchRowsCsv());
        assertEquals("1,2", rule.getShallowRowsCsv());
        assertEquals(null, rule.getDeepRowsCsv());
        assertEquals(Integer.valueOf(1), rule.getEnabled());
    }
 
    @Test
    void validateRule_forSingleExtension_rejectsDeepRows() {
        BasCrnDepthRule rule = new BasCrnDepthRule();
        rule.setWhsType(1);
        rule.setCrnNo(1);
        rule.setLayoutType(1);
        rule.setSearchRowsCsv("1,2");
        rule.setDeepRowsCsv("3");
 
        assertThrows(RuntimeException.class, () -> service.validateRule(rule));
    }
 
    @Test
    void validateRule_forDoubleExtension_requiresBothShallowAndDeepRows() {
        BasCrnDepthRule rule = new BasCrnDepthRule();
        rule.setWhsType(1);
        rule.setCrnNo(1);
        rule.setLayoutType(2);
        rule.setSearchRowsCsv("2,1");
        rule.setShallowRowsCsv("2");
 
        assertThrows(RuntimeException.class, () -> service.validateRule(rule));
    }
 
    @Test
    void resolveProfile_prefersConfiguredRule() {
        RowLastno rowLastno = new RowLastno();
        rowLastno.setWhsType(1);
        BasCrnDepthRule rule = new BasCrnDepthRule();
        rule.setWhsType(1);
        rule.setCrnNo(2);
        rule.setLayoutType(2);
        rule.setSearchRowsCsv("6,5");
        rule.setShallowRowsCsv("6");
        rule.setDeepRowsCsv("5");
 
        doReturn(rule).when(service).findEnabledRule(1, 2);
 
        CrnDepthRuleProfile profile = service.resolveProfile(rowLastno, 2, 6);
 
        assertEquals(Integer.valueOf(2), profile.getLayoutType());
        assertEquals(Arrays.asList(6, 5), profile.getSearchRows());
        assertEquals(Arrays.asList(6), profile.getShallowRows());
        assertEquals(Arrays.asList(5), profile.getDeepRows());
        assertEquals(Integer.valueOf(5), profile.getPairedDeepRow(6));
    }
 
    @Test
    void previewTemplate_buildsLegacyRowsForSingleExtensionWarehouse() {
        RowLastno rowLastno = new RowLastno();
        rowLastno.setWhsType(1);
        rowLastno.setsCrnNo(1);
        rowLastno.seteCrnNo(2);
        rowLastno.setsRow(1);
        rowLastno.seteRow(4);
        rowLastno.setTypeId(2);
        when(rowLastnoService.selectById(1)).thenReturn(rowLastno);
 
        BasCrnDepthRuleTemplateParam param = new BasCrnDepthRuleTemplateParam();
        param.setWhsType(1);
 
        List<BasCrnDepthRule> preview = service.previewTemplate(param);
 
        assertEquals(2, preview.size());
        assertEquals(Integer.valueOf(1), preview.get(0).getLayoutType());
        assertEquals("1,2", preview.get(0).getSearchRowsCsv());
        assertEquals("3,4", preview.get(1).getSearchRowsCsv());
    }
 
    @Test
    void previewTemplate_buildsLegacyRowsForDoubleExtensionWarehouse() {
        RowLastno rowLastno = new RowLastno();
        rowLastno.setWhsType(1);
        rowLastno.setsCrnNo(1);
        rowLastno.seteCrnNo(1);
        rowLastno.setsRow(1);
        rowLastno.seteRow(4);
        rowLastno.setTypeId(1);
        when(rowLastnoService.selectById(1)).thenReturn(rowLastno);
 
        BasCrnDepthRuleTemplateParam param = new BasCrnDepthRuleTemplateParam();
        param.setWhsType(1);
 
        List<BasCrnDepthRule> preview = service.previewTemplate(param);
 
        assertEquals(1, preview.size());
        assertEquals("2,3", preview.get(0).getSearchRowsCsv());
        assertTrue(preview.get(0).getShallowRowsCsv().contains("2"));
        assertTrue(preview.get(0).getDeepRowsCsv().contains("1"));
    }
 
    private SlaveProperties buildSlaveProperties() {
        SlaveProperties slaveProperties = new SlaveProperties();
        slaveProperties.setDoubleDeep(true);
        slaveProperties.setDoubleLocs(Arrays.asList(1, 4, 5, 8));
        slaveProperties.setDoubleLocsLeft(Arrays.asList(1, 5));
        slaveProperties.setDoubleLocsRight(Arrays.asList(4, 8));
        slaveProperties.setGroupCount(4);
        return slaveProperties;
    }
}