use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeaturesServiceImplTest method testInstallAndStop.
@Test
public void testInstallAndStop() throws Exception {
Capture<Bundle> stoppedBundle = Capture.newInstance();
Bundle bundle = EasyMock.niceMock(Bundle.class);
BundleStartLevel bundleStartLevel = EasyMock.niceMock(BundleStartLevel.class);
BundleRevision bundleRevision = EasyMock.niceMock(BundleRevision.class);
FeaturesServiceConfig cfg = new FeaturesServiceConfig();
BundleInstallSupport installSupport = EasyMock.niceMock(BundleInstallSupport.class);
FrameworkInfo dummyInfo = new FrameworkInfo();
expect(installSupport.getInfo()).andReturn(dummyInfo).atLeastOnce();
expect(installSupport.installBundle(EasyMock.eq("root"), EasyMock.eq("a100"), anyObject())).andReturn(bundle);
installSupport.startBundle(bundle);
expectLastCall();
expect(bundle.getBundleId()).andReturn(1L).anyTimes();
expect(bundle.getSymbolicName()).andReturn("a").anyTimes();
expect(bundle.getVersion()).andReturn(new Version("1.0.0")).anyTimes();
expect(bundle.getHeaders()).andReturn(new Hashtable<>()).anyTimes();
expect(bundle.adapt(BundleStartLevel.class)).andReturn(bundleStartLevel).anyTimes();
expect(bundle.adapt(BundleRevision.class)).andReturn(bundleRevision).anyTimes();
expect(bundleRevision.getBundle()).andReturn(bundle).anyTimes();
expect(bundleRevision.getCapabilities(null)).andReturn(Collections.emptyList()).anyTimes();
expect(bundleRevision.getRequirements(null)).andReturn(Collections.emptyList()).anyTimes();
EasyMock.replay(installSupport, bundle, bundleStartLevel, bundleRevision);
FeaturesService featureService = new FeaturesServiceImpl(new Storage(), null, null, this.resolver, installSupport, null, cfg) {
@Override
protected DownloadManager createDownloadManager() throws IOException {
return new TestDownloadManager(FeaturesServiceImplTest.class, "data1");
}
};
URI repoA = URI.create("custom:data1/features.xml");
featureService.addRepository(repoA);
Feature test100 = featureService.getFeature("f", "1.0.0");
installFeature(featureService, test100);
assertInstalled(featureService, test100);
dummyInfo.bundles.put(1L, bundle);
Map<String, Map<String, FeatureState>> states = new HashMap<>();
states.computeIfAbsent("root", k -> new HashMap<>()).put("f/1.0.0", FeatureState.Resolved);
EasyMock.reset(installSupport, bundle, bundleRevision, bundleStartLevel);
expect(installSupport.getInfo()).andReturn(dummyInfo).anyTimes();
installSupport.stopBundle(EasyMock.capture(stoppedBundle), EasyMock.anyInt());
expectLastCall();
expect(bundle.getBundleId()).andReturn(1L).anyTimes();
expect(bundle.getSymbolicName()).andReturn("a").anyTimes();
expect(bundle.getVersion()).andReturn(new Version("1.0.0")).anyTimes();
expect(bundle.getHeaders()).andReturn(new Hashtable<>()).anyTimes();
expect(bundle.adapt(BundleStartLevel.class)).andReturn(bundleStartLevel).anyTimes();
expect(bundle.adapt(BundleRevision.class)).andReturn(bundleRevision).anyTimes();
expect(bundleRevision.getBundle()).andReturn(bundle).anyTimes();
expect(bundleRevision.getCapabilities(null)).andReturn(Collections.emptyList()).anyTimes();
expect(bundleRevision.getRequirements(null)).andReturn(Collections.emptyList()).anyTimes();
EasyMock.replay(installSupport, bundle, bundleRevision, bundleStartLevel);
featureService.updateFeaturesState(states, EnumSet.noneOf(Option.class));
assertSame(bundle, stoppedBundle.getValue());
}
use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeaturesServiceImplTest method testGetFeatureStripVersion.
@Test
public void testGetFeatureStripVersion() throws Exception {
Feature transactionFeature = feature("transaction", "1.0.0");
FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature);
Feature[] features = impl.getFeatures("transaction", " 1.0.0 ");
assertEquals(1, features.length);
Feature feature = features[0];
assertNotNull(feature);
assertSame("transaction", feature.getName());
}
use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeaturesServiceImplTest method testListFeatureWithoutVersion.
@Test
public void testListFeatureWithoutVersion() throws Exception {
Feature transactionFeature = feature("transaction", "1.0.0");
FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature);
assertNotNull(impl.getFeatures("transaction", null));
assertSame(transactionFeature, impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)[0]);
}
use of org.apache.karaf.features.Feature in project karaf by apache.
the class FeaturesServiceImplTest method testGetFeature.
@Test
public void testGetFeature() throws Exception {
Feature transactionFeature = feature("transaction", "1.0.0");
FeaturesServiceImpl impl = featuresServiceWithFeatures(transactionFeature);
assertNotNull(impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION));
assertSame(transactionFeature, impl.getFeatures("transaction", org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)[0]);
}
use of org.apache.karaf.features.Feature in project fabric8 by jboss-fuse.
the class FabricFeaturesServiceImpl method getFeature.
@Override
public Feature getFeature(String name) throws Exception {
assertValid();
Feature[] features = listFeatures();
for (Feature feature : features) {
if (name.equals(feature.getName())) {
return feature;
}
}
return null;
}
Aggregations