List of usage examples for javax.naming Reference Reference
public Reference(String className)
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//*from ww w . j av a2 s . c o m*/ public void testGetObjectInstance_WrongClass() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnblds"); // // not javax.sql.DataSource --> exception // Reference ref = new Reference("javax.sql.DataSourceeeee"); Object result = null; boolean exception = false; try { result = dataSourceFactory.getObjectInstance(ref, name, context, environment); } catch (NamingException e) { exception = true; } assertTrue(exception); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. */// w ww .j av a 2 s .c o m public void testGetObjectInstance_WitWrongJNDIName() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnbl"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr url = new StringRefAddr("url", "jdbc:hsqldb:hsql://localhost/funambol"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (BasicDataSource) result; assertNull(bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); // // These are read from the db.xml since there is not the fnbl.xml file // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//* ww w . j a v a 2 s . c om*/ public void testGetObjectInstance_fnblds() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnblds"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr minIdle = new StringRefAddr("minIdle", "3"); ref.add(minIdle); // // At the end this should be overwritten by the value in the fnblds.xml file // RefAddr url = new StringRefAddr("url", "this-is-the-url"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (BasicDataSource) result; assertEquals(3, bds.getMinIdle()); // // These are read from the db.xml // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); // // These are read from the fnblds.xml // assertEquals("", bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//* w w w. j a va 2 s .c om*/ public void testGetObjectInstance_fnblcore() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnblcore"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr minIdle = new StringRefAddr("minIdle", "3"); ref.add(minIdle); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (BasicDataSource) result; assertEquals(3, bds.getMinIdle()); // // These are read from the db.xml // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); // // These are read from the fnblds.xml // assertEquals("ss", bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *///w w w . j a v a 2 s. c o m public void testGetObjectInstance_fnbluser() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnbluser"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr userName = new StringRefAddr("minIdle", "7"); ref.add(userName); // // At the end this should be overwritten by the value in the fnblds.xml file // RefAddr url = new StringRefAddr("url", "this-is-the-url"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (BasicDataSource) result; assertEquals(7, bds.getMinIdle()); // // These are read from the fnbluser.xml // assertEquals("fnbluserpwd", bds.getUsername()); assertEquals("fnblpwd", bds.getPassword()); assertEquals("org.fnbluser", bds.getDriverClassName()); assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *///from ww w . ja v a 2 s .c om public void testGetObjectInstance_fnblcore_with_wrappedFactory() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnblcore"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr wrFactory = new StringRefAddr("wrappedFactory", "org.apache.commons.dbcp.BasicDataSourceFactory"); ref.add(wrFactory); RefAddr minIdle = new StringRefAddr("minIdle", "3"); ref.add(minIdle); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.commons.dbcp.BasicDataSource); org.apache.commons.dbcp.BasicDataSource bds = (org.apache.commons.dbcp.BasicDataSource) result; assertEquals(3, bds.getMinIdle()); // // These are read from the db.xml // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); // // These are read from the fnblds.xml // assertEquals("ss", bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//*from w w w. j a v a 2s . com*/ public void testGetObjectInstance_fnbluser_routing_no_partition() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnbluser-routing-nopartition"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr userName = new StringRefAddr("minIdle", "7"); ref.add(userName); // // At the end this should be overwritten by the value in the fnblds.xml file // RefAddr url = new StringRefAddr("url", "this-is-the-url"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof RoutingDataSource); BasicDataSource bds = (BasicDataSource) PrivateAccessor.getField(result, "defaultDataSource"); assertEquals(7, bds.getMinIdle()); // // These are read from the fnbluser.xml // assertEquals("fnbluserpwd", bds.getUsername()); assertEquals("fnblpwd", bds.getPassword()); assertEquals("org.fnbluser", bds.getDriverClassName()); assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl()); assertEquals(15, bds.getNumTestsPerEvictionRun()); // coming from db.xml }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. */// w w w. ja v a2 s . c o m public void testGetObjectInstance_fnbluser_routing_with_partition() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnbluser-routing-with-partition"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr userName = new StringRefAddr("minIdle", "7"); ref.add(userName); // // At the end this should be overwritten by the value in the fnblds.xml file // RefAddr url = new StringRefAddr("url", "this-is-the-url"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof RoutingDataSource); RoutingDataSource rds = (RoutingDataSource) result; rds.init(); rds.configure(); Map<String, DataSource> datasources = rds.getDataSources(); assertEquals("Wrong number of datasources", 3, datasources.size()); BasicDataSource ds1 = (BasicDataSource) datasources.get("user_part1"); assertNotNull("user_part1 must be not null", ds1); assertEquals("sa", ds1.getUsername()); assertEquals("", ds1.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part1", ds1.getUrl()); assertEquals(15, ds1.getNumTestsPerEvictionRun()); // from db.xml assertEquals(7, ds1.getMinIdle()); // set with StringRefAddr BasicDataSource ds2 = (BasicDataSource) datasources.get("user_part2"); assertNotNull("user_part2 must be not null", ds2); assertEquals("sa", ds2.getUsername()); assertEquals("", ds2.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part2", ds2.getUrl()); assertEquals(15, ds2.getNumTestsPerEvictionRun()); // from db.xml assertEquals(7, ds2.getMinIdle()); // set with StringRefAddr BasicDataSource ds3 = (BasicDataSource) datasources.get("user_part3"); assertNotNull("user_part3 must be not null", ds3); assertEquals("sa", ds3.getUsername()); assertEquals("", ds3.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part3", ds3.getUrl()); assertEquals(15, ds3.getNumTestsPerEvictionRun()); // from db.xml assertEquals(7, ds3.getMinIdle()); // set with StringRefAddr BasicDataSource bds = (BasicDataSource) PrivateAccessor.getField(result, "defaultDataSource"); assertEquals(7, bds.getMinIdle()); // // These are read from the fnbluser.xml // assertEquals("fnbluserpartition", bds.getUsername()); assertEquals("fnblpwd", bds.getPassword()); assertEquals("org.fnbluser", bds.getDriverClassName()); assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl()); assertTrue(rds.getPartitioningCriteria() instanceof MockPartitioningCriteria); }
From source file:org.jzkit.search.util.RecordConversion.FragmentTransformerService.java
public Reference getReference() throws NamingException { return new Reference(FragmentTransformerService.class.getName()); }