use of org.apache.karaf.features.internal.support.TestBundle in project karaf by apache.
the class DeployerTest method testUpdateSimpleFeature.
@Test
public void testUpdateSimpleFeature() throws Exception {
IMocksControl c = EasyMock.createControl();
final String dataDir = "data1";
TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
Feature f100 = repo.getFeatures()[0];
Feature f101 = repo.getFeatures()[1];
Deployer.DeployCallback callback = c.createMock(Deployer.DeployCallback.class);
Deployer deployer = new Deployer(manager, resolver, callback);
final TestBundle bundleA = createTestBundle(1L, Bundle.ACTIVE, dataDir, "a100");
callback.print(EasyMock.anyString(), EasyMock.anyBoolean());
EasyMock.expectLastCall().anyTimes();
callback.callListeners(DeploymentEvent.DEPLOYMENT_STARTED);
EasyMock.expectLastCall();
callback.stopBundle(EasyMock.eq(bundleA), anyInt());
EasyMock.expectLastCall().andStubAnswer(() -> {
bundleA.state = Bundle.RESOLVED;
return null;
});
callback.updateBundle(EasyMock.eq(bundleA), EasyMock.anyObject(), EasyMock.anyObject());
EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
URL loc = getClass().getResource(dataDir + "/" + "a101" + ".mf");
Manifest man = new Manifest(loc.openStream());
Hashtable<String, String> headers = new Hashtable<>();
for (Map.Entry<Object, Object> attr : man.getMainAttributes().entrySet()) {
headers.put(attr.getKey().toString(), attr.getValue().toString());
}
bundleA.update(headers);
return null;
}
});
callback.startBundle(EasyMock.eq(bundleA));
EasyMock.expectLastCall();
callback.replaceDigraph(EasyMock.anyObject(), EasyMock.anyObject());
EasyMock.expectLastCall();
callback.saveState(EasyMock.anyObject());
EasyMock.expectLastCall();
callback.installConfigs(f101);
EasyMock.expectLastCall();
callback.installLibraries(f101);
EasyMock.expectLastCall();
callback.callListeners(DeploymentEvent.BUNDLES_INSTALLED);
EasyMock.expectLastCall();
callback.resolveBundles(EasyMock.eq(Collections.singleton(bundleA)), EasyMock.anyObject(), EasyMock.anyObject());
EasyMock.expectLastCall();
callback.callListeners(DeploymentEvent.BUNDLES_RESOLVED);
EasyMock.expectLastCall();
callback.refreshPackages(EasyMock.eq(Collections.singleton(bundleA)));
EasyMock.expectLastCall();
callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureUninstalled, f100, FeaturesService.ROOT_REGION, false)));
EasyMock.expectLastCall();
callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled, f101, FeaturesService.ROOT_REGION, false)));
EasyMock.expectLastCall();
callback.callListeners(DeploymentEvent.DEPLOYMENT_FINISHED);
EasyMock.expectLastCall();
c.replay();
Deployer.DeploymentState dstate = new Deployer.DeploymentState();
dstate.state = new State();
addToMapSet(dstate.state.installedFeatures, ROOT_REGION, f100.getId());
addToMapSet(dstate.state.managedBundles, ROOT_REGION, 1L);
dstate.bundles = new HashMap<>();
dstate.bundles.put(1L, bundleA);
dstate.bundlesPerRegion = new HashMap<>();
addToMapSet(dstate.bundlesPerRegion, ROOT_REGION, 1L);
dstate.partitionFeatures(Arrays.asList(f100, f101));
dstate.filtersPerRegion = new HashMap<>();
dstate.filtersPerRegion.put(ROOT_REGION, new HashMap<>());
Deployer.DeploymentRequest request = new Deployer.DeploymentRequest();
request.bundleUpdateRange = DEFAULT_BUNDLE_UPDATE_RANGE;
request.featureResolutionRange = DEFAULT_FEATURE_RESOLUTION_RANGE;
request.globalRepository = null;
request.options = EnumSet.noneOf(Option.class);
request.stateChanges = Collections.emptyMap();
request.updateSnaphots = SnapshotUpdateBehavior.None;
request.requirements = new HashMap<>();
addToMapSet(request.requirements, ROOT_REGION, f101.getName() + "/" + new VersionRange(f101.getVersion(), true));
deployer.deploy(dstate, request);
c.verify();
}
use of org.apache.karaf.features.internal.support.TestBundle in project karaf by apache.
the class DeployerTest method createTestBundle.
private TestBundle createTestBundle(long bundleId, int state, String dir, String name) throws IOException, BundleException {
URL loc = getClass().getResource(dir + "/" + name + ".mf");
Manifest man = new Manifest(loc.openStream());
Hashtable<String, String> headers = new Hashtable<>();
for (Map.Entry<Object, Object> attr : man.getMainAttributes().entrySet()) {
headers.put(attr.getKey().toString(), attr.getValue().toString());
}
return new TestBundle(bundleId, name, state, headers);
}
Aggregations