自动化立体仓库 - WMS系统
zwl
8 天以前 7294ef58d1a343bdc765773ba69928820ce0d20f
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.zy.common.service;
 
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.RowLastno;
import com.zy.asrs.entity.RowLastnoType;
import com.zy.asrs.entity.result.FindLocNoAttributeVo;
import com.zy.asrs.service.BasCrnDepthRuleService;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.LocMastService;
import com.zy.common.model.CrnDepthRuleProfile;
import com.zy.common.entity.Parameter;
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.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.LinkedHashMap;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
 
@ExtendWith(MockitoExtension.class)
class CommonServiceDoubleExtensionSameGoodsTest {
 
    @Mock
    private BasCrnDepthRuleService basCrnDepthRuleService;
 
    @Mock
    private LocMastService locMastService;
 
    @Mock
    private LocDetlService locDetlService;
 
    private CommonService commonService;
 
    private Parameter originalParameter;
 
    @BeforeEach
    void setUp() {
        commonService = new CommonService();
        ReflectionTestUtils.setField(commonService, "basCrnDepthRuleService", basCrnDepthRuleService);
        ReflectionTestUtils.setField(commonService, "locMastService", locMastService);
        ReflectionTestUtils.setField(commonService, "locDetlService", locDetlService);
        originalParameter = (Parameter) ReflectionTestUtils.getField(Parameter.class, "instance");
        ReflectionTestUtils.setField(Parameter.class, "instance", buildParameter());
    }
 
    @org.junit.jupiter.api.AfterEach
    void tearDown() {
        ReflectionTestUtils.setField(Parameter.class, "instance", originalParameter);
    }
 
    @Test
    void doubleExtension_shouldReturnShallowLocWhenSameStandby1DeepLocHasEmptyPartner() {
        RowLastno rowLastno = buildRowLastno();
        CrnDepthRuleProfile profile = buildDoubleExtensionProfile();
        when(basCrnDepthRuleService.resolveProfile(rowLastno, 1, 2)).thenReturn(profile);
 
        LocMast deepLoc = buildLoc("D-001", 1, 1, 1, "F", 1);
        LocMast shallowLoc = buildLoc("S-001", 2, 1, 1, "O", 1);
        LocDetl deepDetl = buildDetl("D-001", "PO-001");
 
        when(locMastService.selectList(any())).thenReturn(Arrays.asList(deepLoc));
        when(locDetlService.selectList(any())).thenReturn(Arrays.asList(deepDetl));
        when(locMastService.selectOne(any())).thenReturn(shallowLoc);
 
        LocMast result = ReflectionTestUtils.invokeMethod(commonService, "findConfiguredEmptyLocForCrn",
                rowLastno, buildRowLastnoType(), 1, 2, null, buildAttributeVo("PO-001"), false);
 
        assertEquals("S-001", result.getLocNo());
        assertEquals(Integer.valueOf(2), result.getRow1());
        assertEquals("O", result.getLocSts());
    }
 
    @Test
    void doubleExtension_shouldFallBackWhenSameStandby1DeepLocHasNoEmptyShallowPartner() {
        RowLastno rowLastno = buildRowLastno();
        CrnDepthRuleProfile profile = buildDoubleExtensionProfile();
        when(basCrnDepthRuleService.resolveProfile(rowLastno, 1, 2)).thenReturn(profile);
 
        LocMast sameGoodsDeepLoc = buildLoc("D-001", 1, 1, 1, "F", 1);
        LocMast genericShallowLoc = buildLoc("S-002", 2, 2, 1, "O", 1);
        LocMast genericDeepFallbackLoc = buildLoc("D-002", 1, 2, 1, "F", 1);
        LocDetl deepDetl = buildDetl("D-001", "PO-001");
 
        when(locMastService.selectList(any())).thenReturn(Arrays.asList(sameGoodsDeepLoc), Arrays.asList(genericShallowLoc));
        when(locDetlService.selectList(any())).thenReturn(Arrays.asList(deepDetl));
        when(locMastService.selectOne(any())).thenReturn(null, null, genericDeepFallbackLoc);
 
        LocMast result = ReflectionTestUtils.invokeMethod(commonService, "findConfiguredEmptyLocForCrn",
                rowLastno, buildRowLastnoType(), 1, 2, null, buildAttributeVo("PO-001"), false);
 
        assertEquals("S-002", result.getLocNo());
        assertEquals(Integer.valueOf(2), result.getRow1());
        assertEquals("O", result.getLocSts());
    }
 
