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());
}
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;
}
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));
}
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);
}
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());
}
Aggregations