ConfigurationManager { public String[] recoverConfigurationValue( ConfigurationOptions configurationOption) throws ConnectionException { String[] optionValue = {}; try { Map<String, String> config = configuration.getClusterOptions(); if (config != null) { String strPorts = config.get(configurationOption.getOptionName()); if (strPorts != null) { optionValue = PropertyValueRecovered.recoveredValueASArray(String.class, strPorts); } else { optionValue = configurationOption.getDefaultValue(); } } else { optionValue = configurationOption.getDefaultValue(); } }catch(ExecutionException e){ String msg = String.format("Error recovering [%s] option ",configurationOption.getOptionName()); logger.error(msg); throw new ConnectionException(msg,e); } return optionValue; } ConfigurationManager(ConnectorClusterConfig configuration); String[] recoverConfigurationValue( ConfigurationOptions configurationOption);  }
@Test public void testRecoverConfigurationValueDefault() throws ConnectionException { ConnectorClusterConfig connectorClusterConfig = new ConnectorClusterConfig(new ClusterName("CLUSTER_NAME"), Collections.EMPTY_MAP,Collections.EMPTY_MAP); ConfigurationManager configurationManager = new ConfigurationManager(connectorClusterConfig); String[] value = configurationManager.recoverConfigurationValue(ConfigurationOptions.HOST); assertEquals("The value must be one",1,value.length); assertEquals("The value must be the default value",ConfigurationOptions.HOST.getDefaultValue()[0],value[0]); }
@Test public void testRecoverConfigurationValueSet() throws ConnectionException { Map<String, String> clusterOption = new HashMap<>(); clusterOption.put(ConfigurationOptions.HOST.getOptionName(), HOST_VALUE); ConnectorClusterConfig connectorClusterConfig = new ConnectorClusterConfig(new ClusterName("CLUSTER_NAME"), Collections.EMPTY_MAP,clusterOption); ConfigurationManager configurationManager = new ConfigurationManager(connectorClusterConfig); String[] value = configurationManager.recoverConfigurationValue(ConfigurationOptions.HOST); assertEquals("The value must be one",1,value.length); assertEquals("The value must be the set value",HOST_VALUE,value[0]); }
@Test public void testRecoverConfigurationValueDefaultConfigSet() throws ConnectionException { Map<String, String> clusterOption = new HashMap<>(); clusterOption.put(ConfigurationOptions.HOST.getOptionName(), HOST_VALUE); ConnectorClusterConfig connectorClusterConfig = new ConnectorClusterConfig(new ClusterName("CLUSTER_NAME"), Collections.EMPTY_MAP,clusterOption); ConfigurationManager configurationManager = new ConfigurationManager(connectorClusterConfig); String[] value = configurationManager.recoverConfigurationValue(ConfigurationOptions.PORT); assertEquals("The value must be one",1,value.length); assertEquals("The value must be the default value",ConfigurationOptions.PORT.getDefaultValue()[0],value[0]); }