URI uri = tmp.toURI();
// loads the state
Preferences prefs = EasyMock.createMock(Preferences.class);
PreferencesService preferencesService = EasyMock.createMock(PreferencesService.class);
Preferences repositoriesNode = EasyMock.createMock(Preferences.class);
Preferences featuresNode = EasyMock.createMock(Preferences.class);
BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
Bundle installedBundle = EasyMock.createMock(Bundle.class);
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();
// Installs first feature name = f1, version = 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 second feature name = f1, version = 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();
// Installs third feature name = f2, version = 0.2
expect(bundleContext.getBundles()).andReturn(new Bundle[0]);
expect(bundleContext.installBundle(isA(String.class),
isA(InputStream.class))).andReturn(installedBundle);
expect(installedBundle.getBundleId()).andReturn(1234567L);
expect(bundleContext.getBundle(1234567L)).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");
featuresNode.put("f2" + FeatureImpl.SPLIT_FOR_NAME_AND_VERSION + "0.2", "1234567");
prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
expect(preferencesService.getUserPreferences("FeaturesServiceState")).andStubReturn(prefs);
expect(prefs.node("repositories")).andReturn(repositoriesNode);
repositoriesNode.clear();
repositoriesNode.putInt("count", 0);
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");
featuresNode.put("f2" + FeatureImpl.SPLIT_FOR_NAME_AND_VERSION + "0.2", "1234567");
prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
expect(installedBundle.getHeaders()).andReturn(new Hashtable()).anyTimes();
// uninstallAllFeatures
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");
featuresNode.put("f2" + FeatureImpl.SPLIT_FOR_NAME_AND_VERSION + "0.2", "1234567");
prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
// uninstalls first feature name = f1, version = 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");
featuresNode.put("f2" + FeatureImpl.SPLIT_FOR_NAME_AND_VERSION + "0.2", "1234567");
prefs.putBoolean("bootFeaturesInstalled", false);
prefs.flush();
// uninstalls third feature name = f2, version = 0.2
expect(bundleContext.getBundle(1234567)).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 second feature name = f1, version = 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();
expect(preferencesService.getUserPreferences("FeaturesServiceState")).andStubReturn(prefs);
expect(prefs.node("repositories")).andReturn(repositoriesNode);
repositoriesNode.clear();
repositoriesNode.putInt("count", 0);
repositoriesNode.put("item.0", uri.toString());
expect(prefs.node("features")).andReturn(featuresNode);