public static Map<String, String> loadProperties() throws IOException { Map<String, String> result = new TreeMap<>(); String configFile = System.getProperty("config"); if (configFile != null) { result.putAll(loadPropertiesFrom(configFile)); } result.putAll(getSystemProperties()); return ImmutableSortedMap.copyOf(result); }
@Test public void testLoadsFromSystemProperties() throws IOException { System.setProperty("test", "foo"); ConfigurationLoader loader = new ConfigurationLoader(); Map<String, String> properties = loader.loadProperties(); assertEquals(properties.get("test"), "foo"); System.getProperties().remove("test"); }
ConfigurationLoader loader = new ConfigurationLoader(); requiredProperties = loader.loadPropertiesFrom(configFile);
@Test public void testLoadsFromSystemProperties() throws IOException { System.setProperty("test", "foo"); Map<String, String> properties = loadProperties(); assertEquals(properties.get("test"), "foo"); System.getProperties().remove("test"); }
@Test public void testLoadsFromSystemProperties() throws IOException { System.setProperty("test", "foo"); Map<String, String> properties = loadProperties(); assertEquals(properties.get("test"), "foo"); System.getProperties().remove("test"); }
public static Map<String, String> loadProperties() throws IOException { Map<String, String> result = new TreeMap<>(); String configFile = System.getProperty("config"); if (configFile != null) { result.putAll(loadPropertiesFrom(configFile)); } result.putAll(getSystemProperties()); return ImmutableSortedMap.copyOf(result); }
@Test public void testLoadsFromFile() throws IOException { final File file = File.createTempFile("config", ".properties", tempDir); PrintStream out = new PrintStream(new FileOutputStream(file)); try { out.print("test: foo"); } catch (Exception e) { out.close(); } System.setProperty("config", file.getAbsolutePath()); ConfigurationLoader loader = new ConfigurationLoader(); Map<String, String> properties = loader.loadProperties(); assertEquals(properties.get("test"), "foo"); assertEquals(properties.get("config"), file.getAbsolutePath()); System.getProperties().remove("config"); }
@Test public void testLoadsFromFile() throws IOException { final File file = File.createTempFile("config", ".properties", tempDir); PrintStream out = new PrintStream(new FileOutputStream(file)); try { out.print("test: foo"); } catch (Exception e) { out.close(); } System.setProperty("config", file.getAbsolutePath()); Map<String, String> properties = loadProperties(); assertEquals(properties.get("test"), "foo"); assertEquals(properties.get("config"), file.getAbsolutePath()); System.getProperties().remove("config"); }
public Map<String, String> loadProperties() throws IOException { Map<String, String> result = Maps.newTreeMap(); String configFile = System.getProperty("config"); if (configFile != null) { result.putAll(loadPropertiesFrom(configFile)); } result.putAll(getSystemProperties()); return ImmutableSortedMap.copyOf(result); }
@Test public void testSystemOverridesFile() throws IOException { final File file = File.createTempFile("config", ".properties", tempDir); PrintStream out = new PrintStream(new FileOutputStream(file)); try { out.println("key1: original"); out.println("key2: original"); } catch (Exception e) { out.close(); } System.setProperty("config", file.getAbsolutePath()); System.setProperty("key1", "overridden"); ConfigurationLoader loader = new ConfigurationLoader(); Map<String, String> properties = loader.loadProperties(); assertEquals(properties.get("config"), file.getAbsolutePath()); assertEquals(properties.get("key1"), "overridden"); assertEquals(properties.get("key2"), "original"); System.getProperties().remove("config"); } }
@Test public void testLoadsFromFile() throws IOException { final File file = File.createTempFile("config", ".properties", tempDir); PrintStream out = new PrintStream(new FileOutputStream(file)); try { out.print("test: foo"); } catch (Exception e) { out.close(); } System.setProperty("config", file.getAbsolutePath()); Map<String, String> properties = loadProperties(); assertEquals(properties.get("test"), "foo"); assertEquals(properties.get("config"), file.getAbsolutePath()); System.getProperties().remove("config"); }
String configFile = System.getProperty("config"); if (configFile != null) { requiredProperties = loadPropertiesFrom(configFile); properties.putAll(getSystemProperties()); properties = ImmutableSortedMap.copyOf(properties);
@Test public void testSystemOverridesFile() throws IOException { final File file = File.createTempFile("config", ".properties", tempDir); PrintStream out = new PrintStream(new FileOutputStream(file)); try { out.println("key1: original"); out.println("key2: original"); } catch (Exception e) { out.close(); } System.setProperty("config", file.getAbsolutePath()); System.setProperty("key1", "overridden"); Map<String, String> properties = loadProperties(); assertEquals(properties.get("config"), file.getAbsolutePath()); assertEquals(properties.get("key1"), "overridden"); assertEquals(properties.get("key2"), "original"); System.getProperties().remove("config"); } }
String configFile = System.getProperty("config"); if (configFile != null) { requiredProperties = loadPropertiesFrom(configFile); properties.putAll(getSystemProperties()); properties = ImmutableSortedMap.copyOf(properties);
@Test public void testSystemOverridesFile() throws IOException { final File file = File.createTempFile("config", ".properties", tempDir); PrintStream out = new PrintStream(new FileOutputStream(file)); try { out.println("key1: original"); out.println("key2: original"); } catch (Exception e) { out.close(); } System.setProperty("config", file.getAbsolutePath()); System.setProperty("key1", "overridden"); Map<String, String> properties = loadProperties(); assertEquals(properties.get("config"), file.getAbsolutePath()); assertEquals(properties.get("key1"), "overridden"); assertEquals(properties.get("key2"), "original"); System.getProperties().remove("config"); } }