Search in sources :

Example 46 with Feature

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());
}
Also used : Option(org.apache.karaf.features.FeaturesService.Option) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) FeaturesService(org.apache.karaf.features.FeaturesService) Assert.assertSame(org.junit.Assert.assertSame) java.net(java.net) Slf4jResolverLog(org.apache.karaf.features.internal.resolver.Slf4jResolverLog) Map(java.util.Map) After(org.junit.After) TestBase(org.apache.karaf.features.TestBase) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) EnumSet(java.util.EnumSet) Hashtable(java.util.Hashtable) Before(org.junit.Before) OutputStream(java.io.OutputStream) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Capture(org.easymock.Capture) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Feature(org.apache.karaf.features.Feature) FeatureState(org.apache.karaf.features.FeatureState) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) ResolverImpl(org.apache.felix.resolver.ResolverImpl) EasyMock(org.easymock.EasyMock) Resolver(org.osgi.service.resolver.Resolver) EasyMock.expect(org.easymock.EasyMock.expect) Field(java.lang.reflect.Field) Version(org.osgi.framework.Version) File(java.io.File) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) Assert.assertFalse(org.junit.Assert.assertFalse) DownloadManager(org.apache.karaf.features.internal.download.DownloadManager) Collections(java.util.Collections) FrameworkInfo(org.apache.karaf.features.internal.service.BundleInstallSupport.FrameworkInfo) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) FrameworkInfo(org.apache.karaf.features.internal.service.BundleInstallSupport.FrameworkInfo) Hashtable(java.util.Hashtable) Feature(org.apache.karaf.features.Feature) Version(org.osgi.framework.Version) TestDownloadManager(org.apache.karaf.features.internal.support.TestDownloadManager) BundleRevision(org.osgi.framework.wiring.BundleRevision) FeaturesService(org.apache.karaf.features.FeaturesService) Option(org.apache.karaf.features.FeaturesService.Option) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 47 with Feature

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());
}
Also used : Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 48 with Feature

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]);
}
Also used : Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 49 with Feature

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]);
}
Also used : Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 50 with Feature

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;
}
Also used : Feature(org.apache.karaf.features.Feature)

Aggregations

Feature (org.apache.karaf.features.Feature)127 Test (org.junit.Test)56 FeaturesService (org.apache.karaf.features.FeaturesService)43 HashSet (java.util.HashSet)41 Repository (org.apache.karaf.features.Repository)39 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)18 Bundle (org.osgi.framework.Bundle)18 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 Map (java.util.Map)16 Dependency (org.apache.karaf.features.Dependency)15 BundleInfo (org.apache.karaf.features.BundleInfo)14 Application (org.codice.ddf.admin.application.service.Application)14 URI (java.net.URI)13 IOException (java.io.IOException)12 VersionRange (org.apache.felix.utils.version.VersionRange)12 LinkedHashSet (java.util.LinkedHashSet)11 Version (org.osgi.framework.Version)11 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 EnumSet (java.util.EnumSet)9