#
Junjie
14 小时以前 5d68f36fb16c07ea5459a167c9711f681c2f71b2
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
package com.zy.asrs.task;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.WrkAnalysisService;
import com.zy.asrs.service.WrkMastService;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.StationCommandType;
import com.zy.core.enums.WrkStsType;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.thread.StationThread;
import com.zy.core.utils.StationOperateProcessUtils;
import org.junit.jupiter.api.Test;
 
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class WrkAnalysisStationArrivalScannerTest {
 
    @Test
    void scanInboundStationArrival_completesTaskWhenRecentArrivalWasObserved() {
        WrkMastService wrkMastService = mock(WrkMastService.class);
        BasStationService basStationService = mock(BasStationService.class);
        WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class);
        StationOperateProcessUtils stationOperateProcessUtils = mock(StationOperateProcessUtils.class);
 
        WrkAnalysisStationArrivalScanner scanner = new WrkAnalysisStationArrivalScanner(
                wrkMastService,
                basStationService,
                wrkAnalysisService,
                stationOperateProcessUtils
        );
 
        WrkMast wrkMast = new WrkMast();
        wrkMast.setWrkNo(1001);
        wrkMast.setIoType(1);
        wrkMast.setWrkSts(WrkStsType.INBOUND_STATION_RUN.sts);
        wrkMast.setStaNo(12);
 
        BasStation basStation = new BasStation();
        basStation.setStationId(12);
        basStation.setDeviceNo(3);
 
        when(wrkMastService.list(any(QueryWrapper.class))).thenReturn(List.of(wrkMast));
        when(basStationService.getOne(any())).thenReturn(basStation);
        when(wrkAnalysisService.completeInboundStationRun(any(WrkMast.class), any(Date.class))).thenReturn(true);
 
        ArrivalAwareStationThread stationThread = new ArrivalAwareStationThread(true);
        StationProtocol stationProtocol = new StationProtocol();
        stationProtocol.setStationId(12);
        stationProtocol.setTaskNo(0);
        stationProtocol.setLoading(false);
        stationThread.putStatus(stationProtocol);
 
        SlaveConnection.put(SlaveType.Devp, 3, stationThread);
        try {
            scanner.scanInboundStationArrival();
        } finally {
            SlaveConnection.remove(SlaveType.Devp, 3);
        }
 
        verify(wrkAnalysisService).completeInboundStationRun(any(WrkMast.class), any(Date.class));
    }
 
    private static class ArrivalAwareStationThread implements StationThread {
 
        private final boolean recentArrival;
        private final Map<Integer, StationProtocol> statusMap = new HashMap<>();
 
        private ArrivalAwareStationThread(boolean recentArrival) {
            this.recentArrival = recentArrival;
        }
 
        private void putStatus(StationProtocol stationProtocol) {
            statusMap.put(stationProtocol.getStationId(), stationProtocol);
        }
 
        @Override
        public List<StationProtocol> getStatus() {
            return Collections.emptyList();
        }
 
        @Override
        public Map<Integer, StationProtocol> getStatusMap() {
            return statusMap;
        }
 
        public boolean hasRecentArrival(Integer stationId, Integer taskNo) {
            return recentArrival;
        }
 
        @Override
        public StationCommand getCommand(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() {
        }
    }
}