Junjie
8 天以前 1b93474a67aa2323d20630b1bb026713b2bad009
src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java
@@ -2,9 +2,14 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.zy.ai.domain.autotune.AutoTuneRoutePressureSnapshot;
import com.zy.ai.domain.autotune.AutoTuneRuleSnapshotItem;
import com.zy.ai.domain.autotune.AutoTuneSnapshot;
import com.zy.ai.domain.autotune.AutoTuneStationRuntimeItem;
import com.zy.ai.domain.autotune.AutoTuneTaskDetailItem;
import com.zy.ai.domain.autotune.AutoTuneTaskSnapshot;
import com.zy.ai.service.FlowTopologySnapshotService;
import com.zy.ai.service.RoutePressureSnapshotService;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.WrkMast;
@@ -14,6 +19,8 @@
import com.zy.core.enums.WrkIoType;
import com.zy.core.enums.WrkStsType;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.system.service.ConfigService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -26,6 +33,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -39,7 +47,11 @@
    @BeforeEach
    void setUp() {
        ConfigService configService = mock(ConfigService.class);
        service = new AutoTuneSnapshotServiceImpl();
        ReflectionTestUtils.setField(service, "configService", configService);
        ReflectionTestUtils.setField(service, "autoTuneControlModeService",
                new AutoTuneControlModeServiceImpl(configService));
    }
    @Test
@@ -147,6 +159,42 @@
    }
    @Test
    void buildSnapshotIncludesRoutePressureSnapshot() {
        WrkMastService wrkMastService = mock(WrkMastService.class);
        FlowTopologySnapshotService flowTopologySnapshotService = mock(FlowTopologySnapshotService.class);
        RoutePressureSnapshotService routePressureSnapshotService = mock(RoutePressureSnapshotService.class);
        AutoTuneRoutePressureSnapshot routePressureSnapshot = new AutoTuneRoutePressureSnapshot();
        List<WrkMast> activeTasks = Collections.singletonList(
                outboundTask(190263, WrkStsType.NEW_OUTBOUND.sts, 101, 1,
                        "BATCH", 8, "目标出库站:101 已达出库任务上限,当前=1,上限=1")
        );
        when(wrkMastService.list(any(Wrapper.class))).thenReturn(activeTasks);
        when(flowTopologySnapshotService.buildSnapshot(any())).thenReturn(Collections.emptyList());
        when(routePressureSnapshotService.buildSnapshot(any(), any(), any())).thenReturn(routePressureSnapshot);
        ReflectionTestUtils.setField(service, "wrkMastService", wrkMastService);
        ReflectionTestUtils.setField(service, "flowTopologySnapshotService", flowTopologySnapshotService);
        ReflectionTestUtils.setField(service, "routePressureSnapshotService", routePressureSnapshotService);
        AutoTuneSnapshot snapshot = service.buildSnapshot();
        assertSame(routePressureSnapshot, snapshot.getRoutePressureSnapshot());
        assertEquals(1, snapshot.getTaskSnapshot().getActiveTaskCount());
        ArgumentCaptor<List<WrkMast>> activeTasksCaptor = ArgumentCaptor.forClass(List.class);
        ArgumentCaptor<AutoTuneTaskSnapshot> taskSnapshotCaptor = ArgumentCaptor.forClass(AutoTuneTaskSnapshot.class);
        ArgumentCaptor<List<AutoTuneStationRuntimeItem>> stationRuntimeCaptor = ArgumentCaptor.forClass(List.class);
        verify(routePressureSnapshotService).buildSnapshot(
                activeTasksCaptor.capture(),
                taskSnapshotCaptor.capture(),
                stationRuntimeCaptor.capture()
        );
        assertSame(activeTasks, activeTasksCaptor.getValue());
        assertSame(snapshot.getTaskSnapshot(), taskSnapshotCaptor.getValue());
        assertSame(snapshot.getStationRuntimeSnapshot(), stationRuntimeCaptor.getValue());
        verify(wrkMastService).list(any(Wrapper.class));
    }
    @Test
    void loadOutStationListOnlyQueriesBasDevpOutStations() {
        BasStationService basStationService = mock(BasStationService.class);
        BasDevpService basDevpService = mock(BasDevpService.class);
@@ -190,6 +238,20 @@
        verify(basStationService, never()).list(any(Wrapper.class));
    }
    @Test
    void toRuntimeItemExposesRunBlockForRoutePressure() {
        StationProtocol protocol = new StationProtocol();
        protocol.setStationId(101);
        protocol.setAutoing(true);
        protocol.setLoading(false);
        protocol.setTaskNo(0);
        protocol.setRunBlock(true);
        AutoTuneStationRuntimeItem item = ReflectionTestUtils.invokeMethod(service, "toRuntimeItem", protocol);
        assertEquals(1, item.getRunBlock());
    }
    private BasStation station(Integer stationId, Integer outTaskLimit) {
        return station(stationId, outTaskLimit, null);
    }