Skip to content

Commit

Permalink
Fix #143 Config file name should be configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ishubin committed Nov 16, 2014
1 parent d108278 commit 529ba46
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions config2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
galen.range.approximation = 12345
4 changes: 2 additions & 2 deletions src/main/java/net/mindengine/galen/config/GalenConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ private GalenConfig() {

private void loadConfig() throws IOException {
this.properties = new Properties();
File configFile = new File("config");
File configFile = new File(System.getProperty("galen.config.file", "config"));

if (configFile.exists()) {
if (configFile.exists() && configFile.isFile()) {
InputStream in = new FileInputStream(configFile);
properties.load(in);
in.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class GalenConfigTest {

@AfterClass
@AfterMethod
public void resetConfigToDefault() throws IOException {
deleteSystemProperty("galen.range.approximation");
deleteSystemProperty("galen.reporting.listeners");
deleteSystemProperty("galen.config.file");
GalenConfig.getConfig().reset();
}

Expand All @@ -67,6 +69,20 @@ public void resetConfigToDefault() throws IOException {
assertThat(config.getReportingListeners(), Matchers.contains("net.mindengine.CustomListener", "net.mindengine.CustomListener2"));
config.reset();
}

@Test public void shouldRead_configFile_fromSpecifiedLocation() throws IOException {

File configFile = new File("config2");
configFile.createNewFile();
FileUtils.copyFile(new File(getClass().getResource("/config2").getFile()), configFile);

System.setProperty("galen.config.file", "config2");

GalenConfig config = GalenConfig.getConfig();
config.reset();

MatcherAssert.assertThat(config.getRangeApproximation(), is(12345));
}

@Test public void shouldRead_configForLocalProject_fromSystemProperties() throws IOException {
GalenConfig config = GalenConfig.getConfig();
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/config2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
galen.range.approximation = 12345

0 comments on commit 529ba46

Please sign in to comment.