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);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationServiceImplTest method testFindApplicationFeaturesException.
/**
* Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
* for the case where an exception is thrown by the featuresService
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testFindApplicationFeaturesException() 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 = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
doThrow(new NullPointerException()).when(featuresService).listRepositories();
appService.findApplicationFeatures(TEST_APP_NAME);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(NO_REPO_FEATURES);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusException.
/**
* Tests the {@link ApplicationServiceImpl#getApplicationStatus(Application)} method
* for the case where an exception is thrown in the main block
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetApplicationStatusException() 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));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationServiceImpl appService = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Application testApp = mock(ApplicationImpl.class);
doThrow(new NullPointerException()).when(testApp).getFeatures();
ApplicationStatus result = appService.getApplicationStatus(testApp);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(APP_STATUS_EX);
}
}));
assertThat("State of resulting ApplicationStatus should be UNKNOWN.", result.getState(), is(ApplicationState.UNKNOWN));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationServiceBeanTest method testRemoveApplicationASE.
/**
* Tests the {@link ApplicationServiceBean#removeApplication(String)} method
* for the case where an ApplicationServiceException is thrown by the AppService
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationASE() 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);
ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
doThrow(new ApplicationServiceException()).when(testAppService).removeApplication(any(String.class));
serviceBean.removeApplication(TEST_APP_NAME);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(REMOVE_APP_ASE);
}
}));
}
Aggregations