Search in sources :

Example 6 with Version

use of org.osgi.framework.Version in project aries by apache.

the class DeploymentContentImplTest method testDeploymentContent003.

@Test
public void testDeploymentContent003() throws Exception {
    DeploymentContentImpl dc = new DeploymentContentImpl("com.travel.reservation.data;deployed-version=2.1.1");
    assertEquals("2.1.1", dc.getAttribute("deployed-version"));
    VersionRange vi = dc.getVersion();
    assertTrue(vi.isExactVersion());
    assertEquals(new Version("2.1.1"), dc.getExactVersion());
    assertEquals("com.travel.reservation.data", dc.getContentName());
    assertEquals("{deployed-version=2.1.1}", dc.getNameValueMap().toString());
}
Also used : Version(org.osgi.framework.Version) VersionRange(org.apache.aries.util.VersionRange) Test(org.junit.Test)

Example 7 with Version

use of org.osgi.framework.Version 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 Version

use of org.osgi.framework.Version 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 9 with Version

use of org.osgi.framework.Version 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)

Example 10 with Version

use of org.osgi.framework.Version in project aries by apache.

the class BundleStateMBeanTest method testMBeanInterface.

@Test
public void testMBeanInterface() throws Exception {
    // exportedPackages
    String[] exports = mbean.getExportedPackages(a.getBundleId());
    assertEquals(2, exports.length);
    List<String> packages = Arrays.asList(exports);
    assertTrue(packages.contains("org.apache.aries.jmx.test.bundlea.api;2.0.0"));
    assertTrue(packages.contains("org.apache.aries.jmx.test.fragmentc;0.0.0"));
    // fragments
    long[] fragments = mbean.getFragments(a.getBundleId());
    assertEquals(1, fragments.length);
    assertEquals(fragc.getBundleId(), fragments[0]);
    // headers
    TabularData headers = mbean.getHeaders(b.getBundleId());
    assertNotNull(headers);
    assertEquals(BundleStateMBean.HEADERS_TYPE, headers.getTabularType());
    assertTrue(headers.values().size() >= 4);
    assertEquals("org.apache.aries.jmx.test.bundleb", Header.from(headers.get(new Object[] { Constants.BUNDLE_SYMBOLICNAME })).getValue());
    // hosts
    long[] hosts = mbean.getHosts(fragc.getBundleId());
    assertEquals(1, hosts.length);
    assertEquals(a.getBundleId(), hosts[0]);
    //imported packages
    String[] imports = mbean.getImportedPackages(a.getBundleId());
    assertTrue(imports.length >= 3);
    List<String> importedPackages = Arrays.asList(imports);
    Version version = getPackageVersion("org.osgi.framework");
    assertTrue(importedPackages.contains("org.osgi.framework;" + version.toString()));
    assertTrue(importedPackages.contains("org.apache.aries.jmx.test.bundleb.api;1.1.0"));
    //last modified
    assertTrue(mbean.getLastModified(b.getBundleId()) > 0);
    //location
    assertEquals(b.getLocation(), mbean.getLocation(b.getBundleId()));
    //registered services
    long[] serviceIds = mbean.getRegisteredServices(a.getBundleId());
    assertEquals(1, serviceIds.length);
    //required bundles
    long[] required = mbean.getRequiredBundles(d.getBundleId());
    assertEquals(1, required.length);
    assertEquals(a.getBundleId(), required[0]);
    //requiring bundles
    long[] requiring = mbean.getRequiringBundles(a.getBundleId());
    assertEquals(2, requiring.length);
    assertTrue(fragc.getSymbolicName(), arrayContains(fragc.getBundleId(), requiring));
    assertTrue(d.getSymbolicName(), arrayContains(d.getBundleId(), requiring));
    //services in use
    long[] servicesInUse = mbean.getServicesInUse(a.getBundleId());
    assertEquals(1, servicesInUse.length);
    //start level
    long startLevel = mbean.getStartLevel(b.getBundleId());
    assertTrue(startLevel >= 0);
    //state
    assertEquals("ACTIVE", mbean.getState(b.getBundleId()));
    //isFragment
    assertFalse(mbean.isFragment(b.getBundleId()));
    assertTrue(mbean.isFragment(fragc.getBundleId()));
    //isRemovalPending
    assertFalse(mbean.isRemovalPending(b.getBundleId()));
    // isRequired
    assertTrue(mbean.isRequired(a.getBundleId()));
    assertTrue(mbean.isRequired(b.getBundleId()));
    // listBundles
    TabularData bundlesTable = mbean.listBundles();
    assertNotNull(bundlesTable);
    assertEquals(BundleStateMBean.BUNDLES_TYPE, bundlesTable.getTabularType());
    assertEquals(bundleContext.getBundles().length, bundlesTable.values().size());
    // notifications
    final List<Notification> received = new ArrayList<Notification>();
    mbeanServer.addNotificationListener(objectName, new NotificationListener() {

        public void handleNotification(Notification notification, Object handback) {
            received.add(notification);
        }
    }, null, null);
    assertEquals(Bundle.ACTIVE, b.getState());
    b.stop();
    assertEquals(Bundle.RESOLVED, b.getState());
    b.start();
    assertEquals(Bundle.ACTIVE, b.getState());
    int i = 0;
    while (received.size() < 2 && i < 3) {
        Thread.sleep(1000);
        i++;
    }
    assertEquals(2, received.size());
}
Also used : ArrayList(java.util.ArrayList) AttributeChangeNotification(javax.management.AttributeChangeNotification) Notification(javax.management.Notification) TabularData(javax.management.openmbean.TabularData) Version(org.osgi.framework.Version) NotificationListener(javax.management.NotificationListener) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Aggregations

Version (org.osgi.framework.Version)165 Test (org.junit.Test)30 Bundle (org.osgi.framework.Bundle)26 ArrayList (java.util.ArrayList)22 Capability (org.osgi.resource.Capability)19 File (java.io.File)17 HashMap (java.util.HashMap)16 Resource (org.osgi.resource.Resource)14 IOException (java.io.IOException)13 InputStream (java.io.InputStream)11 Manifest (java.util.jar.Manifest)11 Map (java.util.Map)9 HashSet (java.util.HashSet)8 Content (org.apache.aries.application.Content)8 AriesApplication (org.apache.aries.application.management.AriesApplication)8 VersionRange (org.apache.felix.utils.version.VersionRange)8 BundleRevision (org.osgi.framework.wiring.BundleRevision)8 List (java.util.List)7 BundleWiring (org.osgi.framework.wiring.BundleWiring)7 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)6