use of org.osgi.framework.BundleEvent in project aries by apache.
the class RecursiveBundleTrackerTest method testCompositeLifeCycle.
@Test
public void testCompositeLifeCycle() {
makeSUT();
CompositeBundle cb = composite("test.composite", "1.0.0");
assertNoTrackers();
// full lifecycle
sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
assertTracker(cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.RESOLVED, cb), cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STARTING, cb), cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STARTED, cb), cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STOPPING, cb), cb);
sut.removedBundle(cb, new BundleEvent(BundleEvent.STOPPED, cb), cb);
assertNoTrackers();
// short lifecycle
sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
assertTracker(cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.RESOLVED, cb), cb);
sut.removedBundle(cb, new BundleEvent(BundleEvent.UNRESOLVED, cb), cb);
assertNoTrackers();
// shortest lifecycle
sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
assertTracker(cb);
sut.removedBundle(cb, new BundleEvent(BundleEvent.UNINSTALLED, cb), cb);
assertNoTrackers();
}
use of org.osgi.framework.BundleEvent in project aries by apache.
the class BundleEventDataTest method testToCompositeData.
@Test
public void testToCompositeData() throws Exception {
BundleEvent event = mock(BundleEvent.class);
Bundle bundle = mock(Bundle.class);
when(event.getBundle()).thenReturn(bundle);
when(bundle.getSymbolicName()).thenReturn("test");
when(bundle.getBundleId()).thenReturn(new Long(4));
when(bundle.getLocation()).thenReturn("location");
when(event.getType()).thenReturn(BundleEvent.INSTALLED);
BundleEventData eventData = new BundleEventData(event);
CompositeData eventCompositeData = eventData.toCompositeData();
assertEquals(new Long(4), (Long) eventCompositeData.get(IDENTIFIER));
assertEquals("test", (String) eventCompositeData.get(SYMBOLIC_NAME));
assertEquals(new Integer(BundleEvent.INSTALLED), (Integer) eventCompositeData.get(EVENT));
assertEquals("location", (String) eventCompositeData.get(LOCATION));
}
use of org.osgi.framework.BundleEvent in project aries by apache.
the class BlueprintContainerUseSystemContextTest method regiserHook.
@Before
public void regiserHook() {
final BundleContext systemContext = context().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
eventHook = context().registerService(EventHook.class, new EventHook() {
@Override
public void event(BundleEvent event, Collection contexts) {
if ("org.apache.aries.blueprint.sample".equals(event.getBundle().getSymbolicName())) {
// hide sample from everything but the system bundle
// TODO on R6 we should be able to even try hiding from the system bundle
// R5 it was not clear if hooks could hide from the system bundle
// equinox R5 does allow hiding from system bundle
contexts.retainAll(Collections.singleton(systemContext));
}
}
}, null);
findHook = context().registerService(FindHook.class, new FindHook() {
@Override
public void find(BundleContext context, Collection bundles) {
if (context.equals(systemContext)) {
// equinox R5 does allow hiding from system bundle
return;
}
for (Iterator iBundles = bundles.iterator(); iBundles.hasNext(); ) {
if ("org.apache.aries.blueprint.sample".equals(((Bundle) iBundles.next()).getSymbolicName())) {
// hide sample from everything
iBundles.remove();
}
}
}
}, null);
}
Aggregations