@After public void tearDown() throws Exception { HashMap<String, String> newenv = new HashMap<>(); newenv.put(CONFIG_ENV_VAR, ""); setEnv(newenv); }
@Test public void testGetProperties() throws Exception { String pathToProperties = this.getClass().getClassLoader().getResource("config-service-unit-test.properties").toURI().getPath(); Map<String,String> newEnv = new HashMap<>(); newEnv.put(CONFIG_ENV_VAR, pathToProperties); setEnv(newEnv); Properties properties = _service.getConfigProperties(); assertTrue(StringUtils.equals( properties.getProperty("foo.zookeeper.quorum"), "bar.test.local") ); assertTrue(StringUtils.equals( properties.getProperty("foo.zookeeper.port"), "2222") ); assertTrue(StringUtils.equals( properties.getProperty("foo.master"), "bar.test.local:33333") ); assertTrue(StringUtils.equals( properties.getProperty("drilldown.endpoint"), "http://some.host/some.data/") ); }
@Test(expected = ConfigException.class) public void testGetProperties_invalidPathToPropertiesInEnvVar() throws Exception { Map<String,String> newEnv = new HashMap<>(); newEnv.put(CONFIG_ENV_VAR, "invalid/path/to.properties"); setEnv(newEnv); Properties properties = _service.getConfigProperties(); assertNull(properties.get( "foo.zookeeper.quorum" )); }
@Test public void testReplaceProperties_envVarIsNull_usesDefaultReplacements() throws Exception { HashMap<String, String> newenv = new HashMap<>(); newenv.put(CONFIG_ENV_VAR, ""); setEnv(newenv); Properties properties = _service.getConfigProperties(); assertTrue(StringUtils.equals( properties.getProperty("hbase.zookeeper.quorum"), "some.host") ); assertTrue(StringUtils.equals( properties.getProperty("hbase.zookeeper.port"), "12345") ); assertTrue(StringUtils.equals( properties.getProperty("hbase.master"), "foo") ); assertTrue(StringUtils.equals( properties.getProperty("drilldown.endpoint"), "http://some.endpoint/somedata") ); }