How to use invoke method of com.consol.citrus.ws.server.WebServiceEndpoint class

Best Citrus code snippet using com.consol.citrus.ws.server.WebServiceEndpoint.invoke

Source:WebServiceEndpointTest.java Github

copy

Full Screen

...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 1047 when(messageContext.getPropertyNames()).thenReturn(new String[]{});1048 1049 when(soapRequest.getSoapHeader()).thenReturn(soapRequestHeader);1050 when(soapRequestHeader.getSource()).thenReturn(null);1051 1052 Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();1053 when(soapRequestHeader.examineAllHeaderElements()).thenReturn(emptyHeaderSet.iterator());1054 1055 when(soapRequest.getSoapAction()).thenReturn(null);1056 1057 Set<Attachment> emptyAttachmentSet = Collections.emptySet();1058 when(soapRequest.getAttachments()).thenReturn(emptyAttachmentSet.iterator());1059 1060 when(messageContext.getResponse()).thenReturn(soapResponse);1061 1062 endpoint.invoke(messageContext);1063 1064 Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());1065 }1066 private String getSoapRequestPayload() {1067 return "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +1068 "<SOAP-ENV:Header/>\n" +1069 "<SOAP-ENV:Body>\n" +1070 requestPayload +1071 "</SOAP-ENV:Body>\n" +1072 "</SOAP-ENV:Envelope>";1073 }1074}...

Full Screen

Full Screen

Source:WebServiceEndpoint.java Github

copy

Full Screen

...70 71 /** JMS headers begin with this prefix */72 private static final String DEFAULT_JMS_HEADER_PREFIX = "JMS";73 /**74 * @see org.springframework.ws.server.endpoint.MessageEndpoint#invoke(org.springframework.ws.context.MessageContext)75 * @throws CitrusRuntimeException76 */77 public void invoke(final MessageContext messageContext) throws Exception {78 Assert.notNull(messageContext.getRequest(), "Request must not be null - unable to send message");79 80 Message requestMessage = endpointConfiguration.getMessageConverter().convertInbound(messageContext.getRequest(), messageContext, endpointConfiguration);81 if (log.isDebugEnabled()) {82 log.debug("Received SOAP request:\n" + requestMessage.toString());83 }84 85 //delegate request processing to endpoint adapter86 Message replyMessage = endpointAdapter.handleMessage(requestMessage);87 88 if (simulateHttpStatusCode(replyMessage)) {89 return;90 }91 ...

Full Screen

Full Screen

invoke

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.ws.server.WebServiceEndpoint;2import com.consol.citrus.ws.message.SoapMessage;3import com.consol.citrus.context.TestContext;4import com.consol.citrus.message.Message;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;7import com.consol.citrus.dsl.builder.SendMessageBuilder;8import com.consol.citrus.dsl.builder.SendSoapMessageBuilder;9import com.consol.citrus.dsl.builder.ReceiveSoapMessageBuilder;10import com.consol.citrus.dsl.builder.SendSoapFaultBuilder;11import com.consol.citrus.dsl.builder.ReceiveSoapFaultBuilder;12import com.consol.citrus.dsl.builder.SendSoapFaultResponseBuilder;13import com.consol.citrus.dsl.builder.ReceiveSoapFaultResponseBuilder;14import com.consol.citrus.dsl.builder.ReceiveTimeoutBuilder;15import com.consol.citrus.dsl.builder.SendTimeoutBuilder;16import com.consol.citrus.dsl.builder.SendEmptyMessageBuilder;17import com.consol.citrus.dsl.builder.ReceiveEmptyMessageBuilder;18import com.consol.citrus.dsl.builder.SendBuilder;19import com.consol.citrus.dsl.builder.ReceiveBuilder;20import com.consol.citrus.dsl.builder.PurgeEndpointBuilder;21import com.consol.citrus.dsl.builder.CreateVariablesBuilder;22import com.consol.citrus.dsl.builder.PurgeChannelsBuilder;23import com.consol.citrus.dsl.builder.EchoActionBuilder;24import com.consol.citrus.dsl.builder.FailActionBuilder;25import com.consol.citrus.dsl.builder.StopTimeActionBuilder;26import com.consol.citrus.dsl.builder.StartTimeActionBuilder;27import com.consol.citrus.dsl.builder.PauseActionBuilder;28import com.consol.citrus.dsl.builder.StopActionBuilder;29import com.consol.citrus.dsl.builder.StartActionBuilder;30import com.consol.citrus.dsl.builder.ExecutePLSQLBuilder;31import com.consol.citrus.dsl.builder.ExecuteSQLBuilder;32import com.consol.citrus.dsl.builder.ExecutePLSQLQueryBuilder;33import com.consol.citrus.dsl.builder.ExecuteSQLQueryBuilder;34import com.consol.citrus.dsl.builder.ExecutePLSQLStoredProcBuilder;35import com.consol.citrus.dsl.builder.ExecuteSQLStoredProcBuilder;36import com.consol.citrus.dsl.builder.CreateSoapFaultBuilder;37import com.consol.citrus.dsl.builder.CreateSoapFaultResponseBuilder

Full Screen

Full Screen

invoke

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.ws.server.WebServiceEndpoint;2import com.consol.citrus.ws.message.SoapMessage;3import com.consol.citrus.context.TestContext;4import com.consol.citrus.message.Message;5import com.consol.citrus.exceptions.CitrusRuntimeException;6import org.springframework.ws.WebServiceMessage;7import org.springframework.ws.WebServiceMessageFactory;8import org.springframework.ws.soap.SoapMessageFactory;9import org.springframework.ws.soap.SoapMessage;10import org.springframework.ws.soap.SoapBody;11import org.springframework.ws.soap.SoapHeader;12import org.springframework.ws.soap.SoapEnvelope;13import org.springframework.ws.soap.SoapFault;14import org.springframework.ws.soap.SoapVersion;15import org.springframework.ws.soap.SoapHeaderElement;16import org.springframework.ws.soap.SoapFaultDetail;17import org.springframework.ws.soap.SoapFaultDetailElement;18import org.springframework.ws.soap.SoapFaultReason;19import org.springframework.ws.soap.SoapFaultDetail;20import org.springframework.ws.soap.SoapFaultDetailElement;21import org.springframework.ws.soap.SoapFaultReasonText;22import org.springframework.ws.soap.SoapBodyElement;23import javax.xml.namespace.QName;24import java.util.ArrayList;25import java.util.List;26import java.util.HashMap;27import java.util.Map;28import java.util.Iterator;29import java.util.Set;30import java.util.HashSet;31import java.util.Collection;32import java.util.Collections;33import java.util.Iterator;34import java.util.List;35import java.util.Map;36import java.util.Set;37import java.util.Map.Entry;38import java.util.concurrent.ConcurrentHashMap;39import java.util.concurrent.CopyOnWriteArrayList;40import java.util.concurrent.CopyOnWriteArraySet;41import java.util.concurrent.atomic.AtomicBoolean;42import java.util.concurrent.locks.Lock;43import java.util.concurrent.locks.ReentrantLock;44import org.springframework.ws.context.MessageContext;45import org.springframework.ws.transport.WebServiceConnection;46import org.springframework.ws.transport.WebServiceMessageSender;47import org.springframework.ws.transport.WebServiceMessageReceiver;48import org.springframework.ws.transport.WebServiceMessageSender;49import org.springframework.ws.transport.WebServiceMessageReceiver;50import org.springframework.ws.transport.WebServiceMessageSender;51import org.springframework.ws.transport.WebServiceMessageReceiver;52import org.springframework.ws.transport.WebServiceConnection;53import org.springframework.ws.transport.WebServiceConnection;

Full Screen

Full Screen

invoke

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.ws.server.WebServiceEndpoint;3import org.springframework.context.support.ClassPathXmlApplicationContext;4public class 3 {5 public static void main(String[] args) {6 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("3.xml");7 WebServiceEndpoint wsEndpoint = context.getBean("wsEndpoint", WebServiceEndpoint.class);8 }9}

Full Screen

Full Screen

invoke

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import org.springframework.context.support.ClassPathXmlApplicationContext;3public class InvokeMethod {4public static void main(String[] args) {5ClassPathXmlApplicationContext("applicationContext.xml");6ctx.getBean("webServiceEndpoint");7ctx.getBean("webServiceEndpoint1");8ctx.getBean("webServiceEndpoint2");9ctx.getBean("webServiceEndpoint3");10ctx.getBean("webServiceEndpoint4");11ctx.getBean("webServiceEndpoint5");12ctx.getBean("webServiceEndpoint6");13ctx.getBean("webServiceEndpoint7");14ctx.getBean("webServiceEndpoint8");15ctx.getBean("webServiceEndpoint9");16ctx.getBean("webServiceEndpoint10");17ctx.getBean("webServiceEndpoint11");18ctx.getBean("webServiceEndpoint12");19ctx.getBean("webServiceEndpoint13");20ctx.getBean("webServiceEndpoint14");21ctx.getBean("webServiceEndpoint15");22ctx.getBean("webServiceEndpoint16");23ctx.getBean("webServiceEndpoint17");24ctx.getBean("webServiceEndpoint18");25ctx.getBean("webServiceEndpoint19");26ctx.getBean("webServiceEndpoint20");27ctx.getBean("webServiceEndpoint21");28ctx.getBean("webServiceEndpoint22");29ctx.getBean("webServiceEndpoint23");30ctx.getBean("webServiceEndpoint24");31ctx.getBean("webServiceEndpoint25");32ctx.getBean("webServiceEndpoint26");33ctx.getBean("webServiceEndpoint27");34ctx.getBean("webServiceEndpoint28");35ctx.getBean("webServiceEndpoint29");36ctx.getBean("webServiceEndpoint30");37ctx.getBean("webServiceEndpoint31");38ctx.getBean("webServiceEndpoint32");39ctx.getBean("webServiceEndpoint33");40ctx.getBean("webServiceEndpoint34");41ctx.getBean("webServiceEndpoint35");42ctx.getBean("webServiceEndpoint36");43ctx.getBean("webServiceEndpoint37");44ctx.getBean("webServiceEndpoint38");45ctx.getBean("webServiceEndpoint39");46ctx.getBean("webServiceEndpoint40");47ctx.getBean("webServiceEndpoint41");48ctx.getBean("webServiceEndpoint42");49ctx.getBean("webServiceEndpoint43");50ctx.getBean("webServiceEndpoint44");51ctx.getBean("webServiceEndpoint45");52ctx.getBean("webServiceEndpoint46");53ctx.getBean("webServiceEndpoint47");54ctx.getBean("webServiceEndpoint48");55ctx.getBean("webServiceEndpoint49");56ctx.getBean("webServiceEndpoint50");57ctx.getBean("webServiceEndpoint51");58ctx.getBean("webServiceEndpoint52");59ctx.getBean("webServiceEndpoint53");60ctx.getBean("webServiceEndpoint54");61ctx.getBean("

Full Screen

Full Screen

invoke

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.ws.client.WebServiceClient;6import com.consol.citrus.ws.message.SoapMessage;7import com.consol.citrus.ws.server.WebServiceEndpoint;8import org.springframework.beans.factory.annotation.Autowired;9import org.springframework.beans.factory.annotation.Qualifier;10import org.testng.annotations.Test;11public class InvokeWebServiceEndpointJavaIT extends TestNGCitrusTestRunner {12 @Qualifier("webServiceClient")13 private WebServiceClient webServiceClient;14 @Qualifier("webServiceEndpoint")15 private WebServiceEndpoint webServiceEndpoint;16 public void invokeWebServiceEndpoint() {17 SoapMessage request = new SoapMessage();18 "</ns0:HelloWorldRequest>");19 SoapMessage response = new SoapMessage();20 "</ns0:HelloWorldResponse>");21 webServiceEndpoint.invoke(request, response);22 }23}

Full Screen

Full Screen

invoke

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.server;2import com.consol.citrus.ws.WebServiceEndpoint;3import org.springframework.context.ApplicationContext;4import org.springframework.context.support.ClassPathXmlApplicationContext;5import org.springframework.ws.WebServiceMessage;6import org.springframework.ws.WebServiceMessageFactory;7import org.springframework.ws.soap.SoapMessage;8import org.springframework.ws.soap.SoapMessageFactory;9import org.sprin

Full Screen

Full Screen

invoke

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.ws.server.WebServiceEndpoint;2import com.consol.citrus.ws.server.WebServiceEndpointConfiguration;3import com.consol.citrus.ws.server.WebServiceEndpointConfigurationBuilder;4import com.consol.citrus.ws.server.WebServiceEndpointBuilder;5import com.consol.citrus.ws.server.WebServiceServer;6import org.springframework.context.ApplicationContext;7import org.springframework.context.support.ClassPathXmlApplicationContext;8import org.springframework.ws.WebServiceMessage;9import org.springframework.ws.context.MessageContext;10import org.springframework.ws.server.endpoint.MethodEndpoint;11import org.springframework.ws.soap.SoapMessage;12import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;13import javax.xml.namespace.QName;14import javax.xml.soap.MessageFactory;15import javax.xml.soap.SOAPException;16import javax.xml.soap.SOAPMessage;17import javax.xml.transform.Source;18import javax.xml.transform.dom.DOMSource;19import org.w3c.dom.Document;20import org.w3c.dom.Element;21import org.w3c.dom.NodeList;22public class 3 {23 public static void main(String[] args) throws Exception {24 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");25 WebServiceServer server = context.getBean("webServiceServer", WebServiceServer.class);26 WebServiceEndpointConfigurationBuilder builder = new WebServiceEndpointConfigurationBuilder();27 builder.servicePort("SayHelloPort");28 builder.endpointAdapter(new MyEndpointAdapter());29 builder.messageFactory(new SaajSoapMessageFactory(MessageFactory.newInstance()));30 WebServiceEndpointConfiguration configuration = builder.build();31 WebServiceEndpoint endpoint = WebServiceEndpointBuilder.endpoint().configuration(configuration).build();32 server.getEndpointRegistry().addEndpoint(endpoint);33 server.start();34 }35 public static class MyEndpointAdapter implements org.springframework.ws.server.EndpointAdapter {36 public boolean supports(Object endpoint) {37 return endpoint instanceof SayHello;38 }39 public WebServiceMessage invoke(MessageContext messageContext, Object endpoint) throws Exception {40 SOAPMessage soapMessage = ((SoapMessage) messageContext.getRequest()).getSaajMessage();

Full Screen

Full Screen

invoke

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws;2import java.util.HashMap;3import java.util.Map;4import org.springframework.context.support.ClassPathXmlApplicationContext;5import com.consol.citrus.ws.client.WebServiceClient;6import com.consol.citrus.ws.server.WebServiceEndpoint;7public class InvokeWebService {8 public static void main(String[] args) {9 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(10 "applicationContext.xml");11 WebServiceEndpoint endpoint = (WebServiceEndpoint) context12 .getBean("helloWorldEndpoint");13 WebServiceClient client = new WebServiceClient();14 client.setDefaultSchema("helloWorld.xsd");15 Map<String, Object> requestPayload = new HashMap<String, Object>();16 requestPayload.put("text", "Hello Citrus!");17 Map<String, Object> responsePayload = new HashMap<String, Object>();18 responsePayload.put("text", "Hello Citrus!");19 endpoint.invoke(client, requestPayload, responsePayload);20 }21}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful