Search in sources :

Example 26 with Application

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

the class ApplicationUploadEndpointTest method testApplicationUploadEndpointUpdateAppStarted.

/**
     * Tests the {@link ApplicationUploadEndpoint#update(MultipartBody, UriInfo)} method
     * for the case where the application exists and has already been started
     *
     * @throws Exception
     */
@Test
public void testApplicationUploadEndpointUpdateAppStarted() throws Exception {
    Application testApp = mock(Application.class);
    when(testAppService.getApplication(anyString())).thenReturn(testApp);
    when(testAppService.isApplicationStarted(testApp)).thenReturn(true);
    ApplicationUploadEndpoint applicationUploadEndpoint = new ApplicationUploadEndpoint(testAppService);
    applicationUploadEndpoint.setDefaultFileLocation(TEST_FILE_LOCATION);
    Response response = applicationUploadEndpoint.update(testMultipartBody, testUriInfo);
    Response testResponse = Response.ok("{\"status\":\"success\"}").type("application/json").build();
    assertThat("Returned status is success", response.getStatus(), is(testResponse.getStatus()));
    verify(testAppService).removeApplication(testApp);
    verify(testAppService).startApplication(anyString());
}
Also used : Response(javax.ws.rs.core.Response) Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Example 27 with Application

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

the class ApplicationServiceImpl method getApplicationTree.

@Override
public Set<ApplicationNode> getApplicationTree() {
    Set<ApplicationNode> applicationTree = new TreeSet<ApplicationNode>();
    Set<Application> unfilteredApplications = getApplications();
    Set<Application> filteredApplications = new HashSet<Application>();
    for (Application application : unfilteredApplications) {
        if (!ignoredApplicationNames.contains(application.getName())) {
            filteredApplications.add(application);
        }
    }
    Map<Application, ApplicationNodeImpl> appMap = new HashMap<Application, ApplicationNodeImpl>(filteredApplications.size());
    // add all values into a map
    for (Application curApp : filteredApplications) {
        appMap.put(curApp, new ApplicationNodeImpl(curApp, getApplicationStatus(curApp)));
    }
    // The boolean is used because this function is used twice in a row.
    //   The proper output should be that of the second call rather than the first.
    traverseDependencies(appMap, filteredApplications, false);
    traverseDependencies(appMap, filteredApplications, true);
    // determine the root applications (contain no parent) and return those
    for (Entry<Application, ApplicationNodeImpl> curAppNode : appMap.entrySet()) {
        if (curAppNode.getValue().getParent() == null) {
            LOGGER.debug("Adding {} as a root application.", curAppNode.getKey().getName());
            applicationTree.add(curAppNode.getValue());
        }
    }
    return applicationTree;
}
Also used : HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet)

Example 28 with Application

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

the class StopApplicationCommandTest method testStopApplicationCommandTest.

/**
     * Tests the {@link StopApplicationCommand} class and its associated methods
     *
     * @throws Exception
     */
@Test
public void testStopApplicationCommandTest() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Application testApp = mock(ApplicationImpl.class);
    ApplicationStatus testStatus = mock(ApplicationStatus.class);
    StopApplicationCommand stopApplicationCommand = new StopApplicationCommand();
    stopApplicationCommand.appName = APP_NAME;
    when(testStatus.getState()).thenReturn(ApplicationState.ACTIVE);
    when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
    when(testAppService.getApplication(APP_NAME)).thenReturn(testApp);
    stopApplicationCommand.doExecute(testAppService);
    verify(testAppService).stopApplication(APP_NAME);
}
Also used : ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 29 with Application

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

the class StopApplicationCommandTest method testStopApplicationCommandAlreadyStopped.

/**
     * Tests the {@link StopApplicationCommand} class and its associated methods
     * for the case where the application parameter has already been stopped
     *
     * @throws Exception
     */
@Test
public void testStopApplicationCommandAlreadyStopped() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Application testApp = mock(ApplicationImpl.class);
    ApplicationStatus testStatus = mock(ApplicationStatus.class);
    StopApplicationCommand stopApplicationCommand = new StopApplicationCommand();
    stopApplicationCommand.appName = APP_NAME;
    when(testStatus.getState()).thenReturn(ApplicationState.INACTIVE);
    when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
    when(testAppService.getApplication(APP_NAME)).thenReturn(testApp);
    // Should handle this condition gracefully without throwing an exception
    // If an exception is thrown, this test fails...
    stopApplicationCommand.doExecute(testAppService);
}
Also used : ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 30 with Application

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

the class ActiveApplicationsCompleterTest method testActiveApplicationsCompleter.

/**
     * Tests the {@link ActiveApplicationsCompleter#complete(String, int, List)} method,
     * as well as the associated constructor
     */
@Test
public void testActiveApplicationsCompleter() {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Application testApp = mock(ApplicationImpl.class);
    Set<Application> appSet = new HashSet<>();
    appSet.add(testApp);
    ApplicationStatus testStatus = mock(ApplicationStatusImpl.class);
    ApplicationState testState = ApplicationState.ACTIVE;
    when(testAppService.getApplications()).thenReturn(appSet);
    when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
    when(testStatus.getState()).thenReturn(testState);
    when(testApp.getName()).thenReturn("TestApp");
    ActiveApplicationsCompleter activeApplicationsCompleter = new ActiveApplicationsCompleter();
    activeApplicationsCompleter.setApplicationService(testAppService);
    CommandLine commandLine = mock(CommandLine.class);
    assertThat("If the return value is -1, the expected match was not found.", activeApplicationsCompleter.complete(null, commandLine, new ArrayList<>()), is(not(-1)));
}
Also used : CommandLine(org.apache.karaf.shell.api.console.CommandLine) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ApplicationState(org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState) 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

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