final Serializable result04 = context.mock(Serializable.class, "result04");
final AsyncCallback actionCb01 = context.mock(AsyncCallback.class, "actionCb01");
final AsyncCallback actionCb02 = context.mock(AsyncCallback.class, "actionCb02");
final AsyncCallback actionCb03 = context.mock(AsyncCallback.class, "actionCb03");
final AsyncCallback actionCb04 = context.mock(AsyncCallback.class, "actionCb04");
final ParamInterceptor paramInt01 = new ParamInterceptor();
final ParamInterceptor paramInt02 = new ParamInterceptor();
final ParamInterceptor paramInt03 = new ParamInterceptor();
final ParamInterceptor paramInt04 = new ParamInterceptor();
// -- send out a few requests --
context.checking(new Expectations()
{
{
oneOf(service).execute((ActionRequest[]) with(anything()), with(any(AsyncCallback.class)));
will(paramInt01);
oneOf(service).execute((ActionRequest[]) with(anything()), with(any(AsyncCallback.class)));
will(paramInt02);
oneOf(service).execute((ActionRequest[]) with(anything()), with(any(AsyncCallback.class)));
will(paramInt03);
oneOf(service).execute((ActionRequest[]) with(anything()), with(any(AsyncCallback.class)));
will(paramInt04);
}
});
sut.makeRequest(ACTION1, param01, actionCb01);
sut.makeRequest(ACTION2, param02, actionCb02);
sut.makeRequest(ACTION3, param03, actionCb03);
sut.makeRequest(ACTION4, param04, actionCb04);
context.assertIsSatisfied();
// -- make 1, 2, 4 fail with a session exception; 3 will succeed. once all are back, SUT should request session.
// out of order on purpose. --
// 1 fails
((AsyncCallback) paramInt01.getParam(1)).onSuccess(new ActionRequest[] { new ActionResponse(
((ActionRequest[]) paramInt01.getParam(0))[0], new SessionException()) });
// 4 fails
((AsyncCallback) paramInt04.getParam(1)).onSuccess(new ActionRequest[] { new ActionResponse(
((ActionRequest[]) paramInt04.getParam(0))[0], new SessionException()) });
// 3 succeeds
context.checking(new Expectations()
{
{
oneOf(actionCb03).onSuccess(with(same(result03)));