How to use GlobalMessageConstructionInterceptors class of com.consol.citrus.validation.interceptor package

Best Citrus code snippet using com.consol.citrus.validation.interceptor.GlobalMessageConstructionInterceptors

Source:TestContext.java Github

copy

Full Screen

...26import com.consol.citrus.report.MessageListeners;27import com.consol.citrus.report.TestListeners;28import com.consol.citrus.util.TypeConversionUtils;29import com.consol.citrus.validation.MessageValidatorRegistry;30import com.consol.citrus.validation.interceptor.GlobalMessageConstructionInterceptors;31import com.consol.citrus.validation.matcher.ValidationMatcherRegistry;32import com.consol.citrus.variable.GlobalVariables;33import com.consol.citrus.variable.VariableUtils;34import com.consol.citrus.xml.namespace.NamespaceContextBuilder;35import org.slf4j.Logger;36import org.slf4j.LoggerFactory;37import org.springframework.context.ApplicationContext;38import org.springframework.util.*;39import java.lang.reflect.Field;40import java.util.*;41import java.util.Map.Entry;42import java.util.concurrent.ConcurrentHashMap;43/**44 * Class holding and managing test variables. The test context also provides utility methods45 * for replacing dynamic content(variables and functions) in message payloads and headers.46 * 47 * @author Christoph Deppisch48 */49public class TestContext {50 /**51 * Logger52 */53 private static Logger log = LoggerFactory.getLogger(TestContext.class);54 55 /** Local variables */56 protected Map<String, Object> variables;57 58 /** Global variables */59 private GlobalVariables globalVariables;60 /** Message store */61 private MessageStore messageStore = new DefaultMessageStore();62 63 /** Function registry holding all available functions */64 private FunctionRegistry functionRegistry = new FunctionRegistry();65 /** Endpoint factory creates endpoint instances */66 private EndpointFactory endpointFactory;67 /** Bean reference resolver */68 private ReferenceResolver referenceResolver;69 70 /** Registered message validators */71 private MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();72 73 /** Registered validation matchers */74 private ValidationMatcherRegistry validationMatcherRegistry = new ValidationMatcherRegistry();75 /** List of test listeners to be informed on test events */76 private TestListeners testListeners = new TestListeners();77 /** List of message listeners to be informed on inbound and outbound message exchange */78 private MessageListeners messageListeners = new MessageListeners();79 /** List of global message construction interceptors */80 private GlobalMessageConstructionInterceptors globalMessageConstructionInterceptors = new GlobalMessageConstructionInterceptors();81 /** Central namespace context builder */82 private NamespaceContextBuilder namespaceContextBuilder = new NamespaceContextBuilder();83 /** Spring bean application context */84 private ApplicationContext applicationContext;85 /** Timers registered in test context, that can be stopped */86 protected Map<String, StopTimer> timers = new ConcurrentHashMap<>();87 /** List of exceptions that actions raised during execution of forked operations */88 private List<CitrusRuntimeException> exceptions = new ArrayList<>();89 /**90 * Default constructor91 */92 public TestContext() {93 variables = new ConcurrentHashMap<>();94 }95 96 /**97 * Gets the value for the given variable expression. Expression usually is the 98 * simple variable name, with optional expression prefix/suffix.99 * 100 * In case variable is not known to the context throw runtime exception.101 * 102 * @param variableExpression expression to search for.103 * @throws CitrusRuntimeException104 * @return value of the variable105 */106 public String getVariable(final String variableExpression) {107 return getVariable(variableExpression, String.class);108 }109 /**110 * Gets typed variable value.111 * @param variableExpression112 * @param type113 * @param <T>114 * @return115 */116 public <T> T getVariable(String variableExpression, Class<T> type) {117 return TypeConversionUtils.convertIfNecessary(getVariableObject(variableExpression), type);118 }119 /**120 * Gets the value for the given variable as object representation.121 * Use this method if you seek for test objects stored in the context.122 * 123 * @param variableExpression expression to search for.124 * @throws CitrusRuntimeException125 * @return value of the variable as object126 */127 public Object getVariableObject(final String variableExpression) {128 String variableName = VariableUtils.cutOffVariablesPrefix(variableExpression);129 if (variableName.startsWith(Citrus.VARIABLE_ESCAPE) && variableName.endsWith(Citrus.VARIABLE_ESCAPE)) {130 return Citrus.VARIABLE_PREFIX + VariableUtils.cutOffVariablesEscaping(variableName) + Citrus.VARIABLE_SUFFIX;131 } else if (variables.containsKey(variableName)) {132 return variables.get(variableName);133 } else if (variableName.contains(".")) {134 String objectName = variableName.substring(0, variableName.indexOf("."));135 if (variables.containsKey(objectName)) {136 return getVariable(variables.get(objectName), variableName.substring(variableName.indexOf(".") + 1));137 }138 }139 throw new CitrusRuntimeException("Unknown variable '" + variableName + "'");140 }141 /**142 * Gets variable from path expression. Variable paths are translated to reflection fields on object instances.143 * Path separators are '.'. Each separator is handled as object hierarchy.144 * @param instance145 * @param pathExpression146 */147 private Object getVariable(Object instance, String pathExpression) {148 String leftOver = null;149 String fieldName;150 if (pathExpression.contains(".")) {151 fieldName = pathExpression.substring(0, pathExpression.indexOf("."));152 leftOver = pathExpression.substring(pathExpression.indexOf(".") + 1);153 } else {154 fieldName = pathExpression;155 }156 Field field = ReflectionUtils.findField(instance.getClass(), fieldName);157 if (field == null) {158 throw new CitrusRuntimeException(String.format("Failed to get variable - unknown field '%s' on type %s", fieldName, instance.getClass().getName()));159 }160 ReflectionUtils.makeAccessible(field);161 Object fieldValue = ReflectionUtils.getField(field, instance);162 if (StringUtils.hasText(leftOver)) {163 return getVariable(fieldValue, leftOver);164 }165 return fieldValue;166 }167 /**168 * Creates a new variable in this test context with the respective value. In case variable already exists 169 * variable is overwritten.170 * 171 * @param variableName the name of the new variable172 * @param value the new variable value173 * @throws CitrusRuntimeException174 * @return175 */176 public void setVariable(final String variableName, Object value) {177 if (!StringUtils.hasText(variableName) || VariableUtils.cutOffVariablesPrefix(variableName).length() == 0) {178 throw new CitrusRuntimeException("Can not create variable '"+ variableName + "', please define proper variable name");179 }180 if (value == null) {181 throw new VariableNullValueException("Trying to set variable: " + VariableUtils.cutOffVariablesPrefix(variableName) + ", but variable value is null");182 }183 if (log.isDebugEnabled()) {184 log.debug("Setting variable: " + VariableUtils.cutOffVariablesPrefix(variableName) + " with value: '" + value + "'");185 }186 variables.put(VariableUtils.cutOffVariablesPrefix(variableName), value);187 }188 /**189 * Add variables to context.190 * @param variableNames the variable names to set191 * @param variableValues the variable values to set192 */193 public void addVariables(String[] variableNames, Object[] variableValues) {194 if (variableNames.length != variableValues.length) {195 throw new CitrusRuntimeException(String.format(196 "Invalid context variable usage - received '%s' variables with '%s' values",197 variableNames.length,198 variableValues.length));199 }200 for (int i = 0; i < variableNames.length; i++) {201 if (variableValues[i] != null) {202 setVariable(variableNames[i], variableValues[i]);203 }204 }205 }206 207 /**208 * Add several new variables to test context. Existing variables will be 209 * overwritten.210 * 211 * @param variablesToSet the list of variables to set.212 */213 public void addVariables(Map<String, Object> variablesToSet) {214 for (Entry<String, Object> entry : variablesToSet.entrySet()) {215 if (entry.getValue() != null) {216 setVariable(entry.getKey(), entry.getValue());217 } else {218 setVariable(entry.getKey(), "");219 }220 }221 }222 /**223 * Replaces variables and functions inside a map with respective values and returns a new224 * map representation.225 *226 * @param map optionally having variable entries.227 * @return the constructed map without variable entries.228 */229 public <T> Map<String, T> resolveDynamicValuesInMap(final Map<String, T> map) {230 Map<String, T> target = new LinkedHashMap<>(map.size());231 for (Entry<String, T> entry : map.entrySet()) {232 String key = replaceDynamicContentInString(entry.getKey());233 T value = entry.getValue();234 if (value instanceof String) {235 //put value into target map, but check if value is variable or function first236 target.put(key, (T) replaceDynamicContentInString((String) value));237 } else {238 target.put(key, value);239 }240 }241 return target;242 }243 /**244 * Replaces variables and functions in a list with respective values and245 * returns the new list representation.246 *247 * @param list having optional variable entries.248 * @return the constructed list without variable entries.249 */250 public <T> List<T> resolveDynamicValuesInList(final List<T> list) {251 List<T> variableFreeList = new ArrayList<>(list.size());252 for (T value : list) {253 if (value instanceof String) {254 //add new value after check if it is variable or function255 variableFreeList.add((T) replaceDynamicContentInString((String) value));256 }257 }258 return variableFreeList;259 }260 /**261 * Replaces variables and functions in array with respective values and262 * returns the new array representation.263 *264 * @param array having optional variable entries.265 * @return the constructed list without variable entries.266 */267 public <T> T[] resolveDynamicValuesInArray(final T[] array) {268 return resolveDynamicValuesInList(Arrays.asList(array)).toArray(Arrays.copyOf(array, array.length));269 }270 271 /**272 * Clears variables in this test context. Initially adds all global variables.273 */274 public void clear() {275 variables.clear();276 variables.putAll(globalVariables.getVariables());277 }278 279 /**280 * Checks if variables are present right now.281 * @return boolean flag to mark existence282 */283 public boolean hasVariables() {284 return !CollectionUtils.isEmpty(variables);285 }286 287 /**288 * Method replacing variable declarations and place holders as well as 289 * function expressions in a string290 * 291 * @param str the string to parse.292 * @return resulting string without any variable place holders.293 */294 public String replaceDynamicContentInString(String str) {295 return replaceDynamicContentInString(str, false);296 }297 /**298 * Method replacing variable declarations and functions in a string, optionally 299 * the variable values get surrounded with single quotes.300 * 301 * @param str the string to parse for variable place holders.302 * @param enableQuoting flag marking surrounding quotes should be added or not.303 * @return resulting string without any variable place holders.304 */305 public String replaceDynamicContentInString(final String str, boolean enableQuoting) {306 String result = null;307 if (str != null) {308 result = VariableUtils.replaceVariablesInString(str, this, enableQuoting);309 result = FunctionUtils.replaceFunctionsInString(result, this, enableQuoting);310 }311 return result;312 }313 314 /**315 * Checks weather the given expression is a variable or function and resolves the value316 * accordingly317 * @param expression the expression to resolve318 * @return the resolved expression value319 */320 public String resolveDynamicValue(String expression) {321 if (VariableUtils.isVariableName(expression)) {322 return getVariable(expression);323 } else if (functionRegistry.isFunction(expression)) {324 return FunctionUtils.resolveFunction(expression, this);325 }326 return expression;327 }328 /**329 * Handles error creating a new CitrusRuntimeException and330 * informs test listeners.331 * @param testName332 * @param packageName333 * @param message334 * @param cause335 * @return336 */337 public CitrusRuntimeException handleError(String testName, String packageName, String message, Exception cause) {338 // Create empty dummy test case for logging purpose339 TestCase dummyTest = new TestCase();340 dummyTest.setName(testName);341 dummyTest.setPackageName(packageName);342 CitrusRuntimeException exception = new CitrusRuntimeException(message, cause);343 // inform test listeners with failed test344 testListeners.onTestStart(dummyTest);345 testListeners.onTestFailure(dummyTest, exception);346 testListeners.onTestFinish(dummyTest);347 return exception;348 }349 350 /**351 * Setter for test variables in this context.352 * @param variables353 */354 public void setVariables(Map<String, Object> variables) {355 this.variables = variables;356 }357 /**358 * Getter for test variables in this context.359 * @return test variables for this test context.360 */361 public Map<String, Object> getVariables() {362 return variables;363 }364 /**365 * Get global variables.366 * @param globalVariables367 */368 public void setGlobalVariables(GlobalVariables globalVariables) {369 this.globalVariables = globalVariables;370 371 variables.putAll(globalVariables.getVariables());372 }373 /**374 * Set global variables.375 * @return the globalVariables376 */377 public Map<String, Object> getGlobalVariables() {378 return globalVariables.getVariables();379 }380 /**381 * Sets the messageStore property.382 *383 * @param messageStore384 */385 public void setMessageStore(MessageStore messageStore) {386 this.messageStore = messageStore;387 }388 /**389 * Gets the value of the messageStore property.390 *391 * @return the messageStore392 */393 public MessageStore getMessageStore() {394 return messageStore;395 }396 /**397 * Get the current function registry.398 * @return the functionRegistry399 */400 public FunctionRegistry getFunctionRegistry() {401 return functionRegistry;402 }403 /**404 * Set the function registry.405 * @param functionRegistry the functionRegistry to set406 */407 public void setFunctionRegistry(FunctionRegistry functionRegistry) {408 this.functionRegistry = functionRegistry;409 }410 /**411 * Set the message validator registry.412 * @param messageValidatorRegistry the messageValidatorRegistry to set413 */414 public void setMessageValidatorRegistry(MessageValidatorRegistry messageValidatorRegistry) {415 this.messageValidatorRegistry = messageValidatorRegistry;416 }417 /**418 * Get the message validator registry.419 * @return the messageValidatorRegistry420 */421 public MessageValidatorRegistry getMessageValidatorRegistry() {422 return messageValidatorRegistry;423 }424 /**425 * Get the current validation matcher registry426 * @return427 */428 public ValidationMatcherRegistry getValidationMatcherRegistry() {429 return validationMatcherRegistry;430 }431 /**432 * Set the validation matcher registry433 * @param validationMatcherRegistry434 */435 public void setValidationMatcherRegistry(ValidationMatcherRegistry validationMatcherRegistry) {436 this.validationMatcherRegistry = validationMatcherRegistry;437 }438 /**439 * Gets the message listeners.440 * @return441 */442 public MessageListeners getMessageListeners() {443 return messageListeners;444 }445 /**446 * Set the message listeners.447 * @param messageListeners448 */449 public void setMessageListeners(MessageListeners messageListeners) {450 this.messageListeners = messageListeners;451 }452 /**453 * Gets the test listeners.454 * @return455 */456 public TestListeners getTestListeners() {457 return testListeners;458 }459 /**460 * Set the test listeners.461 * @param testListeners462 */463 public void setTestListeners(TestListeners testListeners) {464 this.testListeners = testListeners;465 }466 /**467 * Gets the global message construction interceptors.468 * @return469 */470 public GlobalMessageConstructionInterceptors getGlobalMessageConstructionInterceptors() {471 return globalMessageConstructionInterceptors;472 }473 /**474 * Sets the global messsage construction interceptors.475 * @param messageConstructionInterceptors476 */477 public void setGlobalMessageConstructionInterceptors(GlobalMessageConstructionInterceptors messageConstructionInterceptors) {478 this.globalMessageConstructionInterceptors = messageConstructionInterceptors;479 }480 /**481 * Gets the endpoint factory.482 * @return483 */484 public EndpointFactory getEndpointFactory() {485 return endpointFactory;486 }487 /**488 * Sets the endpoint factory.489 * @param endpointFactory490 */491 public void setEndpointFactory(EndpointFactory endpointFactory) {...

Full Screen

Full Screen

Source:TestContextFactory.java Github

copy

Full Screen

...19import com.consol.citrus.functions.FunctionRegistry;20import com.consol.citrus.report.MessageListeners;21import com.consol.citrus.report.TestListeners;22import com.consol.citrus.validation.MessageValidatorRegistry;23import com.consol.citrus.validation.interceptor.GlobalMessageConstructionInterceptors;24import com.consol.citrus.validation.matcher.ValidationMatcherRegistry;25import com.consol.citrus.variable.GlobalVariables;26import com.consol.citrus.xml.namespace.NamespaceContextBuilder;27import org.slf4j.Logger;28import org.slf4j.LoggerFactory;29import org.springframework.beans.BeansException;30import org.springframework.beans.factory.FactoryBean;31import org.springframework.beans.factory.annotation.Autowired;32import org.springframework.context.ApplicationContext;33import org.springframework.context.ApplicationContextAware;34import org.springframework.util.CollectionUtils;35/**36 * Factory bean implementation taking care of {@link FunctionRegistry} and {@link GlobalVariables}.37 * 38 * @author Christoph Deppisch39 */40public class TestContextFactory implements FactoryBean<TestContext>, ApplicationContextAware {41 42 @Autowired43 private FunctionRegistry functionRegistry;44 45 @Autowired46 private ValidationMatcherRegistry validationMatcherRegistry;47 48 @Autowired(required = false)49 private GlobalVariables globalVariables = new GlobalVariables();50 @Autowired51 private MessageValidatorRegistry messageValidatorRegistry;52 @Autowired53 private TestListeners testListeners;54 @Autowired55 private MessageListeners messageListeners;56 @Autowired57 private EndpointFactory endpointFactory;58 @Autowired59 private ReferenceResolver referenceResolver;60 @Autowired61 private GlobalMessageConstructionInterceptors globalMessageConstructionInterceptors;62 @Autowired(required=false)63 private NamespaceContextBuilder namespaceContextBuilder;64 /** Spring bean application context */65 private ApplicationContext applicationContext;66 67 /** Logger */68 private static Logger log = LoggerFactory.getLogger(TestContextFactory.class);69 /**70 * Create new empty instance that has71 * @return72 */73 public static TestContextFactory newInstance() {74 TestContextFactory factory = new TestContextFactory();75 factory.setFunctionRegistry(new FunctionRegistry());76 factory.setValidationMatcherRegistry(new ValidationMatcherRegistry());77 factory.setGlobalVariables(new GlobalVariables());78 factory.setMessageValidatorRegistry(new MessageValidatorRegistry());79 factory.setTestListeners(new TestListeners());80 factory.setMessageListeners(new MessageListeners());81 factory.setGlobalMessageConstructionInterceptors(new GlobalMessageConstructionInterceptors());82 factory.setEndpointFactory(new DefaultEndpointFactory());83 factory.setReferenceResolver(new SpringBeanReferenceResolver());84 factory.setNamespaceContextBuilder(new NamespaceContextBuilder());85 return factory;86 }87 /**88 * Construct new factory instance from application context.89 * @param applicationContext90 * @return91 */92 public static TestContextFactory newInstance(ApplicationContext applicationContext) {93 TestContextFactory factory = new TestContextFactory();94 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(FunctionRegistry.class))) {95 factory.setFunctionRegistry(applicationContext.getBean(FunctionRegistry.class));96 }97 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(ValidationMatcherRegistry.class))) {98 factory.setValidationMatcherRegistry(applicationContext.getBean(ValidationMatcherRegistry.class));99 }100 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(GlobalVariables.class))) {101 factory.setGlobalVariables(applicationContext.getBean(GlobalVariables.class));102 }103 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(MessageValidatorRegistry.class))) {104 factory.setMessageValidatorRegistry(applicationContext.getBean(MessageValidatorRegistry.class));105 }106 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(TestListeners.class))) {107 factory.setTestListeners(applicationContext.getBean(TestListeners.class));108 }109 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(MessageListeners.class))) {110 factory.setMessageListeners(applicationContext.getBean(MessageListeners.class));111 }112 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(GlobalMessageConstructionInterceptors.class))) {113 factory.setGlobalMessageConstructionInterceptors(applicationContext.getBean(GlobalMessageConstructionInterceptors.class));114 }115 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(EndpointFactory.class))) {116 factory.setEndpointFactory(applicationContext.getBean(EndpointFactory.class));117 }118 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(ReferenceResolver.class))) {119 factory.setReferenceResolver(applicationContext.getBean(ReferenceResolver.class));120 }121 if (!CollectionUtils.isEmpty(applicationContext.getBeansOfType(NamespaceContextBuilder.class))) {122 factory.setNamespaceContextBuilder(applicationContext.getBean(NamespaceContextBuilder.class));123 }124 factory.setApplicationContext(applicationContext);125 return factory;126 }127 128 /**129 * @see org.springframework.beans.factory.FactoryBean#getObject()130 */131 public TestContext getObject() {132 TestContext context = new TestContext();133 context.setFunctionRegistry(functionRegistry);134 context.setValidationMatcherRegistry(validationMatcherRegistry);135 context.setGlobalVariables(globalVariables);136 context.setMessageValidatorRegistry(messageValidatorRegistry);137 context.setTestListeners(testListeners);138 context.setMessageListeners(messageListeners);139 context.setGlobalMessageConstructionInterceptors(globalMessageConstructionInterceptors);140 context.setEndpointFactory(endpointFactory);141 context.setReferenceResolver(referenceResolver);142 context.setApplicationContext(applicationContext);143 if (namespaceContextBuilder != null) {144 context.setNamespaceContextBuilder(namespaceContextBuilder);145 }146 if (log.isDebugEnabled()) {147 log.debug("Created new test context - using global variables: '"148 + context.getGlobalVariables() + "'");149 }150 151 return context;152 }153 /**154 * @see org.springframework.beans.factory.FactoryBean#getObjectType()155 */156 @SuppressWarnings({ "unchecked", "rawtypes" })157 public Class getObjectType() {158 return TestContext.class;159 }160 /**161 * @see org.springframework.beans.factory.FactoryBean#isSingleton()162 */163 public boolean isSingleton() {164 return false;165 }166 /**167 * @param functionRegistry the functionRegistry to set168 */169 public void setFunctionRegistry(FunctionRegistry functionRegistry) {170 this.functionRegistry = functionRegistry;171 }172 /**173 * @return the functionRegistry174 */175 public FunctionRegistry getFunctionRegistry() {176 return functionRegistry;177 }178 179 /**180 * @param validationMatcherRegistry the validationMatcherRegistry to set181 */182 public void setValidationMatcherRegistry(183 ValidationMatcherRegistry validationMatcherRegistry) {184 this.validationMatcherRegistry = validationMatcherRegistry;185 }186 /**187 * @return the validationMatcherRegistry188 */189 public ValidationMatcherRegistry getValidationMatcherRegistry() {190 return validationMatcherRegistry;191 }192 /**193 * @param globalVariables the globalVariables to set194 */195 public void setGlobalVariables(GlobalVariables globalVariables) {196 this.globalVariables = globalVariables;197 }198 /**199 * @return the globalVariables200 */201 public GlobalVariables getGlobalVariables() {202 return globalVariables;203 }204 /**205 * Gets the endpoint factory.206 * @return207 */208 public EndpointFactory getEndpointFactory() {209 return endpointFactory;210 }211 /**212 * Sets the endpoint factory.213 * @param endpointFactory214 */215 public void setEndpointFactory(EndpointFactory endpointFactory) {216 this.endpointFactory = endpointFactory;217 }218 /**219 * Gets the value of the referenceResolver property.220 *221 * @return the referenceResolver222 */223 public ReferenceResolver getReferenceResolver() {224 return referenceResolver;225 }226 /**227 * Sets the referenceResolver property.228 *229 * @param referenceResolver230 */231 public void setReferenceResolver(ReferenceResolver referenceResolver) {232 this.referenceResolver = referenceResolver;233 }234 /**235 * Sets the namespace context builder.236 * @param namespaceContextBuilder237 */238 public void setNamespaceContextBuilder(NamespaceContextBuilder namespaceContextBuilder) {239 this.namespaceContextBuilder = namespaceContextBuilder;240 }241 /**242 * Gets the namespace context builder.243 * @return244 */245 public NamespaceContextBuilder getNamespaceContextBuilder() {246 return namespaceContextBuilder;247 }248 /**249 * Sets the test listeners.250 * @param testListeners251 */252 public void setTestListeners(TestListeners testListeners) {253 this.testListeners = testListeners;254 }255 /**256 * Gets the test listeners.257 * @return258 */259 public TestListeners getTestListeners() {260 return testListeners;261 }262 /**263 * Sets the message validator registry.264 * @param messageValidatorRegistry265 */266 public void setMessageValidatorRegistry(MessageValidatorRegistry messageValidatorRegistry) {267 this.messageValidatorRegistry = messageValidatorRegistry;268 }269 /**270 * Gets the message validator registry.271 * @return272 */273 public MessageValidatorRegistry getMessageValidatorRegistry() {274 return messageValidatorRegistry;275 }276 /**277 * Sets the message listeners.278 * @param messageListeners279 */280 public void setMessageListeners(MessageListeners messageListeners) {281 this.messageListeners = messageListeners;282 }283 /**284 * Gets the message listeners.285 * @return286 */287 public MessageListeners getMessageListeners() {288 return messageListeners;289 }290 /**291 * Sets the message construction interceptors.292 * @param messageConstructionInterceptors293 */294 public void setGlobalMessageConstructionInterceptors(GlobalMessageConstructionInterceptors messageConstructionInterceptors) {295 this.globalMessageConstructionInterceptors = messageConstructionInterceptors;296 }297 /**298 * Gets the message construction interceptors.299 * @return300 */301 public GlobalMessageConstructionInterceptors getGlobalMessageConstructionInterceptors() {302 return globalMessageConstructionInterceptors;303 }304 @Override305 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {306 this.applicationContext = applicationContext;307 }308}...

