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);
}
}
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);
}
}
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()));
}
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());
}
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;
}
Aggregations