Search in sources :

Example 76 with ApplicationService

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

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

the class ApplicationServiceImplTest method testStopApplicationException.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
     * for the case where an Exception is thrown
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testStopApplicationException() 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);
    when(testApp.getMainFeature()).thenReturn(mainFeatureRepo.getFeatures()[1]);
    doThrow(new NullPointerException()).when(testApp).getFeatures();
    appService.stopApplication(testApp);
}
Also used : Repository(org.apache.karaf.features.Repository) 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) Test(org.junit.Test)

Example 78 with ApplicationService

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

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

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsActiveWhenBundleStateServiceStateIsUnknown.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#ACTIVE} is returned when the
     * extended bundle state reported by an injection framework states that one
     * bundle is in an {@link BundleState#Unknown} state and the rest of the
     * bundles are in an {@link BundleState#Active} state.
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsActiveWhenBundleStateServiceStateIsUnknown() throws Exception {
    ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo, BundleState.Unknown);
    assertNotNull("Repository \"" + mainFeatureRepo.getName() + "\" does not contain any bundles", appService);
    assertEquals(mainFeatureRepo.getName() + " returned unexpected state", ApplicationState.ACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)82 Test (org.junit.Test)79 FeaturesService (org.apache.karaf.features.FeaturesService)51 HashSet (java.util.HashSet)45 Repository (org.apache.karaf.features.Repository)37 Application (org.codice.ddf.admin.application.service.Application)26 Feature (org.apache.karaf.features.Feature)19 Logger (org.slf4j.Logger)14 Appender (ch.qos.logback.core.Appender)13 URI (java.net.URI)13 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)13 ArgumentMatcher (org.mockito.ArgumentMatcher)13 Mockito.anyString (org.mockito.Mockito.anyString)10 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)9 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 EnumSet (java.util.EnumSet)3 ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)3 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)3