List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration()
XMLConfiguration
. From source file:edu.cornell.med.icb.R.TestRConnectionPool.java
/** * Tests re-establishing connections to embedded Rserve instances. * @throws ConfigurationException/* ww w . ja v a 2 s .c om*/ * @throws RserveException */ // @Test - TODO - disabled for now since the command is different on each platform public void embeddedServer() throws ConfigurationException, RserveException { final String xml = "<RConnectionPool><RConfiguration><RServer host=\"localhost\" port=\"6312\" embedded=\"true\" command=\"C:\\\\Program\\ Files\\\\R\\\\R-2.6.0\\\\library\\\\Rserve\\\\Rserve_d.exe\"/></RConfiguration></RConnectionPool>"; final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(xml)); pool = new RConnectionPool(configuration); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections()); final RConnection connection = pool.borrowConnection(); assertNotNull(connection); assertTrue(connection.isConnected()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("The connections should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("The connections should not be idle", 0, pool.getNumberOfIdleConnections()); final RConnection newConnection = pool.reEstablishConnection(connection); assertNotNull(newConnection); assertFalse(connection.isConnected()); assertTrue(newConnection.isConnected()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("The connections should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("The connections should not be idle", 0, pool.getNumberOfIdleConnections()); pool.returnConnection(newConnection); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections()); }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests loading a non well formed XML from a string. *///from www . ja v a2s . c o m @Test(expected = ConfigurationException.class) public void testLoadInvalidXML() throws Exception { String xml = "<?xml version=\"1.0\"?><config><test>1</rest></config>"; conf = new XMLConfiguration(); conf.load(new StringReader(xml)); }
From source file:edu.cornell.med.icb.R.RUtils.java
/** * Make an an XMLConfiguration fo RConnectionPool. * @param hostname the hostname to connect to * @param port the port on localhost to connect to * @param username the username to use for the connection * @param password the password to use for the connection * @return the XMLConfiguration//from www .j a v a 2s . c o m * @throws ConfigurationException problem configuring with specified parameters */ public static XMLConfiguration makeConfiguration(final String hostname, final int port, final String username, final String password) throws ConfigurationException { final StringBuilder xml = new StringBuilder(); xml.append("<?xml version='1.0' encoding='UTF-8'?>"); xml.append("<RConnectionPool xsi:noNamespaceSchemaLocation='RConnectionPool.xsd'"); xml.append(" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"); xml.append("<RConfiguration publish='false'>"); xml.append("<RServer "); xml.append("host='").append(hostname).append("' "); xml.append("port='").append(port).append("' "); if (username != null) { xml.append("username='").append(username).append("' "); } if (password != null) { xml.append("password='").append(password).append("' "); } xml.append("/>"); xml.append("</RConfiguration>"); xml.append("</RConnectionPool>"); final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(xml.toString())); return configuration; }
From source file:io.datalayer.conf.XmlConfigurationTest.java
@Test public void testAddProperty() { // add a property to a non initialized xml configuration XMLConfiguration config = new XMLConfiguration(); config.addProperty("test.string", "hello"); assertEquals("'test.string'", "hello", config.getString("test.string")); }
From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java
/** * Run the void readConfig() method test. * /*from w w w .ja va2s . c om*/ * @throws Exception * * @generatedBy CodePro at 9/3/14 3:44 PM */ @Test public void testReadConfig_4() throws Exception { MailMessageConfig fixture = new MailMessageConfig(); fixture.config = new XMLConfiguration(); fixture.configFile = new File(""); fixture.readConfig(); // An unexpected exception was thrown in user code while executing this test: // java.lang.SecurityException: Cannot write to files while generating test cases // at // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76) // at java.io.FileOutputStream.<init>(FileOutputStream.java:209) // at java.io.FileOutputStream.<init>(FileOutputStream.java:171) // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490) // at // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204) // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63) // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71) }
From source file:io.datalayer.conf.XmlConfigurationTest.java
@Test public void testSave() throws Exception { // add an array of strings to the configuration conf.addProperty("string", "value1"); for (int i = 1; i < 5; i++) { conf.addProperty("test.array", "value" + i); }/*from w w w . j a va 2 s. c om*/ // add an array of strings in an attribute for (int i = 1; i < 5; i++) { conf.addProperty("test.attribute[@array]", "value" + i); } // add comma delimited lists with escaped delimiters conf.addProperty("split.list5", "a\\,b\\,c"); conf.setProperty("element3", "value\\,value1\\,value2"); conf.setProperty("element3[@name]", "foo\\,bar"); // save the configuration conf.save(testSaveConf.getAbsolutePath()); // read the configuration and compare the properties XMLConfiguration checkConfig = new XMLConfiguration(); checkConfig.setFileName(testSaveConf.getAbsolutePath()); checkSavedConfig(checkConfig); }
From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java
/** * Run the void readConfig() method test. * /*from ww w .ja v a2s. c o m*/ * @throws Exception * * @generatedBy CodePro at 9/3/14 3:44 PM */ @Test public void testReadConfig_5() throws Exception { MailMessageConfig fixture = new MailMessageConfig(); fixture.config = new XMLConfiguration(); fixture.configFile = new File(""); fixture.readConfig(); // An unexpected exception was thrown in user code while executing this test: // java.lang.SecurityException: Cannot write to files while generating test cases // at // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76) // at java.io.FileOutputStream.<init>(FileOutputStream.java:209) // at java.io.FileOutputStream.<init>(FileOutputStream.java:171) // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490) // at // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204) // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63) // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71) }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests saving to a URL.//www . j av a 2 s . c o m */ @Test public void testSaveToURL() throws Exception { conf.save(testSaveConf.toURI().toURL()); XMLConfiguration checkConfig = new XMLConfiguration(); checkConfig.setFile(testSaveConf); checkSavedConfig(checkConfig); }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests saving to a stream./*from w w w. j a va 2 s.co m*/ */ @Test public void testSaveToStream() throws Exception { assertNull(conf.getEncoding()); conf.setEncoding("UTF8"); FileOutputStream out = null; try { out = new FileOutputStream(testSaveConf); conf.save(out); } finally { if (out != null) { out.close(); } } XMLConfiguration checkConfig = new XMLConfiguration(); checkConfig.setFile(testSaveConf); checkSavedConfig(checkConfig); try { out = new FileOutputStream(testSaveConf); conf.save(out, "UTF8"); } finally { if (out != null) { out.close(); } } checkConfig.clear(); checkSavedConfig(checkConfig); }
From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java
/** * Run the void readConfig() method test. * //from ww w.ja v a 2 s . com * @throws Exception * * @generatedBy CodePro at 9/3/14 3:44 PM */ @Test public void testReadConfig_6() throws Exception { MailMessageConfig fixture = new MailMessageConfig(); fixture.config = new XMLConfiguration(); fixture.configFile = new File(""); fixture.readConfig(); // An unexpected exception was thrown in user code while executing this test: // java.lang.SecurityException: Cannot write to files while generating test cases // at // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76) // at java.io.FileOutputStream.<init>(FileOutputStream.java:209) // at java.io.FileOutputStream.<init>(FileOutputStream.java:171) // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490) // at // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204) // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63) // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71) }