private void installAndStartBundles(BundleContext context) throws BundleException {

    m_framework.start();

    StartLevel sl = getStartLevelService(context);

    for (ProvisionOption bundle : m_bundles) {
      Bundle b = null;
      b = context.installBundle(bundle.getURL());
      int startLevel = getStartLevel(bundle);
      sl.setBundleStartLevel(b, startLevel);
      b.start();
      LOG.info("+ Install (start@" + startLevel + ") " + bundle);
    }
    LOG.info("++++ Jump to startlevel: " + Constants.START_LEVEL_TEST_BUNDLE);
    sl.setStartLevel(Constants.START_LEVEL_TEST_BUNDLE);
    // Work around for FELIX-2942
    final CountDownLatch latch = new CountDownLatch(1);
    context.addFrameworkListener(
        new FrameworkListener() {
          public void frameworkEvent(FrameworkEvent frameworkEvent) {
            switch (frameworkEvent.getType()) {
              case FrameworkEvent.STARTLEVEL_CHANGED:
                latch.countDown();
            }
          }
        });
    try {
      latch.await(m_timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
  @Test
  public void testStartLevel() throws Exception {

    assertNotNull("StartLevel injected", startLevel);
    int initialStartLevel = startLevel.getInitialBundleStartLevel();
    assertEquals("Initial bundle start level", 1, initialStartLevel);

    assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());
    assertEquals("arq465-bundle", bundle.getSymbolicName());

    int bundleStartLevel = startLevel.getBundleStartLevel(bundle);
    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() {
          public void frameworkEvent(FrameworkEvent event) {
            if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED) latch.countDown();
          }
        });
    startLevel.setStartLevel(3);
    latch.await(3, TimeUnit.SECONDS);

    // The bundle should now be started
    assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundle.getState());

    bundle.stop();
    assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());

    bundle.uninstall();
    assertEquals("Bundle UNINSTALLED", Bundle.UNINSTALLED, bundle.getState());
  }