use of org.codice.ddf.admin.application.service.ApplicationService 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.ApplicationService 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)));
}
use of org.codice.ddf.admin.application.service.ApplicationService 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)));
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class AddApplicationCommandTest method testAddApplicationCommandASE.
/**
* Tests the {@link AddApplicationCommand} class and its contained methods
* for the case where the ApplicationService throws an ApplicationServiceException
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testAddApplicationCommandASE() 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);
root.setLevel(Level.ALL);
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
AddApplicationCommand addApplicationCommand = new AddApplicationCommand();
addApplicationCommand.appName = "TestApp";
addApplicationCommand.setApplicationService(testAppService);
doThrow(new ApplicationServiceException()).when(testAppService).addApplication(any(URI.class));
addApplicationCommand.execute();
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(CMD_ERROR_STRING);
}
}));
}
use of org.codice.ddf.admin.application.service.ApplicationService 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);
}
}));
}
Aggregations