NvaConfiguration implements ConfigurationValidation { public void validate(AzureClient azureClient) throws ConfigurationException { Preconditions.checkNotNull(azureClient, "azureClient cannot be null"); List<String> invalidNetworkInterfaces = this.networkInterfaces.stream() .map(r -> r.getId()) .filter(id -> !azureClient.checkExistenceById(id)) .collect(Collectors.toList()); if (invalidNetworkInterfaces.size() > 0) { throw new ConfigurationException("Invalid network interface(s): " + invalidNetworkInterfaces.stream().collect(Collectors.joining(", "))); } NetworkInterface probeNetworkInterface = azureClient.getNetworkInterfaceById(this.probeNetworkInterface); if (probeNetworkInterface == null) { throw new ConfigurationException("probeNetworkInterface '" + this.probeNetworkInterface + "' does not exist"); } this.probeSocketAddress = new InetSocketAddress(probeNetworkInterface.primaryPrivateIp(), this.probePort); } @JsonCreator  NvaConfiguration(@JsonProperty("probeNetworkInterface")String probeNetworkInterface,
                            @JsonProperty("probePort")Integer probePort,
                            @JsonProperty("networkInterfaces")List<NamedResourceId> networkInterfaces); @JsonIgnore SocketAddress getProbeSocketAddress(); List<NamedResourceId> getNetworkInterfaces(); void validate(AzureClient azureClient);  }
@Test void test_validate_null_azure_client() { NvaConfiguration nvaConfiguration = new NvaConfiguration("probe-network-interface", 1234, Arrays.asList(new NamedResourceId("nic1", "nic1-id"))); Assertions.assertThrows(NullPointerException.class, () -> nvaConfiguration.validate(null)); }
@Test void test_validate_invalid_network_interfaces() { AzureClient azureClient = mock(AzureClient.class); List<NamedResourceId> networkInterfaces = new ArrayList<>(); networkInterfaces.add(new NamedResourceId("nic1", "nic1-id")); NvaConfiguration nvaConfiguration = new NvaConfiguration("probe-network-interface", 1234, networkInterfaces); when(azureClient.checkExistenceById(anyString())) .thenReturn(false); Assertions.assertThrows(ConfigurationException.class, () -> nvaConfiguration.validate(azureClient)); }
@Test void test_validate_invalid_probe_network_interfaces() { AzureClient azureClient = mock(AzureClient.class); List<NamedResourceId> networkInterfaces = new ArrayList<>(); networkInterfaces.add(new NamedResourceId("nic1", "nic1-id")); NvaConfiguration nvaConfiguration = new NvaConfiguration("probe-network-interface", 1234, networkInterfaces); when(azureClient.checkExistenceById(anyString())) .thenReturn(true); when(azureClient.getNetworkInterfaceById(anyString())) .thenReturn(null); Assertions.assertThrows(ConfigurationException.class, () -> nvaConfiguration.validate(azureClient)); }