EntitiesBundleMonitor implements BundleListener, ServiceListener { public void start(File src, boolean startBundle) { LOGGER.debug("Starting bundle from: {}", src); try (InputStream stream = new FileInputStream(src)) { Bundle entitiesBundle = getEntitiesBundle(); if (entitiesBundle == null) { LOGGER.info("Entities bundle does not exist"); install(stream); } else if (Bundle.INSTALLED == entitiesBundle.getState()) { LOGGER.info("Entities bundle exists and it is installed"); update(stream); } else { LOGGER.info("Entities bundle exists and it is resolved"); stopEntitiesBundle(); update(stream); } if (startBundle) { start(); } } catch (IOException e) { throw new MdsException("Unable to read temporary entities bundle", e); } }  void init(); @Override void bundleChanged(BundleEvent event); @Override void serviceChanged(ServiceEvent event); void waitForEntitiesContext(); void start(File src, boolean startBundle); String bundleLocation(); void start(); @Autowired void setBundleContext(BundleContext bundleContext); void stopEntitiesBundle();  }
@Test(expected = MdsEntityWireException.class) public void shouldThrowEntityWireExceptionWhenUnableToResolveEntitiesBundle() throws BundleException { when(bundleContext.getBundles()).thenReturn(new Bundle[] { entitiesBundle }); doThrow(new BundleException("Error resolving bundle", BundleException.RESOLVE_ERROR)) .when(entitiesBundle).start(); monitor.start(); }
@Test(expected = MdsException.class) public void shouldThrowEntityMdsExceptionForNonResolveErrors() throws BundleException { when(bundleContext.getBundles()).thenReturn(new Bundle[] { entitiesBundle }); doThrow(new BundleException("Error resolving bundle", BundleException.MANIFEST_ERROR)) .when(entitiesBundle).start(); monitor.start(); }