| | |
| | | package com.zy.ai.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.zy.asrs.entity.BasStation; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.Map; |
| | | |
| | | 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.mock; |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.when; |
| | | |
| | | class AutoTuneSnapshotServiceImplTest { |
| | | |
| | | private AutoTuneSnapshotServiceImpl service; |
| | | |
| | | @BeforeEach |
| | | void setUp() { |
| | | service = new AutoTuneSnapshotServiceImpl(); |
| | | } |
| | | |
| | | @Test |
| | | void buildStationOutTaskLimitMapPreservesNullZeroAndNegativeLimits() { |
| | | AutoTuneSnapshotServiceImpl service = new AutoTuneSnapshotServiceImpl(); |
| | | |
| | | Map<String, Integer> result = service.buildStationOutTaskLimitMap(Arrays.asList( |
| | | station(101, null), |
| | | station(102, 0), |
| | |
| | | assertEquals(5, result.get("104")); |
| | | } |
| | | |
| | | @Test |
| | | void loadActiveTasksIncludesNullWrkStatusInGroupedCondition() { |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | when(wrkMastService.list(any(Wrapper.class))).thenReturn(Collections.emptyList()); |
| | | ReflectionTestUtils.setField(service, "wrkMastService", wrkMastService); |
| | | |
| | | ReflectionTestUtils.invokeMethod(service, "loadActiveTasks"); |
| | | |
| | | ArgumentCaptor<Wrapper<WrkMast>> wrapperCaptor = ArgumentCaptor.forClass(Wrapper.class); |
| | | verify(wrkMastService).list(wrapperCaptor.capture()); |
| | | String sqlSegment = wrapperCaptor.getValue().getSqlSegment(); |
| | | String normalizedSqlSegment = sqlSegment.replaceAll("\\s+", " "); |
| | | assertTrue(normalizedSqlSegment.contains("(wrk_sts NOT IN")); |
| | | assertTrue(normalizedSqlSegment.contains("OR wrk_sts IS NULL")); |
| | | } |
| | | |
| | | private BasStation station(Integer stationId, Integer outTaskLimit) { |
| | | BasStation station = new BasStation(); |
| | | station.setStationId(stationId); |