Search in sources :

Example 81 with BundleEvent

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();
}
Also used : BundleEvent(org.osgi.framework.BundleEvent) CompositeBundle(org.osgi.service.framework.CompositeBundle) Test(org.junit.Test)

Example 82 with BundleEvent

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));
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BundleEvent(org.osgi.framework.BundleEvent) Test(org.junit.Test)

Example 83 with BundleEvent

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);
}
Also used : EventHook(org.osgi.framework.hooks.bundle.EventHook) FindHook(org.osgi.framework.hooks.bundle.FindHook) Iterator(java.util.Iterator) BundleEvent(org.osgi.framework.BundleEvent) Collection(java.util.Collection) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Aggregations

BundleEvent (org.osgi.framework.BundleEvent)83 Bundle (org.osgi.framework.Bundle)49 Test (org.junit.Test)24 SynchronousBundleListener (org.osgi.framework.SynchronousBundleListener)17 BundleListener (org.osgi.framework.BundleListener)15 FeatureDTO (com.amitinside.featureflags.dto.FeatureDTO)11 File (java.io.File)10 IOException (java.io.IOException)10 BundleException (org.osgi.framework.BundleException)10 BundleContext (org.osgi.framework.BundleContext)9 FrameworkEvent (org.osgi.framework.FrameworkEvent)7 StartLevel (org.osgi.service.startlevel.StartLevel)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 BundleTracker (org.osgi.util.tracker.BundleTracker)5 Map (java.util.Map)4 ServiceReference (org.osgi.framework.ServiceReference)4 BundleTrackerCustomizer (org.osgi.util.tracker.BundleTrackerCustomizer)4 FileInputStream (java.io.FileInputStream)3