Skip to content

Commit

Permalink
Use #toString instead of #getExternalForm in ConfigurationKey
Browse files Browse the repository at this point in the history
  • Loading branch information
tsegismont committed May 12, 2015
1 parent 08ec1cf commit 56e4c3c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public static Configuration from(Properties properties) {
int udpPort = getIntProperty(properties, UDP_PORT, 5140);
int tcpPort = getIntProperty(properties, TCP_PORT, 5140);
int gangliaPort = getIntProperty(properties, GANGLIA_PORT, 8649);
String gangliaGroup = properties.getProperty(GANGLIA_GROUP.getExternalForm(), "239.2.11.71");
String multicastIfOverride = properties.getProperty(GANGLIA_MULTICAST_INTERFACE.getExternalForm());
String gangliaGroup = properties.getProperty(GANGLIA_GROUP.toString(), "239.2.11.71");
String multicastIfOverride = properties.getProperty(GANGLIA_MULTICAST_INTERFACE.toString());
int statsDport = getIntProperty(properties, STATSD_PORT, 8125);
int collectdPort = getIntProperty(properties, COLLECTD_PORT, 25826);
int minimumBatchSize = getIntProperty(properties, BATCH_SIZE, 50);
int maximumBatchDelay = getIntProperty(properties, BATCH_DELAY, 1);
URI restUrl = URI.create(properties.getProperty(REST_URL.getExternalForm(),
URI restUrl = URI.create(properties.getProperty(REST_URL.toString(),
"http://localhost:8080/hawkular/metrics/gauges/data"));
String tenant = properties.getProperty(TENANT.getExternalForm(), "default");
String tenant = properties.getProperty(TENANT.toString(), "default");
int restCloseAfterRequests = getIntProperty(properties, REST_CLOSE_AFTER_REQUESTS, 200);
int spoolSize = getIntProperty(properties, SPOOL_SIZE, 10000);
return new Configuration(
Expand All @@ -136,9 +136,9 @@ public static Configuration from(Properties properties) {
}

private static Set<Service> getServices(Properties properties, Set<String> validationMessages) {
String servicesProperty = properties.getProperty(SERVICES.getExternalForm());
String servicesProperty = properties.getProperty(SERVICES.toString());
if (servicesProperty == null) {
validationMessages.add(String.format(Locale.ROOT, "Property %s not found", SERVICES.getExternalForm()));
validationMessages.add(String.format(Locale.ROOT, "Property %s not found", SERVICES.toString()));
return Collections.emptySet();
}
Set<Service> services = EnumSet.noneOf(Service.class);
Expand All @@ -162,7 +162,7 @@ private static Set<Service> getServices(Properties properties, Set<String> valid
}

private static int getIntProperty(Properties properties, ConfigurationKey key, int defaultValue) {
String property = properties.getProperty(key.getExternalForm());
String property = properties.getProperty(key.toString());
if (property == null) {
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public enum ConfigurationKey {
/**
* @return string representation of this configuration key
*/
public String getExternalForm() {
@Override
public String toString() {
return externalForm;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void shouldExitWithErrorIfServicesPropertyIsMissing() throws Exception {
try (InputStream in = new FileInputStream(ptransConfFile)) {
properties.load(in);
}
properties.remove(SERVICES.getExternalForm());
properties.remove(SERVICES.toString());
try (OutputStream out = new FileOutputStream(ptransConfFile)) {
properties.store(out, "");
}
Expand All @@ -71,7 +71,7 @@ public void shouldExitWithErrorIfServicesListIsEmpty() throws Exception {
try (InputStream in = new FileInputStream(ptransConfFile)) {
properties.load(in);
}
properties.setProperty(SERVICES.getExternalForm(), " , , ,,,, ,,,, ,");
properties.setProperty(SERVICES.toString(), " , , ,,,, ,,,, ,");
try (OutputStream out = new FileOutputStream(ptransConfFile)) {
properties.store(out, "");
}
Expand All @@ -95,7 +95,7 @@ public void shouldExitWithErrorIfServicesListContainsUnknownService() throws Exc
try (InputStream in = new FileInputStream(ptransConfFile)) {
properties.load(in);
}
properties.setProperty(SERVICES.getExternalForm(), "marseille, collectd");
properties.setProperty(SERVICES.toString(), "marseille, collectd");
try (OutputStream out = new FileOutputStream(ptransConfFile)) {
properties.store(out, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void shouldBindPortsForEnabledServicesOnly() throws Exception {
try (InputStream in = new FileInputStream(ptransConfFile)) {
properties.load(in);
}
properties.setProperty(SERVICES.getExternalForm(), Service.COLLECTD.getExternalForm());
properties.setProperty(SERVICES.toString(), Service.COLLECTD.getExternalForm());
try (OutputStream out = new FileOutputStream(ptransConfFile)) {
properties.store(out, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void constructorShouldThrowExceptionWhenProvidedConfigurationIsInvalid()
@Test
public void constructorShouldNotThrowExceptionWhenProvidedConfigurationIsValid() {
Properties properties = new Properties();
properties.setProperty(SERVICES.getExternalForm(), COLLECTD.getExternalForm());
properties.setProperty(SERVICES.toString(), COLLECTD.getExternalForm());
new PTrans(Configuration.from(properties));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void setUp() throws Exception {

Properties properties = new Properties();
String addGaugeDataUrl = "http://" + BASE_URI + "/gauges/data";
properties.setProperty(ConfigurationKey.REST_URL.getExternalForm(), addGaugeDataUrl);
properties.setProperty(ConfigurationKey.TENANT.getExternalForm(), TENANT);
properties.setProperty(ConfigurationKey.REST_URL.toString(), addGaugeDataUrl);
properties.setProperty(ConfigurationKey.TENANT.toString(), TENANT);
Configuration configuration = Configuration.from(properties);

restForwardingHandler = new RestForwardingHandler(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ public void configurePTrans() throws Exception {
try (InputStream in = new FileInputStream(ptransConfFile)) {
properties.load(in);
}
properties.setProperty(ConfigurationKey.SERVICES.getExternalForm(), Service.COLLECTD.getExternalForm());
properties.setProperty(ConfigurationKey.BATCH_DELAY.getExternalForm(), String.valueOf(1));
properties.setProperty(ConfigurationKey.BATCH_SIZE.getExternalForm(), String.valueOf(1));
properties.setProperty(ConfigurationKey.SERVICES.toString(), Service.COLLECTD.getExternalForm());
properties.setProperty(ConfigurationKey.BATCH_DELAY.toString(), String.valueOf(1));
properties.setProperty(ConfigurationKey.BATCH_SIZE.toString(), String.valueOf(1));
String restUrl = "http://" + BASE_URI + "/gauges/data";
properties.setProperty(ConfigurationKey.REST_URL.getExternalForm(), restUrl);
properties.setProperty(ConfigurationKey.TENANT.getExternalForm(), tenant);
properties.setProperty(ConfigurationKey.REST_URL.toString(), restUrl);
properties.setProperty(ConfigurationKey.TENANT.toString(), tenant);
try (OutputStream out = new FileOutputStream(ptransConfFile)) {
properties.store(out, "");
}
Expand Down

0 comments on commit 56e4c3c

Please sign in to comment.