| | |
| | | package com.ruoyi.config; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.junit.jupiter.api.Test; |
| | | import com.ruoyi.device.bts.BtsDevelopmentSimulator; |
| | | import com.ruoyi.device.discovery.InMemoryDeviceDiscoveryCandidateStore; |
| | | import com.ruoyi.system.mapper.TCollectorMapper; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.verify; |
| | | |
| | | class DevelopmentCollectorStatusSynchronizerTest |
| | | { |
| | | @Test |
| | | void productionConstructorIsExplicitlyAutowired() |
| | | { |
| | | var constructors = DevelopmentCollectorStatusSynchronizer.class.getDeclaredConstructors(); |
| | | assertEquals(2, constructors.length); |
| | | var production = java.util.Arrays.stream(constructors) |
| | | .filter(item -> item.isAnnotationPresent(Autowired.class)).findFirst().orElseThrow(); |
| | | assertEquals(4, production.getParameterCount()); |
| | | } |
| | | @Test |
| | | void synchronizesOnlyConfiguredCollectorsWithoutRegisteringThem() throws Exception |
| | | { |
| | | try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0)) |
| | | { |
| | | InMemoryDeviceDiscoveryCandidateStore store = new InMemoryDeviceDiscoveryCandidateStore(); |
| | | TCollectorMapper collectorMapper = mock(TCollectorMapper.class); |
| | | DevelopmentCollectorStatusSynchronizer synchronizer = |
| | | new DevelopmentCollectorStatusSynchronizer(simulator, store); |
| | | new DevelopmentCollectorStatusSynchronizer(simulator, store, collectorMapper); |
| | | simulator.updateCollector(1, "127.0.1.2", 4, false); |
| | | |
| | | synchronizer.synchronizeOnlineStatus(); |
| | | |
| | | assertEquals(false, store.snapshot(java.time.Instant.now()).collectors().get(0).online()); |
| | | verify(collectorMapper).updateRegisteredObservation("dev-sim-collector-1", "OFFLINE"); |
| | | |
| | | simulator.deleteCollector(1); |
| | | synchronizer.synchronizeOnlineStatus(); |