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.setFaultCode("{http://www.consol.de/citrus}citrus:TEC-1000");
responseMessage.setFaultString("Invalid request");
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);
Soap12Body soapResponseBody = EasyMock.createMock(Soap12Body.class);
final Soap12Fault soapFault = EasyMock.createMock(Soap12Fault.class);
StringResult soapResponsePayload = new StringResult();
reset(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody, soapFault);
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<Soap12Fault>() {
public Soap12Fault answer() throws Throwable {
Assert.assertEquals(EasyMock.getCurrentArguments()[0], "Invalid request");
return soapFault;
}
});
soapFault.addFaultSubcode((QName)anyObject());
expectLastCall().andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
QName faultQName = (QName)EasyMock.getCurrentArguments()[0];
Assert.assertEquals(faultQName.getLocalPart(), "TEC-1000");
Assert.assertEquals(faultQName.getPrefix(), "citrus");
Assert.assertEquals(faultQName.getNamespaceURI(), "http://www.consol.de/citrus");
return null;
}
}).once();
replay(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody, soapFault);
endpoint.invoke(messageContext);
Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
verify(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody, soapFault);
}