Search in sources :

Example 91 with Feature

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

the class ApplicationServiceImplTest method testStopApplicationMainFeatureStringParam.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(String)} method
     * for the case where a main feature exists
     *
     * @throws Exception
     */
@Test
public void testStopApplicationMainFeatureStringParam() 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 = mainFeatureRepo.getFeatures();
    appService.stopApplication(TEST_APP);
    verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].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 92 with Feature

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

the class ApplicationServiceImplTest method testStartApplicationMainFeature.

/**
     * Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
     * for the case where there a main feature exists
     *
     * @throws Exception
     */
@Test
public void testStartApplicationMainFeature() 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 = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    Application testApp = mock(ApplicationImpl.class);
    Feature testFeature = mock(Feature.class);
    when(testFeature.getName()).thenReturn(TEST_FEATURE_1_NAME);
    Set<Feature> features = new HashSet<>(Arrays.asList(testFeature));
    Set<String> featureNames = new HashSet<>(features.size());
    features.forEach(f -> featureNames.add(f.getName()));
    when(testApp.getAutoInstallFeatures()).thenReturn(features);
    appService.startApplication(testApp);
    verify(featuresService, atLeastOnce()).installFeatures(featureNames, EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Mockito.anyString(org.mockito.Mockito.anyString) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 93 with Feature

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

the class ApplicationServiceImplTest method testFindApplicationFeatures.

/**
     * Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
     *
     * @throws Exception
     */
@Test
public void testFindApplicationFeatures() 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 testFeature1 = mock(Feature.class);
    Feature[] featureList = { testFeature1 };
    Repository testRepo = mock(Repository.class);
    when(testFeature1.getRepositoryUrl()).thenReturn(TEST_REPO_URI);
    when(testRepo.getURI()).thenReturn(new URI(TEST_REPO_URI));
    when(testRepo.getFeatures()).thenReturn(featureList);
    Repository[] repositoryList = { testRepo };
    when(featuresService.getFeature(TEST_APP_NAME)).thenReturn(testFeature1);
    when(featuresService.listRepositories()).thenReturn(repositoryList);
    when(featuresService.isInstalled(testFeature1)).thenReturn(true);
    List<FeatureDetails> result = appService.findApplicationFeatures(TEST_APP_NAME);
    assertThat("Should return one feature.", result.size(), is(1));
}
Also used : Repository(org.apache.karaf.features.Repository) FeatureDetails(org.codice.ddf.admin.application.rest.model.FeatureDetails) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) URI(java.net.URI) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 94 with Feature

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

the class ApplicationServiceImplTest method testRemoveApplicationApplicationParam.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
     *
     * @throws Exception
     */
@Test
public void testRemoveApplicationApplicationParam() 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();
    Application testApp = mock(ApplicationImpl.class);
    Feature testFeature1 = mock(Feature.class);
    Feature testFeature2 = mock(Feature.class);
    Set<Feature> featureSet = new HashSet<>();
    featureSet.add(testFeature1);
    featureSet.add(testFeature2);
    featuresService.installFeature(testFeature1, EnumSet.noneOf(Option.class));
    featuresService.installFeature(testFeature2, EnumSet.noneOf(Option.class));
    when(testApp.getFeatures()).thenReturn(featureSet);
    when(featuresService.isInstalled(testFeature1)).thenReturn(true);
    when(featuresService.isInstalled(testFeature2)).thenReturn(true);
    when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testFeature1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    when(testFeature2.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testFeature2.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    when(testApp.getURI()).thenReturn(null);
    appService.removeApplication(testApp);
    verify(testApp).getURI();
    verify(featuresService, Mockito.times(2)).uninstallFeature(TEST_FEATURE_1_NAME, TEST_FEATURE_VERSION, EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService).removeRepository(null, false);
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Option(org.apache.karaf.features.FeaturesService.Option) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 95 with Feature

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

the class StatusApplicationCommand method doExecute.

@Override
protected void doExecute(ApplicationService applicationService) throws ApplicationServiceException {
    Application application = applicationService.getApplication(appName);
    if (application != null) {
        ApplicationStatus appStatus = applicationService.getApplicationStatus(application);
        console.println(application.getName());
        console.println("\nCurrent State is: " + appStatus.getState().toString());
        console.println("\nFeatures Located within this Application:");
        for (Feature curFeature : application.getFeatures()) {
            console.println("\t" + curFeature.getName());
        }
        console.println("\nRequired Features Not Started");
        if (appStatus.getErrorFeatures().isEmpty()) {
            console.print(Ansi.ansi().fg(Ansi.Color.GREEN).toString());
            console.println("\tNONE");
            console.print(Ansi.ansi().reset().toString());
        } else {
            for (Feature curFeature : appStatus.getErrorFeatures()) {
                console.print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                console.println("\t" + curFeature.getName());
                console.print(Ansi.ansi().reset().toString());
            }
        }
        console.println("\nRequired Bundles Not Started");
        if (appStatus.getErrorBundles().isEmpty()) {
            console.print(Ansi.ansi().fg(Ansi.Color.GREEN).toString());
            console.println("\tNONE");
            console.print(Ansi.ansi().reset().toString());
        } else {
            for (Bundle curBundle : appStatus.getErrorBundles()) {
                console.print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                console.println("\t[" + curBundle.getBundleId() + "]\t" + curBundle.getSymbolicName());
                console.print(Ansi.ansi().reset().toString());
            }
        }
    } else {
        console.println("No application found with name " + appName);
    }
    return;
}
Also used : Bundle(org.osgi.framework.Bundle) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) Application(org.codice.ddf.admin.application.service.Application) 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