SoapMessageConverter implements WebServiceMessageConverter { @Override public WebServiceMessage convertOutbound(final Message internalMessage, final WebServiceEndpointConfiguration endpointConfiguration, final TestContext context) { final WebServiceMessage message = endpointConfiguration.getMessageFactory().createWebServiceMessage(); convertOutbound(message, internalMessage, endpointConfiguration, context); return message; }  @Override WebServiceMessage convertOutbound(final Message internalMessage,
                                             final WebServiceEndpointConfiguration endpointConfiguration,
                                             final TestContext context); @Override void convertOutbound(final WebServiceMessage webServiceMessage,
                                final Message message,
                                final WebServiceEndpointConfiguration endpointConfiguration,
                                final TestContext context); @Override SoapMessage convertInbound(final WebServiceMessage message,
                                      final WebServiceEndpointConfiguration endpointConfiguration,
                                      final TestContext context); @Override SoapMessage convertInbound(final WebServiceMessage webServiceMessage,
                                      final MessageContext messageContext,
                                      final WebServiceEndpointConfiguration endpointConfiguration); String getCharset(); void setCharset(final String charset);  }
@Test public void testOutboundSoapMessageCreation() { final Message testMessage = new DefaultMessage(payload); final WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration(); endpointConfiguration.setMessageFactory(soapMessageFactory); final StringResult soapBodyResult = new StringResult(); when(soapMessageFactory.createWebServiceMessage()).thenReturn(soapRequest); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(soapBodyResult); soapMessageConverter.convertOutbound(testMessage, endpointConfiguration, context); Assert.assertEquals(soapBodyResult.toString(), XML_PROCESSING_INSTRUCTION + payload); }
@Test public void testOutboundSoapBody() { final Message testMessage = new DefaultMessage(payload); final StringResult soapBodyResult = new StringResult(); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(soapBodyResult); soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(soapBodyResult.toString(), XML_PROCESSING_INSTRUCTION + payload); }
@Test public void testOutboundSoapAction() { final Message testMessage = new DefaultMessage(payload) .setHeader(SoapMessageHeaders.SOAP_ACTION, "soapAction"); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); verify(soapRequest).setSoapAction("soapAction"); }
@Test public void testOutboundSoapHeaderContent() { final String soapHeaderContent = "<header>" + "<operation>unitTest</operation>" + "<messageId>123456789</messageId>" + "</header>"; final Message testMessage = new DefaultMessage(payload) .addHeaderData(soapHeaderContent); final StringResult soapHeaderResult = new StringResult(); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); when(soapRequest.getSoapHeader()).thenReturn(soapHeader); when(soapHeader.getResult()).thenReturn(soapHeaderResult); soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(soapHeaderResult.toString(), soapHeaderContent); }
@Test public void testMultipleOutboundSoapHeaderContent() { final String soapHeaderContent = "<header>" + "<operation>unitTest</operation>" + "<messageId>123456789</messageId>" + "</header>"; final Message testMessage = new DefaultMessage(payload) .addHeaderData(soapHeaderContent) .addHeaderData("<AppInfo><appId>123456789</appId></AppInfo>"); final StringResult soapHeaderResult = new StringResult(); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); when(soapRequest.getSoapHeader()).thenReturn(soapHeader); when(soapHeader.getResult()).thenReturn(soapHeaderResult); soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(soapHeaderResult.toString(), soapHeaderContent + "<AppInfo><appId>123456789</appId></AppInfo>"); }
@Test public void testOutboundSoapHeader() { final Message testMessage = new DefaultMessage(payload) .setHeader("operation", "unitTest") .setHeader("messageId", "123456789"); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); when(soapRequest.getSoapHeader()).thenReturn(soapHeader); when(soapHeader.addHeaderElement(eq(new QName("", "operation", "")))).thenReturn(soapHeaderElement); when(soapHeader.addHeaderElement(eq(new QName("", "messageId", "")))).thenReturn(soapHeaderElement); soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); verify(soapHeaderElement).setText("unitTest"); verify(soapHeaderElement).setText("123456789"); }
@Test public void testOutboundSoapHeaderQNameString() { final Message testMessage = new DefaultMessage(payload) .setHeader("{http: .setHeader("{http: when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); when(soapRequest.getSoapHeader()).thenReturn(soapHeader); when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeader.addHeaderElement(eq(new QName("http: soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); verify(soapHeaderElement).setText("unitTest"); verify(soapHeaderElement).setText("123456789"); }
@Test @SuppressWarnings("rawtypes") public void testOutboundSoapMimeHeader() { final Message testMessage = new DefaultMessage(payload) .setHeader(SoapMessageHeaders.HTTP_PREFIX + "operation", "unitTest") .setHeader(SoapMessageHeaders.HTTP_PREFIX + "messageId", "123456789"); final SaajSoapMessage saajSoapRequest = mock(SaajSoapMessage.class); final SOAPMessage saajMessage = mock(SOAPMessage.class); final MimeHeaders mimeHeaders = new MimeHeaders(); when(saajSoapRequest.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); when(saajSoapRequest.getSaajMessage()).thenReturn(saajMessage); when(saajMessage.getMimeHeaders()).thenReturn(mimeHeaders); soapMessageConverter.convertOutbound(saajSoapRequest, testMessage, new WebServiceEndpointConfiguration(), context); final Iterator it = mimeHeaders.getAllHeaders(); Assert.assertEquals(((MimeHeader)it.next()).getName(), "operation"); Assert.assertEquals(((MimeHeader)it.next()).getValue(), "123456789"); Assert.assertFalse(it.hasNext()); }
@Test @SuppressWarnings("rawtypes") public void testOutboundSoapMimeHeaderSkipped() { final Message testMessage = new DefaultMessage(payload) .setHeader(SoapMessageHeaders.HTTP_PREFIX + "operation", "unitTest") .setHeader(SoapMessageHeaders.HTTP_PREFIX + "messageId", "123456789"); final WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration(); endpointConfiguration.setHandleMimeHeaders(false); final SaajSoapMessage saajSoapRequest = mock(SaajSoapMessage.class); when(saajSoapRequest.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); soapMessageConverter.convertOutbound(saajSoapRequest, testMessage, endpointConfiguration, context); }
@Test public void testOutboundSoapAttachment() { final SoapAttachment attachment = new SoapAttachment(); attachment.setContentId("attContentId"); attachment.setContent("This is a SOAP attachment\nwith multi-line"); attachment.setContentType("plain/text"); final SoapMessage testMessage = new SoapMessage(payload); testMessage.addAttachment(attachment); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); doAnswer(invocation -> { InputStreamSource contentStream = (InputStreamSource)invocation.getArguments()[1]; BufferedReader reader = new BufferedReader(new InputStreamReader(contentStream.getInputStream())); Assert.assertEquals(reader.readLine(), "This is a SOAP attachment"); Assert.assertEquals(reader.readLine(), "with multi-line"); reader.close(); return null; }).when(soapRequest).addAttachment(eq("<attContentId>"), any(InputStreamSource.class), eq(attachment.getContentType())); soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); verify(soapRequest).addAttachment(eq("<attContentId>"), any(InputStreamSource.class), eq(attachment.getContentType())); }
@Test public void testEmptyOutboundSoapBodyNotParsed(){ final DefaultMessage emptyMessage = new DefaultMessage(""); final WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration(); endpointConfiguration.setMessageFactory(soapMessageFactory); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(new StringResult()); soapMessageConverter.convertOutbound(soapRequest, emptyMessage, endpointConfiguration, context); verify(soapRequest, never()).getPayloadResult(); }