Search in sources :

Example 31 with AriesApplication

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

the class IsolatedRuntimeTest method testAppWithoutApplicationManifest.

@Test
@Ignore
public void testAppWithoutApplicationManifest() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    assertHelloWorldService("test.eba");
    manager.uninstall(ctx);
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 32 with AriesApplication

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

the class AriesApplicationManagerImplTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    DeploymentMetadata depMf = createUpdateDepMf();
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
    _appMgr.setApplicationContextManager(ctxMgr);
    _appMgr.update(app, depMf);
    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) AriesApplication(org.apache.aries.application.management.AriesApplication) Test(org.junit.Test)

Example 33 with AriesApplication

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

the class AriesApplicationManagerImpl method createApplication.

/**
   * Create an application from a URL. 
   * The first version of this method isn't smart enough to check whether
   * the input URL is file://
   */
public AriesApplication createApplication(URL url) throws ManagementException {
    OutputStream os = null;
    AriesApplication app = null;
    try {
        File tempFile = _localPlatform.getTemporaryFile();
        InputStream is = url.openStream();
        os = new FileOutputStream(tempFile);
        IOUtils.copy(is, os);
        IDirectory downloadedSource = FileSystem.getFSRoot(tempFile);
        app = createApplication(downloadedSource);
    } catch (IOException iox) {
        throw new ManagementException(iox);
    } finally {
        IOUtils.close(os);
    }
    return app;
}
Also used : ManagementException(org.apache.aries.application.management.ManagementException) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) AriesApplication(org.apache.aries.application.management.AriesApplication) IOException(java.io.IOException) IFile(org.apache.aries.util.filesystem.IFile) File(java.io.File)

Example 34 with AriesApplication

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

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

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