use of org.osgi.framework.Version in project aries by apache.
the class ManifestProcessorTest method testManifestMetadata.
/**
* Check metadata can be extracted from a simple manifest.
*/
@Test
public void testManifestMetadata() throws Exception {
ApplicationMetadataFactoryImpl manager = new ApplicationMetadataFactoryImpl();
InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF");
ApplicationMetadata am = manager.parseApplicationMetadata(in);
assertNotNull(am);
assertEquals(am.getApplicationName(), appName);
//"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
List<Content> contents = am.getApplicationContents();
for (Content content : contents) {
if ("com.travel.reservation.web".equals(content.getContentName())) {
VersionRange vr = content.getVersion();
assertEquals(vr.getMinimumVersion(), new Version("1.1.0"));
assertEquals(vr.getMaximumVersion(), new Version("1.2.0"));
} else if ("com.travel.reservation.business".equals(content.getContentName())) {
VersionRange vr = content.getVersion();
assertEquals(new Version(0, 0, 0), vr.getMinimumVersion());
} else
fail("Unexepcted content name " + content.getContentName());
}
}
use of org.osgi.framework.Version in project aries by apache.
the class DeploymentContentImplTest method testDeploymentContent001.
@Test
public void testDeploymentContent001() throws Exception {
DeploymentContentImpl dc = new DeploymentContentImpl("com.travel.reservation.web;deployed-version=\"1.1.0\"");
assertEquals("1.1.0", dc.getAttribute("deployed-version"));
VersionRange vi = dc.getVersion();
assertTrue(vi.isExactVersion());
assertEquals(new Version("1.1.0"), dc.getExactVersion());
assertEquals("com.travel.reservation.web", dc.getContentName());
assertEquals("{deployed-version=1.1.0}", dc.getNameValueMap().toString());
}
use of org.osgi.framework.Version in project aries by apache.
the class DeploymentContentImplTest method testDeploymentContent002.
@Test
public void testDeploymentContent002() throws Exception {
DeploymentContentImpl dc = new DeploymentContentImpl("com.travel.reservation.business;deployed-version=2.0");
assertEquals("2.0", dc.getAttribute("deployed-version"));
VersionRange vi = dc.getVersion();
assertTrue(vi.isExactVersion());
assertEquals(new Version("2.0"), dc.getExactVersion());
assertEquals("com.travel.reservation.business", dc.getContentName());
assertEquals("{deployed-version=2.0}", dc.getNameValueMap().toString());
}
use of org.osgi.framework.Version in project aries by apache.
the class BundleDataTest method testToCompositeData.
@Test
public void testToCompositeData() throws Exception {
Bundle bundle = mock(Bundle.class);
BundleContext context = mock(BundleContext.class);
PackageAdmin packageAdmin = mock(PackageAdmin.class);
StartLevel startLevel = mock(StartLevel.class);
Bundle b1 = mock(Bundle.class);
when(b1.getSymbolicName()).thenReturn("b1");
when(b1.getBundleId()).thenReturn(new Long(44));
Bundle b2 = mock(Bundle.class);
when(b2.getSymbolicName()).thenReturn("b2");
when(b2.getBundleId()).thenReturn(new Long(55));
Bundle b3 = mock(Bundle.class);
when(b3.getSymbolicName()).thenReturn("b3");
when(b3.getBundleId()).thenReturn(new Long(66));
when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
when(bundle.getSymbolicName()).thenReturn("test");
when(bundle.getVersion()).thenReturn(Version.emptyVersion);
when(bundle.getBundleId()).thenReturn(new Long(1));
when(bundle.getLastModified()).thenReturn(new Long(12345));
when(bundle.getLocation()).thenReturn("location");
//headers
Dictionary<String, String> headers = new Hashtable<String, String>();
headers.put(Constants.BUNDLE_SYMBOLICNAME, "test");
headers.put(Constants.BUNDLE_VERSION, "0.0.0");
when(bundle.getHeaders()).thenReturn(headers);
//exported packages
ExportedPackage exported = mock(ExportedPackage.class);
when(exported.getName()).thenReturn("org.apache.aries.jmx");
when(exported.getVersion()).thenReturn(new Version("1.0.0"));
when(exported.getExportingBundle()).thenReturn(bundle);
when(packageAdmin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[] { exported });
//imported packages
ExportedPackage ep1 = mock(ExportedPackage.class);
when(ep1.getImportingBundles()).thenReturn(new Bundle[] { bundle, b2, b3 });
when(ep1.getName()).thenReturn("org.apache.aries.jmx.b1");
when(ep1.getVersion()).thenReturn(Version.emptyVersion);
when(ep1.getExportingBundle()).thenReturn(b1);
ExportedPackage ep2 = mock(ExportedPackage.class);
when(ep2.getImportingBundles()).thenReturn(new Bundle[] { bundle, b3 });
when(ep2.getName()).thenReturn("org.apache.aries.jmx.b2");
when(ep2.getVersion()).thenReturn(Version.parseVersion("2.0.1"));
when(ep2.getExportingBundle()).thenReturn(b2);
headers.put(Constants.DYNAMICIMPORT_PACKAGE, "*");
when(packageAdmin.getExportedPackages(b1)).thenReturn(new ExportedPackage[] { ep1 });
when(packageAdmin.getExportedPackages(b2)).thenReturn(new ExportedPackage[] { ep2 });
when(packageAdmin.getExportedPackages(b3)).thenReturn(null);
//required bundles
RequiredBundle rb1 = mock(RequiredBundle.class);
when(rb1.getBundle()).thenReturn(b1);
when(rb1.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b2 });
RequiredBundle rb2 = mock(RequiredBundle.class);
when(rb2.getBundle()).thenReturn(b2);
when(rb2.getRequiringBundles()).thenReturn(new Bundle[] { b1 });
RequiredBundle rb3 = mock(RequiredBundle.class);
when(rb3.getBundle()).thenReturn(b3);
when(rb3.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b1, b2 });
headers.put(Constants.REQUIRE_BUNDLE, "b1;bundle-version=\"1.0.0\",b3;bundle-version=\"2.0.0\"");
when(packageAdmin.getRequiredBundles("b1")).thenReturn(new RequiredBundle[] { rb1 });
when(packageAdmin.getRequiredBundles("b2")).thenReturn(new RequiredBundle[] { rb2 });
when(packageAdmin.getRequiredBundles("b3")).thenReturn(new RequiredBundle[] { rb3 });
//services in use
ServiceReference s1 = mock(ServiceReference.class);
when(s1.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(15));
ServiceReference s2 = mock(ServiceReference.class);
when(s2.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(16));
ServiceReference s3 = mock(ServiceReference.class);
when(s3.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(17));
when(bundle.getServicesInUse()).thenReturn(new ServiceReference[] { s1, s2, s3 });
BundleData b = new BundleData(context, bundle, packageAdmin, startLevel);
CompositeData compositeData = b.toCompositeData();
assertEquals("test", compositeData.get(SYMBOLIC_NAME));
assertEquals("0.0.0", compositeData.get(VERSION));
TabularData headerTable = (TabularData) compositeData.get(HEADERS);
assertEquals(4, headerTable.values().size());
CompositeData header = headerTable.get(new Object[] { Constants.BUNDLE_SYMBOLICNAME });
assertNotNull(header);
String value = (String) header.get(VALUE);
assertEquals("test", value);
String key = (String) header.get(KEY);
assertEquals(Constants.BUNDLE_SYMBOLICNAME, key);
TabularData bundleTable = new TabularDataSupport(BUNDLES_TYPE);
bundleTable.put(b.toCompositeData());
CompositeData bundleData = bundleTable.get(new Object[] { Long.valueOf(1) });
assertNotNull(bundleData);
String location = (String) bundleData.get(LOCATION);
assertEquals("location", location);
assertArrayEquals(new String[] { "org.apache.aries.jmx;1.0.0" }, (String[]) compositeData.get(EXPORTED_PACKAGES));
assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0", "org.apache.aries.jmx.b2;2.0.1" }, (String[]) compositeData.get(IMPORTED_PACKAGES));
assertEquals(toSet(new long[] { 44, 55, 66 }), toSet((Long[]) compositeData.get(REQUIRED_BUNDLES)));
assertArrayEquals(new Long[] { new Long(15), new Long(16), new Long(17) }, (Long[]) compositeData.get(SERVICES_IN_USE));
//default no return stub
assertEquals("UNKNOWN", compositeData.get(STATE));
assertEquals(0, ((Long[]) compositeData.get(HOSTS)).length);
assertEquals(0, ((Long[]) compositeData.get(FRAGMENTS)).length);
}
use of org.osgi.framework.Version in project aries by apache.
the class FrameworkMBeanTest method testRefreshBundlesAndWait2.
@Test
public void testRefreshBundlesAndWait2() throws Exception {
Bundle bundleA = getBundleByName("org.apache.aries.jmx.test.bundlea");
Bundle bundleB = getBundleByName("org.apache.aries.jmx.test.bundleb");
BundleWiring bw = (BundleWiring) bundleB.adapt(BundleWiring.class);
List<BundleWire> initialRequiredWires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(1, initialRequiredWires.size());
BundleWire wire = initialRequiredWires.get(0);
Map<String, Object> capabilityAttributes = wire.getCapability().getAttributes();
assertEquals("Precondition", bundleA.getSymbolicName(), capabilityAttributes.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
assertEquals("Precondition", new Version("1.0"), capabilityAttributes.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
assertEquals("Precondition", "org.apache.aries.jmx.test.bundlea.api", capabilityAttributes.get(BundleRevision.PACKAGE_NAMESPACE));
// Create an updated version of Bundle A, which an extra export and version 1.1
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea");
manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, "1.1");
manifest.getMainAttributes().putValue(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api,org.apache.aries.jmx.test.bundlea.impl");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(baos, manifest);
addResourceToJar("org/apache/aries/jmx/test/bundlea/api/InterfaceA.class", jos, bundleA);
addResourceToJar("org/apache/aries/jmx/test/bundlea/impl/A2.class", jos, bundleA);
jos.close();
assertEquals("Precondition", 1, ((BundleRevisions) bundleA.adapt(BundleRevisions.class)).getRevisions().size());
bundleA.update(new ByteArrayInputStream(baos.toByteArray()));
assertEquals("There should be 2 revisions now", 2, ((BundleRevisions) bundleA.adapt(BundleRevisions.class)).getRevisions().size());
assertEquals("No refresh called, the bundle wiring for B should still be the old one", bw, ((BundleWiring) bundleB.adapt(BundleWiring.class)));
FrameworkMBean framework = getMBean(FrameworkMBean.OBJECTNAME, FrameworkMBean.class);
CompositeData result = framework.refreshBundlesAndWait(null);
Set<Long> completed = new HashSet<Long>(Arrays.asList((Long[]) result.get(FrameworkMBean.COMPLETED)));
assertTrue(completed.contains(bundleA.getBundleId()));
assertTrue(completed.contains(bundleB.getBundleId()));
List<BundleWire> requiredWires = ((BundleWiring) bundleB.adapt(BundleWiring.class)).getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(2, requiredWires.size());
List<String> imported = new ArrayList<String>();
for (BundleWire w : requiredWires) {
Map<String, Object> ca = w.getCapability().getAttributes();
assertEquals(bundleA.getSymbolicName(), ca.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
imported.add(ca.get(BundleRevision.PACKAGE_NAMESPACE).toString());
if ("org.apache.aries.jmx.test.bundlea.impl".equals(ca.get(BundleRevision.PACKAGE_NAMESPACE))) {
// Came across an issue where equinox was reporting the other package as still coming from from the 1.0 bundle
// not sure if this is a bug or not...
assertEquals(new Version("1.1"), ca.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
}
}
assertEquals(Arrays.asList("org.apache.aries.jmx.test.bundlea.api", "org.apache.aries.jmx.test.bundlea.impl"), imported);
}
Aggregations