From 14ac9c2a2384f1e55b4c01eb7a104033b589d1e0 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 29 八月 2026 16:47:05 +0800
Subject: [PATCH] 增加模拟器设备总开关

---
 ruoyi-admin/src/test/java/com/ruoyi/web/controller/device/BtsDevelopmentSimulatorControllerTest.java |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/ruoyi-admin/src/test/java/com/ruoyi/web/controller/device/BtsDevelopmentSimulatorControllerTest.java b/ruoyi-admin/src/test/java/com/ruoyi/web/controller/device/BtsDevelopmentSimulatorControllerTest.java
index 720b47c..7cec568 100644
--- a/ruoyi-admin/src/test/java/com/ruoyi/web/controller/device/BtsDevelopmentSimulatorControllerTest.java
+++ b/ruoyi-admin/src/test/java/com/ruoyi/web/controller/device/BtsDevelopmentSimulatorControllerTest.java
@@ -14,6 +14,7 @@
 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;
@@ -124,6 +125,47 @@
     }
 
     @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))

--
Gitblit v1.7.1