use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationConfigInstallerTest method testRunInvalidURI.
/**
* Tests the {@link ApplicationConfigInstaller#run()} method to test if it handles
* an invalid URI cleanly
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunInvalidURI() 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);
ApplicationServiceImpl testAppService = mock(ApplicationServiceImpl.class);
URL fileURL = this.getClass().getResource("/" + INVALID_FILE);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), testAppService, null, START_FEATURE, STOP_FEATURE);
configInstaller.run();
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(RUN_INVALID_URI);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationUploadEndpointTest method testApplicationUploadEndpointCreateFileNotFound.
/**
* Tests the {@link ApplicationUploadEndpoint#create(MultipartBody, UriInfo)} method
* for the case where the file cannot be found (inside of createFileAttachement(..))
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testApplicationUploadEndpointCreateFileNotFound() 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);
ApplicationUploadEndpoint applicationUploadEndpoint = new ApplicationUploadEndpoint(testAppService);
testFile = new File(File.class.getResource(TEST_FILE_NAME).getPath());
testIS = null;
when(testDataHandler.getInputStream()).thenReturn(testIS);
when(testDisp.getParameter(FILENAME_CONTENT_DISPOSITION_PARAMETER_NAME)).thenReturn(TEST_FILE_NAME);
applicationUploadEndpoint.setDefaultFileLocation(TEST_FILE_LOCATION);
applicationUploadEndpoint.create(testMultipartBody, testUriInfo);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(FILE_NOT_FOUND);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationUploadEndpointTest method testApplicationUploadEndpointCreateIOException.
/**
* Tests the {@link ApplicationUploadEndpoint#create(MultipartBody, UriInfo)} method
* for the case where the source file causes an IOException when it is read
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testApplicationUploadEndpointCreateIOException() 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);
ApplicationUploadEndpoint applicationUploadEndpoint = new ApplicationUploadEndpoint(testAppService);
doThrow(new IOException()).when(testDataHandler).getInputStream();
when(testDisp.getParameter(FILENAME_CONTENT_DISPOSITION_PARAMETER_NAME)).thenReturn(BAD_FILE_NAME);
applicationUploadEndpoint.setDefaultFileLocation(TEST_FILE_LOCATION);
applicationUploadEndpoint.create(testMultipartBody, testUriInfo);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains("ddf.home");
}
}));
}
use of ch.qos.logback.core.Appender 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 ch.qos.logback.core.Appender 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