yeg
2026-09-05 7259e265b9237286996b09da03038ea5a133e1e0
ruoyi-admin/src/test/java/com/battery/business/service/impl/DeviceDiscoveryPersistenceServiceTest.java
@@ -20,6 +20,36 @@
class DeviceDiscoveryPersistenceServiceTest
{
    @Test
    void failedDiscoveryInvalidatesSuccessfulSnapshotUntilSoftwareReturns() throws Exception
    {
        try (var simulator = new com.battery.device.simulator.BtsDevelopmentSimulator(0);
             var registry = new DeviceAdapterRegistry(List.of(new com.battery.device.bts.BtsDeviceAdapterFactory())))
        {
            registry.synchronize(new com.battery.device.api.registry.AdapterInstanceConfig("dev-sim", "BTS",
                    "127.0.0.1", simulator.port(), 5000, "Asia/Hong_Kong", true,
                    com.battery.device.api.model.AdapterCapabilities.observeOnly()));
            var store = new InMemoryDeviceDiscoveryCandidateStore();
            var mapper = Mockito.mock(TDetectionCabinetMapper.class);
            var persistence = new DeviceDiscoveryPersistenceService(store, mapper);
            var scheduler = new com.battery.business.runtime.DevelopmentSimulatorDiscoveryScheduler(registry, persistence);
            simulator.updateChannel(1, 1, true, com.battery.device.api.model.DeviceWorkStatus.WORKING);
            scheduler.discover();
            var before = store.snapshot(java.time.Instant.now()).cabinets().get(0);
            org.junit.jupiter.api.Assertions.assertNotNull(before.channels().get(0).latestSnapshot());
            simulator.setSoftwareAccessible(false);
            scheduler.discover();
            var failed = store.snapshot(java.time.Instant.now()).cabinets().get(0);
            assertEquals(before.deviceCode(), failed.deviceCode());
            org.junit.jupiter.api.Assertions.assertFalse(failed.online());
            org.junit.jupiter.api.Assertions.assertNull(failed.channels().get(0).latestSnapshot());
            verify(mapper).markRegisteredCabinetsOffline("dev-sim");
            simulator.setSoftwareAccessible(true);
            scheduler.discover();
            org.junit.jupiter.api.Assertions.assertTrue(store.snapshot(java.time.Instant.now()).cabinets().get(0).online());
        }
    }
    @Test
    void discoveryPersistsCandidatesWithoutReceivingTest()
    {
        InMemoryDeviceDiscoveryCandidateStore candidateStore = new InMemoryDeviceDiscoveryCandidateStore();