private MessageContext messageContext = EasyMock.createMock(MessageContext.class);
@Test
public void testMessageProcessing() throws Exception {
WebServiceEndpoint endpoint = new WebServiceEndpoint();
final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");
final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");
endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
public Message handleMessageInternal(Message message) {
Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());
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);
StringResult soapResponsePayload = new StringResult();
reset(messageContext, soapRequest, soapRequestHeader, soapResponse);
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(null).anyTimes();
Set<Attachment> emptyAttachmentSet = Collections.emptySet();
expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
expect(messageContext.getResponse()).andReturn(soapResponse).once();
expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
replay(messageContext, soapRequest, soapRequestHeader, soapResponse);
endpoint.invoke(messageContext);
Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
verify(messageContext, soapRequest, soapRequestHeader, soapResponse);
}