SoapMessage soapMessage = (SoapMessage) message;
Assert.assertEquals(soapMessage.getAttachments().size(), 1L);
Attachment attachment = soapMessage.getAttachments().get(0);
Assert.assertEquals(attachment.getContentId(), "myContentId");
Assert.assertEquals(attachment.getContentType(), "text/xml");
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);
StringResult soapResponsePayload = new StringResult();
Set<Attachment> attachments = new HashSet<Attachment>();
Attachment attachment = EasyMock.createMock(Attachment.class);
attachments.add(attachment);
reset(messageContext, soapRequest, soapRequestHeader, soapResponse, attachment);
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();
expect(soapRequest.getAttachments()).andReturn(attachments.iterator()).once();
expect(attachment.getContentId()).andReturn("myContentId").anyTimes();
expect(attachment.getContentType()).andReturn("text/xml").anyTimes();
expect(messageContext.getResponse()).andReturn(soapResponse).once();
expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
expect(attachment.getInputStream()).andReturn(new ByteArrayInputStream("AttachmentBody".getBytes())).once();
replay(messageContext, soapRequest, soapRequestHeader, soapResponse, attachment);
endpoint.invoke(messageContext);