自动化立体仓库 - WMS系统
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
package com.zy.asrs.task.support;
 
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.entity.Parameter;
import org.junit.jupiter.api.AfterEach;
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.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
 
@ExtendWith(MockitoExtension.class)
class OutboundBatchSeqReleaseGuardTest {
 
    @Mock
    private WrkMastService wrkMastService;
 
    private OutboundBatchSeqReleaseGuard guard;
 
    @BeforeEach
    void setUp() throws Exception {
        guard = new OutboundBatchSeqReleaseGuard();
        ReflectionTestUtils.setField(guard, "wrkMastService", wrkMastService);
        setThreshold("2");
    }
 
    @AfterEach
    void tearDown() throws Exception {
        setParameterInstance(null);
    }
 
    @Test
    void rejectsEmptyBatchSeq() {
        String message = guard.validateReady("ORD1", "");
 
        assertEquals("出库进仓编号(batchSeq)为空,跳过下发, userNo=ORD1", message);
    }
 
    @Test
    void blocksWhenEarlierBatchSeqStillRunning() {
        when(wrkMastService.selectList(any())).thenReturn(Arrays.asList(
                wrkMast("1", 12L),
                wrkMast("2", 11L)));
 
        String message = guard.validateReady("ORD1", "2");
 
        assertTrue(message.contains("blockingBatchSeq=1"));
    }
 
    @Test
    void allowsWhenEarlierBatchSeqIsReleaseStatusAndStatus25BelowThreshold() {
        when(wrkMastService.selectList(any())).thenReturn(Arrays.asList(
                wrkMast("1", 25L),
                wrkMast("2", 11L)));
 
        assertNull(guard.validateReady("ORD1", "2"));
    }
 
    @Test
    void blocksWhenStatus25CountReachesThreshold() throws Exception {
        setThreshold("1");
        when(wrkMastService.selectList(any())).thenReturn(Arrays.asList(
                wrkMast("1", 25L),
                wrkMast("2", 11L)));
 
        String message = guard.validateReady("ORD1", "2");
 
        assertTrue(message.contains("status25Count=1"));
        assertTrue(message.contains("threshold=1"));
    }
 
    @Test
    void treatsErpReportPendingStatusAsReleased() {
        when(wrkMastService.selectList(any())).thenReturn(Arrays.asList(
                wrkMast("1", 17L),
                wrkMast("2", 11L)));
 
        assertNull(guard.validateReady("ORD1", "2"));
    }
 
    @Test
    void firstBatchSeqIsNotBlockedByThreshold() throws Exception {
        setThreshold("1");
        when(wrkMastService.selectList(any())).thenReturn(Collections.singletonList(wrkMast("1", 25L)));
 
        assertNull(guard.validateReady("ORD1", "1"));
    }
 
    private static WrkMast wrkMast(String batchSeq, Long wrkSts) {
        WrkMast wrkMast = new WrkMast();
        wrkMast.setBatchSeq(batchSeq);
        wrkMast.setWrkSts(wrkSts);
        return wrkMast;
    }
 
    private static void setThreshold(String threshold) throws Exception {
        Constructor<Parameter> constructor = Parameter.class.getDeclaredConstructor();
        constructor.setAccessible(true);
        Parameter parameter = constructor.newInstance();
        parameter.setOutBatchSeqStatus25Threshold(threshold);
        setParameterInstance(parameter);
    }
 
    private static void setParameterInstance(Parameter parameter) throws Exception {
        Field instance = Parameter.class.getDeclaredField("instance");
        instance.setAccessible(true);
        instance.set(null, parameter);
    }
}