How to use getScriptValidationContext method of com.consol.citrus.dsl.builder.ReceiveMessageBuilder class

Best Citrus code snippet using com.consol.citrus.dsl.builder.ReceiveMessageBuilder.getScriptValidationContext

Source:ReceiveMessageBuilder.java Github

copy

Full Screen

...402 * @param validationScript403 * @return404 */405 public T validateScript(String validationScript) {406 getScriptValidationContext().setValidationScript(validationScript);407 return self;408 }409 410 /**411 * Reads validation script file resource and sets content as validation script.412 * @param scriptResource413 * @return414 */415 public T validateScript(Resource scriptResource) {416 return validateScript(scriptResource, FileUtils.getDefaultCharset());417 }418 /**419 * Reads validation script file resource and sets content as validation script.420 * @param scriptResource421 * @param charset422 * @return423 */424 public T validateScript(Resource scriptResource, Charset charset) {425 try {426 validateScript(FileUtils.readToString(scriptResource, charset));427 } catch (IOException e) {428 throw new CitrusRuntimeException("Failed to read script resource file", e);429 }430 return self;431 }432 /**433 * Adds script validation file resource.434 * @param fileResourcePath435 * @return436 */437 public T validateScriptResource(String fileResourcePath) {438 getScriptValidationContext().setValidationScriptResourcePath(fileResourcePath);439 return self;440 }441 442 /**443 * Adds custom validation script type.444 * @param type445 * @return446 */447 public T validateScriptType(String type) {448 getScriptValidationContext().setScriptType(type);449 return self;450 }451 /**452 * Sets a explicit message type for this receive action.453 * @param messageType454 * @return455 */456 public T messageType(MessageType messageType) {457 messageType(messageType.name());458 return self;459 }460 461 /**462 * Sets a explicit message type for this receive action.463 * @param messageType464 * @return465 */466 public T messageType(String messageType) {467 this.messageType = messageType;468 getAction().setMessageType(messageType);469 if (getAction().getValidationContexts().isEmpty()) {470 getAction().getValidationContexts().add(headerValidationContext);471 getAction().getValidationContexts().add(xmlMessageValidationContext);472 getAction().getValidationContexts().add(jsonMessageValidationContext);473 }474 return self;475 }476 477 /**478 * Sets schema validation enabled/disabled for this message.479 * @param enabled480 * @return481 */482 public T schemaValidation(boolean enabled) {483 xmlMessageValidationContext.setSchemaValidation(enabled);484 jsonMessageValidationContext.setSchemaValidation(enabled);485 return self;486 }487 /**488 * Validates XML namespace with prefix and uri.489 * @param prefix490 * @param namespaceUri491 * @return492 */493 public T validateNamespace(String prefix, String namespaceUri) {494 xmlMessageValidationContext.getControlNamespaces().put(prefix, namespaceUri);495 return self;496 }497 498 /**499 * Adds message element validation.500 * @param path501 * @param controlValue502 * @return503 */504 public T validate(String path, Object controlValue) {505 if (JsonPathMessageValidationContext.isJsonPathExpression(path)) {506 getJsonPathValidationContext().getJsonPathExpressions().put(path, controlValue);507 } else {508 getXPathValidationContext().getXpathExpressions().put(path, controlValue);509 }510 return self;511 }512 513 /**514 * Adds ignore path expression for message element.515 * @param path516 * @return517 */518 public T ignore(String path) {519 if (messageType.equalsIgnoreCase(MessageType.XML.name())520 || messageType.equalsIgnoreCase(MessageType.XHTML.name())) {521 xmlMessageValidationContext.getIgnoreExpressions().add(path);522 } else if (messageType.equalsIgnoreCase(MessageType.JSON.name())) {523 jsonMessageValidationContext.getIgnoreExpressions().add(path);524 }525 return self;526 }527 528 /**529 * Adds XPath message element validation.530 * @param xPathExpression531 * @param controlValue532 * @return533 */534 public T xpath(String xPathExpression, Object controlValue) {535 validate(xPathExpression, controlValue);536 return self;537 }538 /**539 * Adds JsonPath message element validation.540 * @param jsonPathExpression541 * @param controlValue542 * @return543 */544 public T jsonPath(String jsonPathExpression, Object controlValue) {545 validate(jsonPathExpression, controlValue);546 return self;547 }548 549 /**550 * Sets explicit schema instance name to use for schema validation.551 * @param schemaName552 * @return553 */554 public T xsd(String schemaName) {555 xmlMessageValidationContext.setSchema(schemaName);556 return self;557 }558 /**559 * Sets explicit schema instance name to use for schema validation.560 * @param schemaName The name of the schema bean561 */562 public T jsonSchema(String schemaName) {563 jsonMessageValidationContext.setSchema(schemaName);564 return self;565 }566 567 /**568 * Sets explicit xsd schema repository instance to use for validation.569 * @param schemaRepository570 * @return571 */572 public T xsdSchemaRepository(String schemaRepository) {573 xmlMessageValidationContext.setSchemaRepository(schemaRepository);574 return self;575 }576 /**577 * Sets explicit json schema repository instance to use for validation.578 * @param schemaRepository The name of the schema repository bean579 * @return580 */581 public T jsonSchemaRepository(String schemaRepository) {582 jsonMessageValidationContext.setSchemaRepository(schemaRepository);583 return self;584 }585 586 /**587 * Adds explicit namespace declaration for later path validation expressions.588 * @param prefix589 * @param namespaceUri590 * @return591 */592 public T namespace(String prefix, String namespaceUri) {593 getXpathVariableExtractor().getNamespaces().put(prefix, namespaceUri);594 xmlMessageValidationContext.getNamespaces().put(prefix, namespaceUri);595 return self;596 }597 598 /**599 * Sets default namespace declarations on this action builder.600 * @param namespaceMappings601 * @return602 */603 public T namespaces(Map<String, String> namespaceMappings) {604 getXpathVariableExtractor().getNamespaces().putAll(namespaceMappings);605 xmlMessageValidationContext.getNamespaces().putAll(namespaceMappings);606 return self;607 }608 609 /**610 * Sets message selector string.611 * @param messageSelector612 * @return613 */614 public T selector(String messageSelector) {615 getAction().setMessageSelector(messageSelector);616 return self;617 }618 619 /**620 * Sets message selector elements.621 * @param messageSelector622 * @return623 */624 public T selector(Map<String, Object> messageSelector) {625 getAction().setMessageSelectorMap(messageSelector);626 return self;627 }628 629 /**630 * Sets explicit message validators for this receive action.631 * @param validators632 * @return633 */634 public T validator(MessageValidator<? extends ValidationContext> ... validators) {635 Stream.of(validators).forEach(getAction()::addValidator);636 return self;637 }638 639 /**640 * Sets explicit message validators by name.641 * @param validatorNames642 * @return643 */644 @SuppressWarnings("unchecked")645 public T validator(String ... validatorNames) {646 Assert.notNull(applicationContext, "Citrus application context is not initialized!");647 for (String validatorName : validatorNames) {648 getAction().addValidator(applicationContext.getBean(validatorName, MessageValidator.class));649 }650 return self;651 }652 /**653 * Sets explicit header validator for this receive action.654 * @param validators655 * @return656 */657 public T headerValidator(HeaderValidator... validators) {658 Stream.of(validators).forEach(headerValidationContext::addHeaderValidator);659 return self;660 }661 /**662 * Sets explicit header validators by name.663 * @param validatorNames664 * @return665 */666 @SuppressWarnings("unchecked")667 public T headerValidator(String ... validatorNames) {668 Assert.notNull(applicationContext, "Citrus application context is not initialized!");669 for (String validatorName : validatorNames) {670 headerValidationContext.addHeaderValidator(applicationContext.getBean(validatorName, HeaderValidator.class));671 }672 return self;673 }674 /**675 * Sets explicit data dictionary for this receive action.676 * @param dictionary677 * @return678 */679 public T dictionary(DataDictionary dictionary) {680 getAction().setDataDictionary(dictionary);681 return self;682 }683 /**684 * Sets explicit data dictionary by name.685 * @param dictionaryName686 * @return687 */688 @SuppressWarnings("unchecked")689 public T dictionary(String dictionaryName) {690 Assert.notNull(applicationContext, "Citrus application context is not initialized!");691 DataDictionary dictionary = applicationContext.getBean(dictionaryName, DataDictionary.class);692 getAction().setDataDictionary(dictionary);693 return self;694 }695 696 /**697 * Extract message header entry as variable.698 * @param headerName699 * @param variable700 * @return701 */702 public T extractFromHeader(String headerName, String variable) {703 if (headerExtractor == null) {704 headerExtractor = new MessageHeaderVariableExtractor();705 getAction().getVariableExtractors().add(headerExtractor);706 }707 708 headerExtractor.getHeaderMappings().put(headerName, variable);709 return self;710 }711 712 /**713 * Extract message element via XPath or JSONPath from message payload as new test variable.714 * @param path715 * @param variable716 * @return717 */718 public T extractFromPayload(String path, String variable) {719 if (JsonPathMessageValidationContext.isJsonPathExpression(path)) {720 getJsonPathVariableExtractor().getJsonPathExpressions().put(path, variable);721 } else {722 getXpathVariableExtractor().getXpathExpressions().put(path, variable);723 }724 return self;725 }726 727 /**728 * Adds validation callback to the receive action for validating 729 * the received message with Java code.730 * @param callback731 * @return732 */733 public T validationCallback(ValidationCallback callback) {734 if (callback instanceof ApplicationContextAware) {735 ((ApplicationContextAware) callback).setApplicationContext(applicationContext);736 }737 getAction().setValidationCallback(callback);738 return self;739 }740 /**741 * Sets the Spring bean application context.742 * @param applicationContext743 */744 public T withApplicationContext(ApplicationContext applicationContext) {745 this.applicationContext = applicationContext;746 return self;747 }748 /**749 * Get message builder, if already registered or create a new message builder and register it750 *751 * @return the message builder in use752 */753 protected AbstractMessageContentBuilder getMessageContentBuilder() {754 if (getAction().getMessageBuilder() != null && getAction().getMessageBuilder() instanceof AbstractMessageContentBuilder) {755 return (AbstractMessageContentBuilder) getAction().getMessageBuilder();756 } else {757 PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();758 getAction().setMessageBuilder(messageBuilder);759 return messageBuilder;760 }761 }762 /**763 * Creates new variable extractor and adds it to test action.764 */765 private XpathPayloadVariableExtractor getXpathVariableExtractor() {766 if (xpathExtractor == null) {767 xpathExtractor = new XpathPayloadVariableExtractor();768 getAction().getVariableExtractors().add(xpathExtractor);769 }770 return xpathExtractor;771 }772 /**773 * Creates new variable extractor and adds it to test action.774 */775 private JsonPathVariableExtractor getJsonPathVariableExtractor() {776 if (jsonPathExtractor == null) {777 jsonPathExtractor = new JsonPathVariableExtractor();778 getAction().getVariableExtractors().add(jsonPathExtractor);779 }780 return jsonPathExtractor;781 }782 /**783 * Gets the validation context as XML validation context an raises exception if existing validation context is784 * not a XML validation context.785 * @return786 */787 private XpathMessageValidationContext getXPathValidationContext() {788 if (xmlMessageValidationContext instanceof XpathMessageValidationContext) {789 return ((XpathMessageValidationContext)xmlMessageValidationContext);790 } else {791 XpathMessageValidationContext xPathContext = new XpathMessageValidationContext();792 xPathContext.setNamespaces(xmlMessageValidationContext.getNamespaces());793 xPathContext.setControlNamespaces(xmlMessageValidationContext.getControlNamespaces());794 xPathContext.setIgnoreExpressions(xmlMessageValidationContext.getIgnoreExpressions());795 xPathContext.setSchema(xmlMessageValidationContext.getSchema());796 xPathContext.setSchemaRepository(xmlMessageValidationContext.getSchemaRepository());797 xPathContext.setSchemaValidation(xmlMessageValidationContext.isSchemaValidationEnabled());798 xPathContext.setDTDResource(xmlMessageValidationContext.getDTDResource());799 getAction().getValidationContexts().remove(xmlMessageValidationContext);800 getAction().getValidationContexts().add(xPathContext);801 xmlMessageValidationContext = xPathContext;802 return xPathContext;803 }804 }805 /**806 * Creates new script validation context if not done before and gets the script validation context.807 */808 private ScriptValidationContext getScriptValidationContext() {809 if (scriptValidationContext == null) {810 scriptValidationContext = new ScriptValidationContext(messageType.toString());811 getAction().getValidationContexts().add(scriptValidationContext);812 }813 return scriptValidationContext;814 }815 /**816 * Creates new JSONPath validation context if not done before and gets the validation context.817 */818 private JsonPathMessageValidationContext getJsonPathValidationContext() {819 if (jsonPathValidationContext == null) {820 jsonPathValidationContext = new JsonPathMessageValidationContext();821 getAction().getValidationContexts().add(jsonPathValidationContext);822 }...

Full Screen

Full Screen

getScriptValidationContext

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.ReceiveMessageBuilder2def receiveMessageBuilder = new ReceiveMessageBuilder()3def scriptValidationContext = receiveMessageBuilder.getScriptValidationContext()4import com.consol.citrus.dsl.builder.SendMessageBuilder5def sendMessageBuilder = new SendMessageBuilder()6def scriptValidationContext = sendMessageBuilder.getScriptValidationContext()7import com.consol.citrus.dsl.builder.PurgeMessageChannelBuilder8def purgeMessageChannelBuilder = new PurgeMessageChannelBuilder()9def scriptValidationContext = purgeMessageChannelBuilder.getScriptValidationContext()10import com.consol.citrus.dsl.builder.CreateVariablesBuilder11def createVariablesBuilder = new CreateVariablesBuilder()12def scriptValidationContext = createVariablesBuilder.getScriptValidationContext()13import com.consol.citrus.dsl.builder.SetVariablesBuilder14def setVariablesBuilder = new SetVariablesBuilder()15def scriptValidationContext = setVariablesBuilder.getScriptValidationContext()16import com.consol.citrus.dsl.builder.EchoBuilder17def echoBuilder = new EchoBuilder()18def scriptValidationContext = echoBuilder.getScriptValidationContext()19import com.consol.citrus.dsl.builder.PurgeJmsQueuesBuilder20def purgeJmsQueuesBuilder = new PurgeJmsQueuesBuilder()21def scriptValidationContext = purgeJmsQueuesBuilder.getScriptValidationContext()22import com.consol.citrus.dsl.builder.PurgeJmsTopicsBuilder23def purgeJmsTopicsBuilder = new PurgeJmsTopicsBuilder()24def scriptValidationContext = purgeJmsTopicsBuilder.getScriptValidationContext()

Full Screen

Full Screen

getScriptValidationContext

Using AI Code Generation

copy

Full Screen

1ReceiveMessageBuilder getMessageBuilder = receive(messageEndpoint)2 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")3 .messageType(MessageType.XML)4 .getScriptValidationContext();5SendMessageBuilder sendMessageBuilder = send(messageEndpoint)6 .payload("<TestResponse><Message>Hello World!</Message></TestResponse>")7 .messageType(MessageType.XML)8 .getScriptValidationContext();9PurgeEndpointBuilder purgeEndpointBuilder = purgeEndpoints()10 .messageEndpoints(messageEndpoint)11 .getScriptValidationContext();12EchoActionBuilder echoActionBuilder = echo("Hello Citrus!")13 .getScriptValidationContext();14FailActionBuilder failActionBuilder = fail("Oops")15 .getScriptValidationContext();16StopTimeActionBuilder stopTimeActionBuilder = stopTime()17 .getScriptValidationContext();18StartTimeActionBuilder startTimeActionBuilder = startTime()19 .getScriptValidationContext();20PauseActionBuilder pauseActionBuilder = pause()21 .getScriptValidationContext();22CreateVariablesActionBuilder createVariablesActionBuilder = createVariables()23 .variable("var1", "value1")24 .variable("var2", "value2")25 .getScriptValidationContext();26ExecutePLSQLActionBuilder executePLSQLActionBuilder = plsql()27 .statement("SELECT * FROM DUAL")28 .getScriptValidationContext();

Full Screen

Full Screen

getScriptValidationContext

Using AI Code Generation

copy

Full Screen

1ReceiveMessageAction.Builder receiveMessageActionBuilder = receiveMessageActionBuilder()2 .messageType(MessageType.PLAINTEXT)3 .message("Hello Citrus!")4 .getScriptValidationContext("validationContext");5ReceiveMessageAction.Builder receiveMessageActionBuilder = receiveMessageActionBuilder()6 .messageType(MessageType.PLAINTEXT)7 .message("Hello Citrus!")8 .getScriptValidationContext("validationContext")9 .getScriptValidationContext("otherValidationContext");10ReceiveMessageAction.Builder receiveMessageActionBuilder = receiveMessageActionBuilder()11 .messageType(MessageType.PLAINTEXT)12 .message("Hello Citrus!")13 .getScriptValidationContext("validationContext")14 .getScriptValidationContext("otherValidationContext")15 .getScriptValidationContext("yetAnotherValidationContext");16ReceiveMessageAction.Builder receiveMessageActionBuilder = receiveMessageActionBuilder()17 .messageType(MessageType.PLAINTEXT)18 .message("Hello Citrus!")19 .getScriptValidationContext("validationContext")20 .getScriptValidationContext("otherValidationContext")21 .getScriptValidationContext("yetAnotherValidationContext")22 .getScriptValidationContext("andAnotherValidationContext");23ReceiveMessageAction.Builder receiveMessageActionBuilder = receiveMessageActionBuilder()24 .messageType(MessageType.PLAINTEXT)25 .message("Hello Citrus!")26 .getScriptValidationContext("validationContext")27 .getScriptValidationContext("otherValidationContext")28 .getScriptValidationContext("yetAnotherValidationContext")29 .getScriptValidationContext("andAnotherValidationContext")30 .getScriptValidationContext("yetAnotherValidationContext");31ReceiveMessageAction.Builder receiveMessageActionBuilder = receiveMessageActionBuilder()32 .messageType(MessageType

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