| | |
| | | assertEquals(new BigDecimal("120.50"), savedCabinet.getCapacity()); |
| | | assertEquals("OFFLINE", savedCabinet.getOnlineStatus()); |
| | | assertEquals("0", savedCabinet.getStatus()); |
| | | assertNull(savedCabinet.getCurrentTest()); |
| | | assertTrue(savedCabinet.getRelatedTests().isEmpty()); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 验证检测柜主列表从通道事实派生旧页面展示字段,不读取数据库不存在的列。 |
| | | * 验证检测柜主列表保留操作校验所需派生状态,不读取数据库不存在的列。 |
| | | */ |
| | | @Test |
| | | void detectionCabinetListSqlShouldDeriveLegacyPresentationFields() throws IOException |
| | | void detectionCabinetListSqlShouldDeriveOperationStateWithoutCurrentTest() throws IOException |
| | | { |
| | | try (InputStream input = getClass().getResourceAsStream( |
| | | "/mapper/battery/TDetectionCabinetMapper.xml")) |
| | |
| | | assertFalse(selectSql.contains("online_status, test_status")); |
| | | assertFalse(selectSql.contains("current_test, status")); |
| | | assertTrue(selectSql.contains("as test_status")); |
| | | assertTrue(selectSql.contains("as current_test")); |
| | | assertFalse(selectSql.contains("current_test")); |
| | | String activeTestSql = sqlFragment(mapperXml, "activeCabinetTestExists"); |
| | | assertTrue(activeTestSql.contains("t_test_channel_binding")); |
| | | assertTrue(activeTestSql.contains("t_detection_channel")); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 验证设备选择列表读取 Redis 候选,并保持原前端字段和状态文本。 |
| | | * 验证设备选择列表读取候选的设备事实,不推断系统测试关系。 |
| | | */ |
| | | @Test |
| | | void selectDiscoveredCabinetListShouldMapPersistedCabinetFacts() |
| | |
| | | assertEquals("192.168.1.10", devices.get(0).getIp()); |
| | | assertEquals("AA:BB:CC:DD:EE:FF", devices.get(0).getMac()); |
| | | assertEquals("在线", devices.get(0).getOnlineStatus()); |
| | | assertEquals("测试中", devices.get(0).getTestStatus()); |
| | | assertEquals("待确认", devices.get(0).getCurrentTest()); |
| | | var fields = new com.fasterxml.jackson.databind.ObjectMapper().valueToTree(devices.get(0)); |
| | | assertFalse(fields.has("testStatus")); |
| | | assertFalse(fields.has("currentTest")); |
| | | assertEquals("一号模拟柜", devices.get(0).getName()); |
| | | assertEquals("开发模拟器", devices.get(0).getManufacturer()); |
| | | assertEquals("BTS Virtual Cabinet", devices.get(0).getModel()); |
| | | 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()); |
| | | } |
| | | |