use of org.osgi.service.packageadmin.ExportedPackage in project aries by apache.
the class PackageStateTest method testGetExportingBundles.
@Test
public void testGetExportingBundles() throws IOException {
ExportedPackage exported = Mockito.mock(ExportedPackage.class);
Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
Mockito.when(exported.getExportingBundle()).thenReturn(bundle);
Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(5));
ExportedPackage exported2 = Mockito.mock(ExportedPackage.class);
Bundle bundle2 = Mockito.mock(Bundle.class);
Mockito.when(exported2.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
Mockito.when(exported2.getExportingBundle()).thenReturn(bundle2);
Mockito.when(bundle2.getBundleId()).thenReturn(Long.valueOf(6));
Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[] { exported, exported2 });
long[] ids = mbean.getExportingBundles("test", "1.0.0");
Assert.assertNotNull(ids);
Assert.assertArrayEquals(new long[] { 5, 6 }, ids);
}
use of org.osgi.service.packageadmin.ExportedPackage in project aries by apache.
the class PackageStateTest method testGetImportingBundles.
@Test
public void testGetImportingBundles() throws IOException {
ExportedPackage exported = Mockito.mock(ExportedPackage.class);
Bundle bundle = Mockito.mock(Bundle.class);
Bundle exportingBundle = Mockito.mock(Bundle.class);
Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
Mockito.when(exported.getExportingBundle()).thenReturn(exportingBundle);
Mockito.when(exportingBundle.getBundleId()).thenReturn(Long.valueOf(2));
Mockito.when(exported.getImportingBundles()).thenReturn(new Bundle[] { bundle });
Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(4));
Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[] { exported });
long[] ids = mbean.getImportingBundles("test", "1.0.0", 2);
Assert.assertArrayEquals(new long[] { 4 }, ids);
}
use of org.osgi.service.packageadmin.ExportedPackage in project aries by apache.
the class PackageStateTest method testIsRemovalPending.
@Test
public void testIsRemovalPending() throws IOException {
ExportedPackage exported = Mockito.mock(ExportedPackage.class);
Bundle expBundle = Mockito.mock(Bundle.class);
Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
Mockito.when(exported.isRemovalPending()).thenReturn(true);
Mockito.when(exported.getExportingBundle()).thenReturn(expBundle);
Mockito.when(expBundle.getBundleId()).thenReturn(Long.valueOf(2));
Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[] { exported });
boolean isRemoval = mbean.isRemovalPending("test", "1.0.0", Long.valueOf(2));
Assert.assertTrue(isRemoval);
}
use of org.osgi.service.packageadmin.ExportedPackage in project aries by apache.
the class PackageStateTest method testListPackages.
@Test
public void testListPackages() throws IOException {
Bundle bundle = Mockito.mock(Bundle.class);
Bundle impBundle = Mockito.mock(Bundle.class);
Mockito.when(context.getBundles()).thenReturn(new Bundle[] { bundle });
ExportedPackage exported = Mockito.mock(ExportedPackage.class);
Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
Mockito.when(exported.getImportingBundles()).thenReturn(new Bundle[] { impBundle });
Mockito.when(exported.getName()).thenReturn("test");
Mockito.when(exported.getExportingBundle()).thenReturn(bundle);
Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(4));
Mockito.when(impBundle.getBundleId()).thenReturn(Long.valueOf(5));
Mockito.when(admin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[] { exported });
TabularData table = mbean.listPackages();
Assert.assertEquals(PackageStateMBean.PACKAGES_TYPE, table.getTabularType());
Collection values = table.values();
Assert.assertEquals(1, values.size());
CompositeData data = (CompositeData) values.iterator().next();
Long[] exportingBundles = (Long[]) data.get(PackageStateMBean.EXPORTING_BUNDLES);
Assert.assertArrayEquals(new Long[] { Long.valueOf(4) }, exportingBundles);
String name = (String) data.get(PackageStateMBean.NAME);
Assert.assertEquals("test", name);
String version = (String) data.get(PackageStateMBean.VERSION);
Assert.assertEquals("1.0.0", version);
}
use of org.osgi.service.packageadmin.ExportedPackage in project sling by apache.
the class PackageAdminClassLoader method findBundlesForPackage.
/**
* Find the bundle for a given package.
* @param pckName The package name.
* @return The bundle or <code>null</code>
*/
private Set<Bundle> findBundlesForPackage(final String pckName) {
final ExportedPackage[] exportedPackages = this.packageAdmin.getExportedPackages(pckName);
Set<Bundle> bundles = new LinkedHashSet<>();
if (exportedPackages != null) {
for (ExportedPackage exportedPackage : exportedPackages) {
if (!exportedPackage.isRemovalPending()) {
Bundle bundle = exportedPackage.getExportingBundle();
if (isBundleActive(bundle)) {
bundles.add(bundle);
}
}
}
}
return bundles;
}
Aggregations