expect(bundleContext.getDataFile(EasyMock.<String>anyObject())).andReturn(dataFile).anyTimes();
replay(bundleContext, installedBundle);
FeaturesServiceImpl svc = new FeaturesServiceImpl();
svc.setBundleContext(bundleContext);
svc.addRepository(uri);
verify(bundleContext, installedBundle);
reset(bundleContext, installedBundle);
// required since the sorted set uses it
expect(installedBundle.compareTo(EasyMock.<Bundle>anyObject())).andReturn(0).anyTimes();
// 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(installedBundle.getBundleId()).andReturn(12345L);
expect(installedBundle.getBundleId()).andReturn(12345L);
expect(bundleContext.getBundle(12345L)).andReturn(installedBundle);
expect(installedBundle.getHeaders()).andReturn(new Hashtable());
installedBundle.start();
// 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(installedBundle.getBundleId()).andReturn(123456L);
expect(installedBundle.getBundleId()).andReturn(123456L);
expect(bundleContext.getBundle(123456L)).andReturn(installedBundle);
expect(installedBundle.getHeaders()).andReturn(new Hashtable());
installedBundle.start();
// UnInstalls f1 and 0.1
expect(bundleContext.getBundle(12345)).andReturn(installedBundle);
installedBundle.uninstall();
// UnInstalls f1 and 0.2
expect(bundleContext.getBundle(123456)).andReturn(installedBundle);
installedBundle.uninstall();
expect(bundleContext.getDataFile(EasyMock.<String>anyObject())).andReturn(dataFile).anyTimes();
// refresh
expect(bundleContext.getBundle(0)).andStubReturn(sysBundle);
expect(sysBundle.adapt(FrameworkWiring.class)).andStubReturn(frameworkWiring);
final Capture<FrameworkListener> listeners = new Capture<FrameworkListener>();
frameworkWiring.refreshBundles(EasyMock.<Collection<Bundle>>eq(null), capture(listeners));
expectLastCall().andStubAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
for (FrameworkListener listener : listeners.getValues()) {
listener.frameworkEvent(new FrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, sysBundle, null));
}
return null;
}
});
replay(bundleContext, installedBundle, sysBundle, frameworkWiring);
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");
}