prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
replay(preferencesService, prefs, repositoriesNode, featuresNode, bundleContext, installedBundle);
FeaturesServiceImpl svc = new FeaturesServiceImpl();
svc.setPreferences(preferencesService);
svc.setBundleContext(bundleContext);
svc.addRepository(uri);
verify(preferencesService, prefs, repositoriesNode, featuresNode, bundleContext, installedBundle);
reset(preferencesService, prefs, repositoriesNode, featuresNode, bundleContext, installedBundle);
// Installs f1 and 0.1
expect(bundleContext.getBundles()).andReturn(new Bundle[0]);
expect(bundleContext.installBundle(isA(String.class),
isA(InputStream.class))).andReturn(installedBundle);
expect(installedBundle.getBundleId()).andReturn(12345L);
expect(bundleContext.getBundle(12345L)).andReturn(installedBundle);
expect(installedBundle.getHeaders()).andReturn(new Hashtable());
installedBundle.start();
expect(preferencesService.getUserPreferences("FeaturesServiceState")).andStubReturn(prefs);
expect(prefs.node("repositories")).andReturn(repositoriesNode);
repositoriesNode.clear();
repositoriesNode.putInt("count", 1);
repositoriesNode.put("item.0", uri.toString());
expect(prefs.node("features")).andReturn(featuresNode);
featuresNode.clear();
featuresNode.put("f1" + FeatureImpl.SPLIT_FOR_NAME_AND_VERSION + "0.1", "12345");
prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
// Installs f1 and 0.2
expect(bundleContext.getBundles()).andReturn(new Bundle[0]);
expect(bundleContext.installBundle(isA(String.class),
isA(InputStream.class))).andReturn(installedBundle);
expect(installedBundle.getBundleId()).andReturn(123456L);
expect(bundleContext.getBundle(123456L)).andReturn(installedBundle);
expect(installedBundle.getHeaders()).andReturn(new Hashtable());
installedBundle.start();
expect(preferencesService.getUserPreferences("FeaturesServiceState")).andStubReturn(prefs);
expect(prefs.node("repositories")).andReturn(repositoriesNode);
repositoriesNode.clear();
repositoriesNode.putInt("count", 1);
repositoriesNode.put("item.0", uri.toString());
expect(prefs.node("features")).andReturn(featuresNode);
featuresNode.clear();
featuresNode.put("f1" + FeatureImpl.SPLIT_FOR_NAME_AND_VERSION + "0.1", "12345");
featuresNode.put("f1" + FeatureImpl.SPLIT_FOR_NAME_AND_VERSION + "0.2", "123456");
prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
// UnInstalls f1 and 0.1
expect(bundleContext.getBundle(12345)).andReturn(installedBundle);
installedBundle.uninstall();
expect(preferencesService.getUserPreferences("FeaturesServiceState")).andStubReturn(prefs);
expect(prefs.node("repositories")).andReturn(repositoriesNode);
repositoriesNode.clear();
repositoriesNode.putInt("count", 1);
repositoriesNode.put("item.0", uri.toString());
expect(prefs.node("features")).andReturn(featuresNode);
featuresNode.clear();
featuresNode.put("f1" + FeatureImpl.SPLIT_FOR_NAME_AND_VERSION + "0.2", "123456");
prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
// UnInstalls f1 and 0.2
expect(bundleContext.getBundle(123456)).andReturn(installedBundle);
installedBundle.uninstall();
expect(preferencesService.getUserPreferences("FeaturesServiceState")).andStubReturn(prefs);
expect(prefs.node("repositories")).andReturn(repositoriesNode);
repositoriesNode.clear();
repositoriesNode.putInt("count", 1);
repositoriesNode.put("item.0", uri.toString());
expect(prefs.node("features")).andReturn(featuresNode);
featuresNode.clear();
prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
replay(preferencesService, prefs, repositoriesNode, featuresNode, bundleContext, installedBundle);
try {
svc.uninstallFeature("f1");
fail("Uninstall should have failed as feature is not installed");
} catch (Exception e) {
// ok
}
svc.installFeature("f1", "0.1", EnumSet.of(FeaturesService.Option.NoAutoRefreshBundles));
svc.installFeature("f1", "0.2", EnumSet.of(FeaturesService.Option.NoAutoRefreshBundles));
try {
svc.uninstallFeature("f1");
fail("Uninstall should have failed as feature is installed in multiple versions");
} catch (Exception e) {
// ok
}
svc.uninstallFeature("f1", "0.1");
svc.uninstallFeature("f1");
}