| | |
| | | assertEquals(8, devices.get(0).getChannelCount()); |
| | | } |
| | | |
| | | @Test |
| | | void offlineCabinetRemainsDiscoverableAndCanBeRegistered() |
| | | { |
| | | var store = new InMemoryDeviceDiscoveryCandidateStore(); |
| | | store.recordCabinets(List.of(candidate("CABINET-001", false, DeviceWorkStatus.UNOBSERVABLE))); |
| | | var service = new TDetectionCabinetServiceImpl(detectionCabinetMapper, store); |
| | | when(detectionCabinetMapper.selectRegisteredCabinetCodes()).thenReturn(List.of()); |
| | | var devices = service.selectDiscoveredCabinetList(); |
| | | assertEquals(1, devices.size()); |
| | | assertEquals("离线", devices.get(0).getOnlineStatus()); |
| | | when(detectionCabinetMapper.insertDetectionCabinet(any(TDetectionCabinet.class))).thenReturn(1); |
| | | assertEquals(1, service.insertDetectionCabinet(detectionCabinet)); |
| | | assertEquals("OFFLINE", detectionCabinet.getOnlineStatus()); |
| | | when(detectionCabinetMapper.selectRegisteredCabinetCodes()).thenReturn(List.of("CABINET-001")); |
| | | assertEquals(0, service.selectDiscoveredCabinetList().size()); |
| | | } |
| | | |
| | | /** |
| | | * 验证重复设备编码会阻止新增且不会执行写库操作。 |
| | | */ |
| | |
| | | ServiceException exception = assertThrows(ServiceException.class, |
| | | () -> detectionCabinetService.insertDetectionCabinet(detectionCabinet)); |
| | | |
| | | assertEquals("请先选择在线的发现候选设备", exception.getMessage()); |
| | | assertEquals("请先选择有效的发现候选设备", exception.getMessage()); |
| | | verify(detectionCabinetMapper, never()).insertDetectionCabinet(any()); |
| | | } |
| | | |