Search in sources :

Example 21 with AriesApplicationContext

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

the class JdbcBlogSampleWithEbaTest method test.

@Test
public void test() throws Exception {
    MavenArtifactUrlReference eba = maven().groupId("org.apache.aries.samples.blog").artifactId("org.apache.aries.samples.blog.jdbc.eba").versionAsInProject().type("eba");
    AriesApplicationContext ctx = installEba(eba);
    /* Check that the Blog Sample bundles are present an started */
    assertBundleStarted("org.apache.aries.samples.blog.api");
    assertBundleStarted("org.apache.aries.samples.blog.web");
    assertBundleStarted("org.apache.aries.samples.blog.biz");
    assertBundleStarted("org.apache.aries.samples.blog.persistence.jdbc");
    assertBlogServicesStarted();
    checkBlogWebAccess();
    ctx.stop();
    manager.uninstall(ctx);
}
Also used : AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) MavenArtifactUrlReference(org.ops4j.pax.exam.options.MavenArtifactUrlReference) Test(org.junit.Test)

Example 22 with AriesApplicationContext

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

the class JpaBlogSampleWithEbaTest method test.

@Test
public void test() throws Exception {
    MavenArtifactUrlReference eba = maven().groupId("org.apache.aries.samples.blog").artifactId("org.apache.aries.samples.blog.jpa.eba").versionAsInProject().type("eba");
    AriesApplicationContext ctx = installEba(eba);
    /* Find and check all the blog sample bundles */
    assertBundleStarted("org.apache.aries.samples.blog.api");
    assertBundleStarted("org.apache.aries.samples.blog.web");
    assertBundleStarted("org.apache.aries.samples.blog.biz");
    assertBundleStarted("org.apache.aries.samples.blog.persistence.jpa");
    assertBundleStarted("org.apache.aries.samples.blog.datasource");
    assertBundleStarted("org.apache.aries.transaction.manager");
    assertBlogServicesStarted();
    checkBlogWebAccess();
    ctx.stop();
    manager.uninstall(ctx);
}
Also used : AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) MavenArtifactUrlReference(org.ops4j.pax.exam.options.MavenArtifactUrlReference) Test(org.junit.Test)

Example 23 with AriesApplicationContext

use of org.apache.aries.application.management.AriesApplicationContext 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 AriesApplicationContext

use of org.apache.aries.application.management.AriesApplicationContext 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 AriesApplicationContext

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

the class AriesApplicationManagerImpl method install.

public AriesApplicationContext install(AriesApplication app) throws BundleException, ManagementException, ResolverException {
    if (!app.isResolved()) {
        app = resolve(app);
    }
    // Register an Application Repository for this application if none exists
    String appScope = app.getApplicationMetadata().getApplicationScope();
    ServiceReference[] ref = null;
    try {
        String filter = "(" + BundleRepository.REPOSITORY_SCOPE + "=" + appScope + ")";
        ref = _bundleContext.getServiceReferences(BundleRepository.class.getName(), filter);
    } catch (InvalidSyntaxException e) {
    // Something went wrong attempting to find a service so we will act as if 
    // there is no existing service.
    }
    if (ref == null || ref.length == 0) {
        Dictionary dict = new Hashtable();
        dict.put(BundleRepository.REPOSITORY_SCOPE, appScope);
        ServiceRegistration serviceReg = _bundleContext.registerService(BundleRepository.class.getName(), new ApplicationRepository(app), dict);
        serviceRegistrations.put(app, serviceReg);
    }
    AriesApplicationContext result = _applicationContextManager.getApplicationContext(app);
    // When installing bundles in the .eba file we use the jar url scheme. This results in a
    // JarFile being held open, which is bad as on windows we cannot delete the .eba file
    // so as a work around we open a url connection to one of the bundles in the eba and
    // if it is a jar url we close the associated JarFile.
    Iterator<BundleInfo> bi = app.getBundleInfo().iterator();
    if (bi.hasNext()) {
        String location = bi.next().getLocation();
        if (location.startsWith("jar")) {
            try {
                URL url = new URL(location);
                JarURLConnection urlc = (JarURLConnection) url.openConnection();
                // Make sure that we pick up the cached version rather than creating a new one
                urlc.setUseCaches(true);
                urlc.getJarFile().close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return result;
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) JarURLConnection(java.net.JarURLConnection) ApplicationRepository(org.apache.aries.application.management.repository.ApplicationRepository) IOException(java.io.IOException) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) URL(java.net.URL) ServiceReference(org.osgi.framework.ServiceReference) BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)34 AriesApplication (org.apache.aries.application.management.AriesApplication)24 Test (org.junit.Test)23 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)19 File (java.io.File)18 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)18 HelloWorld (org.apache.aries.sample.HelloWorld)7 Ignore (org.junit.Ignore)7 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)6 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)6 ArrayList (java.util.ArrayList)5 Repository (org.apache.felix.bundlerepository.Repository)5 UpdateException (org.apache.aries.application.management.UpdateException)4 MavenArtifactUrlReference (org.ops4j.pax.exam.options.MavenArtifactUrlReference)4 Bundle (org.osgi.framework.Bundle)4 URL (java.net.URL)3 DeploymentContent (org.apache.aries.application.DeploymentContent)3 BundleException (org.osgi.framework.BundleException)3 AriesApplicationContextManager (org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager)2 MethodCall (org.apache.aries.unittest.mocks.MethodCall)2