Best Citrus code snippet using com.consol.citrus.ws.message.converter.SoapMessageConverterTest.getSoapRequestPayload
Source:SoapMessageConverterTest.java
...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 }469}...
getSoapRequestPayload
Using AI Code Generation
1package com.consol.citrus.ws.message.converter;2import com.consol.citrus.exceptions.CitrusRuntimeException;3import com.consol.citrus.message.DefaultMessage;4import com.consol.citrus.message.Message;5import com.consol.citrus.testng.AbstractTestNGUnitTest;6import com.consol.citrus.ws.message.SoapFault;7import com.consol.citrus.ws.message.SoapMessage;8import org.springframework.ws.soap.SoapBody;9import org.springframework.ws.soap.SoapBodyException;10import org.springframework.ws.soap.SoapEnvelope;11import org.springframework.ws.soap.SoapFaultDetail;12import org.springframework.ws.soap.SoapFaultDetailElement;13import org.springframework.ws.soap.SoapFaultReason;14import org.springframework.ws.soap.SoapFaultReasonText;15import org.springframework.ws.soap.SoapMessageFactory;16import org.springframework.ws.soap.SoapVersion;17import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;18import org.springframework.xml.transform.StringSource;19import org.testng.Assert;20import org.testng.annotations.Test;21import javax.xml.namespace.QName;22import javax.xml.soap.SOAPException;23import javax.xml.soap.SOAPFactory;24import java.util.ArrayList;25import java.util.List;26public class SoapMessageConverterTest extends AbstractTestNGUnitTest {27 public void testConvertSoapMessage() throws Exception {28 SoapMessageConverter converter = new SoapMessageConverter();29 converter.setMessageFactory(getSoapMessageFactory());30 SoapMessage soapMessage = new SoapMessage();31 soapMessage.setPayload("<TestRequest><Message>Hello World!</Message></TestRequest>");32 soapMessage.setHeader("operation", "TestRequest");33 soapMessage.setHeader("citrus_soap_action", "TestRequest");34 org.springframework.ws.soap.SoapMessage soapMessageResult = converter.convertOutbound(soapMessage, context);35 Assert.assertEquals(soapMessageResult.getSoapBody().getPayloadSource().toString(), "<TestRequest><Message>Hello World!</Message></TestRequest>");36 Assert.assertEquals(soapMessageResult.getSoapHeader().getResult().toString(), "<operation>TestRequest</operation>");37 Assert.assertEquals(soapMessageResult.getSoapAction(), "
getSoapRequestPayload
Using AI Code Generation
1import com.consol.citrus.dsl.runner.TestRunner2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner3import com.consol.citrus.ws.message.converter.SoapMessageConverter4import org.springframework.context.ApplicationContext5import org.springframework.context.support.ClassPathXmlApplicationContext6import org.testng.annotations.Test7class SoapMessageConverterTest extends TestNGCitrusTestDesigner{8 def void testGetSoapRequestPayload() {9 def runner = new TestRunner()10 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml")11 SoapMessageConverter soapMessageConverter = context.getBean("soapMessageConverter", SoapMessageConverter)12 def soapMessage = runner.xmlBuilder().build()13 def soapRequestPayload = soapMessageConverter.getSoapRequestPayload(soapMessage)14 assert soapRequestPayload.contains("<soapenv:Envelope")15 assert soapRequestPayload.contains("<soapenv:Body>")16 assert soapRequestPayload.contains("</soapenv:Body>")17 assert soapRequestPayload.contains("</soapenv:Envelope>")18 }19}
getSoapRequestPayload
Using AI Code Generation
1import org.testng.annotations.Test;2import org.testng.Assert;3import com.consol.citrus.ws.message.converter.SoapMessageConverterTest;4public class SoapMessageConverterTestTest {5 public void testGetSoapRequestPayload() throws Exception {6 SoapMessageConverterTest soapMessageConverterTest = new SoapMessageConverterTest();7 String soapRequestPayload = soapMessageConverterTest.getSoapRequestPayload();8 Assert.assertNotNull(soapRequestPayload);9 }10}
getSoapRequestPayload
Using AI Code Generation
1public class SoapMessageConverterTest {2 public static void main(String[] args) {3 SoapMessageConverter converter = new SoapMessageConverter();4 DefaultSoapMessage message = new DefaultSoapMessage();5 message.setPayload("<TestMessage><Text>Hello World!</Text></TestMessage>");6 message.setSoapAction("TestAction");7 message.setHeader(new SoapHeader());
getSoapRequestPayload
Using AI Code Generation
1public void testSoapRequestPayload() {2 String soapRequestPayload = new SoapMessageConverter().getSoapRequestPayload("citrus:soap:clientRequestMessage");3 assertThat(soapRequestPayload).isEqualTo("citrus:soap:expectedRequestMessage");4}5public void testSoapResponsePayload() {6 String soapResponsePayload = new SoapMessageConverter().getSoapResponsePayload("citrus:soap:clientResponseMessage");7 assertThat(soapResponsePayload).isEqualTo("citrus:soap:expectedResponseMessage");8}9public void testSoapFaultPayload() {10 String soapFaultPayload = new SoapMessageConverter().getSoapFaultPayload("citrus:soap:clientFaultMessage");11 assertThat(soapFaultPayload).isEqualTo("citrus:soap:expectedFaultMessage");12}
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!!