Best Citrus code snippet using com.consol.citrus.ws.WebServiceEndpointTest.handleMessageInternal
Source:WebServiceEndpointTest.java
...65 WebServiceEndpoint endpoint = new WebServiceEndpoint();66 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");67 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");68 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {69 public Message handleMessageInternal(Message message) {70 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());71 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());72 return responseMessage;73 }74 });75 StringResult soapResponsePayload = new StringResult();76 77 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse);78 when(messageContext.getRequest()).thenReturn(soapRequest);79 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);80 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));81 82 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));83 84 when(messageContext.getPropertyNames()).thenReturn(new String[]{});85 86 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);87 when(soapRequestHeader.getSource()).thenReturn(null);88 89 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();90 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());91 92 when(soapRequest.getSoapAction()).thenReturn(null);93 94 Set<Attachment> emptyAttachmentSet = Collections.emptySet();95 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());96 97 when(messageContext.getResponse()).thenReturn(soapResponse);98 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);99 100 endpoint.invoke(messageContext);101 102 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());103 }104 @Test105 public void testMessageProcessingWithSoapAction() throws Exception {106 WebServiceEndpoint endpoint = new WebServiceEndpoint();107 Map<String, Object> requestHeaders = new HashMap<String, Object>();108 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");109 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);110 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");111 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {112 public Message handleMessageInternal(Message message) {113 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());114 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));115 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");116 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());117 return responseMessage;118 }119 });120 StringResult soapResponsePayload = new StringResult();121 122 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse);123 when(messageContext.getRequest()).thenReturn(soapRequest);124 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);125 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));126 127 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));128 129 when(messageContext.getPropertyNames()).thenReturn(new String[]{});130 131 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);132 when(soapRequestHeader.getSource()).thenReturn(null);133 134 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();135 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());136 137 when(soapRequest.getSoapAction()).thenReturn("sayHello");138 139 Set<Attachment> emptyAttachmentSet = Collections.emptySet();140 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());141 142 when(messageContext.getResponse()).thenReturn(soapResponse);143 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);144 145 endpoint.invoke(messageContext);146 147 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());148 }149 150 @Test151 public void testMessageProcessingWithSoapRequestHeaders() throws Exception {152 WebServiceEndpoint endpoint = new WebServiceEndpoint();153 Map<String, Object> requestHeaders = new HashMap<String, Object>();154 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");155 requestHeaders.put("Operation", "sayHello");156 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);157 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");158 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {159 public Message handleMessageInternal(Message message) {160 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());161 Assert.assertNotNull(message.getHeader("Operation"));162 Assert.assertEquals(message.getHeader("Operation"), "sayHello");163 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());164 return responseMessage;165 }166 });167 Set<SoapHeaderElement> soapRequestHeaders = new HashSet<SoapHeaderElement>();168 soapRequestHeaders.add(soapRequestHeaderEntry);169 StringResult soapResponsePayload = new StringResult();170 171 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapRequestHeaderEntry, soapResponse);172 when(messageContext.getRequest()).thenReturn(soapRequest);173 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);174 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));175 176 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));177 178 when(messageContext.getPropertyNames()).thenReturn(new String[]{});179 180 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);181 when(soapRequestHeader.getSource()).thenReturn(null);182 183 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(soapRequestHeaders.iterator());184 185 when(soapRequestHeaderEntry.getName()).thenReturn(new QName("http://www.consol.de/citrus", "Operation", "citrus"));186 when(soapRequestHeaderEntry.getText()).thenReturn("sayHello");187 188 when(soapRequest.getSoapAction()).thenReturn("sayHello");189 190 Set<Attachment> emptyAttachmentSet = Collections.emptySet();191 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());192 193 when(messageContext.getResponse()).thenReturn(soapResponse);194 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);195 196 endpoint.invoke(messageContext);197 198 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());199 }200 201 @Test202 public void testMessageProcessingWithMimeRequestHeaders() throws Exception {203 WebServiceEndpoint endpoint = new WebServiceEndpoint();204 WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration();205 endpointConfiguration.setHandleMimeHeaders(true);206 endpoint.setEndpointConfiguration(endpointConfiguration);207 Map<String, Object> requestHeaders = new HashMap<String, Object>();208 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");209 requestHeaders.put("Operation", "sayHello");210 requestHeaders.put("Host", "localhost:8080");211 requestHeaders.put("Content-Length", "236");212 requestHeaders.put("Accept", "text/xml, text/html, image/gif, image/jpeg");213 requestHeaders.put("Content-Type", "text/xml");214 215 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);216 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");217 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {218 public Message handleMessageInternal(Message message) {219 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());220 Assert.assertNotNull(message.getHeader("Operation"));221 Assert.assertEquals(message.getHeader("Operation"), "sayHello");222 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());223 return responseMessage;224 }225 });226 227 SOAPMessage soapRequestMessage = Mockito.mock(SOAPMessage.class);228 MimeHeaders mimeHeaders = new MimeHeaders();229 mimeHeaders.addHeader("Host", "localhost:8080");230 mimeHeaders.addHeader("Content-Length", "236");231 mimeHeaders.addHeader("Accept", "text/xml");232 mimeHeaders.addHeader("Accept", "text/html");233 mimeHeaders.addHeader("Accept", "image/gif");234 mimeHeaders.addHeader("Accept", "image/jpeg");235 mimeHeaders.addHeader("Content-Type", "text/xml");236 237 Set<SoapHeaderElement> soapRequestHeaders = new HashSet<SoapHeaderElement>();238 soapRequestHeaders.add(soapRequestHeaderEntry);239 StringResult soapResponsePayload = new StringResult();240 241 reset(messageContext, soapEnvelope, soapRequestHeader, soapBody, soapRequestHeaderEntry, soapResponse, saajSoapRequest, soapRequestMessage);242 when(saajSoapRequest.getEnvelope()).thenReturn(soapEnvelope);243 when(saajSoapRequest.getSoapAction()).thenReturn("sayHello");244 Set<Attachment> emptyAttachmentSet = Collections.emptySet();245 when(saajSoapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());246 247 when(saajSoapRequest.getSaajMessage()).thenReturn(soapRequestMessage);248 when(soapRequestMessage.getMimeHeaders()).thenReturn(mimeHeaders);249 when(messageContext.getRequest()).thenReturn(saajSoapRequest);250 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));251 when(soapEnvelope.getBody()).thenReturn(soapBody);252 when(soapBody.getPayloadSource()).thenReturn(new StringSource(requestPayload));253 254 when(soapEnvelope.getHeader()).thenReturn(soapRequestHeader);255 when(soapRequestHeader.getSource()).thenReturn(null);256 257 when(messageContext.getPropertyNames()).thenReturn(new String[]{});258 259 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(soapRequestHeaders.iterator());260 261 when(soapRequestHeaderEntry.getName()).thenReturn(new QName("http://www.consol.de/citrus", "Operation", "citrus"));262 when(soapRequestHeaderEntry.getText()).thenReturn("sayHello");263 264 when(messageContext.getResponse()).thenReturn(soapResponse);265 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);266 267 endpoint.invoke(messageContext);268 269 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());270 }271 272 @Test273 public void testMessageProcessingWithSoapResponseHeaders() throws Exception {274 WebServiceEndpoint endpoint = new WebServiceEndpoint();275 Map<String, Object> requestHeaders = new HashMap<String, Object>();276 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");277 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);278 Map<String, Object> responseHeaders = new HashMap<String, Object>();279 responseHeaders.put("{http://www.consol.de/citrus}citrus:Operation", "sayHello");280 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);281 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {282 public Message handleMessageInternal(Message message) {283 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());284 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));285 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");286 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());287 return responseMessage;288 }289 });290 StringResult soapResponsePayload = new StringResult();291 292 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapRequestHeaderEntry);293 when(messageContext.getRequest()).thenReturn(soapRequest);294 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);295 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));296 297 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));298 299 when(messageContext.getPropertyNames()).thenReturn(new String[]{});300 301 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);302 when(soapRequestHeader.getSource()).thenReturn(null);303 304 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();305 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());306 307 when(soapRequest.getSoapAction()).thenReturn("sayHello");308 309 Set<Attachment> emptyAttachmentSet = Collections.emptySet();310 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());311 312 when(messageContext.getResponse()).thenReturn(soapResponse);313 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);314 315 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);316 doAnswer(new Answer<SoapHeaderElement>() {317 @Override318 public SoapHeaderElement answer(InvocationOnMock invocation) throws Throwable {319 QName headerQName = (QName)invocation.getArguments()[0];320 Assert.assertEquals(headerQName.getLocalPart(), "Operation");321 Assert.assertEquals(headerQName.getPrefix(), "citrus");322 Assert.assertEquals(headerQName.getNamespaceURI(), "http://www.consol.de/citrus");323 return soapRequestHeaderEntry;324 }325 }).when(soapResponseHeader).addHeaderElement((QName)any());326 endpoint.invoke(messageContext);327 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());328 verify(soapRequestHeaderEntry).setText("sayHello");329 }330 331 @Test332 public void testMessageProcessingWithDefaultHeaderQName() throws Exception {333 WebServiceEndpoint endpoint = new WebServiceEndpoint();334 Map<String, Object> requestHeaders = new HashMap<String, Object>();335 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");336 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);337 Map<String, Object> responseHeaders = new HashMap<String, Object>();338 responseHeaders.put("Operation", "sayHello");339 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);340 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {341 public Message handleMessageInternal(Message message) {342 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());343 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));344 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");345 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());346 return responseMessage;347 }348 });349 endpoint.setDefaultNamespaceUri("http://www.consol.de/citrus");350 endpoint.setDefaultPrefix("citrus");351 StringResult soapResponsePayload = new StringResult();352 353 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);354 when(messageContext.getRequest()).thenReturn(soapRequest);355 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);356 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));357 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));358 359 when(messageContext.getPropertyNames()).thenReturn(new String[]{});360 361 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);362 when(soapRequestHeader.getSource()).thenReturn(null);363 364 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();365 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());366 367 when(soapRequest.getSoapAction()).thenReturn("sayHello");368 369 Set<Attachment> emptyAttachmentSet = Collections.emptySet();370 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());371 372 when(messageContext.getResponse()).thenReturn(soapResponse);373 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);374 375 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);376 doAnswer(new Answer<SoapHeaderElement>() {377 @Override378 public SoapHeaderElement answer(InvocationOnMock invocation) throws Throwable {379 QName headerQName = (QName)invocation.getArguments()[0];380 Assert.assertEquals(headerQName.getLocalPart(), "Operation");381 Assert.assertEquals(headerQName.getPrefix(), "citrus");382 Assert.assertEquals(headerQName.getNamespaceURI(), "http://www.consol.de/citrus");383 return soapRequestHeaderEntry;384 }385 }).when(soapResponseHeader).addHeaderElement((QName)any());386 endpoint.invoke(messageContext);387 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());388 verify(soapRequestHeaderEntry).setText("sayHello");389 }390 391 @Test392 public void testMessageProcessingWithDefaultHeaderQNameNoPrefix() throws Exception {393 WebServiceEndpoint endpoint = new WebServiceEndpoint();394 Map<String, Object> requestHeaders = new HashMap<String, Object>();395 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");396 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);397 Map<String, Object> responseHeaders = new HashMap<String, Object>();398 responseHeaders.put("Operation", "sayHello");399 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);400 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {401 public Message handleMessageInternal(Message message) {402 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());403 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));404 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");405 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());406 return responseMessage;407 }408 });409 endpoint.setDefaultNamespaceUri("http://www.consol.de/citrus");410 StringResult soapResponsePayload = new StringResult();411 412 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);413 when(messageContext.getRequest()).thenReturn(soapRequest);414 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);415 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));416 417 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));418 419 when(messageContext.getPropertyNames()).thenReturn(new String[]{});420 421 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);422 when(soapRequestHeader.getSource()).thenReturn(null);423 424 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();425 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());426 427 when(soapRequest.getSoapAction()).thenReturn("sayHello");428 429 Set<Attachment> emptyAttachmentSet = Collections.emptySet();430 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());431 432 when(messageContext.getResponse()).thenReturn(soapResponse);433 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);434 435 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);436 doAnswer(new Answer<SoapHeaderElement>() {437 @Override438 public SoapHeaderElement answer(InvocationOnMock invocation) throws Throwable {439 QName headerQName = (QName)invocation.getArguments()[0];440 Assert.assertEquals(headerQName.getLocalPart(), "Operation");441 Assert.assertEquals(headerQName.getPrefix(), "");442 Assert.assertEquals(headerQName.getNamespaceURI(), "http://www.consol.de/citrus");443 return soapRequestHeaderEntry;444 }445 }).when(soapResponseHeader).addHeaderElement((QName)any());446 endpoint.invoke(messageContext);447 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());448 verify(soapRequestHeaderEntry, times(2)).setText("sayHello");449 }450 451 @Test(expectedExceptions = SoapHeaderException.class)452 public void testMessageProcessingMissingNamespaceUri() throws Exception {453 WebServiceEndpoint endpoint = new WebServiceEndpoint();454 Map<String, Object> requestHeaders = new HashMap<String, Object>();455 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");456 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);457 Map<String, Object> responseHeaders = new HashMap<String, Object>();458 responseHeaders.put("Operation", "sayHello");459 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);460 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {461 public Message handleMessageInternal(Message message) {462 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());463 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));464 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");465 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());466 return responseMessage;467 }468 });469 StringResult soapResponsePayload = new StringResult();470 471 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);472 when(messageContext.getRequest()).thenReturn(soapRequest);473 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);474 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));475 476 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));477 478 when(messageContext.getPropertyNames()).thenReturn(new String[]{});479 480 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);481 when(soapRequestHeader.getSource()).thenReturn(null);482 483 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();484 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());485 486 when(soapRequest.getSoapAction()).thenReturn("sayHello");487 488 Set<Attachment> emptyAttachmentSet = Collections.emptySet();489 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());490 491 when(messageContext.getResponse()).thenReturn(soapResponse);492 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);493 494 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);495 doAnswer(new Answer<SoapHeaderElement>() {496 @Override497 public SoapHeaderElement answer(InvocationOnMock invocation) throws Throwable {498 QName headerQName = (QName)invocation.getArguments()[0];499 Assert.assertEquals(headerQName.getLocalPart(), "Operation");500 Assert.assertEquals(headerQName.getPrefix(), "");501 Assert.assertEquals(headerQName.getNamespaceURI(), "");502 return soapRequestHeaderEntry;503 }504 }).when(soapResponseHeader).addHeaderElement((QName)any());505 endpoint.invoke(messageContext);506 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());507 verify(soapRequestHeaderEntry).setText("sayHello");508 }509 510 @Test511 public void testMessageProcessingWithSoapAttachment() throws Exception {512 WebServiceEndpoint endpoint = new WebServiceEndpoint();513 Map<String, Object> requestHeaders = new HashMap<>();514 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");515 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);516 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");517 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {518 public Message handleMessageInternal(Message message) {519 Assert.assertTrue(SoapMessage.class.isInstance(message));520 SoapMessage soapMessage = (SoapMessage) message;521 Assert.assertEquals(soapMessage.getAttachments().size(), 1L);522 Attachment attachment = soapMessage.getAttachments().get(0);523 Assert.assertEquals(attachment.getContentId(), "myContentId");524 Assert.assertEquals(attachment.getContentType(), "text/xml");525 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");526 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());527 return responseMessage;528 }529 });530 StringResult soapResponsePayload = new StringResult();531 532 Set<Attachment> attachments = new HashSet<Attachment>();533 Attachment attachment = Mockito.mock(Attachment.class);534 attachments.add(attachment);535 536 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, attachment);537 when(messageContext.getRequest()).thenReturn(soapRequest);538 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);539 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));540 541 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));542 543 when(messageContext.getPropertyNames()).thenReturn(new String[]{});544 545 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);546 when(soapRequestHeader.getSource()).thenReturn(null);547 548 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();549 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());550 551 when(soapRequest.getSoapAction()).thenReturn("sayHello");552 553 when(soapRequest.getAttachments()).thenReturn(attachments.iterator());554 when(attachment.getContentId()).thenReturn("myContentId");555 when(attachment.getContentType()).thenReturn("text/xml");556 557 when(messageContext.getResponse()).thenReturn(soapResponse);558 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);559 560 when(attachment.getInputStream()).thenReturn(new ByteArrayInputStream("AttachmentBody".getBytes()));561 endpoint.invoke(messageContext);562 563 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());564 }565 @Test566 public void testMessageProcessingWithSoapAttachmentInResponse() throws Exception {567 WebServiceEndpoint endpoint = new WebServiceEndpoint();568 final SoapMessage responseMessage = new SoapMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");569 responseMessage.addAttachment(new SoapAttachment("This is an attachment"));570 responseMessage.getAttachments().get(0).setContentId("myAttachment");571 responseMessage.getAttachments().get(0).setContentType("text/plain");572 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {573 public Message handleMessageInternal(Message message) {574 return responseMessage;575 }576 });577 StringResult soapResponsePayload = new StringResult();578 Set<Attachment> attachments = new HashSet<Attachment>();579 Attachment attachment = Mockito.mock(Attachment.class);580 attachments.add(attachment);581 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, attachment);582 when(messageContext.getRequest()).thenReturn(soapRequest);583 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);584 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));585 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));586 when(messageContext.getPropertyNames()).thenReturn(new String[]{});587 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);588 when(soapRequestHeader.getSource()).thenReturn(null);589 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();590 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());591 when(soapRequest.getSoapAction()).thenReturn("sayHello");592 when(soapRequest.getAttachments()).thenReturn(attachments.iterator());593 when(attachment.getContentId()).thenReturn("myContentId");594 when(attachment.getContentType()).thenReturn("text/xml");595 when(messageContext.getResponse()).thenReturn(soapResponse);596 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);597 when(soapResponse.addAttachment(eq("<myAttachment>"), any(DataHandler.class))).thenReturn(Mockito.mock(Attachment.class));598 when(attachment.getInputStream()).thenReturn(new ByteArrayInputStream("AttachmentBody".getBytes()));599 endpoint.invoke(messageContext);600 verify(soapResponse).addAttachment(eq("<myAttachment>"), any(DataHandler.class));601 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());602 }603 604 @Test605 public void testMessageProcessingWithServerSoapFaultInResponse() throws Exception {606 WebServiceEndpoint endpoint = new WebServiceEndpoint();607 Map<String, Object> requestHeaders = new HashMap<String, Object>();608 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");609 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);610 final SoapFault responseMessage = new SoapFault();611 responseMessage.faultCode("SERVER");612 responseMessage.faultString("Invalid request, because of unknown error");613 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {614 public Message handleMessageInternal(Message message) {615 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());616 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));617 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");618 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());619 return responseMessage;620 }621 });622 StringResult soapResponsePayload = new StringResult();623 624 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapBody);625 when(messageContext.getRequest()).thenReturn(soapRequest);626 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);627 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));628 629 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));630 631 when(messageContext.getPropertyNames()).thenReturn(new String[]{});632 633 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);634 when(soapRequestHeader.getSource()).thenReturn(null);635 636 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();637 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());638 639 when(soapRequest.getSoapAction()).thenReturn("sayHello");640 641 Set<Attachment> emptyAttachmentSet = Collections.emptySet();642 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());643 644 when(messageContext.getResponse()).thenReturn(soapResponse);645 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);646 647 when(soapResponse.getSoapBody()).thenReturn(soapBody);648 doAnswer(new Answer<org.springframework.ws.soap.SoapFault>() {649 @Override650 public org.springframework.ws.soap.SoapFault answer(InvocationOnMock invocation) throws Throwable {651 Assert.assertEquals(invocation.getArguments()[0], "Invalid request, because of unknown error");652 return soapFault;653 }654 }).when(soapBody).addServerOrReceiverFault((String)any(), (Locale)any());655 656 endpoint.invoke(messageContext);657 658 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());659 }660 661 @Test662 public void testMessageProcessingWithClientSoapFaultInResponse() throws Exception {663 WebServiceEndpoint endpoint = new WebServiceEndpoint();664 Map<String, Object> requestHeaders = new HashMap<String, Object>();665 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");666 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);667 final SoapFault responseMessage = new SoapFault();668 responseMessage.faultCode("CLIENT");669 responseMessage.faultString("Invalid request");670 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {671 public Message handleMessageInternal(Message message) {672 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());673 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));674 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");675 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());676 return responseMessage;677 }678 });679 StringResult soapResponsePayload = new StringResult();680 681 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapBody);682 when(messageContext.getRequest()).thenReturn(soapRequest);683 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);684 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));685 686 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));687 688 when(messageContext.getPropertyNames()).thenReturn(new String[]{});689 690 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);691 when(soapRequestHeader.getSource()).thenReturn(null);692 693 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();694 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());695 696 when(soapRequest.getSoapAction()).thenReturn("sayHello");697 698 Set<Attachment> emptyAttachmentSet = Collections.emptySet();699 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());700 701 when(messageContext.getResponse()).thenReturn(soapResponse);702 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);703 704 when(soapResponse.getSoapBody()).thenReturn(soapBody);705 doAnswer(new Answer<org.springframework.ws.soap.SoapFault>() {706 @Override707 public org.springframework.ws.soap.SoapFault answer(InvocationOnMock invocation) throws Throwable {708 Assert.assertEquals(invocation.getArguments()[0], "Invalid request");709 return soapFault;710 }711 }).when(soapBody).addClientOrSenderFault((String)any(), (Locale)any());712 713 endpoint.invoke(messageContext);714 715 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());716 }717 718 @Test719 public void testMessageProcessingWithSoapFaultDetail() throws Exception {720 WebServiceEndpoint endpoint = new WebServiceEndpoint();721 Map<String, Object> requestHeaders = new HashMap<String, Object>();722 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");723 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);724 final SoapFault responseMessage = new SoapFault();725 responseMessage.setPayload("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ResponseMessage><text>This request was not OK!</text></ResponseMessage>");726 responseMessage.faultCode("SERVER");727 responseMessage.faultString("Invalid request");728 responseMessage.addFaultDetail("<DetailMessage><text>This request was not OK!</text></DetailMessage>");729 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {730 public Message handleMessageInternal(Message message) {731 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());732 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));733 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");734 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());735 return responseMessage;736 }737 });738 StringResult soapFaultResult = new StringResult();739 740 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapBody, soapFault, soapFaultDetail);741 when(messageContext.getRequest()).thenReturn(soapRequest);742 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);743 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));744 745 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));746 747 when(messageContext.getPropertyNames()).thenReturn(new String[]{});748 749 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);750 when(soapRequestHeader.getSource()).thenReturn(null);751 752 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();753 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());754 755 when(soapRequest.getSoapAction()).thenReturn("sayHello");756 757 Set<Attachment> emptyAttachmentSet = Collections.emptySet();758 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());759 760 when(messageContext.getResponse()).thenReturn(soapResponse);761 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);762 763 when(soapResponse.getSoapBody()).thenReturn(soapBody);764 doAnswer(new Answer<org.springframework.ws.soap.SoapFault>() {765 @Override766 public org.springframework.ws.soap.SoapFault answer(InvocationOnMock invocation) throws Throwable {767 Assert.assertEquals(invocation.getArguments()[0], "Invalid request");768 return soapFault;769 }770 }).when(soapBody).addServerOrReceiverFault((String)any(), (Locale)any());771 772 when(soapFault.addFaultDetail()).thenReturn(soapFaultDetail);773 774 when(soapFaultDetail.getResult()).thenReturn(soapFaultResult);775 776 endpoint.invoke(messageContext);777 778 Assert.assertEquals(soapFaultResult.toString(), "<DetailMessage><text>This request was not OK!</text></DetailMessage>");779 }780 781 @Test782 public void testMessageProcessingWithMultipleSoapFaultDetails() throws Exception {783 WebServiceEndpoint endpoint = new WebServiceEndpoint();784 Map<String, Object> requestHeaders = new HashMap<String, Object>();785 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");786 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);787 final SoapFault responseMessage = new SoapFault();788 responseMessage.setPayload("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ResponseMessage><text>This request was not OK!</text></ResponseMessage>");789 responseMessage.faultCode("SERVER");790 responseMessage.faultString("Invalid request");791 responseMessage.addFaultDetail("<DetailMessage><text>This request was not OK!</text></DetailMessage>");792 responseMessage.addFaultDetail("<Error><text>This request was not OK!</text></Error>");793 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {794 public Message handleMessageInternal(Message message) {795 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());796 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));797 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");798 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());799 return responseMessage;800 }801 });802 StringResult soapFaultResult = new StringResult();803 804 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapBody, soapFault, soapFaultDetail);805 when(messageContext.getRequest()).thenReturn(soapRequest);806 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);807 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));808 809 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));810 811 when(messageContext.getPropertyNames()).thenReturn(new String[]{});812 813 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);814 when(soapRequestHeader.getSource()).thenReturn(null);815 816 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();817 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());818 819 when(soapRequest.getSoapAction()).thenReturn("sayHello");820 821 Set<Attachment> emptyAttachmentSet = Collections.emptySet();822 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());823 824 when(messageContext.getResponse()).thenReturn(soapResponse);825 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);826 827 when(soapResponse.getSoapBody()).thenReturn(soapBody);828 doAnswer(new Answer<org.springframework.ws.soap.SoapFault>() {829 @Override830 public org.springframework.ws.soap.SoapFault answer(InvocationOnMock invocation) throws Throwable {831 Assert.assertEquals(invocation.getArguments()[0], "Invalid request");832 return soapFault;833 }834 }).when(soapBody).addServerOrReceiverFault((String)any(), (Locale)any());835 836 when(soapFault.addFaultDetail()).thenReturn(soapFaultDetail);837 838 when(soapFaultDetail.getResult()).thenReturn(soapFaultResult);839 840 endpoint.invoke(messageContext);841 842 Assert.assertEquals(soapFaultResult.toString(), "<DetailMessage><text>This request was not OK!</text></DetailMessage><Error><text>This request was not OK!</text></Error>");843 }844 845 @Test846 public void testMessageProcessingWithSoapActionInResponse() throws Exception {847 WebServiceEndpoint endpoint = new WebServiceEndpoint();848 Map<String, Object> requestHeaders = new HashMap<String, Object>();849 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");850 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);851 Map<String, Object> responseHeaders = new HashMap<String, Object>();852 responseHeaders.put(SoapMessageHeaders.SOAP_ACTION, "answerHello");853 final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);854 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {855 public Message handleMessageInternal(Message message) {856 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());857 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));858 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");859 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());860 return responseMessage;861 }862 });863 StringResult soapResponsePayload = new StringResult();864 865 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse);866 when(messageContext.getRequest()).thenReturn(soapRequest);867 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);868 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));869 870 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));871 872 when(messageContext.getPropertyNames()).thenReturn(new String[]{});873 874 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);875 when(soapRequestHeader.getSource()).thenReturn(null);876 877 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();878 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());879 880 when(soapRequest.getSoapAction()).thenReturn("sayHello");881 882 Set<Attachment> emptyAttachmentSet = Collections.emptySet();883 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());884 885 when(messageContext.getResponse()).thenReturn(soapResponse);886 when(soapResponse.getPayloadResult()).thenReturn(soapResponsePayload);887 endpoint.invoke(messageContext);888 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());889 verify(soapResponse).setSoapAction("answerHello");890 }891 892 @Test893 public void testMessageProcessingWithSoap11FaultInResponse() throws Exception {894 WebServiceEndpoint endpoint = new WebServiceEndpoint();895 Map<String, Object> requestHeaders = new HashMap<String, Object>();896 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");897 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);898 final SoapFault responseMessage = new SoapFault();899 responseMessage.faultCode("{http://www.consol.de/citrus}citrus:TEC-1000");900 responseMessage.faultString("Invalid request");901 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {902 public Message handleMessageInternal(Message message) {903 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());904 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));905 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");906 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());907 return responseMessage;908 }909 });910 Soap11Body soapResponseBody = Mockito.mock(Soap11Body.class);911 final Soap11Fault soapFault = Mockito.mock(Soap11Fault.class);912 913 StringResult soapResponsePayload = new StringResult();914 915 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody);916 when(messageContext.getRequest()).thenReturn(soapRequest);917 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);918 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));919 920 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));921 922 when(messageContext.getPropertyNames()).thenReturn(new String[]{});923 924 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);925 when(soapRequestHeader.getSource()).thenReturn(null);926 927 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();928 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());929 930 when(soapRequest.getSoapAction()).thenReturn("sayHello");931 932 Set<Attachment> emptyAttachmentSet = Collections.emptySet();933 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());934 935 when(messageContext.getResponse()).thenReturn(soapResponse);936 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);937 938 when(soapResponse.getSoapBody()).thenReturn(soapResponseBody);939 doAnswer(new Answer<org.springframework.ws.soap.SoapFault>() {940 @Override941 public org.springframework.ws.soap.SoapFault answer(InvocationOnMock invocation) throws Throwable {942 QName faultQName = (QName)invocation.getArguments()[0];943 Assert.assertEquals(faultQName.getLocalPart(), "TEC-1000");944 Assert.assertEquals(faultQName.getPrefix(), "citrus");945 Assert.assertEquals(faultQName.getNamespaceURI(), "http://www.consol.de/citrus");946 Assert.assertEquals(invocation.getArguments()[1], "Invalid request");947 return soapFault;948 }949 }).when(soapResponseBody).addFault((QName)any(), (String)any(), (Locale)any());950 951 endpoint.invoke(messageContext);952 953 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());954 }955 956 @Test957 public void testMessageProcessingWithSoap12FaultInResponse() throws Exception {958 WebServiceEndpoint endpoint = new WebServiceEndpoint();959 Map<String, Object> requestHeaders = new HashMap<String, Object>();960 requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");961 final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);962 final SoapFault responseMessage = new SoapFault();963 responseMessage.faultCode("{http://www.consol.de/citrus}citrus:TEC-1000");964 responseMessage.faultString("Invalid request");965 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {966 public Message handleMessageInternal(Message message) {967 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());968 Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));969 Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");970 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());971 return responseMessage;972 }973 });974 Soap12Body soapResponseBody = Mockito.mock(Soap12Body.class);975 final Soap12Fault soapFault = Mockito.mock(Soap12Fault.class);976 977 StringResult soapResponsePayload = new StringResult();978 979 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader, soapResponseBody, soapFault);980 when(messageContext.getRequest()).thenReturn(soapRequest);981 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);982 when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload()));983 984 when(soapRequest.getPayloadSource()).thenReturn(new StringSource(requestPayload));985 986 when(messageContext.getPropertyNames()).thenReturn(new String[]{});987 988 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);989 when(soapRequestHeader.getSource()).thenReturn(null);990 991 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();992 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());993 994 when(soapRequest.getSoapAction()).thenReturn("sayHello");995 996 Set<Attachment> emptyAttachmentSet = Collections.emptySet();997 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());998 999 when(messageContext.getResponse()).thenReturn(soapResponse);1000 when(soapResponse.getSoapHeader()).thenReturn(soapResponseHeader);1001 1002 when(soapResponse.getSoapBody()).thenReturn(soapResponseBody);1003 1004 doAnswer(new Answer<Soap12Fault>() {1005 @Override1006 public Soap12Fault answer(InvocationOnMock invocation) throws Throwable {1007 Assert.assertEquals(invocation.getArguments()[0], "Invalid request");1008 return soapFault;1009 }1010 }).when(soapResponseBody).addServerOrReceiverFault((String)any(), (Locale)any());1011 doAnswer(new Answer() {1012 @Override1013 public Object answer(InvocationOnMock invocation) throws Throwable {1014 QName faultQName = (QName)invocation.getArguments()[0];1015 Assert.assertEquals(faultQName.getLocalPart(), "TEC-1000");1016 Assert.assertEquals(faultQName.getPrefix(), "citrus");1017 Assert.assertEquals(faultQName.getNamespaceURI(), "http://www.consol.de/citrus");1018 return null;1019 }1020 }).when(soapFault).addFaultSubcode((QName)any());1021 endpoint.invoke(messageContext);1022 1023 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());1024 }1025 1026 @Test1027 public void testEmptySoapMessageProcessing() throws Exception {1028 WebServiceEndpoint endpoint = new WebServiceEndpoint();1029 final Message requestMessage = new DefaultMessage("");1030 final Message responseMessage = new DefaultMessage("");1031 endpoint.setEndpointAdapter(new StaticEndpointAdapter() {1032 public Message handleMessageInternal(Message message) {1033 Assert.assertEquals(message.getHeaders().size(), requestMessage.getHeaders().size());1034 Assert.assertEquals(message.getPayload(), requestMessage.getPayload());1035 return responseMessage;1036 }1037 });1038 StringResult soapResponsePayload = new StringResult();1039 1040 reset(messageContext, soapEnvelope, soapRequest, soapRequestHeader, soapResponse);1041 when(messageContext.getRequest()).thenReturn(soapRequest);1042 when(soapRequest.getEnvelope()).thenReturn(soapEnvelope);1043 when(soapEnvelope.getSource()).thenReturn(new StringSource("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body></SOAP-ENV:Body></SOAP-ENV:Envelope>"));1044 1045 when(soapRequest.getPayloadSource()).thenReturn(null);1046 ...
handleMessageInternal
Using AI Code Generation
1org.springframework.ws.soap.SoapMessage soapMessage = new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12);2soapMessage.getSoapBody().addDocument(new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12).getSoapBody().extractContentAsDocument());3handleMessageInternal(soapMessage);4org.springframework.ws.soap.SoapMessage soapMessage = new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12);5soapMessage.getSoapBody().addDocument(new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12).getSoapBody().extractContentAsDocument());6handleMessageInternal(soapMessage);7org.springframework.ws.soap.SoapMessage soapMessage = new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12);8soapMessage.getSoapBody().addDocument(new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12).getSoapBody().extractContentAsDocument());9handleMessageInternal(soapMessage);10org.springframework.ws.soap.SoapMessage soapMessage = new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12);11soapMessage.getSoapBody().addDocument(new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12).getSoapBody().extractContentAsDocument());12handleMessageInternal(soapMessage);13org.springframework.ws.soap.SoapMessage soapMessage = new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion.SOAP_12);14soapMessage.getSoapBody().addDocument(new org.springframework.ws.soap.saaj.SaajSoapMessage(org.springframework.ws.soap.SoapVersion
handleMessageInternal
Using AI Code Generation
1com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()2message.setPayload("Hello Citrus!");3com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()4message.setPayload("Hello Citrus!");5com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()6message.setPayload("Hello Citrus!");7com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()8message.setPayload("Hello Citrus!");9com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()10message.setPayload("Hello Citrus!");11com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()12message.setPayload("Hello Citrus!");13com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()14message.setPayload("Hello Citrus!");15com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()16message.setPayload("Hello Citrus!");17com.consol.citrus.message.Message message = new com.consol.citrus.message.DefaultMessage()18message.setPayload("Hello Citrus!");19handleMessageInternal(message,
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!!