Best Citrus code snippet using com.consol.citrus.NamespaceTest.testWrongNamespace
Source:NamespaceTest.java
...324 }325 326 @Test(expectedExceptions = {ValidationException.class})327 @SuppressWarnings({ "unchecked", "rawtypes" })328 public void testWrongNamespace() {329 reset(endpoint, consumer, endpointConfiguration);330 when(endpoint.createConsumer()).thenReturn(consumer);331 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);332 when(endpointConfiguration.getTimeout()).thenReturn(5000L);333 334 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus'>"335 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"336 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"337 + "</ns1:element>" 338 + "</ns1:root>");339 340 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);341 when(endpoint.getActor()).thenReturn(null);342 343 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();344 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();345 receiveMessageBean.setMessageBuilder(controlMessageBuilder);346 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus/wrong'>"347 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"348 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"349 + "</ns1:element>" 350 + "</ns1:root>");351 352 validationContext.setSchemaValidation(false);353 354 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();355 validationContexts.add(validationContext);356 receiveMessageBean.setValidationContexts(validationContexts);357 receiveMessageBean.execute(context);358 }359 360 @Test361 @SuppressWarnings({ "unchecked", "rawtypes" })362 public void testExpectDefaultNamespace() {363 reset(endpoint, consumer, endpointConfiguration);364 when(endpoint.createConsumer()).thenReturn(consumer);365 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);366 when(endpointConfiguration.getTimeout()).thenReturn(5000L);367 368 Message message = new DefaultMessage("<root xmlns='http://citrus'>"369 + "<element attributeA='attribute-value' attributeB='attribute-value'>"370 + "<sub-element attribute='A'>text-value</sub-element>"371 + "</element>" 372 + "</root>");373 374 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);375 when(endpoint.getActor()).thenReturn(null);376 377 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();378 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();379 receiveMessageBean.setMessageBuilder(controlMessageBuilder);380 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus'>"381 + "<element attributeA='attribute-value' attributeB='attribute-value'>"382 + "<sub-element attribute='A'>text-value</sub-element>"383 + "</element>" 384 + "</root>");385 386 Map<String, String> expectedNamespaces = new HashMap<String, String>();387 expectedNamespaces.put("", "http://citrus");388 389 validationContext.setControlNamespaces(expectedNamespaces);390 391 validationContext.setSchemaValidation(false);392 393 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();394 validationContexts.add(validationContext);395 receiveMessageBean.setValidationContexts(validationContexts);396 receiveMessageBean.execute(context);397 }398 399 @Test400 @SuppressWarnings({ "unchecked", "rawtypes" })401 public void testExpectNamespace() {402 reset(endpoint, consumer, endpointConfiguration);403 when(endpoint.createConsumer()).thenReturn(consumer);404 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);405 when(endpointConfiguration.getTimeout()).thenReturn(5000L);406 407 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus/ns1'>"408 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"409 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"410 + "</ns1:element>" 411 + "</ns1:root>");412 413 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);414 when(endpoint.getActor()).thenReturn(null);415 416 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();417 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();418 receiveMessageBean.setMessageBuilder(controlMessageBuilder);419 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus/ns1'>"420 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"421 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"422 + "</ns1:element>" 423 + "</ns1:root>");424 425 Map<String, String> expectedNamespaces = new HashMap<String, String>();426 expectedNamespaces.put("ns1", "http://citrus/ns1");427 428 validationContext.setControlNamespaces(expectedNamespaces);429 430 validationContext.setSchemaValidation(false);431 432 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();433 validationContexts.add(validationContext);434 receiveMessageBean.setValidationContexts(validationContexts);435 receiveMessageBean.execute(context);436 }437 438 @Test439 @SuppressWarnings({ "unchecked", "rawtypes" })440 public void testExpectMixedNamespaces() {441 reset(endpoint, consumer, endpointConfiguration);442 when(endpoint.createConsumer()).thenReturn(consumer);443 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);444 when(endpointConfiguration.getTimeout()).thenReturn(5000L);445 446 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1'>"447 + "<element attributeA='attribute-value' attributeB='attribute-value'>"448 + "<sub-element attribute='A'>text-value</sub-element>"449 + "</element>" 450 + "</root>");451 452 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);453 when(endpoint.getActor()).thenReturn(null);454 455 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();456 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();457 receiveMessageBean.setMessageBuilder(controlMessageBuilder);458 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1'>"459 + "<element attributeA='attribute-value' attributeB='attribute-value'>"460 + "<sub-element attribute='A'>text-value</sub-element>"461 + "</element>" 462 + "</root>");463 464 Map<String, String> expectedNamespaces = new HashMap<String, String>();465 expectedNamespaces.put("", "http://citrus/default");466 expectedNamespaces.put("ns1", "http://citrus/ns1");467 468 validationContext.setControlNamespaces(expectedNamespaces);469 470 validationContext.setSchemaValidation(false);471 472 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();473 validationContexts.add(validationContext);474 receiveMessageBean.setValidationContexts(validationContexts);475 receiveMessageBean.execute(context);476 }477 478 @Test479 @SuppressWarnings({ "unchecked", "rawtypes" })480 public void testExpectMultipleNamespaces() {481 reset(endpoint, consumer, endpointConfiguration);482 when(endpoint.createConsumer()).thenReturn(consumer);483 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);484 when(endpointConfiguration.getTimeout()).thenReturn(5000L);485 486 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"487 + "<element attributeA='attribute-value' attributeB='attribute-value'>"488 + "<sub-element attribute='A'>text-value</sub-element>"489 + "</element>" 490 + "</root>");491 492 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);493 when(endpoint.getActor()).thenReturn(null);494 495 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();496 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();497 receiveMessageBean.setMessageBuilder(controlMessageBuilder);498 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"499 + "<element attributeA='attribute-value' attributeB='attribute-value'>"500 + "<sub-element attribute='A'>text-value</sub-element>"501 + "</element>" 502 + "</root>");503 504 Map<String, String> expectedNamespaces = new HashMap<String, String>();505 expectedNamespaces.put("", "http://citrus/default");506 expectedNamespaces.put("ns1", "http://citrus/ns1");507 expectedNamespaces.put("ns2", "http://citrus/ns2");508 509 validationContext.setControlNamespaces(expectedNamespaces);510 511 validationContext.setSchemaValidation(false);512 513 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();514 validationContexts.add(validationContext);515 receiveMessageBean.setValidationContexts(validationContexts);516 receiveMessageBean.execute(context);517 }518 519 @Test(expectedExceptions = {ValidationException.class})520 @SuppressWarnings({ "unchecked", "rawtypes" })521 public void testExpectDefaultNamespaceError() {522 reset(endpoint, consumer, endpointConfiguration);523 when(endpoint.createConsumer()).thenReturn(consumer);524 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);525 when(endpointConfiguration.getTimeout()).thenReturn(5000L);526 527 Message message = new DefaultMessage("<root xmlns='http://citrus'>"528 + "<element attributeA='attribute-value' attributeB='attribute-value'>"529 + "<sub-element attribute='A'>text-value</sub-element>"530 + "</element>" 531 + "</root>");532 533 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);534 when(endpoint.getActor()).thenReturn(null);535 536 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();537 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();538 receiveMessageBean.setMessageBuilder(controlMessageBuilder);539 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus'>"540 + "<element attributeA='attribute-value' attributeB='attribute-value'>"541 + "<sub-element attribute='A'>text-value</sub-element>"542 + "</element>" 543 + "</root>");544 545 Map<String, String> expectedNamespaces = new HashMap<String, String>();546 expectedNamespaces.put("", "http://citrus/wrong");547 548 validationContext.setControlNamespaces(expectedNamespaces);549 550 validationContext.setSchemaValidation(false);551 552 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();553 validationContexts.add(validationContext);554 receiveMessageBean.setValidationContexts(validationContexts);555 receiveMessageBean.execute(context);556 }557 558 @Test(expectedExceptions = {ValidationException.class})559 @SuppressWarnings({ "unchecked", "rawtypes" })560 public void testExpectNamespaceError() {561 reset(endpoint, consumer, endpointConfiguration);562 when(endpoint.createConsumer()).thenReturn(consumer);563 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);564 when(endpointConfiguration.getTimeout()).thenReturn(5000L);565 566 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus/ns1'>"567 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"568 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"569 + "</ns1:element>" 570 + "</ns1:root>");571 572 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);573 when(endpoint.getActor()).thenReturn(null);574 575 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();576 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();577 receiveMessageBean.setMessageBuilder(controlMessageBuilder);578 controlMessageBuilder.setPayloadData("<ns1:root xmlns:ns1='http://citrus/ns1'>"579 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value'>"580 + "<ns1:sub-element attribute='A'>text-value</ns1:sub-element>"581 + "</ns1:element>" 582 + "</ns1:root>");583 584 Map<String, String> expectedNamespaces = new HashMap<String, String>();585 expectedNamespaces.put("ns1", "http://citrus/ns1/wrong");586 587 validationContext.setControlNamespaces(expectedNamespaces);588 589 validationContext.setSchemaValidation(false);590 591 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();592 validationContexts.add(validationContext);593 receiveMessageBean.setValidationContexts(validationContexts);594 receiveMessageBean.execute(context);595 }596 597 @Test(expectedExceptions = {ValidationException.class})598 @SuppressWarnings({ "unchecked", "rawtypes" })599 public void testExpectMixedNamespacesError() {600 reset(endpoint, consumer, endpointConfiguration);601 when(endpoint.createConsumer()).thenReturn(consumer);602 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);603 when(endpointConfiguration.getTimeout()).thenReturn(5000L);604 605 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1'>"606 + "<element attributeA='attribute-value' attributeB='attribute-value'>"607 + "<sub-element attribute='A'>text-value</sub-element>"608 + "</element>" 609 + "</root>");610 611 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);612 when(endpoint.getActor()).thenReturn(null);613 614 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();615 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();616 receiveMessageBean.setMessageBuilder(controlMessageBuilder);617 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1'>"618 + "<element attributeA='attribute-value' attributeB='attribute-value'>"619 + "<sub-element attribute='A'>text-value</sub-element>"620 + "</element>" 621 + "</root>");622 623 Map<String, String> expectedNamespaces = new HashMap<String, String>();624 expectedNamespaces.put("", "http://citrus/default/wrong");625 expectedNamespaces.put("ns1", "http://citrus/ns1");626 627 validationContext.setControlNamespaces(expectedNamespaces);628 629 validationContext.setSchemaValidation(false);630 631 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();632 validationContexts.add(validationContext);633 receiveMessageBean.setValidationContexts(validationContexts);634 receiveMessageBean.execute(context);635 }636 637 @Test(expectedExceptions = {ValidationException.class})638 @SuppressWarnings({ "unchecked", "rawtypes" })639 public void testExpectMultipleNamespacesError() {640 reset(endpoint, consumer, endpointConfiguration);641 when(endpoint.createConsumer()).thenReturn(consumer);642 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);643 when(endpointConfiguration.getTimeout()).thenReturn(5000L);644 645 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"646 + "<element attributeA='attribute-value' attributeB='attribute-value'>"647 + "<sub-element attribute='A'>text-value</sub-element>"648 + "</element>" 649 + "</root>");650 651 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);652 when(endpoint.getActor()).thenReturn(null);653 654 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();655 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();656 receiveMessageBean.setMessageBuilder(controlMessageBuilder);657 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"658 + "<element attributeA='attribute-value' attributeB='attribute-value'>"659 + "<sub-element attribute='A'>text-value</sub-element>"660 + "</element>" 661 + "</root>");662 663 Map<String, String> expectedNamespaces = new HashMap<String, String>();664 expectedNamespaces.put("", "http://citrus/default");665 expectedNamespaces.put("ns1", "http://citrus/ns1/wrong");666 expectedNamespaces.put("ns2", "http://citrus/ns2");667 668 validationContext.setControlNamespaces(expectedNamespaces);669 670 validationContext.setSchemaValidation(false);671 672 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();673 validationContexts.add(validationContext);674 receiveMessageBean.setValidationContexts(validationContexts);675 receiveMessageBean.execute(context);676 }677 678 @Test(expectedExceptions = {ValidationException.class})679 @SuppressWarnings({ "unchecked", "rawtypes" })680 public void testExpectWrongNamespacePrefix() {681 reset(endpoint, consumer, endpointConfiguration);682 when(endpoint.createConsumer()).thenReturn(consumer);683 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);684 when(endpointConfiguration.getTimeout()).thenReturn(5000L);685 686 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"687 + "<element attributeA='attribute-value' attributeB='attribute-value'>"688 + "<sub-element attribute='A'>text-value</sub-element>"689 + "</element>" 690 + "</root>");691 692 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);693 when(endpoint.getActor()).thenReturn(null);694 695 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();696 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();697 receiveMessageBean.setMessageBuilder(controlMessageBuilder);698 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"699 + "<element attributeA='attribute-value' attributeB='attribute-value'>"700 + "<sub-element attribute='A'>text-value</sub-element>"701 + "</element>" 702 + "</root>");703 704 Map<String, String> expectedNamespaces = new HashMap<String, String>();705 expectedNamespaces.put("", "http://citrus/default");706 expectedNamespaces.put("nswrong", "http://citrus/ns1");707 expectedNamespaces.put("ns2", "http://citrus/ns2");708 709 validationContext.setControlNamespaces(expectedNamespaces);710 711 validationContext.setSchemaValidation(false);712 713 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();714 validationContexts.add(validationContext);715 receiveMessageBean.setValidationContexts(validationContexts);716 receiveMessageBean.execute(context);717 }718 719 @Test(expectedExceptions = {ValidationException.class})720 @SuppressWarnings({ "unchecked", "rawtypes" })721 public void testExpectDefaultNamespaceButNamespace() {722 reset(endpoint, consumer, endpointConfiguration);723 when(endpoint.createConsumer()).thenReturn(consumer);724 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);725 when(endpointConfiguration.getTimeout()).thenReturn(5000L);726 727 Message message = new DefaultMessage("<ns0:root xmlns:ns0='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"728 + "<ns0:element attributeA='attribute-value' attributeB='attribute-value'>"729 + "<ns0:sub-element attribute='A'>text-value</ns0:sub-element>"730 + "</ns0:element>" 731 + "</ns0:root>");732 733 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);734 when(endpoint.getActor()).thenReturn(null);735 736 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();737 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();738 receiveMessageBean.setMessageBuilder(controlMessageBuilder);739 controlMessageBuilder.setPayloadData("<ns0:root xmlns:ns0='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"740 + "<ns0:element attributeA='attribute-value' attributeB='attribute-value'>"741 + "<ns0:sub-element attribute='A'>text-value</ns0:sub-element>"742 + "</ns0:element>" 743 + "</ns0:root>");744 745 Map<String, String> expectedNamespaces = new HashMap<String, String>();746 expectedNamespaces.put("", "http://citrus/default");747 expectedNamespaces.put("ns1", "http://citrus/ns1");748 expectedNamespaces.put("ns2", "http://citrus/ns2");749 750 validationContext.setControlNamespaces(expectedNamespaces);751 752 validationContext.setSchemaValidation(false);753 754 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();755 validationContexts.add(validationContext);756 receiveMessageBean.setValidationContexts(validationContexts);757 receiveMessageBean.execute(context);758 }759 760 @Test(expectedExceptions = {ValidationException.class})761 @SuppressWarnings({ "unchecked", "rawtypes" })762 public void testExpectNamespaceButDefaultNamespace() {763 reset(endpoint, consumer, endpointConfiguration);764 when(endpoint.createConsumer()).thenReturn(consumer);765 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);766 when(endpointConfiguration.getTimeout()).thenReturn(5000L);767 768 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"769 + "<element attributeA='attribute-value' attributeB='attribute-value'>"770 + "<sub-element attribute='A'>text-value</sub-element>"771 + "</element>" 772 + "</root>");773 774 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);775 when(endpoint.getActor()).thenReturn(null);776 777 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();778 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();779 receiveMessageBean.setMessageBuilder(controlMessageBuilder);780 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"781 + "<element attributeA='attribute-value' attributeB='attribute-value'>"782 + "<sub-element attribute='A'>text-value</sub-element>"783 + "</element>" 784 + "</root>");785 786 Map<String, String> expectedNamespaces = new HashMap<String, String>();787 expectedNamespaces.put("ns0", "http://citrus/default");788 expectedNamespaces.put("ns1", "http://citrus/ns1");789 expectedNamespaces.put("ns2", "http://citrus/ns2");790 791 validationContext.setControlNamespaces(expectedNamespaces);792 793 validationContext.setSchemaValidation(false);794 795 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();796 validationContexts.add(validationContext);797 receiveMessageBean.setValidationContexts(validationContexts);798 receiveMessageBean.execute(context);799 }800 801 @Test(expectedExceptions = {ValidationException.class})802 @SuppressWarnings({ "unchecked", "rawtypes" })803 public void testExpectAdditionalNamespace() {804 reset(endpoint, consumer, endpointConfiguration);805 when(endpoint.createConsumer()).thenReturn(consumer);806 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);807 when(endpointConfiguration.getTimeout()).thenReturn(5000L);808 809 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"810 + "<element attributeA='attribute-value' attributeB='attribute-value'>"811 + "<sub-element attribute='A'>text-value</sub-element>"812 + "</element>" 813 + "</root>");814 815 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);816 when(endpoint.getActor()).thenReturn(null);817 818 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();819 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();820 receiveMessageBean.setMessageBuilder(controlMessageBuilder);821 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2'>"822 + "<element attributeA='attribute-value' attributeB='attribute-value'>"823 + "<sub-element attribute='A'>text-value</sub-element>"824 + "</element>" 825 + "</root>");826 827 Map<String, String> expectedNamespaces = new HashMap<String, String>();828 expectedNamespaces.put("", "http://citrus/default");829 expectedNamespaces.put("ns1", "http://citrus/ns1");830 expectedNamespaces.put("ns2", "http://citrus/ns2");831 expectedNamespaces.put("ns4", "http://citrus/ns4");832 833 validationContext.setControlNamespaces(expectedNamespaces);834 835 validationContext.setSchemaValidation(false);836 837 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();838 validationContexts.add(validationContext);839 receiveMessageBean.setValidationContexts(validationContexts);840 receiveMessageBean.execute(context);841 }842 843 @Test(expectedExceptions = {ValidationException.class})844 @SuppressWarnings({ "unchecked", "rawtypes" })845 public void testExpectNamespaceButNamespaceMissing() {846 reset(endpoint, consumer, endpointConfiguration);847 when(endpoint.createConsumer()).thenReturn(consumer);848 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);849 when(endpointConfiguration.getTimeout()).thenReturn(5000L);850 851 Message message = new DefaultMessage("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2' xmlns:ns4='http://citrus/ns4'>"852 + "<element attributeA='attribute-value' attributeB='attribute-value'>"853 + "<sub-element attribute='A'>text-value</sub-element>"854 + "</element>" 855 + "</root>");856 857 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);858 when(endpoint.getActor()).thenReturn(null);859 860 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();861 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();862 receiveMessageBean.setMessageBuilder(controlMessageBuilder);863 controlMessageBuilder.setPayloadData("<root xmlns='http://citrus/default' xmlns:ns1='http://citrus/ns1' xmlns:ns2='http://citrus/ns2' xmlns:ns4='http://citrus/ns4'>"864 + "<element attributeA='attribute-value' attributeB='attribute-value'>"865 + "<sub-element attribute='A'>text-value</sub-element>"866 + "</element>" 867 + "</root>");868 869 Map<String, String> expectedNamespaces = new HashMap<String, String>();870 expectedNamespaces.put("", "http://citrus/default");871 expectedNamespaces.put("ns1", "http://citrus/ns1");872 expectedNamespaces.put("ns2", "http://citrus/ns2");873 874 validationContext.setControlNamespaces(expectedNamespaces);875 876 validationContext.setSchemaValidation(false);877 878 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();879 validationContexts.add(validationContext);880 receiveMessageBean.setValidationContexts(validationContexts);881 receiveMessageBean.execute(context);882 }883 884 @Test885 @SuppressWarnings({ "unchecked", "rawtypes" })886 public void testValidateMessageElementsWithAdditionalNamespacePrefix() {887 reset(endpoint, consumer, endpointConfiguration);888 when(endpoint.createConsumer()).thenReturn(consumer);889 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);890 when(endpointConfiguration.getTimeout()).thenReturn(5000L);891 892 Message message = new DefaultMessage("<root xmlns='http://citrus/default'>"893 + "<element attributeA='attribute-value' attributeB='attribute-value' >"894 + "<sub-elementA attribute='A'>text-value</sub-elementA>"895 + "<sub-elementB attribute='B'>text-value</sub-elementB>"896 + "<sub-elementC attribute='C'>text-value</sub-elementC>"897 + "</element>" 898 + "</root>");899 900 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);901 when(endpoint.getActor()).thenReturn(null);902 HashMap<String, Object> validateMessageElements = new HashMap<>();903 validateMessageElements.put("//ns1:root/ns1:element/ns1:sub-elementA", "text-value");904 validateMessageElements.put("//ns1:sub-elementB", "text-value");905 906 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();907 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();908 receiveMessageBean.setMessageBuilder(controlMessageBuilder);909 validationContext.setXpathExpressions(validateMessageElements);910 911 Map<String, String> namespaces = new HashMap<String, String>();912 namespaces.put("ns1", "http://citrus/default");913 914 validationContext.setNamespaces(namespaces);915 916 validationContext.setSchemaValidation(false);917 918 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();919 validationContexts.add(validationContext);920 receiveMessageBean.setValidationContexts(validationContexts);921 receiveMessageBean.execute(context);922 }923 924 @Test925 @SuppressWarnings({ "unchecked", "rawtypes" })926 public void testValidateMessageElementsWithDifferentNamespacePrefix() {927 reset(endpoint, consumer, endpointConfiguration);928 when(endpoint.createConsumer()).thenReturn(consumer);929 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);930 when(endpointConfiguration.getTimeout()).thenReturn(5000L);931 932 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus/default'>"933 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value' >"934 + "<ns1:sub-elementA attribute='A'>text-value</ns1:sub-elementA>"935 + "<ns1:sub-elementB attribute='B'>text-value</ns1:sub-elementB>"936 + "<ns1:sub-elementC attribute='C'>text-value</ns1:sub-elementC>"937 + "</ns1:element>" 938 + "</ns1:root>");939 940 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);941 when(endpoint.getActor()).thenReturn(null);942 HashMap<String, Object> validateMessageElements = new HashMap<>();943 validateMessageElements.put("//pfx:root/pfx:element/pfx:sub-elementA", "text-value");944 validateMessageElements.put("//pfx:sub-elementB", "text-value");945 946 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();947 XpathMessageValidationContext validationContext = new XpathMessageValidationContext();948 receiveMessageBean.setMessageBuilder(controlMessageBuilder);949 validationContext.setXpathExpressions(validateMessageElements);950 951 Map<String, String> namespaces = new HashMap<String, String>();952 namespaces.put("pfx", "http://citrus/default");953 954 validationContext.setNamespaces(namespaces);955 956 validationContext.setSchemaValidation(false);957 958 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();959 validationContexts.add(validationContext);960 receiveMessageBean.setValidationContexts(validationContexts);961 receiveMessageBean.execute(context);962 }963 964 @Test(expectedExceptions = {CitrusRuntimeException.class})965 @SuppressWarnings({ "unchecked", "rawtypes" })966 public void testWrongNamespaceContext() {967 reset(endpoint, consumer, endpointConfiguration);968 when(endpoint.createConsumer()).thenReturn(consumer);969 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);970 when(endpointConfiguration.getTimeout()).thenReturn(5000L);971 972 Message message = new DefaultMessage("<ns1:root xmlns:ns1='http://citrus/default'>"973 + "<ns1:element attributeA='attribute-value' attributeB='attribute-value' >"974 + "<ns1:sub-elementA attribute='A'>text-value</ns1:sub-elementA>"975 + "<ns1:sub-elementB attribute='B'>text-value</ns1:sub-elementB>"976 + "<ns1:sub-elementC attribute='C'>text-value</ns1:sub-elementC>"977 + "</ns1:element>" 978 + "</ns1:root>");979 980 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(message);...
testWrongNamespace
Using AI Code Generation
1public void testWrongNamespace() {2 TestCase testCase = new TestCase();3 testCase.setName("testWrongNamespace");4 JavaAction javaAction = new JavaAction();5 javaAction.setName("javaAction");6 javaAction.setClassType("com.consol.citrus.NamespaceTest");7 javaAction.setMethod("testWrongNamespace");8 testCase.addTestAction(javaAction);9 TestRunner runner = new DefaultTestCaseRunner(testCase, applicationContext);10 runner.run();11}12 at com.consol.citrus.TestCase.getTestAction(TestCase.java:162)13 at com.consol.citrus.DefaultTestCaseRunner.run(DefaultTestCaseRunner.java:101)14 at com.consol.citrus.NamespaceTest.testWrongNamespace(NamespaceTest.java:32)
testWrongNamespace
Using AI Code Generation
1@citrus:java(class=com.consol.citrus.NamespaceTest, method=testWrongNamespace)2@citrus:java(class=com.consol.citrus.NamespaceTest, method=testWrongNamespace)3public JavaCitrusTest javaTest() {4 return new JavaCitrusTestBuilder()5 .applicationContext(myApplicationContext)6 .autoStart(false)7 .name("javaTest")8 .description("Java DSL example in Spring
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!!