Full Screen

Full Screen

Source:CitrusSpringConfig.java Github

copy

Full Screen

...21import com.consol.citrus.endpoint.EndpointFactory;22import com.consol.citrus.functions.FunctionConfig;23import com.consol.citrus.report.*;24import com.consol.citrus.validation.MessageValidatorConfig;25import com.consol.citrus.validation.interceptor.GlobalMessageConstructionInterceptors;26import com.consol.citrus.validation.matcher.ValidationMatcherConfig;27import org.springframework.context.annotation.*;28/**29 * @author Christoph Deppisch30 * @since 2.031 */32@Configuration33@Import({ FunctionConfig.class,34 ValidationMatcherConfig.class,35 MessageValidatorConfig.class,36 CitrusConfigImport.class})37@ImportResource(locations = "${systemProperties['citrus.spring.application.context']?:classpath*:citrus-context.xml}", reader = CitrusBeanDefinitionReader.class)38public class CitrusSpringConfig {39 @Bean40 public TestContextFactory testContextFactory() {41 return new TestContextFactory();42 }43 @Bean44 public EndpointFactory endpointFactory() {45 return new DefaultEndpointFactory();46 }47 @Bean48 public ReferenceResolver referenceResolver() {49 return new SpringBeanReferenceResolver();50 }51 @Bean52 public GlobalMessageConstructionInterceptors globalMessageConstructionInterceptors() {53 return new GlobalMessageConstructionInterceptors();54 }55 @Bean56 public LoggingReporter loggingReporter() {57 return new LoggingReporter();58 }59 @Bean60 public HtmlReporter htmlReporter() {61 return new HtmlReporter();62 }63 @Bean64 public JUnitReporter junitReporter() {65 return new JUnitReporter();66 }67 @Bean...

Full Screen

Full Screen

GlobalMessageConstructionInterceptors

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.validation.interceptor;2import java.util.ArrayList;3import java.util.List;4import com.consol.citrus.message.Message;5import com.consol.citrus.validation.MessageValidationContext;6public class GlobalMessageConstructionInterceptors implements MessageConstructionInterceptors {7 private List<MessageConstructionInterceptor> interceptors = new ArrayList<MessageConstructionInterceptor>();8 public GlobalMessageConstructionInterceptors(List<MessageConstructionInterceptor> interceptors) {9 this.interceptors = interceptors;10 }11 public Message interceptMessageConstruction(Message message, MessageValidationContext validationContext) {12 for (MessageConstructionInterceptor interceptor : interceptors) {13 message = interceptor.interceptMessageConstruction(message, validationContext);14 }15 return message;16 }17 public List<MessageConstructionInterceptor> getInterceptors() {18 return interceptors;19 }20 public void setInterceptors(List<MessageConstructionInterceptor> interceptors) {21 this.interceptors = interceptors;22 }23}24package com.consol.citrus.validation.interceptor;25import java.util.ArrayList;26import java.util.List;27import com.consol.citrus.message.Message;28import com.consol.citrus.validation.MessageValidationContext;29public class GlobalMessageConstructionInterceptors implements MessageConstructionInterceptors {30 private List<MessageConstructionInterceptor> interceptors = new ArrayList<MessageConstructionInterceptor>();31 public GlobalMessageConstructionInterceptors(List<MessageConstructionInterceptor> interceptors) {32 this.interceptors = interceptors;33 }34 public Message interceptMessageConstruction(Message message, MessageValidationContext validationContext) {35 for (MessageConstructionInterceptor interceptor : interceptors) {36 message = interceptor.interceptMessageConstruction(message, validationContext);37 }38 return message;39 }40 public List<MessageConstructionInterceptor> getInterceptors() {41 return interceptors;42 }

Full Screen

Full Screen

GlobalMessageConstructionInterceptors

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.validation.interceptor;2import org.springframework.integration.Message;3import org.springframework.integration.support.MessageBuilder;4import org.testng.Assert;5import org.testng.annotations.Test;6import com.consol.citrus.context.TestContext;7import com.consol.citrus.message.DefaultMessage;8import com.consol.citrus.testng.AbstractTestNGUnitTest;9public class GlobalMessageConstructionInterceptorsTest extends AbstractTestNGUnitTest {10public void testGlobalMessageConstructionInterceptors() {11GlobalMessageConstructionInterceptors.setInterceptors(new MessageConstructionInterceptor() {12public Message<?> interceptMessageConstruction(Message<?> message, TestContext context) {13return MessageBuilder.withPayload("Hello World").build();14}15});16Message<?> message = GlobalMessageConstructionInterceptors.interceptMessageConstruction(new DefaultMessage("Hello World"), context);17Assert.assertEquals(message.getPayload(), "Hello World");18}19}

Full Screen

Full Screen

GlobalMessageConstructionInterceptors

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.testng.CitrusParameters;7import org.testng.annotations.Test;8public class GlobalMessageConstructionInterceptorsJavaITest extends TestNGCitrusTestDesigner {9 @CitrusParameters({"param1", "param2"})10 public void globalMessageConstructionInterceptors(String param1, String param2) {11 parallel(12 sequential(13 send("foo")14 .messageType(MessageType.PLAINTEXT)15 .payload(param1)16 sequential(17 send("bar")18 .messageType(MessageType.PLAINTEXT)19 .payload(param2)20 );21 }22}23package com.consol.citrus.dsl.design;24import com.consol.citrus.dsl.design.TestDesigner;25import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;26import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;27import com.consol.citrus.testng.CitrusParameters;28import org.testng.annotations.Test;29public class GlobalMessageConstructionInterceptorsJavaITest extends TestNGCitrusTestDesigner {30 @CitrusParameters({"param1", "param2"})31 public void globalMessageConstructionInterceptors(String param1, String param2) {32 parallel(33 sequential(34 send("foo")35 .messageType(MessageType.PLAINTEXT)36 .payload(param1)37 sequential(38 send("bar")39 .messageType(MessageType.PLAINTEXT)40 .payload(param2)41 );42 }43}

Full Screen

Full Screen

GlobalMessageConstructionInterceptors

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.dsl.builder.GlobalMessageConstructionInterceptors;3import org.springframework.context.annotation.Bean;4import org.springframework.context.annotation.Configuration;5public class GlobalMessageConstructionInterceptorsConfig {6 public GlobalMessageConstructionInterceptors globalMessageConstructionInterceptors() {7 return new GlobalMessageConstructionInterceptors();8 }9}10package com.consol.citrus;11import com.consol.citrus.dsl.builder.GlobalMessageConstructionInterceptors;12import org.springframework.context.annotation.Bean;13import org.springframework.context.annotation.Configuration;14public class GlobalMessageConstructionInterceptorsConfig {15 public GlobalMessageConstructionInterceptors globalMessageConstructionInterceptors() {16 return new GlobalMessageConstructionInterceptors();17 }18}19package com.consol.citrus;20import com.consol.citrus.dsl.builder.GlobalMessageConstructionInterceptors;21import org.springframework.context.annotation.Bean;22import org.springframework.context.annotation.Configuration;23public class GlobalMessageConstructionInterceptorsConfig {24 public GlobalMessageConstructionInterceptors globalMessageConstructionInterceptors() {25 return new GlobalMessageConstructionInterceptors();26 }27}28package com.consol.citrus;29import com.consol.citrus.dsl.builder.GlobalMessageConstructionInterceptors;30import org.springframework.context.annotation.Bean;31import org.springframework.context.annotation.Configuration;32public class GlobalMessageConstructionInterceptorsConfig {33 public GlobalMessageConstructionInterceptors globalMessageConstructionInterceptors() {34 return new GlobalMessageConstructionInterceptors();35 }36}37package com.consol.citrus;38import com.consol.citrus.dsl.builder.GlobalMessageConstructionInterceptors;39import org.springframework.context.annotation.Bean;40import org.springframework.context.annotation.Configuration;41public class GlobalMessageConstructionInterceptorsConfig {42 public GlobalMessageConstructionInterceptors globalMessageConstructionInterceptors() {

Full Screen

Full Screen

GlobalMessageConstructionInterceptors

Using AI Code Generation

copy

Full Screen

1public void test() {2 GlobalMessageConstructionInterceptors interceptors = new GlobalMessageConstructionInterceptors();3 interceptors.setInterceptors(Collections.singletonList(new MessageConstructionInterceptor() {4 public void interceptMessageConstruction(MessageConstructionContext context) {5 context.getMessage().setHeader("foo", "bar");6 }7 }));8 GlobalMessageConstructionInterceptors.setInstance(interceptors);9 run(new TestRunner() {10 public void execute() {11 send("foo");12 receive("bar");13 }14 });15}16public void test() {17 GlobalMessageConstructionInterceptors interceptors = new GlobalMessageConstructionInterceptors();18 interceptors.setInterceptors(Collections.singletonList(new MessageConstructionInterceptor() {19 public void interceptMessageConstruction(MessageConstructionContext context) {20 context.getMessage().setHeader("foo", "bar");21 }22 }));23 GlobalMessageConstructionInterceptors.setInstance(interceptors);24 run(new TestRunner() {25 public void execute() {26 send("foo");27 receive("bar");28 }29 });30}31public void test() {32 GlobalMessageConstructionInterceptors interceptors = new GlobalMessageConstructionInterceptors();33 interceptors.setInterceptors(Collections.singletonList(new MessageConstructionInterceptor() {34 public void interceptMessageConstruction(MessageConstructionContext context) {35 context.getMessage().setHeader("foo", "bar");36 }37 }));38 GlobalMessageConstructionInterceptors.setInstance(interceptors);39 run(new TestRunner() {40 public void execute() {41 send("foo");42 receive("bar");43 }44 });45}46public void test() {47 GlobalMessageConstructionInterceptors interceptors = new GlobalMessageConstructionInterceptors();48 interceptors.setInterceptors(Collections.singletonList(new MessageConstructionInterceptor() {49 public void interceptMessageConstruction(MessageConstructionContext context) {50 context.getMessage().setHeader("foo", "bar");51 }52 }));

Full Screen

Full Screen

GlobalMessageConstructionInterceptors

Using AI Code Generation

copy

Full Screen

1public class GlobalMessageConstructionInterceptors extends GlobalMessageConstructionInterceptors {2 public void addInterceptors(List<MessageConstructionInterceptor> interceptors) {3 interceptors.add(new MyMessageConstructionInterceptor());4 }5}6public class GlobalMessageConstructionInterceptors extends GlobalMessageConstructionInterceptors {7 public void addInterceptors(List<MessageConstructionInterceptor> interceptors) {8 interceptors.add(new MyMessageConstructionInterceptor());9 }10}11public class GlobalMessageConstructionInterceptors extends GlobalMessageConstructionInterceptors {12 public void addInterceptors(List<MessageConstructionInterceptor> interceptors) {13 interceptors.add(new MyMessageConstructionInterceptor());14 }15}16public class GlobalMessageConstructionInterceptors extends GlobalMessageConstructionInterceptors {17 public void addInterceptors(List<MessageConstructionInterceptor> interceptors) {18 interceptors.add(new MyMessageConstructionInterceptor());19 }20}21public class GlobalMessageConstructionInterceptors extends GlobalMessageConstructionInterceptors {22 public void addInterceptors(List<MessageConstructionInterceptor> interceptors) {23 interceptors.add(new MyMessageConstructionInterceptor());24 }25}26public class GlobalMessageConstructionInterceptors extends GlobalMessageConstructionInterceptors {27 public void addInterceptors(List<MessageConstructionInterceptor> interceptors) {28 interceptors.add(new MyMessageConstructionInterceptor());29 }30}31public class GlobalMessageConstructionInterceptors extends GlobalMessageConstructionInterceptors {32 public void addInterceptors(List<MessageConstructionInterceptor> interceptors) {33 interceptors.add(new MyMessageConstructionInterceptor());34 }35}

Full Screen

Full Screen

GlobalMessageConstructionInterceptors

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.http.client.HttpClient;5import com.consol.citrus.validation.interceptor.GlobalMessageConstructionInterceptors;6import com.consol.citrus.validation.interceptor.MessageConstructionInterceptor;7import org.springframework.beans.factory.annotation.Autowired;8import org.springframework.http.HttpStatus;9import org.testng.annotations.Test;10import java.util.Collections;11public class GlobalMessageConstructionInterceptorIT extends TestNGCitrusTestRunner {12 private HttpClient todoClient;13 public void testGetTodo() {14 GlobalMessageConstructionInterceptors.getInstance().setInterceptors(Collections.singletonList(new MessageConstructionInterceptor() {15 public void interceptMessageConstruction(com.consol.citrus.message.Message message) {16 message.setHeader("customHeader", "customHeaderValue");17 }18 }));19 http(httpActionBuilder -> httpActionBuilder.client(todoClient)20 .send()21 .get("/todo"));22 http(httpActionBuilder -> httpActionBuilder.client(todoClient)23 .receive()24 .response(HttpStatus.OK)25 .messageType(MessageType.PLAINTEXT)26 .payload("{\"id\": \"1\", \"task\": \"Buy some Citrus fruit\", \"done\": \"false\"}"));27 }28}29package com.consol.citrus.samples;30import com.consol.citrus.annotations.CitrusTest;31import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;32import com.consol.citrus.http.client.HttpClient;33import com.consol.citrus.validation.interceptor.GlobalMessageConstructionInterceptors;34import com.consol.citrus.validation.interceptor.MessageConstructionInterceptor;35import org.springframework.beans.factory.annotation.Autowired;36import org.springframework.http.HttpStatus;37import org.testng.annotations.Test;38import java.util.Collections;39public class GlobalMessageConstructionInterceptorIT extends TestNGCitrusTestRunner {40 private HttpClient todoClient;

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.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in GlobalMessageConstructionInterceptors

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful