Search in sources :

Example 31 with Application

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

the class NotActiveApplicationsCompleterTest method testNotActiveApplicationsCompleter.

/**
     * Tests the {@link NotActiveApplicationsCompleter#complete(String, int, List)} method
     */
@Test
public void testNotActiveApplicationsCompleter() {
    Application testApp = mock(ApplicationImpl.class);
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Set<Application> appSet = new HashSet<>();
    appSet.add(testApp);
    ApplicationStatus testStatus = mock(ApplicationStatusImpl.class);
    ApplicationStatus.ApplicationState testState = ApplicationStatus.ApplicationState.INACTIVE;
    when(testAppService.getApplications()).thenReturn(appSet);
    when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
    when(testStatus.getState()).thenReturn(testState);
    when(testApp.getName()).thenReturn("TestApp");
    NotActiveApplicationsCompleter activeApplicationsCompleter = new NotActiveApplicationsCompleter();
    activeApplicationsCompleter.setApplicationService(testAppService);
    assertThat("If the return value is -1, then the expected match was not found.", activeApplicationsCompleter.complete(null, commandLine, new ArrayList<>()), is(not(-1)));
}
Also used : ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ArrayList(java.util.ArrayList) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with Application

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

the class ApplicationServiceImplTest method testRemoveApplicationApplicationServiceException.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
     * for the case where an ApplicationServiceException is thrown within uninstallAllFeatures(..)
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationApplicationServiceException() 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 = createPermittedApplicationServiceImpl();
    Application testApp = mock(ApplicationImpl.class);
    doThrow(new ApplicationServiceException()).when(testApp).getFeatures();
    appService.removeApplication(testApp);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_ASE);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Repository(org.apache.karaf.features.Repository) ArgumentMatcher(org.mockito.ArgumentMatcher) 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 33 with Application

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

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

the class ApplicationStatusImplTest method testAppStatusCreation.

/**
     * Tests that the app status is created properly and returns the correct
     * values.
     */
@Test
public void testAppStatusCreation() {
    Application testApp = mock(Application.class);
    ApplicationState testState = ApplicationState.ACTIVE;
    Set<Feature> testFeatures = new HashSet<Feature>();
    Set<Bundle> testBundles = new HashSet<Bundle>();
    Feature testFeature1 = mock(Feature.class);
    Feature testFeature2 = mock(Feature.class);
    List<Feature> testFeatureList = new ArrayList<Feature>(Arrays.asList(testFeature1, testFeature2));
    testFeatures.addAll(testFeatureList);
    Bundle testBundle1 = mock(Bundle.class);
    Bundle testBundle2 = mock(Bundle.class);
    List<Bundle> testBundleList = new ArrayList<Bundle>(Arrays.asList(testBundle1, testBundle2));
    testBundles.addAll(testBundleList);
    ApplicationStatus testStatus = new ApplicationStatusImpl(testApp, testState, testFeatures, testBundles);
    assertEquals("Sanity check for getApplication()", testApp, testStatus.getApplication());
    assertEquals("Sanity check for getState()", testState, testStatus.getState());
    assertTrue("Sanity check for getErrorFeatures()", testStatus.getErrorFeatures().containsAll(testFeatureList));
    assertTrue("Sanity check for getErrorBundles()", testStatus.getErrorBundles().containsAll(testBundleList));
}
Also used : Bundle(org.osgi.framework.Bundle) ApplicationState(org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ArrayList(java.util.ArrayList) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with Application

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

the class ApplicationServiceImplTest method testGetApplicationStatusException.

/**
     * Tests the {@link ApplicationServiceImpl#getApplicationStatus(Application)} method
     * for the case where an exception is thrown in the main block
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetApplicationStatusException() 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));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationServiceImpl appService = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    Application testApp = mock(ApplicationImpl.class);
    doThrow(new NullPointerException()).when(testApp).getFeatures();
    ApplicationStatus result = appService.getApplicationStatus(testApp);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(APP_STATUS_EX);
        }
    }));
    assertThat("State of resulting ApplicationStatus should be UNKNOWN.", result.getState(), is(ApplicationState.UNKNOWN));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) Repository(org.apache.karaf.features.Repository) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet) 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