Search in sources :

Example 26 with ApplicationService

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

the class ApplicationServiceImplTest method testIsApplicationStartedReturnsTrueForActiveApplicationState.

/**
     * Test method for
     * {@link ApplicationServiceImpl#isApplicationStarted(Application)}
     * <p>
     * Verifies that method returns true when application state is
     * {@link ApplicationState#ACTIVE}
     *
     * @throws Exception
     */
@Test
public void testIsApplicationStartedReturnsTrueForActiveApplicationState() throws Exception {
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertTrue(appService.isApplicationStarted(appService.getApplication(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME)));
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 27 with ApplicationService

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

the class ApplicationServiceImplTest method testStopApplicationStringParamASE.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(String)} method
     * for the case where the application cannot be found
     */
@Test(expected = ApplicationServiceException.class)
public void testStopApplicationStringParamASE() 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();
    appService.stopApplication("");
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 28 with ApplicationService

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

the class TreeApplicationCommandTest method testTreeApplicationCommand.

/**
     * Tests the {@link TreeApplicationCommand} class and its associated methods
     *
     * @throws Exception
     */
@Test
public void testTreeApplicationCommand() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    TreeApplicationCommand treeApplicationCommand = new TreeApplicationCommand();
    Set<ApplicationNode> treeSet = new TreeSet<>();
    ApplicationNode testNode1 = mock(ApplicationNodeImpl.class);
    ApplicationNode testNode2 = mock(ApplicationNodeImpl.class);
    treeSet.add(testNode1);
    Set<ApplicationNode> childSet = new TreeSet<>();
    childSet.add(testNode2);
    Application testApp = mock(ApplicationImpl.class);
    when(testApp.getName()).thenReturn("TestApp");
    when(testNode1.getApplication()).thenReturn(testApp);
    when(testNode2.getApplication()).thenReturn(testApp);
    when(testNode2.getChildren()).thenReturn(new TreeSet<ApplicationNode>());
    when(testNode1.getChildren()).thenReturn(childSet);
    when(testAppService.getApplicationTree()).thenReturn(treeSet);
    treeApplicationCommand.doExecute(testAppService);
    verify(testAppService).getApplicationTree();
}
Also used : TreeSet(java.util.TreeSet) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 29 with ApplicationService

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

the class ActiveApplicationsCompleterTest method testActiveApplicationsCompleterNullAppService.

/**
     * Tests the {@link ActiveApplicationsCompleter#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 testActiveApplicationsCompleterNullAppService() {
    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;
    ActiveApplicationsCompleter activeApplicationsCompleter = new ActiveApplicationsCompleter();
    activeApplicationsCompleter.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 30 with ApplicationService

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

the class AllApplicationsCompleterTest method testAllApplicationsCompleter.

/**
     * Tests the {@link AllApplicationsCompleter#complete(String, int, List)} method,
     * and the {@link AllApplicationsCompleter#AllApplicationsCompleter(ApplicationService)} constructor
     */
@Test
public void testAllApplicationsCompleter() {
    Application testApp = mock(ApplicationImpl.class);
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Set<Application> testAppSet = new HashSet<>();
    testAppSet.add(testApp);
    when(testAppService.getApplications()).thenReturn(testAppSet);
    when(testApp.getName()).thenReturn("TestApp");
    AllApplicationsCompleter applicationsCompleter = new AllApplicationsCompleter();
    applicationsCompleter.setApplicationService(testAppService);
    assertThat("If the return value is -1, the expected match was not found.", applicationsCompleter.complete(null, commandLine, new ArrayList<>()), is(not(-1)));
}
Also used : 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)

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