| | |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.ArgumentMatchers.anyInt; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.never; |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.when; |
| | | |
| | | import java.io.IOException; |
| | |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.web.context.request.async.AsyncRequestNotUsableException; |
| | | import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; |
| | | import com.ruoyi.device.bts.BtsDevelopmentSimulator; |
| | | import com.ruoyi.device.discovery.DeviceDiscoveryCandidateStore; |
| | | import com.ruoyi.device.model.ChannelIdentity; |
| | | import com.ruoyi.device.model.DeviceWorkStatus; |
| | | import com.ruoyi.device.model.RealtimeSnapshot; |
| | | import com.battery.device.simulator.BtsDevelopmentSimulator; |
| | | import com.battery.device.discovery.DeviceDiscoveryCandidateStore; |
| | | import com.battery.device.model.ChannelIdentity; |
| | | import com.battery.device.model.DeviceWorkStatus; |
| | | import com.battery.device.model.RealtimeSnapshot; |
| | | import com.ruoyi.system.domain.TTest; |
| | | import com.ruoyi.system.domain.TTestBattery; |
| | | import com.ruoyi.system.domain.TTestChannelBinding; |
| | | import com.ruoyi.system.domain.TTestWarningException; |
| | | import com.ruoyi.system.mapper.TTestMapper; |
| | | import com.ruoyi.system.service.ITTestService; |
| | | import com.ruoyi.system.service.ITestLiveService.LiveState; |
| | | |
| | |
| | | assertEquals(new BigDecimal("3.700"), snapshot.get("voltageV")); |
| | | assertEquals(new BigDecimal("1.200"), snapshot.get("currentA")); |
| | | assertEquals(new BigDecimal("2.500"), snapshot.get("capacityAh")); |
| | | assertEquals(now.toEpochMilli(), snapshot.get("observedAt")); |
| | | } |
| | | |
| | | @Test |
| | | void onlineCabinetWithStoppedWorkStatusShouldRemainOnlineAndNotRaiseSourceAlarm() |
| | | { |
| | | Instant now = Instant.parse("2026-09-02T06:00:00Z"); |
| | | TTestLiveServiceImpl service = liveService(test("RECEIVING"), now, true, DeviceWorkStatus.STOPPED); |
| | | |
| | | LiveState state = service.current(10L); |
| | | var cabinet = state.sources().stream().filter(source -> "CABINET_CHANNEL".equals(source.sourceType())) |
| | | .findFirst().orElseThrow(); |
| | | |
| | | assertEquals("ONLINE", cabinet.deviceStatus()); |
| | | assertTrue(state.exceptions().isEmpty()); |
| | | } |
| | | |
| | | @Test |
| | | void pausedShouldNotExposeUnavailableSourceAsAlarm() |
| | | { |
| | | Instant now = Instant.parse("2026-09-02T06:00:00Z"); |
| | | TTest test = test("PAUSED"); |
| | | TTestLiveServiceImpl service = liveService(test, now, false); |
| | | |
| | | LiveState state = service.current(10L); |
| | | |
| | | assertTrue(state.exceptions().isEmpty()); |
| | | } |
| | | |
| | | @Test |
| | | void completedTestShouldNotExposeOpenWarningInLiveAlarm() |
| | | { |
| | | Instant now = Instant.parse("2026-09-02T06:00:00Z"); |
| | | TTestMapper mapper = mock(TTestMapper.class); |
| | | TTestWarningException warning = new TTestWarningException(); |
| | | warning.setExceptionId(1L); |
| | | warning.setSourceType("COLLECTOR"); |
| | | warning.setMetricCode("TEMPERATURE"); |
| | | warning.setAbnormalValue(new BigDecimal("25.3")); |
| | | warning.setUnit("℃"); |
| | | warning.setExceptionStatus("OPEN"); |
| | | when(mapper.selectWarningExceptions(10L, "OPEN")).thenReturn(List.of(warning)); |
| | | |
| | | TTestLiveServiceImpl service = liveService(test("ENDED"), now, true, DeviceWorkStatus.STOPPED, mapper); |
| | | |
| | | LiveState state = service.current(10L); |
| | | |
| | | assertTrue(state.exceptions().isEmpty()); |
| | | verify(mapper, never()).selectWarningExceptions(10L, "OPEN"); |
| | | } |
| | | |
| | | private static TTest test(String receptionStatus) |
| | |
| | | |
| | | private static TTestLiveServiceImpl liveService(TTest test, Instant now) |
| | | { |
| | | return liveService(test, now, true); |
| | | } |
| | | |
| | | private static TTestLiveServiceImpl liveService(TTest test, Instant now, boolean online) |
| | | { |
| | | return liveService(test, now, online, DeviceWorkStatus.WORKING); |
| | | } |
| | | |
| | | private static TTestLiveServiceImpl liveService(TTest test, Instant now, boolean online, |
| | | DeviceWorkStatus workStatus) |
| | | { |
| | | return liveService(test, now, online, workStatus, null); |
| | | } |
| | | |
| | | private static TTestLiveServiceImpl liveService(TTest test, Instant now, boolean online, |
| | | DeviceWorkStatus workStatus, TTestMapper mapper) |
| | | { |
| | | DeviceDiscoveryCandidateStore candidates = mock(DeviceDiscoveryCandidateStore.class); |
| | | BtsDevelopmentSimulator simulator = mock(BtsDevelopmentSimulator.class); |
| | | ITTestService tests = mock(ITTestService.class); |
| | | when(tests.selectTestById(10L)).thenReturn(test); |
| | | ChannelIdentity identity = new ChannelIdentity("dev-sim", 1, 1, 0, 1); |
| | | RealtimeSnapshot snapshot = new RealtimeSnapshot(identity, DeviceWorkStatus.WORKING, 1, 1, "cc", null, |
| | | RealtimeSnapshot snapshot = new RealtimeSnapshot(identity, workStatus, 1, 1, "cc", null, |
| | | new BigDecimal("1.200"), new BigDecimal("3.700"), new BigDecimal("2.500"), |
| | | new BigDecimal("9.250"), 12L, 12L, "0", now, |
| | | java.util.Map.of()); |
| | | DeviceDiscoveryCandidateStore.ChannelCandidate channel = new DeviceDiscoveryCandidateStore.ChannelCandidate( |
| | | identity, true, DeviceWorkStatus.WORKING, now, snapshot); |
| | | identity, online, workStatus, now, snapshot); |
| | | DeviceDiscoveryCandidateStore.CabinetCandidate cabinet = new DeviceDiscoveryCandidateStore.CabinetCandidate( |
| | | "dev-sim", 1L, "dev-sim", 1, 1, "127.0.0.2", "mac", "cabinet", "vendor", "model", |
| | | List.of(channel), now, now.plusSeconds(60)); |
| | |
| | | var plan = new BtsDevelopmentSimulator.BtsTestSnapshot(1, 1, 1, List.of()); |
| | | when(simulator.btsTest(anyInt(), anyInt())).thenReturn(plan); |
| | | when(simulator.btsTest(anyInt(), anyInt(), anyInt())).thenReturn(plan); |
| | | return new CurrentLiveService(tests, candidates, simulator); |
| | | return new CurrentLiveService(tests, candidates, simulator, mapper); |
| | | } |
| | | |
| | | @Test |
| | |
| | | private static final class CurrentLiveService extends TTestLiveServiceImpl |
| | | { |
| | | private CurrentLiveService(ITTestService tests, DeviceDiscoveryCandidateStore candidates, |
| | | BtsDevelopmentSimulator simulator) |
| | | BtsDevelopmentSimulator simulator, TTestMapper mapper) |
| | | { |
| | | super(tests, candidates, simulator); |
| | | super(tests, candidates, simulator, mapper); |
| | | } |
| | | } |
| | | |