How to use doWithMessage method of com.consol.citrus.ws.message.callback.SoapRequestMessageCallback class

Best Citrus code snippet using com.consol.citrus.ws.message.callback.SoapRequestMessageCallback.doWithMessage

Source:SoapRequestMessageCallbackTest.java Github

copy

Full Screen

...56 57 when(soapRequest.getSoapBody()).thenReturn(soapBody);58 when(soapBody.getPayloadResult()).thenReturn(soapBodyResult);59 60 callback.doWithMessage(soapRequest);61 62 Assert.assertEquals(soapBodyResult.toString(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + requestPayload);63 }64 65 @Test66 public void testSoapAction() throws TransformerException, IOException {67 Message testMessage = new DefaultMessage(requestPayload)68 .setHeader(SoapMessageHeaders.SOAP_ACTION, "soapAction");69 SoapRequestMessageCallback callback = new SoapRequestMessageCallback(testMessage, new WebServiceEndpointConfiguration(), context);70 71 reset(soapRequest, soapBody);72 73 when(soapRequest.getSoapBody()).thenReturn(soapBody);74 when(soapBody.getPayloadResult()).thenReturn(new StringResult());75 callback.doWithMessage(soapRequest);76 verify(soapRequest).setSoapAction("soapAction");77 }78 79 @Test80 public void testSoapHeaderContent() throws TransformerException, IOException {81 String soapHeaderContent = "<header>" + 82 "<operation>unitTest</operation>" + 83 "<messageId>123456789</messageId>" + 84 "</header>";85 86 Message testMessage = new DefaultMessage(requestPayload)87 .addHeaderData(soapHeaderContent);88 SoapRequestMessageCallback callback = new SoapRequestMessageCallback(testMessage, new WebServiceEndpointConfiguration(), context);89 90 StringResult soapHeaderResult = new StringResult();91 92 reset(soapRequest, soapBody, soapHeader);93 94 when(soapRequest.getSoapBody()).thenReturn(soapBody);95 when(soapBody.getPayloadResult()).thenReturn(new StringResult());96 97 when(soapRequest.getSoapHeader()).thenReturn(soapHeader);98 when(soapHeader.getResult()).thenReturn(soapHeaderResult);99 100 callback.doWithMessage(soapRequest);101 102 Assert.assertEquals(soapHeaderResult.toString(), soapHeaderContent);103 }104 @Test105 public void testMultipleSoapHeaderContent() throws TransformerException, IOException {106 String soapHeaderContent = "<header>" +107 "<operation>unitTest</operation>" +108 "<messageId>123456789</messageId>" +109 "</header>";110 Message testMessage = new DefaultMessage(requestPayload)111 .addHeaderData(soapHeaderContent)112 .addHeaderData("<AppInfo><appId>123456789</appId></AppInfo>");113 SoapRequestMessageCallback callback = new SoapRequestMessageCallback(testMessage, new WebServiceEndpointConfiguration(), context);114 StringResult soapHeaderResult = new StringResult();115 reset(soapRequest, soapBody, soapHeader);116 when(soapRequest.getSoapBody()).thenReturn(soapBody);117 when(soapBody.getPayloadResult()).thenReturn(new StringResult());118 when(soapRequest.getSoapHeader()).thenReturn(soapHeader);119 when(soapHeader.getResult()).thenReturn(soapHeaderResult);120 callback.doWithMessage(soapRequest);121 Assert.assertEquals(soapHeaderResult.toString(), soapHeaderContent + "<AppInfo><appId>123456789</appId></AppInfo>");122 }123 124 @Test125 public void testSoapHeader() throws TransformerException, IOException {126 Message testMessage = new DefaultMessage(requestPayload)127 .setHeader("operation", "unitTest")128 .setHeader("messageId", "123456789");129 SoapRequestMessageCallback callback = new SoapRequestMessageCallback(testMessage, new WebServiceEndpointConfiguration(), context);130 131 SoapHeaderElement soapHeaderElement = Mockito.mock(SoapHeaderElement.class);132 133 reset(soapRequest, soapBody, soapHeader, soapHeaderElement);134 135 when(soapRequest.getSoapBody()).thenReturn(soapBody);136 when(soapBody.getPayloadResult()).thenReturn(new StringResult());137 138 when(soapRequest.getSoapHeader()).thenReturn(soapHeader);139 when(soapHeader.addHeaderElement(eq(new QName("", "operation", "")))).thenReturn(soapHeaderElement);140 when(soapHeader.addHeaderElement(eq(new QName("", "messageId", "")))).thenReturn(soapHeaderElement);141 callback.doWithMessage(soapRequest);142 verify(soapHeaderElement).setText("unitTest");143 verify(soapHeaderElement).setText("123456789");144 }145 146 @Test147 public void testSoapHeaderQNameString() throws TransformerException, IOException {148 Message testMessage = new DefaultMessage(requestPayload)149 .setHeader("{http://www.citrus.com}citrus:operation", "unitTest")150 .setHeader("{http://www.citrus.com}citrus:messageId", "123456789");151 SoapRequestMessageCallback callback = new SoapRequestMessageCallback(testMessage, new WebServiceEndpointConfiguration(), context);152 153 SoapHeaderElement soapHeaderElement = Mockito.mock(SoapHeaderElement.class);154 155 reset(soapRequest, soapBody, soapHeader, soapHeaderElement);156 157 when(soapRequest.getSoapBody()).thenReturn(soapBody);158 when(soapBody.getPayloadResult()).thenReturn(new StringResult());159 160 when(soapRequest.getSoapHeader()).thenReturn(soapHeader);161 when(soapHeader.addHeaderElement(eq(new QName("http://www.citrus.com", "operation", "citrus")))).thenReturn(soapHeaderElement);162 when(soapHeader.addHeaderElement(eq(new QName("http://www.citrus.com", "messageId", "citrus")))).thenReturn(soapHeaderElement);163 callback.doWithMessage(soapRequest);164 verify(soapHeaderElement).setText("unitTest");165 verify(soapHeaderElement).setText("123456789");166 }167 168 @Test169 @SuppressWarnings("rawtypes")170 public void testSoapMimeHeader() throws TransformerException, IOException {171 Message testMessage = new DefaultMessage(requestPayload)172 .setHeader(SoapMessageHeaders.HTTP_PREFIX + "operation", "unitTest")173 .setHeader(SoapMessageHeaders.HTTP_PREFIX + "messageId", "123456789");174 SoapRequestMessageCallback callback = new SoapRequestMessageCallback(testMessage, new WebServiceEndpointConfiguration(), context);175 176 177 SaajSoapMessage saajSoapRequest = Mockito.mock(SaajSoapMessage.class);178 SoapEnvelope soapEnvelope = Mockito.mock(SoapEnvelope.class);179 SOAPMessage saajMessage = Mockito.mock(SOAPMessage.class);180 181 MimeHeaders mimeHeaders = new MimeHeaders();182 183 reset(saajSoapRequest, soapBody, soapHeader, soapEnvelope, saajMessage);184 185 when(saajSoapRequest.getEnvelope()).thenReturn(soapEnvelope);186 187 when(soapEnvelope.getBody()).thenReturn(soapBody);188 when(soapBody.getPayloadResult()).thenReturn(new StringResult());189 190 when(saajSoapRequest.getSaajMessage()).thenReturn(saajMessage);191 192 when(saajMessage.getMimeHeaders()).thenReturn(mimeHeaders);193 194 callback.doWithMessage(saajSoapRequest);195 Iterator it = mimeHeaders.getAllHeaders();196 Assert.assertEquals(((MimeHeader)it.next()).getName(), "operation");197 Assert.assertEquals(((MimeHeader)it.next()).getValue(), "123456789");198 Assert.assertFalse(it.hasNext());199 }200 201 @Test202 public void testSoapAttachment() throws TransformerException, IOException {203 SoapAttachment attachment = new SoapAttachment();204 attachment.setContentId("attContentId");205 attachment.setContent("This is a SOAP attachment\nwith multi-line");206 attachment.setContentType("plain/text");207 com.consol.citrus.ws.message.SoapMessage testMessage = new com.consol.citrus.ws.message.SoapMessage(requestPayload)208 .addAttachment(attachment);209 SoapRequestMessageCallback callback = new SoapRequestMessageCallback(testMessage, new WebServiceEndpointConfiguration(), context);210 211 reset(soapRequest, soapBody);212 213 when(soapRequest.getSoapBody()).thenReturn(soapBody);214 when(soapBody.getPayloadResult()).thenReturn(new StringResult());215 216 doAnswer(new Answer() {217 @Override218 public Object answer(InvocationOnMock invocation) throws Throwable {219 InputStreamSource contentStream = (InputStreamSource)invocation.getArguments()[1];220 BufferedReader reader = new BufferedReader(new InputStreamReader(contentStream.getInputStream()));221 Assert.assertEquals(reader.readLine(), "This is a SOAP attachment");222 Assert.assertEquals(reader.readLine(), "with multi-line");223 reader.close();224 return null;225 }226 }).when(soapRequest).addAttachment(eq(attachment.getContentId()), (InputStreamSource)any(), eq(attachment.getContentType()));227 callback.doWithMessage(soapRequest);228 }229}...

Full Screen

Full Screen

Source:SoapRequestMessageCallback.java Github

copy

Full Screen

...50 51 /**52 * Callback method called before request message is sent.53 */54 public void doWithMessage(WebServiceMessage requestMessage) throws IOException, TransformerException {55 endpointConfiguration.getMessageConverter().convertOutbound(requestMessage, message, endpointConfiguration, context);56 }57}...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in SoapRequestMessageCallback

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful