diff --git a/src/main/java/com/gu/conf/ConfigurationFactory.java b/src/main/java/com/gu/conf/ConfigurationFactory.java index d15c41c..3b55346 100644 --- a/src/main/java/com/gu/conf/ConfigurationFactory.java +++ b/src/main/java/com/gu/conf/ConfigurationFactory.java @@ -15,8 +15,8 @@ public Configuration getConfiguration(String applicationName) { public Configuration getConfiguration(String applicationName, String webappConfDirectory) { LOG.info(String.format("Configuring application(%s) using classpath configuration directory(%s)", applicationName, webappConfDirectory)); - PropertiesLoader propertiesLocator = new PropertiesLoader(); - List properties = propertiesLocator.getProperties(applicationName, webappConfDirectory); + PropertiesLoader propertiesLoader = new PropertiesLoader(); + List properties = propertiesLoader.getProperties(applicationName, webappConfDirectory); Configuration configuration = new Configuration(properties); LOG.info(String.format("Configured webapp %s with properties:\n\n%s", applicationName, configuration)); diff --git a/src/main/java/com/gu/conf/PropertiesLoader.java b/src/main/java/com/gu/conf/PropertiesLoader.java index c85f184..19a124e 100644 --- a/src/main/java/com/gu/conf/PropertiesLoader.java +++ b/src/main/java/com/gu/conf/PropertiesLoader.java @@ -12,8 +12,8 @@ class PropertiesLoader { private static final String INSTALLATION_PROPERTIES_FILE = "/etc/gu/installation.properties"; private static final Logger LOG = Logger.getLogger(PropertiesLoader.class); - private FileAndResourceLoader loader = new FileAndResourceLoader(); - private PropertiesWithSource installationProperties; + private FileAndResourceLoader loader; + private Properties installationProperties; PropertiesLoader() { this(new FileAndResourceLoader()); @@ -21,22 +21,25 @@ class PropertiesLoader { PropertiesLoader(FileAndResourceLoader loader) { this.loader = loader; + + LOG.info("Loading installation properties from " + INSTALLATION_PROPERTIES_FILE); + installationProperties = loader.getPropertiesFromFile(INSTALLATION_PROPERTIES_FILE); + + LOG.info("stage: " + getStage()); + LOG.info("int.service.domain: " + getIntServiceDomain()); } String getIntServiceDomain() { - return getInstallationProperties().getStringProperty("int.service.domain"); + return installationProperties.getProperty("int.service.domain"); } String getStage() { - return getInstallationProperties().getStringProperty("stage"); + return installationProperties.getProperty("stage"); } List getProperties(String applicationName, String webappConfDirectory) { List properties = new LinkedList(); - PropertiesWithSource installationProperties = getInstallationProperties(); - properties.add(installationProperties); - String stage = getStage(); if (StringUtils.isBlank(stage)) { LOG.warn("'stage' variable unavailable from " + INSTALLATION_PROPERTIES_FILE); @@ -51,17 +54,6 @@ List getProperties(String applicationName, String webappCo return properties; } - private PropertiesWithSource getInstallationProperties() { - if (installationProperties == null) { - LOG.info("Loading installation properties from " + INSTALLATION_PROPERTIES_FILE); - - Properties properties = loader.getPropertiesFromFile(INSTALLATION_PROPERTIES_FILE); - installationProperties = new PropertiesWithSource(properties, PropertiesSource.INSTALLATION_PROPERTIES); - } - - return installationProperties; - } - private PropertiesWithSource getSystemWebappProperties(String applicationName) { String propertiesFile = String.format("/etc/gu/%s.properties", applicationName); diff --git a/src/main/java/com/gu/conf/PropertiesSource.java b/src/main/java/com/gu/conf/PropertiesSource.java index f78401b..e4b83c4 100644 --- a/src/main/java/com/gu/conf/PropertiesSource.java +++ b/src/main/java/com/gu/conf/PropertiesSource.java @@ -7,8 +7,7 @@ public enum PropertiesSource { WEBAPP_STAGE_PROPERTIES("Webapp Stage Specific Configuration Properties"), WEBAPP_GLOBAL_PROPERTIES("Webapp Global Configuration Properties"), SYSTEM_WEBAPP_PROPERTIES("/etc/gu/ Webapp Systems Configuration Properties"), - DEV_SYSTEM_WEBAPP_PROPERTIES("~/etc/gu/ DEV Webapp Systems Configuration Properties"), - INSTALLATION_PROPERTIES("/etc/gu/installations.properties Installation Properties"); + DEV_SYSTEM_WEBAPP_PROPERTIES("~/etc/gu/ DEV Webapp Systems Configuration Properties"); private String description; diff --git a/src/test/java/com/gu/conf/PropertiesBuilder.java b/src/test/java/com/gu/conf/PropertiesBuilder.java index a6e37cf..76ff3a7 100644 --- a/src/test/java/com/gu/conf/PropertiesBuilder.java +++ b/src/test/java/com/gu/conf/PropertiesBuilder.java @@ -24,10 +24,6 @@ public PropertiesBuilder source(PropertiesSource source) { return this; } - public PropertiesBuilder installationProperties() { - return source(PropertiesSource.INSTALLATION_PROPERTIES); - } - public PropertiesBuilder devOverrideSystemWebappProperties() { return source(PropertiesSource.DEV_SYSTEM_WEBAPP_PROPERTIES); } diff --git a/src/test/java/com/gu/conf/PropertiesLoaderTest.java b/src/test/java/com/gu/conf/PropertiesLoaderTest.java index 9de374c..59ca29c 100644 --- a/src/test/java/com/gu/conf/PropertiesLoaderTest.java +++ b/src/test/java/com/gu/conf/PropertiesLoaderTest.java @@ -23,8 +23,6 @@ public class PropertiesLoaderTest { @Before public void setUp() throws IOException { - loader = new PropertiesLoader(fileLoader); - // INSTALLATION_PROPERTIES Properties properties = new PropertiesBuilder() .property("source", "installation.properties") @@ -57,6 +55,8 @@ public void setUp() throws IOException { .property("source", "webapp.stage.properties") .toProperties(); when(fileLoader.getPropertiesFromResource("/conf/domain.gnl.properties")).thenReturn(properties); + + loader = new PropertiesLoader(fileLoader); } @Test @@ -70,14 +70,14 @@ public void shouldReadStage() throws IOException { } @Test - public void shouldLoadInstallationProperties() { + public void shouldIncludeInstallationPropertiesInConfiguration() { List propertiesList = loader.getProperties("webapp", "/conf"); - PropertiesWithSource properties = getPropertiesWithSource(propertiesList, INSTALLATION_PROPERTIES); - assertThat(properties, notNullValue()); - assertThat(loader.getStage(), is("DEV")); - assertThat(properties.getStringProperty("source"), is("installation.properties")); - assertThat(properties.getStringProperty("no-property"), nullValue()); + for (PropertiesWithSource properties : propertiesList) { + assertThat(properties.getStringProperty("source"), not("installation.properties")); + assertThat(properties.getStringProperty("int.service.domain"), nullValue()); + assertThat(properties.getStringProperty("stage"), nullValue()); + } } @Test @@ -99,6 +99,8 @@ public void shouldNotLoadDevOverrideSystemWebappPropertiesIfNotDevStage() { .toProperties(); when(fileLoader.getPropertiesFromFile("/etc/gu/installation.properties")).thenReturn(installation); + loader = new PropertiesLoader(fileLoader); + List propertiesList = loader.getProperties("webapp", "/conf"); PropertiesWithSource properties = getPropertiesWithSource(propertiesList, DEV_SYSTEM_WEBAPP_PROPERTIES); diff --git a/src/test/java/com/gu/conf/PropertiesSourceTest.java b/src/test/java/com/gu/conf/PropertiesSourceTest.java index d4eb178..39ceecd 100644 --- a/src/test/java/com/gu/conf/PropertiesSourceTest.java +++ b/src/test/java/com/gu/conf/PropertiesSourceTest.java @@ -10,7 +10,6 @@ public class PropertiesSourceTest { @Test public void shouldCompareInPrecendenceOrder() { - assertThat(INSTALLATION_PROPERTIES.compareTo(DEV_SYSTEM_WEBAPP_PROPERTIES), greaterThan(0)); assertThat(DEV_SYSTEM_WEBAPP_PROPERTIES.compareTo(SYSTEM_WEBAPP_PROPERTIES), greaterThan(0)); assertThat(SYSTEM_WEBAPP_PROPERTIES.compareTo(WEBAPP_GLOBAL_PROPERTIES), greaterThan(0)); assertThat(WEBAPP_GLOBAL_PROPERTIES.compareTo(WEBAPP_STAGE_PROPERTIES), greaterThan(0));