Search in sources :

Example 16 with MethodCall

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

the class BundleFrameworkManagerTest method testFailedInstall.

@Test
public void testFailedInstall() throws Exception {
    /*
     * Mock up a failing framework install
     */
    BundleFramework fwk = Skeleton.newMock(new Object() {

        public Bundle install(BundleSuggestion suggestion, AriesApplication app) throws BundleException {
            throw new BundleException("Expected failure");
        }
    }, BundleFramework.class);
    frameworkFactory.setReturnValue(new MethodCall(BundleFrameworkFactory.class, "createBundleFramework", BundleContext.class, BundleFrameworkConfiguration.class), fwk);
    try {
        sut.installIsolatedBundles(Arrays.asList(Skeleton.newMock(BundleSuggestion.class)), Skeleton.newMock(AriesApplication.class));
        fail("Expected a BundleException");
    } catch (BundleException be) {
        // when a failure occurred we need to have cleaned up the new framework, otherwise it is
        // left as floating debris
        Skeleton.getSkeleton(fwk).assertCalled(new MethodCall(BundleFramework.class, "close"));
    }
}
Also used : BundleFrameworkFactory(org.apache.aries.application.management.spi.framework.BundleFrameworkFactory) Bundle(org.osgi.framework.Bundle) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) BundleException(org.osgi.framework.BundleException) MethodCall(org.apache.aries.unittest.mocks.MethodCall) BundleContext(org.osgi.framework.BundleContext) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration) Test(org.junit.Test)

Example 17 with MethodCall

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

the class EJBLocatorTest method assertAnnotation.

private void assertAnnotation(boolean b) {
    Skeleton s = Skeleton.getSkeleton(registry);
    MethodCall mc = new MethodCall(EJBRegistry.class, "addEJBView", "Annotated", "STATELESS", "test.ejbs.StatelessSessionBean", false);
    if (b)
        s.assertCalledExactNumberOfTimes(mc, 1);
    else
        s.assertNotCalled(mc);
    mc = new MethodCall(EJBRegistry.class, "addEJBView", String.class, "STATEFUL", String.class, boolean.class);
    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)

Example 18 with MethodCall

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

the class EJBModellerTest method testModelServicesExportEJB.

@Test
public void testModelServicesExportEJB() throws ModellerException {
    Manifest man = new Manifest();
    setBasicHeaders(man);
    man.getMainAttributes().putValue("Export-EJB", "anEJB , another");
    modeller.modelServices(new BundleManifest(man), bundleLocation);
    ejbLocator.assertCalled(new MethodCall(EJBLocator.class, "findEJBs", BundleManifest.class, bundleLocation, ParsedEJBServices.class));
}
Also used : BundleManifest(org.apache.aries.util.manifest.BundleManifest) Manifest(java.util.jar.Manifest) BundleManifest(org.apache.aries.util.manifest.BundleManifest) EJBLocator(org.apache.aries.ejb.modelling.EJBLocator) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Test(org.junit.Test)

Example 19 with MethodCall

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

the class DeploymentGeneratorTest method checkBasicCircularDependenciesDetected.

@Test
public void checkBasicCircularDependenciesDetected() throws Exception {
    // Override Resolver behaviour. 
    //ImportedBundle isolated = new ImportedBundleImpl ("test.isolated" , "1.0.0"); 
    // When we resolve isolated, we're going to get another bundle which has a dependency on isolated. 
    Collection<ModelledResource> cmr = new ArrayList<ModelledResource>();
    ExportedPackage testIsolatedPkg = createExportedPackage("test.isolated", "1.0.0", new String[] { "test.shared" }, new String[] { "test.isolated.pkg" });
    cmr.add(testIsolatedPkg.getBundle());
    ExportedPackage testSharedPkg = createExportedPackage("test.shared", "1.0.0", new String[] { "test.isolated.pkg" }, new String[] { "test.shared" });
    cmr.add(testSharedPkg.getBundle());
    _resolver.addResult(cmr);
    // The second time DeploymentGenerator calls the Resolver, it will provide just 
    // test.shared. The resolver will return test.shared _plus_ test.isolated. 
    _resolver.addResult(cmr);
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("test.isolated", "1.0.0")));
    try {
        DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, new ArrayList<ModelledResource>(), new ArrayList<Content>());
        deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    } catch (ResolverException rx) {
        List<String> usr = rx.getUnsatisfiedRequirements();
        assertEquals("One unsatisfied requirement expected, not " + usr.size(), usr.size(), 1);
        String chkMsg = "Shared bundle test.shared_1.0.0 has a dependency for package " + "test.shared which is exported from application bundle [test.isolated_1.0.0]";
        assertTrue(chkMsg + " expected, not " + usr, usr.contains(chkMsg));
        return;
    }
    fail("ResolverException expected");
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) MethodCall(org.apache.aries.unittest.mocks.MethodCall) ModelledResource(org.apache.aries.application.modelling.ModelledResource) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 20 with MethodCall

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

the class DeploymentGeneratorTest method checkBundleInAppContentAndProvisionContentButNothingSharedToIsolatedContent.

/**
   * Similar to the checkBundleInAppContentAndProvisionContent scenario. However, this time the provisioned bundle does not provide
   * a package or service to the isolated content, so there is no problem.
   * @throws Exception
   */
@Test
public void checkBundleInAppContentAndProvisionContentButNothingSharedToIsolatedContent() throws Exception {
    List<ModelledResource> cmr = new ArrayList<ModelledResource>();
    cmr.add(createModelledResource("test.util", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
    cmr.add(createModelledResource("test.bundle", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.1.0,2.0.0)\""), Collections.<String>emptyList()));
    cmr.add(createModelledResource("test.provisioned", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
    cmr.add(createModelledResource("test.util", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
    // The second time DeploymentGenerator calls the Resolver, it will provide just 
    // test.shared. The resolver will return test.shared _plus_ test.isolated. 
    _resolver.addResult(cmr);
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("test.util", "1.1.0"), mockContent("test.bundle", "1.0.0")));
    app = Skeleton.newMock(AriesApplication.class);
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
    DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { cmr.get(0), cmr.get(1) }), new ArrayList<Content>());
    Manifest mf = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    assertTrue(mf.getMainAttributes().getValue("Deployed-Content").contains("test.util;deployed-version=1.1.0"));
    assertTrue(mf.getMainAttributes().getValue("Provision-Bundle").contains("test.util;deployed-version=1.0.0"));
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) AriesApplication(org.apache.aries.application.management.AriesApplication) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Manifest(java.util.jar.Manifest) MethodCall(org.apache.aries.unittest.mocks.MethodCall) ModelledResource(org.apache.aries.application.modelling.ModelledResource) 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