    @Test
    void singleExtension_shouldNotApplySameGoodsPrecheck() {
        RowLastno rowLastno = buildRowLastno();
        CrnDepthRuleProfile profile = buildSingleExtensionProfile();
        when(basCrnDepthRuleService.resolveProfile(rowLastno, 1, 2)).thenReturn(profile);
 
        LocMast openLoc = buildLoc("S-010", 2, 1, 1, "O", 1);
        when(locMastService.selectList(any())).thenReturn(Arrays.asList(openLoc));
 
        LocMast result = ReflectionTestUtils.invokeMethod(commonService, "findConfiguredEmptyLocForCrn",
                rowLastno, buildRowLastnoType(), 1, 2, null, buildAttributeVo("PO-001"), false);
 
        assertEquals("S-010", result.getLocNo());
        verifyNoInteractions(locDetlService);
    }
 
    private RowLastno buildRowLastno() {
        RowLastno rowLastno = new RowLastno();
        rowLastno.setWhsType(1);
        rowLastno.setCurrentRow(2);
        return rowLastno;
    }
 
    private RowLastnoType buildRowLastnoType() {
        RowLastnoType rowLastnoType = new RowLastnoType();
        rowLastnoType.setType(1);
        return rowLastnoType;
    }
 
    private FindLocNoAttributeVo buildAttributeVo(String standby1) {
        FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo();
        attributeVo.setStandby1(standby1);
        return attributeVo;
    }
 
    private CrnDepthRuleProfile buildDoubleExtensionProfile() {
        CrnDepthRuleProfile profile = new CrnDepthRuleProfile();
        profile.setLayoutType(2);
        profile.setSearchRows(Arrays.asList(2, 1));
        profile.setShallowRows(Arrays.asList(2));
        profile.setDeepRows(Arrays.asList(1));
        LinkedHashMap<Integer, Integer> shallowToDeep = new LinkedHashMap<Integer, Integer>();
        shallowToDeep.put(2, 1);
        LinkedHashMap<Integer, Integer> deepToShallow = new LinkedHashMap<Integer, Integer>();
        deepToShallow.put(1, 2);
        profile.setShallowToDeepRow(shallowToDeep);
        profile.setDeepToShallowRow(deepToShallow);
        return profile;
    }
 
    private CrnDepthRuleProfile buildSingleExtensionProfile() {
        CrnDepthRuleProfile profile = new CrnDepthRuleProfile();
        profile.setLayoutType(1);
        profile.setSearchRows(Arrays.asList(2));
        profile.setShallowRows(Arrays.asList(2));
        profile.setDeepRows(null);
        profile.setShallowToDeepRow(new LinkedHashMap<Integer, Integer>());
        profile.setDeepToShallowRow(new LinkedHashMap<Integer, Integer>());
        return profile;
    }
 
    private LocMast buildLoc(String locNo, Integer row, Integer bay, Integer lev, String status, Integer crnNo) {
        LocMast locMast = new LocMast();
        locMast.setLocNo(locNo);
        locMast.setRow1(row);
        locMast.setBay1(bay);
        locMast.setLev1(lev);
        locMast.setLocSts(status);
        locMast.setCrnNo(crnNo);
        return locMast;
    }
 
    private LocDetl buildDetl(String locNo, String standby1) {
        LocDetl locDetl = new LocDetl();
        locDetl.setLocNo(locNo);
        locDetl.setStandby1(standby1);
        return locDetl;
    }
 
    private Parameter buildParameter() {
        try {
            Constructor<Parameter> constructor = Parameter.class.getDeclaredConstructor();
            constructor.setAccessible(true);
            Parameter parameter = constructor.newInstance();
            parameter.setHighFreqFrontBayCount("0");
            return parameter;
        } catch (Exception e) {
            throw new IllegalStateException("Failed to initialize Parameter test instance", e);
        }
    }
}