@LocalClient public class MoviesTest extends TestCase { @EJB private Movies movies; @Resource private UserTransaction userTransaction; @PersistenceContext private EntityManager entityManager; public void setUp() throws Exception { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); InitialContext initialContext = new InitialContext(p); // Here's the fun part initialContext.bind("inject", this); }
/** * @throws Exception If failed. */ @Test public void testJndi() throws Exception { IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource(); ids.setUrl("jdbc:ignite:thin://127.0.0.1"); InitialContext ic = getInitialContext(); ic.bind("ds/test", ids); IgniteJdbcThinDataSource ds = (IgniteJdbcThinDataSource)ic.lookup("ds/test"); assertTrue("Cannot looking up DataSource from JNDI", ds != null); assertEquals(ids.getUrl(), ds.getUrl()); }
/** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); initialContext = new InitialContext(); initialContext.createSubcontext("java:comp"); // This is what we need to bind to get handle of JTA's // UserTransaction. initialContext.bind("java:comp/UserTransaction", new KunderaJTAUserTransaction()); emf = Persistence.createEntityManagerFactory("couchdbJTA_pu"); pu = "couchdbJTA_pu"; super.setUpBase(((EntityManagerFactoryImpl) emf).getKunderaMetadataInstance()); em = emf.createEntityManager(); }
@Override public void bind(String name, Object obj) throws NamingException { if (this.initialContext == null) { this.defaultInitCtx.bind(name, obj); } else { this.initialContext.bind(name, obj); } }
@Override public void bind(Name name, Object obj) throws NamingException { if (this.initialContext == null) { this.defaultInitCtx.bind(name, obj); } else { this.initialContext.bind(name, obj); } }
@Override public void bind(Name name, Object obj) throws NamingException { if (this.initialContext == null) { this.defaultInitCtx.bind(name, obj); } else { this.initialContext.bind(name, obj); } }
@Override public void bind(String name, Object obj) throws NamingException { if (this.initialContext == null) { this.defaultInitCtx.bind(name, obj); } else { this.initialContext.bind(name, obj); } }
... sun.jdbc.odbc.ee.DataSource ds = new sun.jdbc.odbc.ee.DataSource(); // Provide user credentials and database name ds.setUser("scott"); ds.setPassword("tiger"); ds.setDatabaseName("dsn1"); ds.setCharSet("..."); // optional property ds.setLoginTimeout(100); // optional property // Establish initial context and bind to the datasource target InitialContext ic = new InitialContext(); ic.bind("jdbc/OdbcDB1",ds); ...
InitialContext ic = new InitialContext(); // Construct DataSource OracleConnectionPoolDataSource ds = new OracleConnectionPoolDataSource(); ds.setURL("url"); ds.setUser("username"); ds.setPassword("password"); ic.bind(DATA_SOURCE_NAME, ds);
public void initContexts() throws Exception { System.setProperty("java.naming.factory.initial", "com.oneandone.iocunit.naming.CdiTesterContextFactory"); initialContext = new InitialContext(); final BeanManager beanManager = get(BeanManager.class); initialContext.bind("java:comp/BeanManager", beanManager); this.creationalContexts = new CreationalContexts(beanManager); postStartupActions(); }
private void bindInternally(String bindName, Reference reference) throws NamingException { try { initialContextInitializer.getInitialContext().bind(bindName, reference); } catch (NameAlreadyBoundException e) { initialContextInitializer.getInitialContext().rebind(bindName, reference); } bindings.put(bindName, reference); }
public static void setupInitialContext() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("jdbc"); PGSimpleDataSource ds = new PGSimpleDataSource(); ds.setDatabaseName("postgres"); ds.setUser("postgres"); ds.setPassword("admin"); ic.bind("jdbc/something", ds); }
public static void bindInJNDI( String name ) throws NamingException { // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.commons.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.bind("java:/" + name, dataSource); }
/** * {@inheritDoc} */ public void bind(String name, Object value) throws NamingException { if (isInitialContextInitializerCall()) { super.bind(name, value); return; } getContext().bind(name, value); }
protected void doBind(Name n, Object obj) throws NamingException { LOG.trace(format("binding obj [%s] into name [%s] %d", obj, n, n.size())); // create context for all except for the last cause that is the name where we // want to bind our obj createContextForBinding(n.getPrefix(n.size()-1)); initialContext.bind(n, obj); }
/** * {@inheritDoc} */ public void bind(Name name, Object value) throws NamingException { if (isInitialContextInitializerCall()) { super.bind(nameToString(name), value); return; } getContext().bind(name, value); }
@BeforeClass public void bindDatasourceInJndi() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, DummyContextFactory.class.getName()); ds = new DummyDataSource(); ds.start(); InitialContext ic = new InitialContext(); ic.bind(getDatasourceLocation(), ds); assert ic.lookup(getDatasourceLocation()) instanceof DummyDataSource; }
@Test public void testBasicBindAndLookup(){ AnInterface foo = new AClass(); try { InitialContext ic = new InitialContext(); ic.bind("service",foo); //no context is available/initialized fail(); } catch (NamingException e) { //expected } }
@Test public void testBindAndLookup() throws Exception { InitialContext ic = new MockInitialContext(); String name = "global/service/AClass"; Object obj = ic.lookup(name); assertNull(obj); AnInterface k = new AClass(); ic.bind(name, k); Object res = ic.lookup(name); assertEquals(k, res); }
@Test public void testBindingFailClass() throws Exception{ InitialContext ic = new MockInitialContext(); String name = "global/service/AClass!aClassThatDoesNotExist"; AnInterface k = new AClass(); try { ic.bind(name, k); fail(); } catch (NamingException e){ //expected } }