| | |
| | | import com.ruoyi.system.domain.TDetectionChannel; |
| | | import com.ruoyi.system.domain.TDeviceAdapter; |
| | | import com.ruoyi.system.mapper.TDeviceAdapterMapper; |
| | | import com.ruoyi.system.mapper.TDetectionCabinetMapper; |
| | | import com.ruoyi.system.service.DeviceAdapterErrorCodes; |
| | | |
| | | @ExtendWith(MockitoExtension.class) |
| | |
| | | @Mock |
| | | private DeviceAdapter deviceAdapter; |
| | | |
| | | @Mock |
| | | private TDetectionCabinetMapper detectionCabinetMapper; |
| | | |
| | | private DeviceAdapterServiceImpl service; |
| | | private TDeviceAdapter adapter; |
| | | private InMemoryDeviceDiscoveryCandidateStore candidateStore; |
| | |
| | | { |
| | | candidateStore = new InMemoryDeviceDiscoveryCandidateStore(); |
| | | service = new DeviceAdapterServiceImpl(adapterMapper, registry, |
| | | new DeviceDiscoveryPersistenceService(candidateStore), candidateStore); |
| | | new DeviceDiscoveryPersistenceService(candidateStore, detectionCabinetMapper), candidateStore); |
| | | adapter = new TDeviceAdapter(); |
| | | adapter.setAdapterId(7L); |
| | | adapter.setAdapterCode("lab-bts"); |
| | |
| | | |
| | | var channel = candidateStore.snapshot(Instant.now()).cabinets().get(0).channels().get(0); |
| | | assertEquals(DeviceWorkStatus.WORKING, channel.workStatus()); |
| | | verify(detectionCabinetMapper).updateRegisteredChannelObservation(eq("lab-bts"), eq(22), eq(1), eq(2), |
| | | eq(3), eq("ONLINE"), eq("WORKING"), any(), eq(true)); |
| | | verify(detectionCabinetMapper).updateRegisteredCabinetObservation(eq("lab-bts"), eq(22), eq(1), |
| | | eq("ONLINE"), any(), eq(true)); |
| | | } |
| | | |
| | | @Test |
| | |
| | | verify(deviceAdapter, never()).inquire(any()); |
| | | assertEquals(false, cabinet.online()); |
| | | assertTrue(cabinet.channels().stream().noneMatch(channel -> channel.online())); |
| | | verify(detectionCabinetMapper).updateRegisteredChannelObservation(eq("lab-bts"), eq(22), eq(1), eq(1), |
| | | eq(1), eq("OFFLINE"), eq("UNKNOWN"), any(), eq(false)); |
| | | verify(detectionCabinetMapper).updateRegisteredCabinetObservation(eq("lab-bts"), eq(22), eq(1), |
| | | eq("OFFLINE"), any(), eq(false)); |
| | | } |
| | | |
| | | @Test |
| | | void availableChannelWithoutSuccessfulSnapshotCannotAdvanceLastSeenBoundary() |
| | | { |
| | | ChannelIdentity identity = new ChannelIdentity("lab-bts", 22, 1, 1, 1); |
| | | when(adapterMapper.selectDeviceAdapterById(7L)).thenReturn(adapter); |
| | | when(deviceAdapter.discoverChannels()).thenReturn(List.of(new DetectedChannel(identity, "127.0.0.1", true))); |
| | | when(deviceAdapter.inquire(Set.of(identity))).thenReturn(Map.of()); |
| | | stubRegistryExecution(); |
| | | |
| | | service.discover(7L); |
| | | |
| | | verify(detectionCabinetMapper).updateRegisteredChannelObservation(eq("lab-bts"), eq(22), eq(1), eq(1), |
| | | eq(1), eq("ONLINE"), eq("UNKNOWN"), any(), eq(false)); |
| | | verify(detectionCabinetMapper).updateRegisteredCabinetObservation(eq("lab-bts"), eq(22), eq(1), |
| | | eq("ONLINE"), any(), eq(false)); |
| | | } |
| | | |
| | | @Test |