Search in sources :

Example 86 with Feature

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

the class ApplicationServiceImplTest method testStopApplicationMainFeature.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
     * for the case where a main feature exists
     *
     * @throws Exception
     */
@Test
public void testStopApplicationMainFeature() 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 testApp1 = mock(ApplicationImpl.class);
    Feature testFeature1 = mock(Feature.class);
    Dependency testDependency1 = mock(Dependency.class);
    List<Dependency> dependencyList1 = new ArrayList<>();
    Set<Feature> featureSet1 = new HashSet<>();
    dependencyList1.add(testDependency1);
    featureSet1.add(testFeature1);
    when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testApp1.getMainFeature()).thenReturn(testFeature1);
    when(testApp1.getFeatures()).thenReturn(featureSet1);
    when(featuresService.isInstalled(testFeature1)).thenReturn(true);
    when(testFeature1.getDependencies()).thenReturn(dependencyList1);
    when(testDependency1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    when(testFeature1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    appService.stopApplication(testApp1);
    verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_1_NAME, TEST_FEATURE_VERSION, EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) ArrayList(java.util.ArrayList) FeaturesService(org.apache.karaf.features.FeaturesService) Dependency(org.apache.karaf.features.Dependency) 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 87 with Feature

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

the class ApplicationServiceImplTest method testFindFeature.

/**
     * Tests the {@link ApplicationServiceImpl#findFeature(Feature)} method
     *
     * @throws Exception
     */
@Test
public void testFindFeature() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Feature testFeature = mainFeatureRepo.getFeatures()[0];
    Application result = appService.findFeature(testFeature);
    assertTrue("Check that the returned application is the correct one.", result.getFeatures().contains(testFeature));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 88 with Feature

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

the class ApplicationServiceImplTest method testStartApplicationNoMainFeature.

/**
     * Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
     * for the case where there is no main feature, but other features exist
     *
     * @throws Exception
     */
@Test
public void testStartApplicationNoMainFeature() 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 testFeature1 = mock(Feature.class);
    Feature testFeature2 = mock(Feature.class);
    Set<Feature> featureSet = new HashSet<Feature>();
    featureSet.add(testFeature1);
    featureSet.add(testFeature2);
    when(testApp.getName()).thenReturn(TEST_APP_NAME);
    when(testApp.getAutoInstallFeatures()).thenReturn(featureSet);
    when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testFeature2.getName()).thenReturn(TEST_FEATURE_2_NAME);
    Set<String> featureNames = new HashSet<>(featureSet.size());
    featureSet.forEach(f -> featureNames.add(f.getName()));
    appService.startApplication(testApp);
    verify(featuresService).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 89 with Feature

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedStatusWhenFeatureDependencyContainsInactiveBundle.

/**
     * Test method for
     * {@link ApplicationService#getApplicationStatus(Application)}
     * <p>
     * Verifies method returns an {@link ApplicationState#FAILED } state for an
     * {@code Application} under the following conditions:
     * <p>
     * <ul>
     * <li>Main feature is installed</li>
     * <li>All dependency features are installed</li>
     * <li>One dependency feature contains a Bundle that is in an inactive state
     * </li>
     * </ul>
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsFailedStatusWhenFeatureDependencyContainsInactiveBundle() throws Exception {
    // Verify the pre-conditions
    int bundleInclusionCount = 0;
    for (Feature feature : mainFeatureRepo2.getFeatures()) {
        for (BundleInfo bundleInfo : feature.getBundles()) {
            if (bundleInfo.getLocation().equals(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION)) {
                ++bundleInclusionCount;
            }
        }
    }
    assertEquals("Bundle is not included in repository the expected number of times", 1, bundleInclusionCount);
    // Execute test
    Set<String> inactiveBundleNames = new HashSet<String>();
    inactiveBundleNames.add(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION);
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo2, null, inactiveBundleNames);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertEquals(ApplicationService.class.getName() + " does not contain the expected number of Applications", 1, appService.getApplications().size());
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : BundleInfo(org.apache.karaf.features.BundleInfo) FeaturesService(org.apache.karaf.features.FeaturesService) Mockito.anyString(org.mockito.Mockito.anyString) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 90 with Feature

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

the class ApplicationServiceImplTest method testRemoveApplicationURIParam.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(URI)} method
     *
     * @throws Exception
     */
@Test
public void testRemoveApplicationURIParam() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Repository[] repoList = { mainFeatureRepo };
    URI testURL = mainFeatureRepo.getURI();
    Feature[] featureList = mainFeatureRepo.getFeatures();
    when(featuresService.listRepositories()).thenReturn(repoList);
    appService.removeApplication(testURL);
    verify(featuresService).removeRepository(testURL, false);
    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) URI(java.net.URI) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

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