Java Code Examples for org.apache.commons.configuration2.io.FileHandler#setBasePath()
The following examples show how to use
org.apache.commons.configuration2.io.FileHandler#setBasePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 6 votes |
@Test public void testIncludeLoadCyclicalReferenceFail() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-cyclical-reference.properties"); try { handler.load(); Assert.fail("Expected " + Configuration.class.getCanonicalName()); } catch (ConfigurationException e) { // expected // e.printStackTrace(); } assertNull(pc.getString("keyA")); }
Example 2
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 6 votes |
@Test public void testIncludeLoadCyclicalMultiStepReferenceFail() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-cyclical-root.properties"); try { handler.load(); Assert.fail("Expected " + Configuration.class.getCanonicalName()); } catch (ConfigurationException e) { // expected // e.printStackTrace(); } assertNull(pc.getString("keyA")); }
Example 3
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 6 votes |
@Test public void testIncludeIncludeLoadCyclicalReferenceFail() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-include-cyclical-reference.properties"); try { handler.load(); Assert.fail("Expected " + Configuration.class.getCanonicalName()); } catch (ConfigurationException e) { // expected // e.printStackTrace(); } assertNull(pc.getString("keyA")); }
Example 4
Source File: SystemConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Sets system properties from a file specified using its base path and * file name. The file can either be a properties file or an XML properties * file. It is loaded, and all properties it contains are added to system * properties. * * @param basePath The base path to look for the property file. * @param fileName The name of the property file. * @throws ConfigurationException if an error occurs. * @since 1.6 */ public static void setSystemProperties(final String basePath, final String fileName) throws ConfigurationException { final FileBasedConfiguration config = fileName.endsWith(".xml") ? new XMLPropertiesConfiguration() : new PropertiesConfiguration(); final FileHandler handler = new FileHandler(config); handler.setBasePath(basePath); handler.setFileName(fileName); handler.load(); setSystemProperties(config); }
Example 5
Source File: TestHierarchicalXMLConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testLoadBasePath1() throws Exception { final FileHandler handler = new FileHandler(config); handler.setBasePath(TEST_DIR); handler.setFileName(TEST_FILENAME); handler.load(); configTest(config); }
Example 6
Source File: TestHierarchicalXMLConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testLoadBasePath2() throws Exception { final FileHandler handler = new FileHandler(config); handler.setBasePath(new File(TEST_FILE).getAbsoluteFile().toURI().toURL().toString()); handler.setFileName(TEST_FILENAME); handler.load(); configTest(config); }
Example 7
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testLoadViaPropertyWithBasePath() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("test.properties"); handler.load(); assertTrue("Make sure we have multiple keys", pc.getBoolean("test.boolean")); }
Example 8
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testLoadIncludeOptional() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("includeoptional.properties"); handler.load(); assertTrue("Make sure we have multiple keys", pc.getBoolean("includeoptional.loaded")); }
Example 9
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testIncludeLoadAllOnNotFound() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setIncludeListener(PropertiesConfiguration.NOOP_INCLUDE_LISTENER); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-not-found.properties"); handler.load(); assertEquals("valueA", pc.getString("keyA")); }
Example 10
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testIncludeIncludeLoadAllOnNotFound() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setIncludeListener(PropertiesConfiguration.NOOP_INCLUDE_LISTENER); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-include-not-found.properties"); handler.load(); assertEquals("valueA", pc.getString("keyA")); assertEquals("valueB", pc.getString("keyB")); }
Example 11
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testIncludeLoadAllOnLoadException() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setIncludeListener(PropertiesConfiguration.NOOP_INCLUDE_LISTENER); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-load-exception.properties"); handler.load(); assertEquals("valueA", pc.getString("keyA")); }
Example 12
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testIncludeLoadCyclicalMultiStepReferenceIgnore() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setIncludeListener(PropertiesConfiguration.NOOP_INCLUDE_LISTENER); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-cyclical-root.properties"); handler.load(); assertEquals("valueA", pc.getString("keyA")); }
Example 13
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testIncludeIncludeLoadCyclicalReferenceIgnore() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setIncludeListener(PropertiesConfiguration.NOOP_INCLUDE_LISTENER); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-include-cyclical-reference.properties"); handler.load(); assertEquals("valueA", pc.getString("keyA")); }
Example 14
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testIncludeLoadCyclicalReferenceIgnore() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); pc.setIncludeListener(PropertiesConfiguration.NOOP_INCLUDE_LISTENER); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath); handler.setFileName("include-cyclical-reference.properties"); handler.load(); assertEquals("valueA", pc.getString("keyA")); }
Example 15
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Test public void testLoadViaPropertyWithBasePath2() throws Exception { final PropertiesConfiguration pc = new PropertiesConfiguration(); final FileHandler handler = new FileHandler(pc); handler.setBasePath(testBasePath2); handler.setFileName("test.properties"); handler.load(); assertTrue("Make sure we have multiple keys", pc.getBoolean("test.boolean")); }
Example 16
Source File: TestPropertiesConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests if the base path is taken into account by the save() method. */ @Test public void testSaveWithBasePath() throws Exception { conf.setProperty("test", "true"); final FileHandler handler = new FileHandler(conf); handler.setBasePath(testSavePropertiesFile.getParentFile().toURI().toURL() .toString()); handler.setFileName(testSavePropertiesFile.getName()); handler.save(); assertTrue(testSavePropertiesFile.exists()); }