Best Citrus code snippet using com.consol.citrus.ws.message.converter.SoapMessageConverter.convertOutbound
Source:SoapMessageConverterTest.java
...91 final StringResult soapBodyResult = new StringResult();92 when(soapMessageFactory.createWebServiceMessage()).thenReturn(soapRequest);93 when(soapRequest.getSoapBody()).thenReturn(soapBody);94 when(soapBody.getPayloadResult()).thenReturn(soapBodyResult);95 soapMessageConverter.convertOutbound(testMessage, endpointConfiguration, context);96 Assert.assertEquals(soapBodyResult.toString(), XML_PROCESSING_INSTRUCTION + payload);97 }98 @Test99 public void testOutboundSoapBody() {100 final Message testMessage = new DefaultMessage(payload);101 final StringResult soapBodyResult = new StringResult();102 when(soapRequest.getSoapBody()).thenReturn(soapBody);103 when(soapBody.getPayloadResult()).thenReturn(soapBodyResult);104 soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context);105 Assert.assertEquals(soapBodyResult.toString(), XML_PROCESSING_INSTRUCTION + payload);106 }107 @Test108 public void testOutboundSoapAction() {109 final Message testMessage = new DefaultMessage(payload)110 .setHeader(SoapMessageHeaders.SOAP_ACTION, "soapAction");111 when(soapRequest.getSoapBody()).thenReturn(soapBody);112 when(soapBody.getPayloadResult()).thenReturn(new StringResult());113 soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context);114 verify(soapRequest).setSoapAction("soapAction");115 }116 @Test117 public void testOutboundSoapHeaderContent() {118 final String soapHeaderContent = "<header>" +119 "<operation>unitTest</operation>" +120 "<messageId>123456789</messageId>" +121 "</header>";122 final Message testMessage = new DefaultMessage(payload)123 .addHeaderData(soapHeaderContent);124 final StringResult soapHeaderResult = new StringResult();125 when(soapRequest.getSoapBody()).thenReturn(soapBody);126 when(soapBody.getPayloadResult()).thenReturn(new StringResult());127 when(soapRequest.getSoapHeader()).thenReturn(soapHeader);128 when(soapHeader.getResult()).thenReturn(soapHeaderResult);129 soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context);130 Assert.assertEquals(soapHeaderResult.toString(), soapHeaderContent);131 }132 @Test133 public void testMultipleOutboundSoapHeaderContent() {134 final String soapHeaderContent = "<header>" +135 "<operation>unitTest</operation>" +136 "<messageId>123456789</messageId>" +137 "</header>";138 final Message testMessage = new DefaultMessage(payload)139 .addHeaderData(soapHeaderContent)140 .addHeaderData("<AppInfo><appId>123456789</appId></AppInfo>");141 final StringResult soapHeaderResult = new StringResult();142 when(soapRequest.getSoapBody()).thenReturn(soapBody);143 when(soapBody.getPayloadResult()).thenReturn(new StringResult());144 when(soapRequest.getSoapHeader()).thenReturn(soapHeader);145 when(soapHeader.getResult()).thenReturn(soapHeaderResult);146 soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context);147 Assert.assertEquals(soapHeaderResult.toString(), soapHeaderContent + "<AppInfo><appId>123456789</appId></AppInfo>");148 }149 @Test150 public void testOutboundSoapHeader() {151 final Message testMessage = new DefaultMessage(payload)152 .setHeader("operation", "unitTest")153 .setHeader("messageId", "123456789");154 when(soapRequest.getSoapBody()).thenReturn(soapBody);155 when(soapBody.getPayloadResult()).thenReturn(new StringResult());156 when(soapRequest.getSoapHeader()).thenReturn(soapHeader);157 when(soapHeader.addHeaderElement(eq(new QName("", "operation", "")))).thenReturn(soapHeaderElement);158 when(soapHeader.addHeaderElement(eq(new QName("", "messageId", "")))).thenReturn(soapHeaderElement);159 soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context);160 verify(soapHeaderElement).setText("unitTest");161 verify(soapHeaderElement).setText("123456789");162 }163 @Test164 public void testOutboundSoapHeaderQNameString() {165 final Message testMessage = new DefaultMessage(payload)166 .setHeader("{http://www.citrus.com}citrus:operation", "unitTest")167 .setHeader("{http://www.citrus.com}citrus:messageId", "123456789");168 when(soapRequest.getSoapBody()).thenReturn(soapBody);169 when(soapBody.getPayloadResult()).thenReturn(new StringResult());170 when(soapRequest.getSoapHeader()).thenReturn(soapHeader);171 when(soapHeader.addHeaderElement(eq(new QName("http://www.citrus.com", "operation", "citrus")))).thenReturn(soapHeaderElement);172 when(soapHeader.addHeaderElement(eq(new QName("http://www.citrus.com", "messageId", "citrus")))).thenReturn(soapHeaderElement);173 soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context);174 verify(soapHeaderElement).setText("unitTest");175 verify(soapHeaderElement).setText("123456789");176 }177 @Test178 @SuppressWarnings("rawtypes")179 public void testOutboundSoapMimeHeader() {180 final Message testMessage = new DefaultMessage(payload)181 .setHeader(SoapMessageHeaders.HTTP_PREFIX + "operation", "unitTest")182 .setHeader(SoapMessageHeaders.HTTP_PREFIX + "messageId", "123456789");183 final SaajSoapMessage saajSoapRequest = mock(SaajSoapMessage.class);184 final SOAPMessage saajMessage = mock(SOAPMessage.class);185 final MimeHeaders mimeHeaders = new MimeHeaders();186 when(saajSoapRequest.getEnvelope()).thenReturn(soapEnvelope);187 when(soapEnvelope.getBody()).thenReturn(soapBody);188 when(soapBody.getPayloadResult()).thenReturn(new StringResult());189 when(saajSoapRequest.getSaajMessage()).thenReturn(saajMessage);190 when(saajMessage.getMimeHeaders()).thenReturn(mimeHeaders);191 soapMessageConverter.convertOutbound(saajSoapRequest, testMessage, new WebServiceEndpointConfiguration(), context);192 final Iterator it = mimeHeaders.getAllHeaders();193 Assert.assertEquals(((MimeHeader)it.next()).getName(), "operation");194 Assert.assertEquals(((MimeHeader)it.next()).getValue(), "123456789");195 Assert.assertFalse(it.hasNext());196 }197 @Test198 @SuppressWarnings("rawtypes")199 public void testOutboundSoapMimeHeaderSkipped() {200 final Message testMessage = new DefaultMessage(payload)201 .setHeader(SoapMessageHeaders.HTTP_PREFIX + "operation", "unitTest")202 .setHeader(SoapMessageHeaders.HTTP_PREFIX + "messageId", "123456789");203 final WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration();204 endpointConfiguration.setHandleMimeHeaders(false);205 final SaajSoapMessage saajSoapRequest = mock(SaajSoapMessage.class);206 when(saajSoapRequest.getEnvelope()).thenReturn(soapEnvelope);207 when(soapEnvelope.getBody()).thenReturn(soapBody);208 when(soapBody.getPayloadResult()).thenReturn(new StringResult());209 soapMessageConverter.convertOutbound(saajSoapRequest, testMessage, endpointConfiguration, context);210 }211 @Test212 public void testOutboundSoapAttachment() {213 final SoapAttachment attachment = new SoapAttachment();214 attachment.setContentId("attContentId");215 attachment.setContent("This is a SOAP attachment\nwith multi-line");216 attachment.setContentType("plain/text");217 final SoapMessage testMessage = new SoapMessage(payload);218 testMessage.addAttachment(attachment);219 when(soapRequest.getSoapBody()).thenReturn(soapBody);220 when(soapBody.getPayloadResult()).thenReturn(new StringResult());221 doAnswer(invocation -> {222 InputStreamSource contentStream = (InputStreamSource)invocation.getArguments()[1];223 BufferedReader reader = new BufferedReader(new InputStreamReader(contentStream.getInputStream()));224 Assert.assertEquals(reader.readLine(), "This is a SOAP attachment");225 Assert.assertEquals(reader.readLine(), "with multi-line");226 reader.close();227 return null;228 }).when(soapRequest).addAttachment(eq("<attContentId>"), any(InputStreamSource.class), eq(attachment.getContentType()));229 soapMessageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context);230 231 verify(soapRequest).addAttachment(eq("<attContentId>"), any(InputStreamSource.class), eq(attachment.getContentType()));232 }233 @Test234 public void testInboundSoapBody() {235 final StringSource soapBodySource = new StringSource(payload);236 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);237 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));238 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);239 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);240 when(soapEnvelope.getHeader()).thenReturn(soapHeader);241 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());242 when(soapHeader.getSource()).thenReturn(null);243 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());244 when(soapResponse.getSoapAction()).thenReturn("");245 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);246 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload);247 Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION));248 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);249 }250 @Test251 public void testInboundSoapBodyOnlyRootElement() {252 final StringSource soapBodySource = new StringSource("<testMessage/>");253 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);254 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));255 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);256 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);257 when(soapEnvelope.getHeader()).thenReturn(soapHeader);258 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());259 when(soapHeader.getSource()).thenReturn(null);260 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());261 when(soapResponse.getSoapAction()).thenReturn("");262 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);263 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage/>");264 Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION));265 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);266 }267 @Test268 public void testInboundSoapAction() {269 final StringSource soapBodySource = new StringSource(payload);270 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);271 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));272 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);273 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);274 when(soapEnvelope.getHeader()).thenReturn(soapHeader);275 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());276 when(soapHeader.getSource()).thenReturn(null);277 when(soapResponse.getSoapAction()).thenReturn("soapOperation");278 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());279 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);280 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload);281 Assert.assertEquals(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION), "soapOperation");282 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);283 }284 @Test285 public void testInboundSoapHeaderContent() {286 final String soapHeaderContent = "<header>" +287 "<operation>unitTest</operation>" +288 "<messageId>123456789</messageId>" +289 "</header>";290 final StringSource soapBodySource = new StringSource(payload);291 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);292 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));293 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);294 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);295 when(soapEnvelope.getHeader()).thenReturn(soapHeader);296 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());297 when(soapHeader.getSource()).thenReturn(new StringSource(soapHeaderContent));298 when(soapResponse.getSoapAction()).thenReturn("\"\"");299 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());300 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);301 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload);302 Assert.assertEquals(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION), "");303 Assert.assertEquals(responseMessage.getHeaderData().size(), 1L);304 Assert.assertEquals(responseMessage.getHeaderData().get(0), XML_PROCESSING_INSTRUCTION + soapHeaderContent);305 }306 @Test307 public void testInboundSoapHeader() {308 final StringSource soapBodySource = new StringSource(payload);309 final Set<SoapHeaderElement> soapHeaders = new HashSet<>();310 soapHeaders.add(soapHeaderElement);311 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);312 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));313 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);314 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);315 when(soapEnvelope.getHeader()).thenReturn(soapHeader);316 when(soapHeader.examineAllHeaderElements()).thenReturn(soapHeaders.iterator());317 when(soapHeader.getSource()).thenReturn(null);318 when(soapHeaderElement.getName()).thenReturn(new QName("{http://citrusframework.org}citrus:messageId"));319 when(soapHeaderElement.getText()).thenReturn("123456789");320 when(soapResponse.getSoapAction()).thenReturn("soapOperation");321 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());322 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);323 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload);324 Assert.assertEquals(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION), "soapOperation");325 Assert.assertEquals(responseMessage.getHeader("{http://citrusframework.org}citrus:messageId"), "123456789");326 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);327 }328 @Test329 public void testInboundSoapAttachment() throws IOException {330 final SoapAttachment attachment = new SoapAttachment();331 attachment.setContentId("attContentId");332 attachment.setContent("This is a SOAP attachment" + System.getProperty("line.separator") + "with multi-line");333 attachment.setContentType("plain/text");334 final StringSource soapBodySource = new StringSource(payload);335 final Set<Attachment> soapAttachments = new HashSet<>();336 soapAttachments.add(attachment);337 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);338 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));339 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);340 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);341 when(soapEnvelope.getHeader()).thenReturn(soapHeader);342 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());343 when(soapHeader.getSource()).thenReturn(null);344 when(soapResponse.getSoapAction()).thenReturn("soapOperation");345 when(soapResponse.getAttachments()).thenReturn(soapAttachments.iterator());346 final SoapMessage responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);347 Assert.assertNotNull(responseMessage);348 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload);349 Assert.assertEquals(responseMessage.getSoapAction(), "soapOperation");350 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);351 final List<SoapAttachment> attachments = responseMessage.getAttachments();352 Assert.assertEquals(attachments.size(), 1L);353 Assert.assertEquals(attachments.get(0).getContentId(), attachment.getContentId());354 Assert.assertEquals(attachments.get(0).getContentType(), attachment.getContentType());355 Assert.assertEquals(FileUtils.readToString(attachments.get(0).getInputStream()), attachment.getContent());356 }357 @Test358 public void testInboundSoapBodyWithNamespaceTranslation() {359 final StringSource soapBodySource = new StringSource(payload);360 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);361 when(soapEnvelope.getSource()).thenReturn(new DOMSource(XMLUtils.parseMessagePayload(getSoapRequestPayload(payload, "xmlns:foo=\"http://citruframework.org/foo\"")).getFirstChild()));362 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);363 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);364 when(soapEnvelope.getHeader()).thenReturn(soapHeader);365 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());366 when(soapHeader.getSource()).thenReturn(null);367 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());368 when(soapResponse.getSoapAction()).thenReturn("");369 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);370 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage xmlns:foo=\"http://citruframework.org/foo\">Hello</testMessage>");371 Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION));372 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);373 }374 @Test375 public void testInboundSoapBodyWithNamespaceTranslationXmlProcessingInstruction() {376 final StringSource soapBodySource = new StringSource(XML_PROCESSING_INSTRUCTION + payload);377 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);378 when(soapEnvelope.getSource()).thenReturn(new DOMSource(XMLUtils.parseMessagePayload(getSoapRequestPayload(payload, "xmlns:foo=\"http://citruframework.org/foo\"")).getFirstChild()));379 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);380 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);381 when(soapEnvelope.getHeader()).thenReturn(soapHeader);382 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());383 when(soapHeader.getSource()).thenReturn(null);384 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());385 when(soapResponse.getSoapAction()).thenReturn("");386 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);387 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage xmlns:foo=\"http://citruframework.org/foo\">Hello</testMessage>");388 Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION));389 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);390 }391 @Test392 public void testInboundSoapBodyWithNamespaceTranslationOnlyRootElement() {393 final String payload = "<testMessage xmlns:foo=\"http://citruframework.org/foo\" xmlns:bar=\"http://citruframework.org/bar\" " +394 "other=\"true\"/>";395 final StringSource soapBodySource = new StringSource(payload);396 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);397 when(soapEnvelope.getSource()).thenReturn(new DOMSource(XMLUtils.parseMessagePayload(getSoapRequestPayload(payload, "skip=\"true\"", "xmlns:foo=\"http://citruframework.org/foo\"",398 "xmlns:new=\"http://citruframework.org/new\"")).getFirstChild()));399 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);400 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);401 when(soapEnvelope.getHeader()).thenReturn(soapHeader);402 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());403 when(soapHeader.getSource()).thenReturn(null);404 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());405 when(soapResponse.getSoapAction()).thenReturn("");406 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);407 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage xmlns:foo=\"http://citruframework.org/foo\" xmlns:bar=\"http://citruframework.org/bar\" " +408 "other=\"true\" xmlns:new=\"http://citruframework.org/new\"/>");409 Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION));410 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);411 }412 @Test413 public void testInboundSoapBodyWithNamespaceTranslationDuplicates() {414 final String payload = "<testMessage xmlns:foo=\"http://citruframework.org/foo\" xmlns:bar=\"http://citruframework.org/bar\" " +415 "other=\"true\">Hello</testMessage>";416 final StringSource soapBodySource = new StringSource(payload);417 when(soapResponse.getEnvelope()).thenReturn(soapEnvelope);418 when(soapEnvelope.getSource()).thenReturn(new DOMSource(XMLUtils.parseMessagePayload(getSoapRequestPayload(payload, "skip=\"true\"", "xmlns:foo=\"http://citruframework.org/foo\"",419 "xmlns:new=\"http://citruframework.org/new\"")).getFirstChild()));420 when(soapResponse.getPayloadSource()).thenReturn(soapBodySource);421 when(soapResponse.getSoapHeader()).thenReturn(soapHeader);422 when(soapEnvelope.getHeader()).thenReturn(soapHeader);423 when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator());424 when(soapHeader.getSource()).thenReturn(null);425 when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator());426 when(soapResponse.getSoapAction()).thenReturn("");427 final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context);428 Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage xmlns:foo=\"http://citruframework.org/foo\" xmlns:bar=\"http://citruframework.org/bar\" " +429 "other=\"true\" xmlns:new=\"http://citruframework.org/new\">Hello</testMessage>");430 Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION));431 Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);432 }433 @Test434 public void testInboundSoapKeepEnvelope() throws IOException {435 final SaajSoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory();436 soapMessageFactory.afterPropertiesSet();437 final WebServiceMessage soapMessage = soapMessageFactory.createWebServiceMessage(new ByteArrayInputStream((XML_PROCESSING_INSTRUCTION + getSoapRequestPayload()).getBytes()));438 final WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration();439 endpointConfiguration.setKeepSoapEnvelope(true);440 final Message responseMessage = soapMessageConverter.convertInbound(soapMessage, endpointConfiguration, context);441 Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)), StringUtils.trimAllWhitespace(XML_PROCESSING_INSTRUCTION + getSoapRequestPayload()));442 Assert.assertEquals(responseMessage.getHeaderData().size(), 1L);443 Assert.assertEquals(responseMessage.getHeaderData().get(0), XML_PROCESSING_INSTRUCTION + "<SOAP-ENV:Header xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"/>");444 }445 @Test446 public void testEmptyOutboundSoapBodyNotParsed(){447 //GIVEN448 final DefaultMessage emptyMessage = new DefaultMessage("");449 final WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration();450 endpointConfiguration.setMessageFactory(soapMessageFactory);451 when(soapRequest.getSoapBody()).thenReturn(soapBody);452 when(soapBody.getPayloadResult()).thenReturn(new StringResult());453 //WHEN454 soapMessageConverter.convertOutbound(soapRequest, emptyMessage, endpointConfiguration, context);455 //THEN456 verify(soapRequest, never()).getPayloadResult();457 }458 private String getSoapRequestPayload() {459 return getSoapRequestPayload(payload);460 }461 private String getSoapRequestPayload(final String payload, final String ... namespaces) {462 return "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " + StringUtils.arrayToDelimitedString(namespaces, " ") + ">\n" +463 "<SOAP-ENV:Header/>\n" +464 "<SOAP-ENV:Body>\n" +465 payload +466 "</SOAP-ENV:Body>\n" +467 "</SOAP-ENV:Envelope>";468 }...
Source:WsAddressingMessageConverter.java
...45 public WsAddressingMessageConverter(WsAddressingHeaders addressingHeaders) {46 this.addressingHeaders = addressingHeaders;47 }48 @Override49 public void convertOutbound(WebServiceMessage webServiceMessage, Message message, WebServiceEndpointConfiguration endpointConfiguration, TestContext context) {50 super.convertOutbound(webServiceMessage, message, endpointConfiguration, context);51 SoapMessage soapMessage = (SoapMessage) webServiceMessage;52 URI messageId;53 if (message.getHeader(WsAddressingMessageHeaders.MESSAGE_ID) != null) {54 messageId = URI.create(context.replaceDynamicContentInString(message.getHeader(WsAddressingMessageHeaders.MESSAGE_ID).toString()));55 } else if (addressingHeaders.getMessageId() != null) {56 messageId = addressingHeaders.getMessageId();57 } else {58 messageId = messageIdStrategy.newMessageId(soapMessage);59 }60 EndpointReference from = addressingHeaders.getFrom();61 if (message.getHeader(WsAddressingMessageHeaders.FROM) != null) {62 from = new EndpointReference(URI.create(context.replaceDynamicContentInString(message.getHeader(WsAddressingMessageHeaders.FROM).toString())));63 }64 URI to = addressingHeaders.getTo();...
convertOutbound
Using AI Code Generation
1import com.consol.citrus.context.TestContext;2import com.consol.citrus.message.Message;3import com.consol.citrus.message.MessageConverter;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.ws.message.converter.SoapMessageConverter;6import org.springframework.ws.soap.SoapMessage;7public class SoapMessageConverterTest {8public static void main(String[] args) {9MessageConverter<SoapMessage> converter = new SoapMessageConverter();10TestContext context = new TestContext();11Message message = Message.Builder.withPayload("payload").build();12SoapMessage soapMessage = converter.convertOutbound(message, context);13System.out.println(soapMessage.getPayloadSource());14System.out.println(soapMessage.getPayloadResult());15System.out.println(soapMessage.getPayloadAsString());16System.out.println(soapMessage.getPayloadAsSource());17System.out.println(soapMessage.getPayloadAsResult());18System.out.println(soapMessage.getPayloadCaching());19System.out.println(soapMessage.getSoapAction());20System.out.println(soapMessage.getSoapVersion());21System.out.println(soapMessage.getSoapBody());22System.out.println(soapMessage.getSoapHeader());23System.out.println(soapMessage.getSoapFault());24System.out.println(soapMessage.getSoapBody().getPayloadSource());25System.out.println(soapMessage.getSoapBody().getPayloadResult());26System.out.println(soapMessage.getSoapBody().getPayloadAsString());27System.out.println(soapMessage.getSoapBody().getPayloadAsSource());28System.out.println(soapMessage.getSoapBody().getPayloadAsResult());29System.out.println(soapMessage.getSoapBody().getPayloadCaching());30System.out.println(soapMessage.getSoapHeader().getResult());31System.out.println(soapMessage.getSoapHeader().getSource());32System.out.println(soapMessage.getSoapHeader().getPayloadSource());33System.out.println(soapMessage.getSoapHeader().getPayloadResult());34System.out.println(soapMessage.getSoapHeader().getPayloadAsString());35System.out.println(soapMessage.getSoapHeader().getPayloadAsSource());36System.out.println(soapMessage.getSoapHeader().getPayloadAsResult());37System.out.println(soapMessage.getSoapHeader().getPayloadCaching());38System.out.println(soapMessage.getSoapFault().getFaultCode());39System.out.println(soapMessage.getSoapFault().getFaultString());40System.out.println(soapMessage.getSoapFault().getFaultActor());41System.out.println(soapMessage.getSoapFault().getFaultDetail());
convertOutbound
Using AI Code Generation
1package com.consol.citrus.ws.message.converter;2import org.springframework.ws.soap.SoapMessage;3import org.springframework.ws.soap.SoapMessageFactory;4import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;5import com.consol.citrus.message.Message;6import com.consol.citrus.message.MessageConverter;7import com.consol.citrus.ws.message.SoapMessageHeaders;8public class SoapMessageConverter implements MessageConverter<SoapMessage> {9 private SoapMessageFactory messageFactory = new SaajSoapMessageFactory();10 public SoapMessage convertInbound(Message message, SoapMessage model) {11 throw new UnsupportedOperationException("Convert inbound not supported for SOAP messages");12 }13 public Message convertOutbound(SoapMessage model, Message message) {14 if(model == null) {15 throw new IllegalArgumentException("SOAP message is empty - unable to convert to Citrus message");16 }17 if(message == null) {18 message = new com.consol.citrus.message.DefaultMessage();19 }20 message.setPayload(model.getPayloadSource());21 message.setHeader(SoapMessageHeaders.SOAP_ACTION, model.getSoapAction());22 return message;23 }24 public void setMessageFactory(SoapMessageFactory messageFactory) {25 this.messageFactory = messageFactory;26 }27}28package com.consol.citrus.ws.message.converter;29import org.springframework.ws.soap.SoapMessage;30import org.springframework.ws.soap.SoapMessageFactory;31import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;32import com.consol.citrus.message.Message;33import com.consol.citrus.message.MessageConverter;34import com.consol.citrus.ws.message.SoapMessageHeaders;35public class SoapMessageConverter implements MessageConverter<SoapMessage> {36 private SoapMessageFactory messageFactory = new SaajSoapMessageFactory();37 public SoapMessage convertInbound(Message message, SoapMessage model) {38 throw new UnsupportedOperationException("Convert inbound not supported for SOAP messages");39 }40 public Message convertOutbound(SoapMessage model, Message message) {41 if(model == null) {42 throw new IllegalArgumentException("SOAP message
convertOutbound
Using AI Code Generation
1package com.consol.citrus.ws.message.converter;2import com.consol.citrus.message.Message;3import com.consol.citrus.ws.message.SoapMessage;4import org.springframework.ws.soap.SoapMessageFactory;5import org.springframework.ws.soap.SoapVersion;6import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;7import javax.xml.soap.MessageFactory;8import javax.xml.soap.SOAPException;9public class SoapMessageConverter {10 public static void main(String[] args) {11 SoapMessageConverter soapMessageConverter = new SoapMessageConverter();12 soapMessageConverter.convertOutbound();13 }14 public void convertOutbound() {15 SoapMessage soapMessage = new SoapMessage();16 + "</testRequest>");17 SoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory();18 soapMessageFactory.setSoapVersion(SoapVersion.SOAP_11);19 soapMessageFactory.afterPropertiesSet();20 MessageFactory messageFactory = soapMessageFactory.getMessageFactory();21 try {22 javax.xml.soap.SOAPMessage soapMessage1 = messageFactory.createMessage();23 soapMessage1.getSOAPBody().addDocument(soapMessage.getPayloadAsDocument());24 soapMessage1.saveChanges();25 soapMessage.setPayload(soapMessage1);26 } catch (SOAPException e) {27 e.printStackTrace();28 }29 com.consol.citrus.message.converter.SoapMessageConverter soapMessageConverter = new com.consol.citrus.message.converter.SoapMessageConverter();30 Message message = soapMessageConverter.convertOutbound(soapMessage, null);31 System.out.println("Converted Message: " + message);32 }33}34Converted Message: Message [payload=org.springframework.ws.soap.saaj.SaajSoapMessage@2a2e9e9f, headers={SOAPAction=, Content-Type=application/soap+xml; charset=UTF-8}]35package com.consol.citrus.ws.message.converter;36import com.consol.citrus.message.Message;37import com.consol.citrus.ws.message.SoapMessage;38import org.springframework.ws.soap.SoapMessageFactory
convertOutbound
Using AI Code Generation
1SoapMessageConverter soapMessageConverter = new SoapMessageConverter();2SoapMessage soapMessage = new SoapMessage();3</soap:Envelope>");4soapMessageConverter.convertOutbound(soapMessage, new DefaultMessage(), context);5SoapMessageConverter soapMessageConverter = new SoapMessageConverter();6SoapMessage soapMessage = new SoapMessage();7</soap:Envelope>");8soapMessageConverter.convertOutbound(soapMessage, new DefaultMessage(), context);9SoapMessageConverter soapMessageConverter = new SoapMessageConverter();10SoapMessage soapMessage = new SoapMessage();11</soap:Envelope>");12soapMessageConverter.convertOutbound(soapMessage, new DefaultMessage(), context);13SoapMessageConverter soapMessageConverter = new SoapMessageConverter();
convertOutbound
Using AI Code Generation
1public class 3 {2public static void main(String[] args) {3SoapMessageConverter soapMessageConverter = new SoapMessageConverter();4SoapMessage soapMessage = new SoapMessage();5</ns0:Envelope>");6soapMessage.setHeader("Content-Type", "text/xml; charset=UTF-8");7soapMessage.setHeader("Content-Length", "287");8soapMessage.setHeader("Host", "localhost:8080");9soapMessage.setHeader("Connection", "Keep-Alive");10soapMessage.setHeader("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)");11soapMessage.setHeader("Accept-Encoding", "gzip,deflate");12soapMessage.setHeader("Content-Type", "text/xml; charset=UTF-8");13soapMessage.setHeader("Content-Length", "287");14soapMessage.setHeader("Host", "localhost:8080");15soapMessage.setHeader("Connection", "Keep-Alive");16soapMessage.setHeader("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)");17soapMessage.setHeader("Accept-Encoding", "gzip,deflate");18soapMessage.setHeader("Content-Type", "text/xml; charset=UTF-8");19soapMessage.setHeader("Content-Length", "287");20soapMessage.setHeader("Host", "localhost:8080");21soapMessage.setHeader("Connection", "Keep-Alive");22soapMessage.setHeader("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)");23soapMessage.setHeader("Accept-Encoding", "gzip,deflate");24soapMessage.setHeader("Content-Type",
convertOutbound
Using AI Code Generation
1package com.consol.citrus.ws;2import com.consol.citrus.message.Message;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.message.builder.DefaultMessageBuilder;5import com.consol.citrus.message.builder.PayloadTemplateMessageBuilder;6import com.consol.citrus.message.converter.MessageConverter;7import com.consol.citrus.message.converter.SoapMessageConverter;8import com.consol.citrus.testng.AbstractTestNGUnitTest;9import com.consol.citrus.ws.message.SoapMessage;10import org.springframework.core.io.ClassPathResource;11import org.testng.Assert;12import org.testng.annotations.Test;13public class SoapMessageConverterTest extends AbstractTestNGUnitTest {14 public void testConvertOutbound() {15 MessageConverter messageConverter = new SoapMessageConverter();16 SoapMessage soapMessage = new SoapMessage();17</soapenv:Envelope>");18 soapMessage.setHeader("operation", "placeOrder");19 Message convertedMessage = messageConverter.convertOutbound(soapMessage, context);
convertOutbound
Using AI Code Generation
1SoapMessageConverter soapMessageConverter = new SoapMessageConverter();2SoapMessage soapMessage = soapMessageConverter.convertOutbound(message, null);3Message message = soapMessageConverter.convertOutbound(soapMessage, null);4SoapMessageConverter soapMessageConverter = new SoapMessageConverter();5SoapMessage soapMessage = soapMessageConverter.convertOutbound(message, null);6Message message = soapMessageConverter.convertOutbound(soapMessage, null);
convertOutbound
Using AI Code Generation
1package com.consol.citrus.samples;2import org.springframework.context.support.ClassPathXmlApplicationContext;3import org.springframework.util.Assert;4import com.consol.citrus.message.Message;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.samples.model.Customer;7import com.consol.citrus.ws.message.converter.SoapMessageConverter;8import com.consol.citrus.ws.message.converter.SoapAttachmentConverter;9public class SoapMessageConverterTest {10 public static void main(String[] args) {11 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");12 SoapMessageConverter soapMessageConverter = context.getBean("soapMessageConverter",SoapMessageConverter.class);13 SoapAttachmentConverter soapAttachmentConverter = context.getBean("soapAttachmentConverter",SoapAttachmentConverter.class);14 soapMessageConverter.setAttachmentConverter(soapAttachmentConverter);15 Customer customer = new Customer();16 customer.setName("John");17 customer.setAge(25);18 Message message = new Message();19 message.setPayload(customer);20 message.setMessageType(MessageType.XML.name());21 String result = soapMessageConverter.convertOutbound(message, null);22 Assert.isTrue(result.contains("<ns1:name>John</ns1:name>"));23 Assert.isTrue(result.contains("<ns1:age>25</ns1:age>"));24 System.out.println(result);25 }26}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!