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());
}
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;
}
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);
}
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);
}
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)));
}
Aggregations