use of org.mockito.ArgumentMatcher in project ddf by codice.
the class ApplicationServiceBeanTest method testGetServicesASE.
/**
* Tests the {@link ApplicationServiceBean#getServices(String)} method
* for the case where an ApplicationServiceException is thrown
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetServicesASE() 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) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Bundle testBundle = mock(Bundle.class);
Bundle[] bundles = { testBundle };
when(bundleContext.getBundles()).thenReturn(bundles);
List<Map<String, Object>> services = new ArrayList<>();
Map<String, Object> testService1 = new HashMap<>();
services.add(testService1);
doThrow(new ApplicationServiceException()).when(testApp).getBundles();
when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(services);
serviceBean.getServices(TEST_APP_NAME);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(GET_SERV_ASE);
}
}));
}
use of org.mockito.ArgumentMatcher in project ddf by codice.
the class ApplicationConfigInstallerTest method testRunConfigFileNotExist.
/**
* Tests the {@link ApplicationConfigInstaller#run()} method for the case
* where the configFile doesn't exist
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunConfigFileNotExist() 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);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(BAD_FILE, null, 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_NO_CONFIG);
}
}));
}
use of org.mockito.ArgumentMatcher in project ddf by codice.
the class ApplicationFileInstallerTest method testInstall.
/**
* Tests the {@link ApplicationFileInstaller#install(File)} method
*
* @Throws Exception
*/
@Test
public void testInstall() throws Exception {
ApplicationFileInstaller testInstaller = new ApplicationFileInstaller();
File testFile = new File(File.class.getResource(TEST_FILE_NAME).getPath());
URI appResource = ApplicationFileInstaller.install(testFile);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(IOEX_STRING);
}
}));
}
use of org.mockito.ArgumentMatcher in project ddf by codice.
the class ApplicationFileInstallerTest method testInstallInvalidZip.
/**
* Tests the {@link ApplicationFileInstaller#install(File)} method
* for the case where the file given is not a valid zip file
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testInstallInvalidZip() throws Exception {
ApplicationFileInstaller testInstaller = new ApplicationFileInstaller();
File testFile = new File(File.class.getResource(BAD_FILE_NAME).getPath());
testInstaller.install(testFile);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(INVALID_ZIP_STRING);
}
}));
}
use of org.mockito.ArgumentMatcher in project hadoop by apache.
the class TestRMAppAttemptTransitions method testAppAttemptSubmittedToFailedState.
/**
* {@link RMAppAttemptState#SUBMITTED} -> {@link RMAppAttemptState#FAILED}
*/
private void testAppAttemptSubmittedToFailedState(String diagnostics) {
sendAttemptUpdateSavedEvent(applicationAttempt);
assertEquals(RMAppAttemptState.FAILED, applicationAttempt.getAppAttemptState());
assertEquals(diagnostics, applicationAttempt.getDiagnostics());
assertEquals(0, applicationAttempt.getJustFinishedContainers().size());
assertNull(applicationAttempt.getMasterContainer());
assertEquals(0.0, (double) applicationAttempt.getProgress(), 0.0001);
assertEquals(0, application.getRanNodes().size());
assertNull(applicationAttempt.getFinalApplicationStatus());
// Check events
verify(masterService).unregisterAttempt(applicationAttempt.getAppAttemptId());
// ATTEMPT_FAILED should be notified to app if app attempt is submitted to
// failed state.
ArgumentMatcher<RMAppEvent> matcher = new ArgumentMatcher<RMAppEvent>() {
@Override
public boolean matches(Object o) {
RMAppEvent event = (RMAppEvent) o;
return event.getType() == RMAppEventType.ATTEMPT_FAILED;
}
};
verify(application).handle(argThat(matcher));
verifyTokenCount(applicationAttempt.getAppAttemptId(), 1);
verifyApplicationAttemptFinished(RMAppAttemptState.FAILED);
}
Aggregations