verify(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody, soapFault, soapFaultDetail);
}
@Test
public void testMessageProcessingWithMultipleSoapFaultDetails() throws Exception {
WebServiceEndpoint endpoint = new WebServiceEndpoint();
Map<String, Object> requestHeaders = new HashMap<String, Object>();
requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");
final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);
final SoapFault responseMessage = new SoapFault();
responseMessage.setPayload("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ResponseMessage><text>This request was not OK!</text></ResponseMessage>");
responseMessage.setFaultCode("SERVER");
responseMessage.setFaultString("Invalid request");
responseMessage.addFaultDetail("<DetailMessage><text>This request was not OK!</text></DetailMessage>");
responseMessage.addFaultDetail("<Error><text>This request was not OK!</text></Error>");
endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
public Message handleMessageInternal(Message message) {
Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());
Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));
Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");
Assert.assertEquals(message.getPayload(), requestMessage.getPayload());
return responseMessage;
}
});
org.springframework.ws.soap.SoapMessage soapRequest = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);
org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
SoapHeader soapResponseHeader = EasyMock.createMock(SoapHeader.class);
SoapBody soapResponseBody = EasyMock.createMock(SoapBody.class);
final org.springframework.ws.soap.SoapFault soapFault = EasyMock.createMock(org.springframework.ws.soap.SoapFault.class);
SoapFaultDetail soapFaultDetail = EasyMock.createMock(SoapFaultDetail.class);
StringResult soapFaultResult = new StringResult();
reset(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody, soapFault, soapFaultDetail);
expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
expect(soapRequest.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
expect(soapRequest.getSoapHeader()).andReturn(soapRequestHeader).once();
expect(soapRequestHeader.getSource()).andReturn(null).once();
Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();
expect(soapRequestHeader.examineAllHeaderElements()).andReturn(emptyHeaderSet.iterator()).once();
expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
Set<Attachment> emptyAttachmentSet = Collections.emptySet();
expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
expect(messageContext.getResponse()).andReturn(soapResponse).once();
expect(soapResponse.getSoapHeader()).andReturn(soapResponseHeader).anyTimes();
expect(soapResponse.getSoapBody()).andReturn(soapResponseBody).once();
expect(soapResponseBody.addServerOrReceiverFault((String)anyObject(), (Locale)anyObject())).andAnswer(new IAnswer<org.springframework.ws.soap.SoapFault>() {
public org.springframework.ws.soap.SoapFault answer() throws Throwable {
Assert.assertEquals(EasyMock.getCurrentArguments()[0], "Invalid request");
return soapFault;
}
});
expect(soapFault.addFaultDetail()).andReturn(soapFaultDetail).once();
expect(soapFaultDetail.getResult()).andReturn(soapFaultResult).times(2);
replay(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody, soapFault, soapFaultDetail);
endpoint.invoke(messageContext);
Assert.assertEquals(soapFaultResult.toString(), "<DetailMessage><text>This request was not OK!</text></DetailMessage><Error><text>This request was not OK!</text></Error>");
verify(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody, soapFault, soapFaultDetail);
}