AzureProbeMonitorConfiguration implements ConfigurationValidation { public static AzureProbeMonitorConfiguration create(MonitorConfiguration monitorConfiguration) throws ConfigurationException { Preconditions.checkNotNull(monitorConfiguration, "monitorConfiguration cannot be null"); try { ObjectMapper mapper = new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); AzureProbeMonitorConfiguration configuration = mapper.convertValue( monitorConfiguration.getSettings(), AzureProbeMonitorConfiguration.class); return configuration; } catch (NullPointerException | IllegalArgumentException e) { throw new ConfigurationException("Error parsing settings", e); } } @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_null_monitor_configuration() { Assertions.assertThrows(NullPointerException.class, () -> AzureProbeMonitorConfiguration.create(null)); }
@Test void test_create_invalid_settings() throws ConfigurationException { ObjectMapper mapper = new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); AzureProbeMonitorConfiguration azureProbeMonitorConfiguration = new AzureProbeMonitorConfiguration(azureConfiguration, nvaConfigurations, routeTables, publicIpAddresses, null, null, null); Map<String, Object> settings = mapper.convertValue(azureProbeMonitorConfiguration, new TypeReference<Map<String, Object>>(){}); settings.remove("azure"); MonitorConfiguration monitorConfiguration = new MonitorConfiguration( "com.company.Monitor", settings); Assertions.assertThrows(ConfigurationException.class, () -> AzureProbeMonitorConfiguration.create(monitorConfiguration)); }
@Test void test_create_settings() throws ConfigurationException { ObjectMapper mapper = new ObjectMapper() .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); AzureProbeMonitorConfiguration azureProbeMonitorConfiguration = new AzureProbeMonitorConfiguration(azureConfiguration, nvaConfigurations, routeTables, publicIpAddresses, null, null, null); Map<String, Object> settings = mapper.convertValue(azureProbeMonitorConfiguration, new TypeReference<Map<String, Object>>(){}); MonitorConfiguration monitorConfiguration = new MonitorConfiguration( "com.company.Monitor", settings); AzureProbeMonitorConfiguration result = AzureProbeMonitorConfiguration.create(monitorConfiguration); Assertions.assertNotNull(result); }