| | |
| | | package com.zy.ai.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.BasStation; |
| | | import com.zy.asrs.entity.StationFlowCapacity; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.BasStationService; |
| | | import com.zy.asrs.service.StationFlowCapacityService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.core.model.StationObjModel; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.mockito.ArgumentCaptor; |
| | |
| | | } |
| | | |
| | | @Test |
| | | void loadStationOutTaskLimitsOnlyQueriesConfiguredOutDirectionStations() { |
| | | void loadStationOutTaskLimitsOnlyQueriesBasDevpOutStations() { |
| | | BasStationService basStationService = mock(BasStationService.class); |
| | | StationFlowCapacityService stationFlowCapacityService = mock(StationFlowCapacityService.class); |
| | | BasDevpService basDevpService = mock(BasDevpService.class); |
| | | ReflectionTestUtils.setField(service, "basStationService", basStationService); |
| | | ReflectionTestUtils.setField(service, "stationFlowCapacityService", stationFlowCapacityService); |
| | | when(stationFlowCapacityService.list(any(Wrapper.class))).thenReturn(Arrays.asList( |
| | | capacity(101, "OUT"), |
| | | capacity(102, "OUT") |
| | | ReflectionTestUtils.setField(service, "basDevpService", basDevpService); |
| | | when(basDevpService.list(any(Wrapper.class))).thenReturn(Arrays.asList( |
| | | basDevp(1, 101, 102), |
| | | basDevp(2, 102) |
| | | )); |
| | | when(basStationService.list(any(Wrapper.class))).thenReturn(Arrays.asList( |
| | | station(101, 2), |
| | |
| | | assertEquals(2, result.get("101")); |
| | | assertEquals(3, result.get("102")); |
| | | |
| | | ArgumentCaptor<Wrapper<StationFlowCapacity>> capacityWrapperCaptor = ArgumentCaptor.forClass(Wrapper.class); |
| | | verify(stationFlowCapacityService).list(capacityWrapperCaptor.capture()); |
| | | assertTrue(capacityWrapperCaptor.getValue().getSqlSegment().contains("direction_code =")); |
| | | ArgumentCaptor<Wrapper<BasDevp>> basDevpWrapperCaptor = ArgumentCaptor.forClass(Wrapper.class); |
| | | verify(basDevpService).list(basDevpWrapperCaptor.capture()); |
| | | assertTrue(basDevpWrapperCaptor.getValue().getSqlSegment().contains("status =")); |
| | | |
| | | ArgumentCaptor<Wrapper<BasStation>> stationWrapperCaptor = ArgumentCaptor.forClass(Wrapper.class); |
| | | verify(basStationService).list(stationWrapperCaptor.capture()); |
| | |
| | | } |
| | | |
| | | @Test |
| | | void loadStationOutTaskLimitsDoesNotQueryStationsWhenNoOutCapacityExists() { |
| | | void loadStationOutTaskLimitsDoesNotQueryStationsWhenBasDevpOutStationsAreEmpty() { |
| | | BasStationService basStationService = mock(BasStationService.class); |
| | | StationFlowCapacityService stationFlowCapacityService = mock(StationFlowCapacityService.class); |
| | | BasDevpService basDevpService = mock(BasDevpService.class); |
| | | ReflectionTestUtils.setField(service, "basStationService", basStationService); |
| | | ReflectionTestUtils.setField(service, "stationFlowCapacityService", stationFlowCapacityService); |
| | | when(stationFlowCapacityService.list(any(Wrapper.class))).thenReturn(Collections.emptyList()); |
| | | ReflectionTestUtils.setField(service, "basDevpService", basDevpService); |
| | | when(basDevpService.list(any(Wrapper.class))).thenReturn(Collections.singletonList(basDevp(1))); |
| | | |
| | | Map<String, Integer> result = ReflectionTestUtils.invokeMethod(service, "loadStationOutTaskLimits"); |
| | | |
| | |
| | | return station; |
| | | } |
| | | |
| | | private StationFlowCapacity capacity(Integer stationId, String directionCode) { |
| | | StationFlowCapacity capacity = new StationFlowCapacity(); |
| | | capacity.setStationId(stationId); |
| | | capacity.setDirectionCode(directionCode); |
| | | return capacity; |
| | | private BasDevp basDevp(Integer devpNo, Integer... stationIds) { |
| | | BasDevp basDevp = new BasDevp(); |
| | | basDevp.setDevpNo(devpNo); |
| | | basDevp.setStatus(1); |
| | | if (stationIds == null || stationIds.length == 0) { |
| | | return basDevp; |
| | | } |
| | | basDevp.setOutStationList(JSON.toJSONString(Arrays.stream(stationIds) |
| | | .map(this::stationObjModel) |
| | | .toList())); |
| | | return basDevp; |
| | | } |
| | | |
| | | private StationObjModel stationObjModel(Integer stationId) { |
| | | StationObjModel stationObjModel = new StationObjModel(); |
| | | stationObjModel.setStationId(stationId); |
| | | return stationObjModel; |
| | | } |
| | | } |