@Test
@Ignore
public void testStartLevel() throws Exception {
FrameworkStartLevel fwStartLevel = context.getBundle().adapt(FrameworkStartLevel.class);
int initialStartLevel = fwStartLevel.getInitialBundleStartLevel();
assertEquals("Initial bundle start level", 1, initialStartLevel);
assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());
assertEquals("start-level-bundle", bundle.getSymbolicName());
BundleStartLevel bStartLevel = bundle.adapt(BundleStartLevel.class);
int bundleStartLevel = bStartLevel.getStartLevel();
assertEquals("Bundle start level", 3, bundleStartLevel);
try {
bundle.start(Bundle.START_TRANSIENT);
fail("Bundle cannot be started due to the Framework's current start level");
} catch (BundleException ex) {
// expected
}
assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());
// The bundle should not be started
bundle.start();
assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());
// Change the frameworkj start level and wait for the changed event
final CountDownLatch latch = new CountDownLatch(1);
context.addFrameworkListener(new FrameworkListener() {
@Override
public void frameworkEvent(FrameworkEvent event) {
if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED)
latch.countDown();
}
});
fwStartLevel.setStartLevel(3);
latch.await(3, TimeUnit.SECONDS);
// The bundle should now be started
assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundle.getState());