List of usage examples for org.apache.commons.configuration Configuration setProperty
void setProperty(String key, Object value);
From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphTest.java
@Test(expected = IllegalStateException.class) public void shouldRequireGraphLocationIfFormatIsSet() { final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphml"); TinkerGraph.open(conf);//from www .j av a 2s . c o m }
From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphTest.java
@Test(expected = IllegalStateException.class) public void shouldRequireGraphFormatIfLocationIsSet() { final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, TestHelper.makeTestDataDirectory(TinkerGraphTest.class)); TinkerGraph.open(conf);/*from ww w . ja v a 2 s. com*/ }
From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphTest.java
@Test public void shouldPersistToGraphML() { final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGraphML.xml"; final File f = new File(graphLocation); if (f.exists() && f.isFile()) f.delete();//from w w w . ja v a 2s .c om final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphml"); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation); final TinkerGraph graph = TinkerGraph.open(conf); TinkerFactory.generateModern(graph); graph.close(); final TinkerGraph reloadedGraph = TinkerGraph.open(conf); IoTest.assertModernGraph(reloadedGraph, true, true); reloadedGraph.close(); }
From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphTest.java
@Test public void shouldPersistToGraphSON() { final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGraphSON.json"; final File f = new File(graphLocation); if (f.exists() && f.isFile()) f.delete();/* ww w .j av a 2s. c o m*/ final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphson"); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation); final TinkerGraph graph = TinkerGraph.open(conf); TinkerFactory.generateModern(graph); graph.close(); final TinkerGraph reloadedGraph = TinkerGraph.open(conf); IoTest.assertModernGraph(reloadedGraph, true, false); reloadedGraph.close(); }
From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphTest.java
@Test public void shouldPersistToGryo() { final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGryo.kryo"; final File f = new File(graphLocation); if (f.exists() && f.isFile()) f.delete();//from w w w. ja v a 2s. c o m final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo"); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation); final TinkerGraph graph = TinkerGraph.open(conf); TinkerFactory.generateModern(graph); graph.close(); final TinkerGraph reloadedGraph = TinkerGraph.open(conf); IoTest.assertModernGraph(reloadedGraph, true, false); reloadedGraph.close(); }
From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphTest.java
@Test public void shouldPersistToAnyGraphFormat() { final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToAnyGraphFormat.dat"; final File f = new File(graphLocation); if (f.exists() && f.isFile()) f.delete();/*ww w .j av a 2 s. c o m*/ final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, TestIoBuilder.class.getName()); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation); final TinkerGraph graph = TinkerGraph.open(conf); TinkerFactory.generateModern(graph); //Test write graph graph.close(); assertEquals(TestIoBuilder.calledRegistry, 1); assertEquals(TestIoBuilder.calledGraph, 1); assertEquals(TestIoBuilder.calledCreate, 1); try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f))) { os.write("dummy string".getBytes()); } catch (Exception e) { e.printStackTrace(); } //Test read graph final TinkerGraph readGraph = TinkerGraph.open(conf); assertEquals(TestIoBuilder.calledRegistry, 1); assertEquals(TestIoBuilder.calledGraph, 1); assertEquals(TestIoBuilder.calledCreate, 1); }
From source file:org.apache.torque.JndiConfigurationTest.java
/** * Binds a DataSource to the jndi and checks that we have successfully * bound it. Then Torque is configured to lookup the DataSource in jndi, * and it is checked if Torque can read from the database. Finally, * the DataSource is closed and unbound. * @throws Exception if the test fails/* w w w .ja v a 2 s .c o m*/ */ public void testExternalBindTorqueLookup() throws Exception { // compose the correct configuration Configuration torqueConfiguration = getTorqueConfiguraton(); String defaultDatabase = getDefaultDatabase(torqueConfiguration); // remove the dsfactory configuration from the configuration { Configuration dsfactoryConfiguration = torqueConfiguration .subset(Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase); dsfactoryConfiguration.clear(); } // add the jndi configuration to the configuration torqueConfiguration.setProperty(Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + DataSourceFactory.FACTORY_KEY, JndiDataSourceFactory.class.getName()); torqueConfiguration.setProperty(Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + JndiDataSourceFactory.JNDI_KEY + "." + JndiDataSourceFactory.PATH_KEY, JNDI_PATH); torqueConfiguration.setProperty( Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + JndiDataSourceFactory.JNDI_KEY + "." + Context.INITIAL_CONTEXT_FACTORY, org.apache.naming.java.javaURLContextFactory.class.getName()); //System.out.println("Configuration for testExternalBindTorqueLookup:"); //debugConfiguration(torqueConfiguration); //System.out.println(); try { // bind datasource and check bind. bindDataSource(); BasicDataSource dataSource = retrieveDataSource(); dataSourceConnect(dataSource); if (Torque.isInit()) { Torque.shutdown(); } // initialize torque with the created configuration // and check that we can connect to the database. try { Torque.init(torqueConfiguration); torqueConnect(); } finally { Torque.shutdown(); } } finally { unbindDataSource(); } }
From source file:org.apache.torque.JndiConfigurationTest.java
/** * Binds a DataSource to the jndi and checks that we have successfully * bound it. Then Torque is configured to lookup the DataSource in jndi, * and it is checked if Torque can read from the database. Finally, * the DataSource is closed and unbound. * @throws Exception if the test fails// w ww .j av a 2 s . c o m */ public void testTorqueBindTorqueLookup() throws Exception { // compose the correct configuration Configuration torqueConfiguration = getTorqueConfiguraton(); String defaultDatabase = getDefaultDatabase(torqueConfiguration); // add the jndi configuration to the configuration torqueConfiguration.setProperty(Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + DataSourceFactory.FACTORY_KEY, JndiDataSourceFactory.class.getName()); torqueConfiguration.setProperty(Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + JndiDataSourceFactory.JNDI_KEY + "." + JndiDataSourceFactory.PATH_KEY, JNDI_PATH); torqueConfiguration.setProperty( Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + JndiDataSourceFactory.JNDI_KEY + "." + Context.INITIAL_CONTEXT_FACTORY, org.apache.naming.java.javaURLContextFactory.class.getName()); // add the datasource configuration torqueConfiguration.setProperty( Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + JndiDataSourceFactory.DATASOURCE_KEY + "." + JndiDataSourceFactory.CLASSNAME_KEY, BasicDataSource.class.getName()); { Map tempStore = new HashMap(); Configuration connectionConfiguration = torqueConfiguration .subset(Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + AbstractDataSourceFactory.CONNECTION_KEY); for (Iterator keyIt = connectionConfiguration.getKeys(); keyIt.hasNext();) { String key = (String) keyIt.next(); String value = connectionConfiguration.getString(key); if ("user".equals(key)) { // setUser() in SharedPoolDataSouce corresponds to // setUsername() in BasicDataSourceFactory key = "username"; } else if ("driver".equals(key)) { // setDriver() in SharedPoolDataSouce corresponds to // setDriverClassName() in BasicDataSourceFactory key = "driverClassName"; } tempStore.put(Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + JndiDataSourceFactory.DATASOURCE_KEY + "." + key, value); } // add the new keys for (Iterator keyIt = tempStore.keySet().iterator(); keyIt.hasNext();) { String key = (String) keyIt.next(); String value = (String) tempStore.get(key); torqueConfiguration.setProperty(key, value); } // remove the configuration for the original datasource connectionConfiguration.clear(); Configuration poolConfiguration = torqueConfiguration .subset(Torque.TORQUE_KEY + "." + DataSourceFactory.DSFACTORY_KEY + "." + defaultDatabase + "." + AbstractDataSourceFactory.POOL_KEY); poolConfiguration.clear(); } //System.out.println("Configuration for testTorqueBindTorqueLookup:"); //debugConfiguration(torqueConfiguration); //System.out.println(); try { // initialize torque with the created configuration // and check that we can connect to the database. try { Torque.init(torqueConfiguration); torqueConnect(); } finally { Torque.shutdown(); } } finally { unbindDataSource(); } }
From source file:org.apache.torque.oid.IDBrokerTest.java
/** * Tests that cleverQuantity increases the quantity value * after an unscheduled retrieval.//from w ww . j av a 2 s .co m * * @throws Exception if the test fails */ public void testCleverQuantityValue() throws Exception { log.trace("testCleverQuantityValue(): start"); Configuration configuration = new PropertiesConfiguration(); configuration.setProperty("idbroker.clever.quantity", "true"); idBroker.start(); idBroker.setConfiguration(configuration); Connection connection = Transaction.begin(); for (int i = 1; i <= 11; ++i) { int id = idBroker.getIdAsInt(connection, AuthorPeer.TABLE_NAME); log.trace("testCleverQuantityValue(): retrieved id " + id); } assertTrue(new BigDecimal("10").compareTo(idBroker.getQuantity(AuthorPeer.TABLE_NAME)) < 0); Transaction.commit(connection); }
From source file:org.apache.torque.oid.IDBrokerTest.java
/** * Tests that the quantity is not increased above cleverQuantityMax. * * @throws Exception if the test fails// ww w . j a va 2s. c o m */ public void testCleverQuantityValueMax() throws Exception { log.trace("testCleverQuantityValueMax(): start"); Configuration configuration = new PropertiesConfiguration(); configuration.setProperty("idbroker.clever.quantity", "true"); configuration.setProperty("idbroker.clever.quantity.max", "14"); idBroker.start(); idBroker.setConfiguration(configuration); Connection connection = Transaction.begin(); for (int i = 1; i <= 11; ++i) { int id = idBroker.getIdAsInt(connection, AuthorPeer.TABLE_NAME); log.trace("testCleverQuantityValueMax(): retrieved id " + id); } assertTrue(new BigDecimal("14").compareTo(idBroker.getQuantity(AuthorPeer.TABLE_NAME)) <= 0); Transaction.commit(connection); }