Search in sources :

Example 11 with MethodCall

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));
}
Also used : InitialContextFactoryBuilder(javax.naming.spi.InitialContextFactoryBuilder) Hashtable(java.util.Hashtable) ExtendedRequest(javax.naming.ldap.ExtendedRequest) InitialLdapContext(javax.naming.ldap.InitialLdapContext) Properties(java.util.Properties) InitialContextFactory(javax.naming.spi.InitialContextFactory) MethodCall(org.apache.aries.unittest.mocks.MethodCall) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Example 12 with MethodCall

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;
}
Also used : InitialLdapContext(javax.naming.ldap.InitialLdapContext) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) BundleContext(org.osgi.framework.BundleContext) LdapContext(javax.naming.ldap.LdapContext) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Name(javax.naming.Name)

Example 13 with MethodCall

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);
}
Also used : BundleContext(org.osgi.framework.BundleContext) Context(javax.naming.Context) ObjectFactory(javax.naming.spi.ObjectFactory) Hashtable(java.util.Hashtable) Reference(javax.naming.Reference) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Name(javax.naming.Name) Test(org.junit.Test)

Example 14 with MethodCall

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);
}
Also used : BundleContext(org.osgi.framework.BundleContext) Context(javax.naming.Context) ObjectFactory(javax.naming.spi.ObjectFactory) Hashtable(java.util.Hashtable) Reference(javax.naming.Reference) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Name(javax.naming.Name) Test(org.junit.Test)

Example 15 with MethodCall

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);
}
Also used : BundleContext(org.osgi.framework.BundleContext) Context(javax.naming.Context) ObjectFactory(javax.naming.spi.ObjectFactory) Hashtable(java.util.Hashtable) Reference(javax.naming.Reference) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Name(javax.naming.Name) Test(org.junit.Test)

Aggregations

MethodCall (org.apache.aries.unittest.mocks.MethodCall)41 Test (org.junit.Test)30 Properties (java.util.Properties)13 BundleContext (org.osgi.framework.BundleContext)13 Hashtable (java.util.Hashtable)12 InitialContext (javax.naming.InitialContext)11 AriesApplication (org.apache.aries.application.management.AriesApplication)10 Context (javax.naming.Context)9 BundleMock (org.apache.aries.mocks.BundleMock)8 Name (javax.naming.Name)7 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)7 ObjectFactory (javax.naming.spi.ObjectFactory)6 Content (org.apache.aries.application.Content)6 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)6 ModelledResource (org.apache.aries.application.modelling.ModelledResource)6 Skeleton (org.apache.aries.unittest.mocks.Skeleton)6 ArrayList (java.util.ArrayList)5 Manifest (java.util.jar.Manifest)5 Reference (javax.naming.Reference)5 ServiceRegistration (org.osgi.framework.ServiceRegistration)5