Skip to content

Commit

Permalink
[Daithi] /etc/gu/installation.properties should not be available to a…
Browse files Browse the repository at this point in the history
…pplications.
  • Loading branch information
daithiocrualaoich committed Feb 17, 2010
1 parent b6b2301 commit 6fca379
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/gu/conf/ConfigurationFactory.java
Expand Up @@ -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<PropertiesWithSource> properties = propertiesLocator.getProperties(applicationName, webappConfDirectory);
PropertiesLoader propertiesLoader = new PropertiesLoader();
List<PropertiesWithSource> properties = propertiesLoader.getProperties(applicationName, webappConfDirectory);

Configuration configuration = new Configuration(properties);
LOG.info(String.format("Configured webapp %s with properties:\n\n%s", applicationName, configuration));
Expand Down
28 changes: 10 additions & 18 deletions src/main/java/com/gu/conf/PropertiesLoader.java
Expand Up @@ -12,31 +12,34 @@ 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());
}

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<PropertiesWithSource> getProperties(String applicationName, String webappConfDirectory) {
List<PropertiesWithSource> properties = new LinkedList<PropertiesWithSource>();

PropertiesWithSource installationProperties = getInstallationProperties();
properties.add(installationProperties);

String stage = getStage();
if (StringUtils.isBlank(stage)) {
LOG.warn("'stage' variable unavailable from " + INSTALLATION_PROPERTIES_FILE);
Expand All @@ -51,17 +54,6 @@ List<PropertiesWithSource> 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);

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/gu/conf/PropertiesSource.java
Expand Up @@ -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;

Expand Down
4 changes: 0 additions & 4 deletions src/test/java/com/gu/conf/PropertiesBuilder.java
Expand Up @@ -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);
}
Expand Down
18 changes: 10 additions & 8 deletions src/test/java/com/gu/conf/PropertiesLoaderTest.java
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -70,14 +70,14 @@ public void shouldReadStage() throws IOException {
}

@Test
public void shouldLoadInstallationProperties() {
public void shouldIncludeInstallationPropertiesInConfiguration() {
List<PropertiesWithSource> 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
Expand All @@ -99,6 +99,8 @@ public void shouldNotLoadDevOverrideSystemWebappPropertiesIfNotDevStage() {
.toProperties();
when(fileLoader.getPropertiesFromFile("/etc/gu/installation.properties")).thenReturn(installation);

loader = new PropertiesLoader(fileLoader);

List<PropertiesWithSource> propertiesList = loader.getProperties("webapp", "/conf");
PropertiesWithSource properties = getPropertiesWithSource(propertiesList, DEV_SYSTEM_WEBAPP_PROPERTIES);

Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/gu/conf/PropertiesSourceTest.java
Expand Up @@ -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));
Expand Down

0 comments on commit 6fca379

Please sign in to comment.