Search in sources :

Example 31 with ApplicationService

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

the class AllApplicationsCompleterTest method testAllApplicationsCompleterNullAppService.

/**
     * Tests the {@link AllApplicationsCompleter#complete(String, int, List)} method
     * for the case where the ApplicationService given to it is null
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testAllApplicationsCompleterNullAppService() {
    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);
    root.setLevel(Level.ALL);
    ApplicationService testAppService = null;
    AllApplicationsCompleter allApplicationsCompleter = new AllApplicationsCompleter();
    allApplicationsCompleter.setApplicationService(testAppService);
    allApplicationsCompleter.complete(null, commandLine, new ArrayList<>());
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(NO_APP_SERV);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) ArgumentMatcher(org.mockito.ArgumentMatcher) Logger(org.slf4j.Logger) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 32 with ApplicationService

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

the class StartApplicationCommandTest method testStartApplicationCommand.

/**
     * Tests the {@link StartApplicationCommand} class and its associated methods
     *
     * @throws Exception
     */
@Test
public void testStartApplicationCommand() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    StartApplicationCommand startApplicationCommand = new StartApplicationCommand();
    startApplicationCommand.appName = APP_NAME;
    startApplicationCommand.doExecute(testAppService);
    verify(testAppService).startApplication(APP_NAME);
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 33 with ApplicationService

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

the class ApplicationServiceImplTest method testGetAllFeaturesFTRException.

/**
 * Tests the {@link ApplicationServiceImpl#getAllFeatures()} method for the case where an
 * exception is thrown in getFeatureToRepository(..)
 */
@Test
public void testGetAllFeaturesFTRException() throws Exception {
    Set<Repository> activeRepos = new HashSet<>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl(featuresService);
    doThrow(new NullPointerException()).when(featuresService).listRepositories();
    List<FeatureDetails> details = appService.getAllFeatures();
    assertThat("List of feature details should have 7 entries", details, hasSize(4));
    details.forEach(d -> assertThat(d.getName() + " should not have a mapped repository", d.getRepository(), is(nullValue())));
}
Also used : Repository(org.apache.karaf.features.Repository) FeatureDetails(org.codice.ddf.admin.application.rest.model.FeatureDetails) FeaturesService(org.apache.karaf.features.FeaturesService) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 34 with ApplicationService

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

the class ApplicationServiceImplTest method testGetInstallProfilesException.

/**
 * Tests the {@link ApplicationServiceImpl#getInstallationProfiles()} method for the case where
 * featuresService.listFeatures() throws an exception
 */
@Test
public void testGetInstallProfilesException() throws Exception {
    Set<Repository> activeRepos = new HashSet<>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = new ApplicationServiceImpl(featuresService, new Security()) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    doThrow(new NullPointerException()).when(featuresService).listFeatures();
    assertThat("No installation profiles should of been found, expected an empty collection", appService.getInstallationProfiles(), is(empty()));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Security(org.codice.ddf.security.impl.Security) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 35 with ApplicationService

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

the class AddApplicationCommandTest method testAddApplicationCommand.

/**
     * Tests the {@link AddApplicationCommand} class and its contained methods
     *
     * @Throws Exception
     */
@Test
public void testAddApplicationCommand() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    AddApplicationCommand addApplicationCommand = new AddApplicationCommand();
    addApplicationCommand.appName = "TestApp";
    addApplicationCommand.doExecute(testAppService);
    verify(testAppService).addApplication(any(URI.class));
}
Also used : URI(java.net.URI) 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 URI (java.net.URI)13 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)13 Logger (org.slf4j.Logger)11 Appender (ch.qos.logback.core.Appender)10 ArgumentMatcher (org.mockito.ArgumentMatcher)10 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)9 Mockito.anyString (org.mockito.Mockito.anyString)9 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 EnumSet (java.util.EnumSet)3 FeatureDetails (org.codice.ddf.admin.application.rest.model.FeatureDetails)3 ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)3