use of org.mockito.ArgumentMatcher in project ddf by codice.
the class ApplicationServiceImplTest method testGetAllFeaturesException.
/**
* Tests the {@link ApplicationServiceImpl#getAllFeatures()} 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 testGetAllFeaturesException() 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();
doThrow(new NullPointerException()).when(featuresService).listFeatures();
appService.getAllFeatures();
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(FEATURE_FAIL_STRING);
}
}));
}
use of org.mockito.ArgumentMatcher in project ddf by codice.
the class ApplicationServiceImplTest method testFindApplicationFeaturesGetRepoFeatException.
/**
* Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
* for the case where an exception is thrown in getRepositoryFeatures
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testFindApplicationFeaturesGetRepoFeatException() 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;
}
};
Repository testRepo = mock(Repository.class);
Repository[] repoList = { testRepo };
when(featuresService.listRepositories()).thenReturn(repoList);
when(testRepo.getName()).thenReturn(TEST_APP_NAME);
doThrow(new Exception()).when(testRepo).getFeatures();
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 org.mockito.ArgumentMatcher in project ddf by codice.
the class ApplicationConfigInstallerTest method testRunASE.
/**
* Tests the {@link ApplicationConfigInstaller#run()} method for the case
* where an ApplicationServiceException is thrown by appService.addApplication(..)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunASE() 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);
FeaturesService featuresService = mock(FeaturesService.class);
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
doThrow(new ApplicationServiceException()).when(testAppService).startApplication(anyString());
URL fileURL = this.getClass().getResource("/" + GOOD_FILE);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), testAppService, featuresService, 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_ASE_EX);
}
}));
}
use of org.mockito.ArgumentMatcher 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 org.mockito.ArgumentMatcher in project ddf by codice.
the class ApplicationFileInstallerTest method testInstallZipFileIOEx.
/**
* Tests the {@link ApplicationFileInstaller#install(File)} method
* for the case where an IOException is thrown when the ZipFile is created
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testInstallZipFileIOEx() throws Exception {
ApplicationFileInstaller testInstaller = new ApplicationFileInstaller();
File testFile = mock(File.class);
when(testFile.getPath()).thenReturn("TestPath");
when(testFile.lastModified()).thenReturn((long) 1);
testInstaller.install(testFile);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(INSTALL_IOEX);
}
}));
}
Aggregations