Junjie
22 小时以前 1a3f0ed6b7f6d4112069a3c8679e7192365d5eef
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
package com.zy.core.plugin.store;
 
import com.zy.asrs.entity.BasDevp;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.thread.StationThread;
import org.junit.jupiter.api.Test;
 
import java.util.List;
import java.util.Map;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
 
class StoreInTaskPolicyTest {
 
    private final StoreInTaskPolicy policy = context -> true;
 
    @Test
    void onApplyFailed_propagatesWarningToBackStation() {
        StationProtocol barcodeStation = new StationProtocol();
        barcodeStation.setStationId(102);
        StationProtocol backStation = new StationProtocol();
        backStation.setStationId(101);
        StationThread stationThread = new FixedStationThread(Map.of(
                102, barcodeStation,
                101, backStation
        ));
 
        StationObjModel backStationModel = new StationObjModel();
        backStationModel.setStationId(101);
        StationObjModel barcodeStationModel = new StationObjModel();
        barcodeStationModel.setStationId(102);
        barcodeStationModel.setBackStation(backStationModel);
 
        StoreInTaskContext context = new StoreInTaskContext(new BasDevp(), stationThread, barcodeStationModel, barcodeStation);
        AsyncInTaskResult result = new AsyncInTaskResult();
        result.setMessage("WMS异常");
 
        policy.onApplyFailed(context, result);
 
        assertEquals("请求入库失败,WMS返回=WMS异常", barcodeStation.getSystemWarning());
        assertEquals("请求入库失败,WMS返回=WMS异常", backStation.getSystemWarning());
    }
 
    private static class FixedStationThread implements StationThread {
 
        private final Map<Integer, StationProtocol> statusMap;
 
        private FixedStationThread(Map<Integer, StationProtocol> statusMap) {
            this.statusMap = statusMap;
        }
 
        @Override
        public List<StationProtocol> getStatus() {
            return List.copyOf(statusMap.values());
        }
 
        @Override
        public Map<Integer, StationProtocol> getStatusMap() {
            return statusMap;
        }
 
        @Override
        public StationCommand getCommand(com.zy.core.enums.StationCommandType commandType, Integer taskNo,
                                         Integer stationId, Integer targetStationId, Integer palletSize) {
            return null;
        }
 
        @Override
        public boolean clearPath(Integer taskNo) {
            return false;
        }
 
        @Override
        public CommandResponse sendCommand(StationCommand command) {
            return null;
        }
 
        @Override
        public CommandResponse sendOriginCommand(String address, short[] data) {
            return null;
        }
 
        @Override
        public byte[] readOriginCommand(String address, int length) {
            return new byte[0];
        }
 
        @Override
        public void run() {
        }
 
        @Override
        public boolean connect() {
            return true;
        }
 
        @Override
        public void close() {
        }
    }
}