Search in sources :

Example 21 with AriesApplication

use of org.apache.aries.application.management.AriesApplication in project aries by apache.

the class UpdateAppTest method updateApp.

private AriesApplicationContext updateApp(AriesApplicationManager manager, AriesApplication app) throws Exception {
    IsolationTestUtils.prepareSampleBundleV2(bundleContext, context().getService(RepositoryGenerator.class), context().getService(RepositoryAdmin.class), context().getService(ModellingManager.class));
    AriesApplication newApp = manager.resolve(app, new ResolveConstraint() {

        public String getBundleName() {
            return "org.apache.aries.isolated.sample";
        }

        public VersionRange getVersionRange() {
            return ManifestHeaderProcessor.parseVersionRange("[2.0.0,2.0.0]", true);
        }
    });
    return manager.update(app, newApp.getDeploymentMetadata());
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) ModellingManager(org.apache.aries.application.modelling.ModellingManager) AriesApplication(org.apache.aries.application.management.AriesApplication) VersionRange(org.apache.aries.util.VersionRange)

Example 22 with AriesApplication

use of org.apache.aries.application.management.AriesApplication in project aries by apache.

the class UpdateAppTest method testFineUpdate.

@Test
@Ignore
public void testFineUpdate() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = setupApp();
    BundleContext oldCtx = IsolationTestUtils.findIsolatedAppBundleContext(bundleContext, SAMPLE_APP_NAME);
    installMockUpdateStrategy();
    updateApp(manager, app);
    BundleContext newCtx = IsolationTestUtils.findIsolatedAppBundleContext(bundleContext, SAMPLE_APP_NAME);
    assertAppMessage("hello brave new world");
    assertTrue("We bounced the app where the update was supposed to do an update in place", oldCtx == newCtx);
}
Also used : AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleContext(org.osgi.framework.BundleContext) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 23 with AriesApplication

use of org.apache.aries.application.management.AriesApplication in project aries by apache.

the class UpdateAppTest method testUpdateThenStart.

@Test
@Ignore
public void testUpdateThenStart() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
    AriesApplicationContext ctx = manager.install(app);
    app = ctx.getApplication();
    BundleContext oldCtx = IsolationTestUtils.findIsolatedAppBundleContext(bundleContext, SAMPLE_APP_NAME);
    installMockUpdateStrategy();
    ctx = updateApp(manager, app);
    BundleContext newCtx = IsolationTestUtils.findIsolatedAppBundleContext(bundleContext, SAMPLE_APP_NAME);
    assertNull("App is not started yet but HelloWorld service is already there", IsolationTestUtils.findHelloWorldService(bundleContext, SAMPLE_APP_NAME));
    ctx.start();
    assertAppMessage("hello brave new world");
    assertTrue("We bounced the app where the update was supposed to do an update in place", oldCtx == newCtx);
}
Also used : AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 24 with AriesApplication

use of org.apache.aries.application.management.AriesApplication in project aries by apache.

the class UpdateAppTest method setupApp.

private AriesApplication setupApp() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
    AriesApplicationContext ctx = manager.install(app);
    app = ctx.getApplication();
    ctx.start();
    assertAppMessage("hello world");
    return app;
}
Also used : AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) File(java.io.File)

Example 25 with AriesApplication

use of org.apache.aries.application.management.AriesApplication in project aries by apache.

the class IsolationTestUtils method prepareSampleBundleV2.

/**
   * Set up the necessary resources for installing version 2 of the org.apache.aries.isolated.sample sample bundle, 
   * which returns the message "hello brave new world" rather than "hello world"
   * 
   * This means setting up a global bundle repository as well as a global OBR repository
   */
public static void prepareSampleBundleV2(BundleContext runtimeCtx, RepositoryGenerator repoGen, RepositoryAdmin repoAdmin, ModellingManager modellingManager) throws Exception {
    BundleRepository repo = new BundleRepository() {

        public int getCost() {
            return 1;
        }

        public BundleSuggestion suggestBundleToUse(DeploymentContent content) {
            if (content.getContentName().equals("org.apache.aries.isolated.sample")) {
                return new BundleSuggestion() {

                    public Bundle install(BundleFramework framework, AriesApplication app) throws BundleException {
                        File f = new File("sample_2.0.0.jar");
                        try {
                            return framework.getIsolatedBundleContext().installBundle(f.toURL().toString());
                        } catch (MalformedURLException mue) {
                            throw new RuntimeException(mue);
                        }
                    }

                    public Version getVersion() {
                        return new Version("2.0.0");
                    }

                    public Set<Content> getImportPackage() {
                        return Collections.emptySet();
                    }

                    public Set<Content> getExportPackage() {
                        return Collections.emptySet();
                    }

                    public int getCost() {
                        return 1;
                    }
                };
            } else {
                return null;
            }
        }
    };
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put(BundleRepository.REPOSITORY_SCOPE, BundleRepository.GLOBAL_SCOPE);
    runtimeCtx.registerService(BundleRepository.class.getName(), repo, props);
    Attributes attrs = new Attributes();
    attrs.putValue("Bundle-ManifestVersion", "2");
    attrs.putValue("Bundle-Version", "2.0.0");
    attrs.putValue("Bundle-SymbolicName", "org.apache.aries.isolated.sample");
    attrs.putValue("Manifest-Version", "1");
    ModelledResource res = modellingManager.getModelledResource(new File("sample_2.0.0.jar").toURI().toString(), attrs, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
    repoGen.generateRepository("repo.xml", Arrays.asList(res), new FileOutputStream("repo.xml"));
    repoAdmin.addRepository(new File("repo.xml").toURI().toString());
}
Also used : MalformedURLException(java.net.MalformedURLException) Hashtable(java.util.Hashtable) AriesApplication(org.apache.aries.application.management.AriesApplication) Attributes(java.util.jar.Attributes) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) DeploymentContent(org.apache.aries.application.DeploymentContent) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Version(org.osgi.framework.Version) DeploymentContent(org.apache.aries.application.DeploymentContent) Content(org.apache.aries.application.Content) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

AriesApplication (org.apache.aries.application.management.AriesApplication)42 Test (org.junit.Test)32 File (java.io.File)25 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)24 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)24 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)23 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)11 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)10 Ignore (org.junit.Ignore)9 Repository (org.apache.felix.bundlerepository.Repository)8 DeploymentContent (org.apache.aries.application.DeploymentContent)7 HelloWorld (org.apache.aries.sample.HelloWorld)7 Version (org.osgi.framework.Version)7 MethodCall (org.apache.aries.unittest.mocks.MethodCall)5 Bundle (org.osgi.framework.Bundle)5 Content (org.apache.aries.application.Content)4 AriesApplicationContextManager (org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager)4 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 DeploymentContentImpl (org.apache.aries.application.impl.DeploymentContentImpl)3