How to use getOrCreateEndpoint method of com.consol.citrus.actions.ReceiveMessageAction class

Best Citrus code snippet using com.consol.citrus.actions.ReceiveMessageAction.getOrCreateEndpoint

Source:ReceiveMessageAction.java Github

copy

Full Screen

...118 * Receives the message with respective message receiver implementation.119 * @return120 */121 private Message receive(TestContext context) {122 Endpoint messageEndpoint = getOrCreateEndpoint(context);123 return receiveTimeout > 0 ? messageEndpoint.createConsumer().receive(context, receiveTimeout) :124 messageEndpoint.createConsumer().receive(context, messageEndpoint.getEndpointConfiguration().getTimeout());125 }126 /**127 * Receives the message with the respective message receiver implementation 128 * also using a message selector.129 * @param context the test context.130 * @param selectorString the message selector string.131 * @return132 */133 private Message receiveSelected(TestContext context, String selectorString) {134 if (log.isDebugEnabled()) {135 log.debug("Setting message selector: '" + selectorString + "'");136 }137 Endpoint messageEndpoint = getOrCreateEndpoint(context);138 Consumer consumer = messageEndpoint.createConsumer();139 if (consumer instanceof SelectiveConsumer) {140 if (receiveTimeout > 0) {141 return ((SelectiveConsumer) messageEndpoint.createConsumer()).receive(142 context.replaceDynamicContentInString(selectorString),143 context, receiveTimeout);144 } else {145 return ((SelectiveConsumer) messageEndpoint.createConsumer()).receive(146 context.replaceDynamicContentInString(selectorString),147 context, messageEndpoint.getEndpointConfiguration().getTimeout());148 }149 } else {150 log.warn(String.format("Unable to receive selective with consumer implementation: '%s'", consumer.getClass()));151 return receive(context);152 }153 }154 /**155 * Override this message if you want to add additional message validation156 * @param receivedMessage157 */158 protected void validateMessage(Message receivedMessage, TestContext context) throws IOException {159 // extract variables from received message content160 for (VariableExtractor variableExtractor : variableExtractors) {161 variableExtractor.extractVariables(receivedMessage, context);162 }163 if (validationCallback != null) {164 if (StringUtils.hasText(receivedMessage.getName())) {165 context.getMessageStore().storeMessage(receivedMessage.getName(), receivedMessage);166 } else {167 context.getMessageStore().storeMessage(context.getMessageStore().constructMessageName(this, getOrCreateEndpoint(context)), receivedMessage);168 }169 validationCallback.validate(receivedMessage, context);170 } else {171 Message controlMessage = createControlMessage(context, messageType);172 if (StringUtils.hasText(controlMessage.getName())) {173 context.getMessageStore().storeMessage(controlMessage.getName(), receivedMessage);174 } else {175 context.getMessageStore().storeMessage(context.getMessageStore().constructMessageName(this, getOrCreateEndpoint(context)), receivedMessage);176 }177 if (!CollectionUtils.isEmpty(validators)) {178 for (MessageValidator<? extends ValidationContext> messageValidator : validators) {179 messageValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);180 }181 if (validators.parallelStream()182 .map(Object::getClass)183 .noneMatch(DefaultMessageHeaderValidator.class::isAssignableFrom)) {184 MessageValidator defaultMessageHeaderValidator = context.getMessageValidatorRegistry().getDefaultMessageHeaderValidator();185 if (defaultMessageHeaderValidator != null) {186 defaultMessageHeaderValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);187 }188 }189 } else {190 List<MessageValidator<? extends ValidationContext>> validators =191 context.getMessageValidatorRegistry().findMessageValidators(messageType, receivedMessage);192 if (validators.isEmpty()) {193 if (controlMessage.getPayload() instanceof String &&194 StringUtils.hasText(controlMessage.getPayload(String.class))) {195 throw new CitrusRuntimeException(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));196 } else if (validationContexts.stream().anyMatch(item -> JsonPathMessageValidationContext.class.isAssignableFrom(item.getClass())197 || XpathMessageValidationContext.class.isAssignableFrom(item.getClass())198 || ScriptValidationContext.class.isAssignableFrom(item.getClass()))) {199 throw new CitrusRuntimeException(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));200 } else {201 log.warn(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));202 }203 }204 for (MessageValidator<? extends ValidationContext> messageValidator : validators) {205 messageValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);206 }207 }208 }209 }210 /**211 * Create control message that is expected.212 * @param context213 * @param messageType214 * @return215 */216 protected Message createControlMessage(TestContext context, String messageType) {217 if (dataDictionary != null) {218 messageBuilder.setDataDictionary(dataDictionary);219 }220 return messageBuilder.buildMessageContent(context, messageType, MessageDirection.INBOUND);221 }222 223 @Override224 public boolean isDisabled(TestContext context) {225 Endpoint messageEndpoint = getOrCreateEndpoint(context);226 if (getActor() == null && messageEndpoint.getActor() != null) {227 return messageEndpoint.getActor().isDisabled();228 }229 230 return super.isDisabled(context);231 }232 /**233 * Setter for messageSelectorMap.234 * @param messageSelectorMap235 */236 public ReceiveMessageAction setMessageSelectorMap(Map<String, Object> messageSelectorMap) {237 this.messageSelectorMap = messageSelectorMap;238 return this;239 }240 /**241 * Set message selector string.242 * @param messageSelector243 */244 public ReceiveMessageAction setMessageSelector(String messageSelector) {245 this.messageSelector = messageSelector;246 return this;247 }248 /**249 * Set list of message validators.250 * @param validators the message validators to set251 */252 public ReceiveMessageAction setValidators(List<MessageValidator<? extends ValidationContext>> validators) {253 this.validators.clear();254 this.validators.addAll(validators);255 return this;256 }257 /**258 * Adds message validator to the list of explicit validators.259 * @param validator the message validator to set260 */261 public ReceiveMessageAction addValidator(MessageValidator<? extends ValidationContext> validator) {262 this.validators.add(validator);263 return this;264 }265 /**266 * Creates or gets the endpoint instance.267 * @param context268 * @return269 */270 public Endpoint getOrCreateEndpoint(TestContext context) {271 if (endpoint != null) {272 return endpoint;273 } else if (StringUtils.hasText(endpointUri)) {274 return context.getEndpointFactory().create(endpointUri, context);275 } else {276 throw new CitrusRuntimeException("Neither endpoint nor endpoint uri is set properly!");277 }278 }279 280 /**281 * Set message endpoint instance.282 * @param endpoint the message endpoint283 */284 public ReceiveMessageAction setEndpoint(Endpoint endpoint) {...

Full Screen

Full Screen

getOrCreateEndpoint

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.actions.ReceiveMessageAction;2import com.consol.citrus.dsl.endpoint.CitrusEndpoints;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.runner.TestRunnerSupport;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.testng.CitrusParameters;7import com.consol.citrus.validation.builder.DefaultMessageBuilder;8import com.consol.citrus.validation.json.JsonTextMessageBuilder;9import com.consol.citrus.validation.script.GroovyScriptMessageBuilder;10import com.consol.citrus.validation.xml.XpathMessageBuilder;11import com.consol.citrus.ws.actions.SoapAction;12import com.consol.citrus.ws.actions.SoapAction.SoapActionBuilder;13import com.consol.citrus.ws.client.WebServiceClient;14import com.consol.citrus.ws.message.SoapAttachment;15import com.consol.citrus.ws.message.SoapMessage;16import com.consol.citrus.ws.message.SoapMessageHeaders;17import com.consol.citrus.ws.message.SoapMessageValidationContext;18import com.consol.citrus.ws.validation.SoapAttachmentValidator;19import com.consol.citrus.ws.validation.SoapFaultDetailValidator;20import com.consol.citrus.ws.validation.SoapFaultValidator;21import com.consol.citrus.ws.validation.SoapHeaderValidator;22import com.consol.citrus.ws.validation.SoapMessageValidator;23import com.consol.citrus.ws.validation.SoapNamespaceValidator;24import com.consol.citrus.ws.validation.SoapSchemaValidator;25import com.consol.citrus.ws.validation.SoapSecurityValidator;26import com.consol.citrus.ws.validation.SoapValidator;27import com.consol.citrus.ws.validation.XsdSchemaRepository;28import com.consol.citrus.ws.validation.matcher.SoapAttachmentValidationMatcher;29import com.consol.citrus.ws.validation.matcher.SoapFaultDetailValidationMatcher;30import com.consol.citrus.ws.validation.matcher.SoapFaultValidationMatcher;31import com.consol.citrus.ws.validation.matcher.SoapHeaderValidationMatcher;32import com.consol.citrus.ws.validation.matcher.SoapMessageValidationMatcher;33import com.consol.citrus.ws.validation.matcher.SoapNamespaceValidationMatcher;34import com.consol.citrus.ws.validation.matcher.SoapSecurityValidationMatcher;35import com.consol.citrus.ws.validation.matcher.SoapValidationMatcher;

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