Search in sources :

Example 46 with ApplicationService

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

the class ApplicationServiceImplTest method testFindApplicationFeaturesException.

/**
     * Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
     * for the case where an exception is thrown by the featuresService
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testFindApplicationFeaturesException() 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);
    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;
        }
    };
    doThrow(new NullPointerException()).when(featuresService).listRepositories();
    appService.findApplicationFeatures(TEST_APP_NAME);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

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

Example 47 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplicationStatusCoreFeature.

@Test
public void testGetApplicationStatusCoreFeature() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(createRepo(TEST_PREREQ_MAIN_FEATURE_FILE_NAME)));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    when(featuresService.isInstalled(any())).thenReturn(false);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Set<Application> applications = appService.getApplications();
    assertEquals(1, applications.size());
    for (Application curApp : applications) {
        ApplicationStatus status = appService.getApplicationStatus(curApp);
        assertEquals(curApp, status.getApplication());
        assertEquals(ApplicationState.INACTIVE, status.getState());
        assertTrue(status.getErrorBundles().isEmpty());
        assertTrue(status.getErrorFeatures().isEmpty());
    }
}
Also used : Repository(org.apache.karaf.features.Repository) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) 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 48 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateIsStopping.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when
     * {@code Bundle} state is {@link Bundle#STOPPING}
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateIsStopping() throws Exception {
    ApplicationService appService = getAppServiceWithBundleInGivenState(mainFeatureRepo2, Bundle.STOPPING);
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.INACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 49 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateIsInstalled.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when
     * {@code Bundle} state is {@link Bundle#INSTALLED}
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateIsInstalled() throws Exception {
    ApplicationService appService = getAppServiceWithBundleInGivenState(mainFeatureRepo2, Bundle.INSTALLED);
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 50 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateIsUninnstalled.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when
     * {@code Bundle} state is {@link Bundle#UNINSTALLED}
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateIsUninnstalled() throws Exception {
    ApplicationService appService = getAppServiceWithBundleInGivenState(mainFeatureRepo2, Bundle.UNINSTALLED);
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, 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