Search in sources :

Example 36 with MethodCall

use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.

the class AriesApplicationManagerImplTest method testRolledbackUpdate.

@Test
public void testRolledbackUpdate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    DeploymentMetadata depMf = createUpdateDepMf();
    DeploymentMetadata oldMf = app.getDeploymentMetadata();
    AriesApplicationContext ctx = Skeleton.newMock(AriesApplicationContext.class);
    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(AriesApplicationContext.class, "getApplication"), app);
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
    Skeleton.getSkeleton(ctxMgr).setReturnValue(new MethodCall(AriesApplicationContextManager.class, "getApplicationContexts"), Collections.singleton(ctx));
    Skeleton.getSkeleton(ctxMgr).setThrows(new MethodCall(AriesApplicationContextManager.class, "update", AriesApplication.class, DeploymentMetadata.class), new UpdateException("", null, true, null));
    _appMgr.setApplicationContextManager(ctxMgr);
    try {
        _appMgr.update(app, depMf);
        fail("Update should have failed.");
    } catch (UpdateException e) {
        assertTrue("Deployment.mf should have been rolled back to the old", app.getDeploymentMetadata() == oldMf);
    }
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContextManager(org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplication(org.apache.aries.application.management.AriesApplication) UpdateException(org.apache.aries.application.management.UpdateException) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Test(org.junit.Test)

Example 37 with MethodCall

use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.

the class AriesApplicationManagerImplTest method createUpdateDepMf.

private DeploymentMetadata createUpdateDepMf() {
    DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "org.apache.aries.application.management.test");
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));
    return depMf;
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) Version(org.osgi.framework.Version) MethodCall(org.apache.aries.unittest.mocks.MethodCall)

Example 38 with MethodCall

use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.

the class AriesApplicationManagerImplTest method testUpdateWithIncorrectDepMf.

@Test(expected = IllegalArgumentException.class)
public void testUpdateWithIncorrectDepMf() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "random.app");
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
    _appMgr.setApplicationContextManager(ctxMgr);
    _appMgr.update(app, depMf);
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContextManager(org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager) Version(org.osgi.framework.Version) AriesApplication(org.apache.aries.application.management.AriesApplication) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Test(org.junit.Test)

Example 39 with MethodCall

use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.

the class AriesApplicationManagerImplTest method testFailedUpdate.

@Test
public void testFailedUpdate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    DeploymentMetadata depMf = createUpdateDepMf();
    AriesApplicationContext ctx = Skeleton.newMock(AriesApplicationContext.class);
    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(AriesApplicationContext.class, "getApplication"), app);
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
    Skeleton.getSkeleton(ctxMgr).setReturnValue(new MethodCall(AriesApplicationContextManager.class, "getApplicationContexts"), Collections.singleton(ctx));
    Skeleton.getSkeleton(ctxMgr).setThrows(new MethodCall(AriesApplicationContextManager.class, "update", AriesApplication.class, DeploymentMetadata.class), new UpdateException("", null, false, null));
    _appMgr.setApplicationContextManager(ctxMgr);
    try {
        _appMgr.update(app, depMf);
        fail("Update should have failed.");
    } catch (UpdateException e) {
        assertTrue("Deployment.mf should have been updated", app.getDeploymentMetadata() == depMf);
    }
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContextManager(org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplication(org.apache.aries.application.management.AriesApplication) UpdateException(org.apache.aries.application.management.UpdateException) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Test(org.junit.Test)

Example 40 with MethodCall

use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.

the class EJBLocatorTest method assertXML.

private void assertXML(boolean b) {
    Skeleton s = Skeleton.getSkeleton(registry);
    MethodCall mc = new MethodCall(EJBRegistry.class, "addEJBView", "XML", "SINGLETON", "local.Iface", false);
    if (b)
        s.assertCalledExactNumberOfTimes(mc, 1);
    else
        s.assertNotCalled(mc);
    mc = new MethodCall(EJBRegistry.class, "addEJBView", "XML", "SINGLETON", "remote.Iface", true);
    if (b)
        s.assertCalledExactNumberOfTimes(mc, 1);
    else
        s.assertNotCalled(mc);
}
Also used : EJBRegistry(org.apache.aries.ejb.modelling.EJBRegistry) Skeleton(org.apache.aries.unittest.mocks.Skeleton) MethodCall(org.apache.aries.unittest.mocks.MethodCall)

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