requestHeaders.put("Host", "localhost:8080");
requestHeaders.put("Content-Length", "236");
requestHeaders.put("Accept", "text/xml, text/html, image/gif, image/jpeg");
requestHeaders.put("Content-Type", "text/xml");
final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);
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.assertNotNull(message.getHeader("Operation"));
Assert.assertEquals(message.getHeader("Operation"), "sayHello");
Assert.assertEquals(message.getPayload(), requestMessage.getPayload());
return responseMessage;
}
});
SaajSoapMessage soapRequest = EasyMock.createMock(SaajSoapMessage.class);
SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);
SoapBody soapRequestBody = EasyMock.createMock(SoapBody.class);
SoapEnvelope soapRequestEnvelope = EasyMock.createMock(SoapEnvelope.class);
SOAPMessage soapRequestMessage = EasyMock.createMock(SOAPMessage.class);
MimeHeaders mimeHeaders = new MimeHeaders();
mimeHeaders.addHeader("Host", "localhost:8080");
mimeHeaders.addHeader("Content-Length", "236");
mimeHeaders.addHeader("Accept", "text/xml");
mimeHeaders.addHeader("Accept", "text/html");
mimeHeaders.addHeader("Accept", "image/gif");
mimeHeaders.addHeader("Accept", "image/jpeg");
mimeHeaders.addHeader("Content-Type", "text/xml");
Set<SoapHeaderElement> soapRequestHeaders = new HashSet<SoapHeaderElement>();
SoapHeaderElement soapRequestHeaderEntry = EasyMock.createMock(SoapHeaderElement.class);
soapRequestHeaders.add(soapRequestHeaderEntry);
org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
StringResult soapResponsePayload = new StringResult();
reset(messageContext, soapRequestEnvelope, soapRequestHeader, soapRequestBody, soapRequestHeaderEntry, soapResponse, soapRequest, soapRequestMessage);
expect(soapRequest.getEnvelope()).andReturn(soapRequestEnvelope).times(3);
expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
Set<Attachment> emptyAttachmentSet = Collections.emptySet();
expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
expect(soapRequest.getSaajMessage()).andReturn(soapRequestMessage).once();
expect(soapRequestMessage.getMimeHeaders()).andReturn(mimeHeaders).once();
expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
expect(soapRequestEnvelope.getBody()).andReturn(soapRequestBody).times(2);
expect(soapRequestBody.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
expect(soapRequestEnvelope.getHeader()).andReturn(soapRequestHeader).once();
expect(soapRequestHeader.getSource()).andReturn(null).once();
expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
expect(soapRequestHeader.examineAllHeaderElements()).andReturn(soapRequestHeaders.iterator()).once();
expect(soapRequestHeaderEntry.getName()).andReturn(QNameUtils.createQName("http://www.consol.de/citrus", "Operation", "citrus")).once();
expect(soapRequestHeaderEntry.getText()).andReturn("sayHello").once();
expect(messageContext.getResponse()).andReturn(soapResponse).once();
expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
replay(messageContext, soapRequestEnvelope, soapRequestHeader, soapRequestBody, soapRequestHeaderEntry, soapResponse, soapRequest, soapRequestMessage);
endpoint.invoke(messageContext);
Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
verify(messageContext, soapRequestEnvelope, soapRequestHeader, soapRequestBody, soapRequestHeaderEntry, soapResponse, soapRequest, soapRequestMessage);
}