Search in sources :

Example 6 with AriesApplication

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

the class OBRResolverTest method testBlogAppResolveFail.

@Test(expected = ResolverException.class)
public void testBlogAppResolveFail() throws ResolverException, Exception {
    //  provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
    generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + "_0.0.0.jar");
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        repositoryAdmin.removeRepository(repo.getURI());
    }
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("blog.eba")));
    //installing requires a valid url for the bundle in repository.xml.
    app = manager.resolve(app);
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) File(java.io.File) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 7 with AriesApplication

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

the class AriesApplicationManagerImplTest method createApplication.

private AriesApplication createApplication(String fileName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ManagementException, ResolverException {
    // This next block is a very long winded way of constructing a BundleInfoImpl
    // against the existing (BundleManifest bm, String location) constructor. If we 
    // find we need a String-based BundleInfoImpl constructor for other reasons, 
    // we could change to using it here. 
    Set<BundleInfo> nextResolverResult = new HashSet<BundleInfo>();
    String persistenceLibraryLocation = "../src/test/resources/bundles/repository/a.handy.persistence.library.jar";
    File persistenceLibrary = new File(persistenceLibraryLocation);
    BundleManifest mf = BundleManifest.fromBundle(persistenceLibrary);
    BundleInfo resolvedPersistenceLibrary = new SimpleBundleInfo(mf, persistenceLibraryLocation);
    Field v = SimpleBundleInfo.class.getDeclaredField("_version");
    v.setAccessible(true);
    v.set(resolvedPersistenceLibrary, new Version("1.1.0"));
    nextResolverResult.add(resolvedPersistenceLibrary);
    _resolver.setNextResult(nextResolverResult);
    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
    AriesApplication app = _appMgr.createApplication(testEba);
    app = _appMgr.resolve(app);
    return app;
}
Also used : Field(java.lang.reflect.Field) BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) Version(org.osgi.framework.Version) IDirectory(org.apache.aries.util.filesystem.IDirectory) BundleManifest(org.apache.aries.util.manifest.BundleManifest) AriesApplication(org.apache.aries.application.management.AriesApplication) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) IFile(org.apache.aries.util.filesystem.IFile) File(java.io.File) HashSet(java.util.HashSet)

Example 8 with AriesApplication

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

the class AriesApplicationManagerImplTest method testStoreAndReload.

@Test
public void testStoreAndReload() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    File dest = new File("ariesApplicationManagerImplTest/stored.eba");
    app.store(dest);
    /* Dest should be a zip file with four entries:
     *  /foo.bar.widgets.jar
     *  /my.business.logic.jar
     *  /META-INF/APPLICATION.MF
     *  /META-INF/DEPLOYMENT.MF
     */
    IDirectory storedEba = FileSystem.getFSRoot(dest);
    assertNotNull(storedEba);
    assertEquals(storedEba.listFiles().size(), 3);
    IFile ifile = storedEba.getFile("META-INF/APPLICATION.MF");
    assertNotNull(ifile);
    ifile = storedEba.getFile("META-INF/DEPLOYMENT.MF");
    assertNotNull(ifile);
    ifile = storedEba.getFile("foo.bar.widgets.jar");
    assertNotNull(ifile);
    ifile = storedEba.getFile("my.business.logic.jar");
    assertNotNull(ifile);
    AriesApplication newApp = _appMgr.createApplication(storedEba);
    DeploymentMetadata dm = newApp.getDeploymentMetadata();
    assertEquals(2, dm.getApplicationDeploymentContents().size());
    assertEquals(1, dm.getApplicationProvisionBundles().size());
    assertEquals(dm.getApplicationSymbolicName(), app.getApplicationMetadata().getApplicationSymbolicName());
    assertEquals(dm.getApplicationVersion(), app.getApplicationMetadata().getApplicationVersion());
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) IFile(org.apache.aries.util.filesystem.IFile) IDirectory(org.apache.aries.util.filesystem.IDirectory) AriesApplication(org.apache.aries.application.management.AriesApplication) IFile(org.apache.aries.util.filesystem.IFile) File(java.io.File) Test(org.junit.Test)

Example 9 with AriesApplication

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

the class AriesApplicationManagerImplTest method testCreate.

@Test
public void testCreate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    assertEquals(appMeta.getApplicationName(), "Test application");
    assertEquals(appMeta.getApplicationSymbolicName(), "org.apache.aries.application.management.test");
    assertEquals(appMeta.getApplicationVersion(), new Version("1.0"));
    List<Content> appContent = appMeta.getApplicationContents();
    assertEquals(appContent.size(), 2);
    Content fbw = new ContentImpl("foo.bar.widgets;version=1.0.0");
    Content mbl = new ContentImpl("my.business.logic;version=1.0.0");
    assertTrue(appContent.contains(fbw));
    assertTrue(appContent.contains(mbl));
    DeploymentMetadata dm = app.getDeploymentMetadata();
    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
    assertEquals(2, dcList.size());
    DeploymentContent dc1 = new DeploymentContentImpl("foo.bar.widgets;deployed-version=1.1.0");
    DeploymentContent dc2 = new DeploymentContentImpl("my.business.logic;deployed-version=1.1.0");
    DeploymentContent dc3 = new DeploymentContentImpl("a.handy.persistence.library;deployed-version=1.1.0");
    assertTrue(dcList.contains(dc1));
    assertTrue(dcList.contains(dc2));
    dcList = dm.getApplicationProvisionBundles();
    assertEquals(1, dcList.size());
    assertTrue(dcList.contains(dc3));
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) DeploymentContent(org.apache.aries.application.DeploymentContent) AriesApplication(org.apache.aries.application.management.AriesApplication) ContentImpl(org.apache.aries.application.impl.ContentImpl) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) DeploymentContent(org.apache.aries.application.DeploymentContent) Test(org.junit.Test)

Example 10 with AriesApplication

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

the class ApplicationRepositoryTest method testBundleNotInApp.

@Test
public void testBundleNotInApp() {
    AriesApplication app = Skeleton.newMock(AriesApplication.class);
    BundleInfo bi = Skeleton.newMock(BundleInfo.class);
    Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getSymbolicName"), "test.bundle");
    Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getVersion"), new Version("1.0.0"));
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getBundleInfo"), new HashSet<BundleInfo>());
    ApplicationRepository rep = new ApplicationRepository(app);
    BundleSuggestion sug = rep.suggestBundleToUse(new DeploymentContentImpl("test.bundle", new Version("2.0.0")));
    assertNull("We have apparently found a bundle that is not in the application in the ApplicationRepository", sug);
}
Also used : DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) BundleInfo(org.apache.aries.application.management.BundleInfo) Version(org.osgi.framework.Version) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) 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