// Override testService in test case.
_testService = mock(TestService.class);
// We use one partner to simulate failing service and receive message upon process completion.
final Mock partner = mock(MessageExchangeContext.class);
// Some processes will complete, but not all.
partner.expects(atMostOnce()).match(invokeOnOperation("respond")).will(new CustomStub("process completed") {
public Object invoke(Invocation invocation) {
((TestService)_testService.proxy()).completed();
return null;
}
});
// There will be multiple calls to invoke.
partner.expects(atLeastOnce()).match(invokeOnOperation("invoke")).will(new CustomStub("invoke failing service") {
public Object invoke(Invocation invocation) {
PartnerRoleMessageExchange mex = (PartnerRoleMessageExchange) invocation.parameterValues.get(0);
if (((TestService)_testService.proxy()).invoke()) {
Message response = mex.createMessage(mex.getOperation().getOutput().getMessage().getQName());
response.setMessage(DOMUtils.newDocument().createElementNS(NAMESPACE, "tns:ResponseElement"));
mex.reply(response);
} else {
mex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, "BangGoesInvoke", null);
}
return null;
}
});
// Faulting a process would send the fault message asynchronously.
// (Which might be a bug, but right now we swallow it).
partner.expects(atMostOnce()).method("onAsyncReply").will(new CustomStub("async reply") {
public Object invoke(Invocation invocation) {
return null;
}
});