| | |
| | | import org.springframework.mock.web.MockHttpServletRequest; |
| | | import org.springframework.mock.web.MockHttpServletResponse; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.server.ResponseStatusException; |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.device.bts.BtsDevelopmentSimulator; |
| | | import com.ruoyi.device.discovery.DeviceDiscoveryCandidateStore.CabinetCandidate; |
| | |
| | | } |
| | | |
| | | @Test |
| | | void controllerPowersAllSimulatorDevicesWithoutResettingHistory() throws Exception |
| | | { |
| | | try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0)) |
| | | { |
| | | BtsDevelopmentSimulatorController controller = controller(simulator); |
| | | simulator.advanceCollectors(Instant.now()); |
| | | long historyCount = controller.state().collectors().get(0).historyRecordCount(); |
| | | |
| | | var poweredOff = controller.setPower( |
| | | new BtsDevelopmentSimulatorController.SimulatorPowerCommand(false)); |
| | | |
| | | assertTrue(poweredOff.devices().stream().noneMatch(device -> device.online() |
| | | || device.channels().stream().anyMatch(channel -> channel.online()))); |
| | | assertTrue(poweredOff.collectors().stream().noneMatch(collector -> collector.online())); |
| | | assertEquals(historyCount, poweredOff.collectors().get(0).historyRecordCount()); |
| | | |
| | | var poweredOn = controller.setPower( |
| | | new BtsDevelopmentSimulatorController.SimulatorPowerCommand(true)); |
| | | assertTrue(poweredOn.devices().stream().allMatch(device -> device.online() |
| | | && device.channels().stream().allMatch(channel -> channel.online() |
| | | && channel.workStatus() == DeviceWorkStatus.STOPPED))); |
| | | assertTrue(poweredOn.collectors().stream().allMatch(collector -> collector.online())); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void simulatorPowerCommandRequiresExplicitState() throws Exception |
| | | { |
| | | try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0)) |
| | | { |
| | | BtsDevelopmentSimulatorController controller = controller(simulator); |
| | | |
| | | ResponseStatusException exception = assertThrows(ResponseStatusException.class, |
| | | () -> controller.setPower(new BtsDevelopmentSimulatorController.SimulatorPowerCommand(null))); |
| | | |
| | | assertEquals(400, exception.getStatusCode().value()); |
| | | assertTrue(controller.state().collectors().get(0).online()); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void virtualIpMustBeUniqueAcrossCabinetsAndCollectors() throws Exception |
| | | { |
| | | try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0)) |