use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.
the class InitialContextTest method testLookFromLdapICF.
@Test
public void testLookFromLdapICF() throws Exception {
InitialContextFactoryBuilder icf = Skeleton.newMock(InitialContextFactoryBuilder.class);
bc.registerService(new String[] { InitialContextFactoryBuilder.class.getName(), icf.getClass().getName() }, icf, (Dictionary) new Properties());
LdapContext backCtx = Skeleton.newMock(LdapContext.class);
InitialContextFactory fac = Skeleton.newMock(InitialContextFactory.class);
Skeleton.getSkeleton(fac).setReturnValue(new MethodCall(InitialContextFactory.class, "getInitialContext", Hashtable.class), backCtx);
Skeleton.getSkeleton(icf).setReturnValue(new MethodCall(InitialContextFactoryBuilder.class, "createInitialContextFactory", Hashtable.class), fac);
Properties props = new Properties();
props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
props.put(Context.INITIAL_CONTEXT_FACTORY, "dummy.factory");
InitialLdapContext ilc = new InitialLdapContext(props, new Control[0]);
ExtendedRequest req = Skeleton.newMock(ExtendedRequest.class);
ilc.extendedOperation(req);
Skeleton.getSkeleton(backCtx).assertCalled(new MethodCall(LdapContext.class, "extendedOperation", req));
}
use of org.apache.aries.unittest.mocks.MethodCall 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 org.apache.aries.unittest.mocks.MethodCall in project aries by apache.
the class ObjectFactoryTest method testSpecifiedFactoryWithMatchingFactory.
@Test
public void testSpecifiedFactoryWithMatchingFactory() throws Exception {
String testObject = "Test object";
ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
Reference ref = new Reference("dummy.class.name", factory.getClass().getName(), "");
bc.registerService(new String[] { ObjectFactory.class.getName(), factory.getClass().getName() }, factory, null);
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertEquals("The naming manager should have returned the test object", testObject, obj);
}
use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.
the class ObjectFactoryTest method testReferenceWithNoClassName.
@Test
public void testReferenceWithNoClassName() throws Exception {
String testObject = "Test object";
ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
bc.registerService(ObjectFactory.class.getName(), factory, null);
Reference ref = new Reference(null);
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertEquals("The naming manager should have returned the test object", testObject, obj);
}
use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.
the class ObjectFactoryTest method testSpecifiedFactoryWithRegisteredButNotMatchingFactory.
@Test
public void testSpecifiedFactoryWithRegisteredButNotMatchingFactory() throws Exception {
String testObject = "Test object";
ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);
Reference ref = new Reference("dummy.class.name", "dummy.factory.class.name", "");
bc.registerService(new String[] { ObjectFactory.class.getName(), factory.getClass().getName() }, factory, null);
Object obj = NamingManager.getObjectInstance(ref, null, null, env);
assertSame("The naming manager should have returned the reference object", ref, obj);
}
Aggregations