Search in sources :

Example 41 with Application

use of org.codice.ddf.admin.application.service.Application 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 42 with Application

use of org.codice.ddf.admin.application.service.Application in project ddf by codice.

the class ApplicationServiceImplTest method testRemoveApplicationApplicationParamASE.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
     * for the case where an exception is thrown
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testRemoveApplicationApplicationParamASE() 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);
    doThrow(new Exception()).when(featuresService).removeRepository(Mockito.any(URI.class), eq(false));
    appService.removeApplication(testApp);
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) URI(java.net.URI) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 43 with Application

use of org.codice.ddf.admin.application.service.Application 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 44 with Application

use of org.codice.ddf.admin.application.service.Application 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 45 with Application

use of org.codice.ddf.admin.application.service.Application 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)

Aggregations

Application (org.codice.ddf.admin.application.service.Application)55 Test (org.junit.Test)43 HashSet (java.util.HashSet)28 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)26 Repository (org.apache.karaf.features.Repository)21 FeaturesService (org.apache.karaf.features.FeaturesService)19 Feature (org.apache.karaf.features.Feature)14 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)13 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)13 ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)11 ArrayList (java.util.ArrayList)9 RepositoryImpl (org.apache.karaf.features.internal.service.RepositoryImpl)7 HashMap (java.util.HashMap)5 Logger (org.slf4j.Logger)5 Appender (ch.qos.logback.core.Appender)4 URI (java.net.URI)4 TreeSet (java.util.TreeSet)4 ArgumentMatcher (org.mockito.ArgumentMatcher)4 Mockito.anyString (org.mockito.Mockito.anyString)4 SecurityServiceException (ddf.security.service.SecurityServiceException)3