Search in sources :

Example 16 with Feature

use of org.apache.karaf.features.Feature in project ddf by codice.

the class ApplicationServiceImplTest method testStopApplicationNoMainFeatureStringParam.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(String)} method
     * for the case where there is no main feature, but other features exist
     *
     * @throws Exception
     */
@Test
public void testStopApplicationNoMainFeatureStringParam() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Feature[] featureList = noMainFeatureRepo1.getFeatures();
    appService.stopApplication(TEST_APP);
    verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService).uninstallFeature(featureList[1].getName(), featureList[1].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 17 with Feature

use of org.apache.karaf.features.Feature in project ddf by codice.

the class ApplicationServiceImplTest method testFindFeatureExceptions.

/**
     * Tests the {@link ApplicationServiceImpl#findFeature(Feature)} method
     * for the case where exceptions are thrown inside findFeature(Feature, Set<Application>)
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix and un-ignore
@Test
@Ignore
public void testFindFeatureExceptions() throws Exception {
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    final Appender mockAppender = mock(Appender.class);
    when(mockAppender.getName()).thenReturn("MOCK");
    root.addAppender(mockAppender);
    Application testApp = mock(ApplicationImpl.class);
    final Set<Application> applicationSet = new HashSet<>();
    applicationSet.add(testApp);
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }

        @Override
        public Set<Application> getApplications() {
            return applicationSet;
        }

        @Override
        public boolean isPermittedToViewFeature(String featureName) {
            return true;
        }
    };
    Feature testFeature = mock(Feature.class);
    doThrow(new NullPointerException()).when(testApp).getFeatures();
    appService.findFeature(testFeature);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(FIND_FEAT_EX);
        }
    }));
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(FIND_FEAT_EX2);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Mockito.anyString(org.mockito.Mockito.anyString) Logger(org.slf4j.Logger) Feature(org.apache.karaf.features.Feature) Repository(org.apache.karaf.features.Repository) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with Feature

use of org.apache.karaf.features.Feature in project ddf by codice.

the class ApplicationImplTest method testAppGetters.

/**
     * Verify that the application is properly exposing the underlying
     * repository.
     *
     * @throws Exception
     */
@Test
public void testAppGetters() throws Exception {
    RepositoryImpl repo = new RepositoryImpl(getClass().getClassLoader().getResource(FILE_NO_MAIN_FEATURES).toURI());
    repo.load();
    Application testApp = new ApplicationImpl(repo);
    assertEquals(TEST_APP, testApp.getName());
    Set<Feature> appFeatures = testApp.getFeatures();
    assertNotNull(appFeatures);
    assertEquals(repo.getFeatures().length, appFeatures.size());
    assertTrue(appFeatures.containsAll(Arrays.asList(repo.getFeatures())));
    assertNull(testApp.getMainFeature());
    assertEquals(NUM_BUNDLES, testApp.getBundles().size());
}
Also used : RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 19 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)

Example 20 with Feature

use of org.apache.karaf.features.Feature in project fabric8 by jboss-fuse.

the class FabricFeaturesServiceImpl method installFeatures.

@Override
public void installFeatures(Set<Feature> features, EnumSet<Option> options) throws Exception {
    StringBuffer sb = new StringBuffer();
    for (Feature feature : features) {
        sb.append("--feature ").append(feature.getName());
    }
    unsupportedInstallFeature(sb.toString());
}
Also used : Feature(org.apache.karaf.features.Feature)

Aggregations

Feature (org.apache.karaf.features.Feature)130 Test (org.junit.Test)57 FeaturesService (org.apache.karaf.features.FeaturesService)44 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 VersionRange (org.apache.felix.utils.version.VersionRange)12 IOException (java.io.IOException)11 LinkedHashSet (java.util.LinkedHashSet)11 Version (org.osgi.framework.Version)11 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 EnumSet (java.util.EnumSet)9