use of javax.naming.Context in project aries by apache.
the class ContextManagerService method getInitialContext.
private Context getInitialContext(Map<?, ?> environment) throws NamingException {
Hashtable<?, ?> env = Utils.toHashtable(environment);
Context context = ContextHelper.getInitialContext(callerContext, env);
contexts.add(context);
return context;
}
use of javax.naming.Context in project aries by apache.
the class InitialContextTest method testURLContextErrorPropagation.
@Test
public void testURLContextErrorPropagation() throws Exception {
ObjectFactory of = new ObjectFactory() {
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
throw new Exception("doh");
}
};
registerURLObjectFactory(of, "test");
ic = initialContext();
try {
ic.lookup("test:something");
Assert.fail("Expected NamingException");
} catch (NamingException ne) {
assertNotNull(ne.getCause());
assertEquals("doh", ne.getCause().getMessage());
}
}
use of javax.naming.Context in project aries by apache.
the class InitialContextTest method dummyContext.
/**
* Creates a context that always returns the given object
* @param toReturn
* @return
*/
private Context dummyContext(Object toReturn) {
Context ctx = Skeleton.newMock(Context.class);
Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", String.class), toReturn);
Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", Name.class), toReturn);
return ctx;
}
use of javax.naming.Context in project aries by apache.
the class ObjectFactoryTest method testFactoriesThatDoUnsafeCastsAreIgnored.
@Test
public void testFactoriesThatDoUnsafeCastsAreIgnored() throws Exception {
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put("aries.object.factory.requires.reference", Boolean.TRUE);
bc.registerService(ObjectFactory.class.getName(), new ObjectFactory() {
public Object getObjectInstance(Object arg0, Name arg1, Context arg2, Hashtable<?, ?> arg3) throws Exception {
return (Reference) arg0;
}
}, props);
NamingManager.getObjectInstance("Some dummy data", null, null, env);
}
use of javax.naming.Context in project geode by apache.
the class QueryAndJtaJUnitTest method testFailedIndexUpdateOnCommitForPut.
@Test
public void testFailedIndexUpdateOnCommitForPut() throws Exception {
Person.THROW_ON_INDEX = true;
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
SimpleListener sl = new SimpleListener();
af.setCacheListener(sl);
Region region = cache.createRegion("sample", af.create());
qs.createIndex("foo", IndexType.FUNCTIONAL, "index", "/sample");
Context ctx = cache.getJNDIContext();
Integer x = new Integer(0);
region.getCache().getCacheTransactionManager().begin();
region.create(x, new Person("xyz", 45));
try {
region.getCache().getCacheTransactionManager().commit();
fail("commit should have thrown an exception because the index maintenance threw");
} catch (org.apache.geode.cache.query.IndexMaintenanceException ie) {
// this is the desired case
}
Person p = (Person) region.get(x);
assertEquals("object shouldn't have made it into region", null, p);
assertEquals(0, sl.creates);
assertEquals(0, sl.updates);
}
Aggregations