| | |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.ArgumentMatchers.isNull; |
| | | import static org.mockito.Mockito.times; |
| | | import static org.mockito.Mockito.never; |
| | | import static org.mockito.Mockito.verify; |
| | |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.junit.jupiter.api.extension.ExtendWith; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.mockito.Mock; |
| | | import org.mockito.junit.jupiter.MockitoExtension; |
| | | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| | |
| | | verify(adapterMapper, never()).updateDeviceAdapterStatus(any(), any(), any()); |
| | | } |
| | | |
| | | /** 单行配置有问题不得拦住后端启动:记下原因,由发现轮询按周期重试并持久化失败。 */ |
| | | /** 单行配置有问题不得拦住后端启动:写日志并把失败落到该行,使"忘了放凭据"在启动后立刻可见。 */ |
| | | @Test |
| | | void startupRestoreSurvivesOneBrokenAdapterRow() |
| | | { |
| | |
| | | vendor.setStatus("0"); |
| | | vendor.setCapabilities("{\"discovery\":true,\"realtimeObservation\":true,\"historyDownload\":true,\"control\":false}"); |
| | | when(adapterMapper.selectEnabledDeviceAdapters()).thenReturn(List.of(vendor)); |
| | | org.mockito.Mockito.doThrow(new DeviceAdapterException("缺少厂商库连接口令:请设置环境变量 X")) |
| | | org.mockito.Mockito.doThrow(new DeviceAdapterException("缺少厂商库连接口令:config/vendor-credentials.properties 中没有键 X")) |
| | | .when(registry).synchronize(any()); |
| | | |
| | | service.synchronizeEnabledAdapters(); |
| | | |
| | | verify(registry).synchronize(any()); |
| | | ArgumentCaptor<String> message = ArgumentCaptor.forClass(String.class); |
| | | verify(adapterMapper).updateDiscoveryFailure(eq(9L), any(), message.capture()); |
| | | assertTrue(message.getValue().contains("缺少厂商库连接口令")); |
| | | } |
| | | |
| | | @Test |
| | |
| | | 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)); |
| | | eq(3), isNull(), eq("ONLINE"), eq("WORKING"), any(), eq(true)); |
| | | verify(detectionCabinetMapper).updateRegisteredCabinetObservation(eq("lab-bts"), eq(22), eq(1), |
| | | eq("ONLINE"), any(), eq(true)); |
| | | } |
| | |
| | | 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)); |
| | | eq(1), isNull(), eq("OFFLINE"), eq("UNKNOWN"), any(), eq(false)); |
| | | verify(detectionCabinetMapper).updateRegisteredCabinetObservation(eq("lab-bts"), eq(22), eq(1), |
| | | eq("OFFLINE"), any(), eq(false)); |
| | | } |
| | |
| | | service.discover(7L); |
| | | |
| | | verify(detectionCabinetMapper).updateRegisteredChannelObservation(eq("lab-bts"), eq(22), eq(1), eq(1), |
| | | eq(1), eq("ONLINE"), eq("UNKNOWN"), any(), eq(false)); |
| | | eq(1), isNull(), eq("ONLINE"), eq("UNKNOWN"), any(), eq(false)); |
| | | verify(detectionCabinetMapper).updateRegisteredCabinetObservation(eq("lab-bts"), eq(22), eq(1), |
| | | eq("ONLINE"), any(), eq(false)); |
| | | } |