AzureProbeMonitorConfiguration implements ConfigurationValidation { public void validate(AzureClient azureClient) throws ConfigurationException { Preconditions.checkNotNull(azureClient, "azureClient cannot be null"); for (NvaConfiguration config : this.nvaConfigurations) { config.validate(azureClient); } if (this.nvaConfigurations.stream() .map(c -> ((InetSocketAddress)c.getProbeSocketAddress()).getHostName()) .distinct() .count() != this.nvaConfigurations.size()) { throw new ConfigurationException("Duplicate probe IP Address found"); } List<String> invalidPublicIpAddresses = this.publicIpAddresses.stream() .map(r -> r.getId()) .filter(id -> !azureClient.checkExistenceById(id)) .collect(Collectors.toList()); if (invalidPublicIpAddresses.size() > 0) { throw new ConfigurationException("Invalid public ip address(es): " + invalidPublicIpAddresses.stream().collect(Collectors.joining(", "))); } List<String> invalidRouteTables = this.routeTables.stream() .filter(id -> !azureClient.checkExistenceById(id)) .collect(Collectors.toList()); if (invalidRouteTables.size() > 0) { throw new ConfigurationException("Invalid route table(s): " + invalidRouteTables.stream().collect(Collectors.joining(", "))); } } @JsonCreator  AzureProbeMonitorConfiguration(@JsonProperty("azure")AzureConfiguration azureConfiguration,
                                          @JsonProperty("nvas")List<NvaConfiguration> nvaConfigurations,
                                          @JsonProperty("routeTables")List<String> routeTables,
                                          @JsonProperty("publicIpAddresses")List<NamedResourceId> publicIpAddresses,
                                          @JsonProperty("numberOfFailuresThreshold")Integer numberOfFailuresThreshold,
                                          @JsonProperty("probeConnectTimeout")Integer probeConnectTimeout,
                                          @JsonProperty("probePollingInterval")Integer probePollingInterval); static AzureProbeMonitorConfiguration create(MonitorConfiguration monitorConfiguration); AzureConfiguration getAzureConfiguration(); int getProbeConnectTimeout(); int getProbePollingInterval(); int getNumberOfFailuresThreshold(); List<String> getRouteTables(); List<NamedResourceId> getPublicIpAddresses(); List<NvaConfiguration> getNvaConfigurations(); void validate(AzureClient azureClient); static final int DEFAULT_NUMBER_OF_FAILURES_THRESHOLD; static final int DEFAULT_PROBE_CONNECT_TIMEOUT; static final int DEFAULT_PROBE_POLLING_INTERVAL; }
@Test void test_validate_null_azure_client() { AzureProbeMonitorConfiguration azureProbeMonitorConfiguration = new AzureProbeMonitorConfiguration(azureConfiguration, nvaConfigurations, routeTables, publicIpAddresses, null, null, null); Assertions.assertThrows(NullPointerException.class, () -> azureProbeMonitorConfiguration.validate(null)); }
@Test void test_validate_duplicate_probe() throws ConfigurationException { String probeNetworkInterfacePrimaryPrivateIp = "127.0.0.1"; AzureProbeMonitorConfiguration azureProbeMonitorConfiguration = new AzureProbeMonitorConfiguration(azureConfiguration, nvaConfigurations, routeTables, publicIpAddresses, null, null, null); AzureClient azureClient = mock(AzureClient.class); when(azureClient.checkExistenceById(anyString())) .thenReturn(true); NetworkInterface probeNetworkInterface = mock(NetworkInterface.class); when(probeNetworkInterface.primaryPrivateIp()) .thenReturn(probeNetworkInterfacePrimaryPrivateIp); when(azureClient.getNetworkInterfaceById(anyString())) .thenReturn(probeNetworkInterface); Assertions.assertThrows(ConfigurationException.class, () -> azureProbeMonitorConfiguration.validate(azureClient)); }
@Test void test_validate_invalid_public_ip_address() throws ConfigurationException { AzureProbeMonitorConfiguration azureProbeMonitorConfiguration = new AzureProbeMonitorConfiguration(azureConfiguration, nvaConfigurations, routeTables, publicIpAddresses, null, null, null); AzureClient azureClient = mock(AzureClient.class); when(azureClient.checkExistenceById(contains("network-interface"))) .thenReturn(true); NetworkInterface networkInterface = mock(NetworkInterface.class); when(networkInterface.primaryPrivateIp()) .thenReturn("127.0.0.1") .thenReturn("127.0.0.2"); when(azureClient.getNetworkInterfaceById(anyString())) .thenReturn(networkInterface); Assertions.assertThrows(ConfigurationException.class, () -> azureProbeMonitorConfiguration.validate(azureClient)); }
@Test void test_validate_invalid_route_table() throws ConfigurationException { AzureProbeMonitorConfiguration azureProbeMonitorConfiguration = new AzureProbeMonitorConfiguration(azureConfiguration, nvaConfigurations, routeTables, publicIpAddresses, null, null, null); AzureClient azureClient = mock(AzureClient.class); when(azureClient.checkExistenceById(contains("network-interface"))) .thenReturn(true); when(azureClient.checkExistenceById(contains("public-ip-address"))) .thenReturn(true); NetworkInterface networkInterface = mock(NetworkInterface.class); when(networkInterface.primaryPrivateIp()) .thenReturn("127.0.0.1") .thenReturn("127.0.0.2"); when(azureClient.getNetworkInterfaceById(anyString())) .thenReturn(networkInterface); Assertions.assertThrows(ConfigurationException.class, () -> azureProbeMonitorConfiguration.validate(azureClient)); }
@Test void test_validate() throws ConfigurationException { AzureProbeMonitorConfiguration azureProbeMonitorConfiguration = new AzureProbeMonitorConfiguration(azureConfiguration, nvaConfigurations, routeTables, publicIpAddresses, null, null, null); AzureClient azureClient = mock(AzureClient.class); when(azureClient.checkExistenceById(anyString())) .thenReturn(true); NetworkInterface networkInterface = mock(NetworkInterface.class); when(networkInterface.primaryPrivateIp()) .thenReturn("127.0.0.1") .thenReturn("127.0.0.2"); when(azureClient.getNetworkInterfaceById(anyString())) .thenReturn(networkInterface); azureProbeMonitorConfiguration.validate(azureClient); }