/** * Add a configuration resource. The properties form this configuration will * overwrite corresponding already loaded property and system property * * @param configFile * Configuration file. */ public void addConfiguration(File configFile) throws ConfigException { LOG.info("Reading configuration from: {}", configFile.getAbsolutePath()); try { configFile = (new VerifyingFileFactory.Builder(LOG).warnForRelativePath().failForNonExistingPath().build()) .validate(configFile); Properties cfg = new Properties(); FileInputStream in = new FileInputStream(configFile); try { cfg.load(in); } finally { in.close(); } parseProperties(cfg); } catch (IOException | IllegalArgumentException e) { LOG.error("Error while configuration from: {}", configFile.getAbsolutePath(), e); throw new ConfigException("Error while processing " + configFile.getAbsolutePath(), e); } }
String clientPortAddress = null; String secureClientPortAddress = null; VerifyingFileFactory vff = new VerifyingFileFactory.Builder(LOG).warnForRelativePath().build(); for (Entry<Object, Object> entry : zkProp.entrySet()) { String key = entry.getKey().toString().trim();
File configFile = (new VerifyingFileFactory.Builder(LOG) .warnForRelativePath() .failForNonExistingPath()
return; File configFile = (new VerifyingFileFactory.Builder(LOG) .warnForRelativePath() .failForNonExistingPath() .build()).create(configFileStr); final File dynamicFile = (new VerifyingFileFactory.Builder(LOG) .warnForRelativePath() .failForNonExistingPath()
@Test public void testForNoWarningOnIntendedRelativePath() { VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) .warnForRelativePath().build(); vff.create("./an/intended/relative/path"); // assertFalse(log.hasWarned); }
@Test public void testForWarningOnRelativePath() { VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) .warnForRelativePath().build(); vff.create("a/relative/path"); // assertTrue(log.hasWarned); }
@Test(expected=IllegalArgumentException.class) public void testForFailForNonExistingPath() { VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) .failForNonExistingPath().build(); vff.create("/I/H0p3/this/path/d035/n0t/ex15t"); }
@Test public void testFileHasCorrectPath() { File file = new File("/some/path"); VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log).build(); assertEquals(file, vff.create(file.getPath())); } }