Search in sources :

Example 46 with InitialContext

use of javax.naming.InitialContext in project mybatis-3 by mybatis.

the class JndiDataSourceFactoryTest method createJndiDataSource.

private void createJndiDataSource() throws Exception {
    try {
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, TEST_INITIAL_CONTEXT_FACTORY);
        MockContext ctx = new MockContext(false);
        ctx.bind(TEST_DATA_SOURCE, expectedDataSource);
        InitialContext initCtx = new InitialContext(env);
        initCtx.bind(TEST_INITIAL_CONTEXT, ctx);
    } catch (NamingException e) {
        throw new DataSourceException("There was an error configuring JndiDataSourceTransactionPool. Cause: " + e, e);
    }
}
Also used : DataSourceException(org.apache.ibatis.datasource.DataSourceException) Hashtable(java.util.Hashtable) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 47 with InitialContext

use of javax.naming.InitialContext in project mybatis-3 by mybatis.

the class JndiDataSourceFactory method setProperties.

@Override
public void setProperties(Properties properties) {
    try {
        InitialContext initCtx;
        Properties env = getEnvProperties(properties);
        if (env == null) {
            initCtx = new InitialContext();
        } else {
            initCtx = new InitialContext(env);
        }
        if (properties.containsKey(INITIAL_CONTEXT) && properties.containsKey(DATA_SOURCE)) {
            Context ctx = (Context) initCtx.lookup(properties.getProperty(INITIAL_CONTEXT));
            dataSource = (DataSource) ctx.lookup(properties.getProperty(DATA_SOURCE));
        } else if (properties.containsKey(DATA_SOURCE)) {
            dataSource = (DataSource) initCtx.lookup(properties.getProperty(DATA_SOURCE));
        }
    } catch (NamingException e) {
        throw new DataSourceException("There was an error configuring JndiDataSourceTransactionPool. Cause: " + e, e);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) DataSourceException(org.apache.ibatis.datasource.DataSourceException) NamingException(javax.naming.NamingException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource)

Example 48 with InitialContext

use of javax.naming.InitialContext in project powermock by powermock.

the class EqualsMockingTest method shouldStubEquals.

@Test
public void shouldStubEquals() throws Exception {
    stub(method(InitialContext.class, "equals")).toReturn(true);
    final InitialContext context = new InitialContext();
    assertTrue(context.equals(new Object()));
}
Also used : InitialContext(javax.naming.InitialContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 49 with InitialContext

use of javax.naming.InitialContext in project powermock by powermock.

the class HashCodeTest method shouldStubHashCode.

@Test
public void shouldStubHashCode() throws Exception {
    stub(method(InitialContext.class, "hashCode")).toReturn(EXPECTED_HASH);
    final InitialContext context = new InitialContext();
    assertEquals(EXPECTED_HASH, context.hashCode());
}
Also used : InitialContext(javax.naming.InitialContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 50 with InitialContext

use of javax.naming.InitialContext in project platformlayer by platformlayer.

the class GuiceDataSourceProvider method bindJndi.

public static Provider<? extends DataSource> bindJndi(final String key) {
    Provider<DataSource> provider = new Provider<DataSource>() {

        @Override
        public DataSource get() {
            try {
                InitialContext context = new InitialContext();
                DataSource dataSource = (DataSource) context.lookup(key);
                return dataSource;
            } catch (NamingException e) {
                throw new IllegalStateException("Error getting JDNI connection: " + key, e);
            }
        }
    };
    return provider;
}
Also used : NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) Provider(com.google.inject.Provider) DataSource(javax.sql.DataSource)

Aggregations

InitialContext (javax.naming.InitialContext)1068 Test (org.junit.Test)325 EJBException (javax.ejb.EJBException)228 Properties (java.util.Properties)213 Context (javax.naming.Context)194 RemoteException (java.rmi.RemoteException)173 TestFailureException (org.apache.openejb.test.TestFailureException)172 NamingException (javax.naming.NamingException)168 AssertionFailedError (junit.framework.AssertionFailedError)168 JMSException (javax.jms.JMSException)167 RemoveException (javax.ejb.RemoveException)66 CreateException (javax.ejb.CreateException)57 DataSource (javax.sql.DataSource)55 Hashtable (java.util.Hashtable)54 Assembler (org.apache.openejb.assembler.classic.Assembler)47 EjbJar (org.apache.openejb.jee.EjbJar)41 NameNotFoundException (javax.naming.NameNotFoundException)40 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)38 Connection (java.sql.Connection)37 StatelessBean (org.apache.openejb.jee.StatelessBean)30