Finds the message validation context that is most appropriate for this validator implementation.
@param validationContexts
@return
517876
protected T findValidationContext(List<ValidationContext> validationContexts) {
        for (ValidationContext validationContext : validationContexts) {
            if (getRequiredValidationContextType().isInstance(validationContext)) {
                return (T) validationContext;
            }
        }

        return null;
    }
279037
@SuppressWarnings("unchecked")
    public T headerValidator(String ... validatorNames) {
        Assert.notNull(applicationContext, "Citrus application context is not initialized!");

        for (String validatorName : validatorNames) {
            headerValidationContext.addHeaderValidator(applicationContext.getBean(validatorName, HeaderValidator.class));
        }

        return self;
    }
75840
protected void validateMessageContent(Message receivedMessage, Message controlMessage, XmlMessageValidationContext validationContext,
            TestContext context) {
        if (controlMessage == null || controlMessage.getPayload() == null) {
            log.debug("Skip message payload validation as no control message was defined");
            return;
        }

        if (!(controlMessage.getPayload() instanceof String)) {
            throw new IllegalArgumentException(
                    "DomXmlMessageValidator does only support message payload of type String, " +
                    "but was " + controlMessage.getPayload().getClass());
        }

        String controlMessagePayload = controlMessage.getPayload(String.class);

        if (receivedMessage.getPayload() == null || !StringUtils.hasText(receivedMessage.getPayload(String.class))) {
            Assert.isTrue(!StringUtils.hasText(controlMessagePayload),
                    "Unable to validate message payload - received message payload was empty, control message payload is not");
            return;
        } else if (!StringUtils.hasText(controlMessagePayload)) {
            return;
        }

        log.debug("Start XML tree validation ...");

        Document received = XMLUtils.parseMessagePayload(receivedMessage.getPayload(String.class));
        Document source = XMLUtils.parseMessagePayload(controlMessagePayload);

        XMLUtils.stripWhitespaceNodes(received);
        XMLUtils.stripWhitespaceNodes(source);

        if (log.isDebugEnabled()) {
            log.debug("Received message:\n" + XMLUtils.serialize(received));
            log.debug("Control message:\n" + XMLUtils.serialize(source));
        }

        validateXmlTree(received, source, validationContext, namespaceContextBuilder.buildContext(
                receivedMessage, validationContext.getNamespaces()), context);
    }
288980
@SuppressWarnings("PMD.UseStringBufferForStringAppends")
    public static String getContextMarkers(final AdminContext context) {
        String res = "";
        if (isForAdmin(context)) {
            if (isForMain(context)) {
                res += "M";
            }
            res += "A";
        }
        return res;
    }
1219633
public void validatePersonLookup(PersonQuery personQuery, MessageContext context) {
        final RequestContext requestContext = RequestContextHolder.getRequestContext();
        final ExternalContext externalContext = requestContext.getExternalContext();
        final Set<String> queryAttributes = personLookupHelper.getQueryAttributes(externalContext);

        final Map<String, Attribute> attributes = personQuery.getAttributes();
        for (final String attribute : attributes.keySet()) {
            if (!queryAttributes.contains(attribute)) {
                final MessageBuilder messageBuilder = new MessageBuilder();
                messageBuilder.error();
                messageBuilder.source("attributes[" + attribute + "].value");
                messageBuilder.code("personLookup.invalidQueryAttribute");
                messageBuilder.arg(attribute);

                final MessageResolver errorMessage = messageBuilder.build();
                context.addMessage(errorMessage);
            }
        }
    }
191230
public SuperCsvValidationException.Builder createValidationException(final CsvContext context) {
        
        String message = getValidationMessage();
        if(Utils.isEmpty(message)) {
            message = getDefaultValidationMessage();
        }
        
        return new SuperCsvValidationException.Builder(context, this)
                .validationMessage(message);
    }
1182319
private void addSchemaInformationToValidationContext(Element messageElement, SchemaValidationContext context) {
        String schemaValidation = messageElement.getAttribute("schema-validation");
        if (StringUtils.hasText(schemaValidation)) {
            context.setSchemaValidation(Boolean.valueOf(schemaValidation));
        }

        String schema = messageElement.getAttribute("schema");
        if (StringUtils.hasText(schema)) {
            context.setSchema(schema);
        }

        String schemaRepository = messageElement.getAttribute("schema-repository");
        if (StringUtils.hasText(schemaRepository)) {
            context.setSchemaRepository(schemaRepository);
        }
    }
816557
void handleValidationChange(CmsValidationContext validationContext) {

        if (validationContext.hasValidationErrors()) {
            String locales = "";
            for (String id : validationContext.getInvalidEntityIds()) {
                if (locales.length() > 0) {
                    locales += ", ";
                }
                String locale = CmsContentDefinition.getLocaleFromId(id);
                if (m_availableLocales.containsKey(locale)) {
                    locales += m_availableLocales.get(locale);
                }
            }
            disableSave(Messages.get().key(Messages.GUI_TOOLBAR_VALIDATION_ERRORS_1, locales));
        } else if (!m_changedEntityIds.isEmpty()) {
            enableSave();
        }
    }
878967
public String getMessage(Context context) {
        if (customMessage != null) {
            return customMessage;
        }
        return context.getResources().getString(message);
    }
1111479
protected void validateMessage(Message receivedMessage, TestContext context) throws IOException {
        // extract variables from received message content
        for (VariableExtractor variableExtractor : variableExtractors) {
            variableExtractor.extractVariables(receivedMessage, context);
        }

        if (validationCallback != null) {
            if (StringUtils.hasText(receivedMessage.getName())) {
                context.getMessageStore().storeMessage(receivedMessage.getName(), receivedMessage);
            } else {
                context.getMessageStore().storeMessage(context.getMessageStore().constructMessageName(this, getOrCreateEndpoint(context)), receivedMessage);
            }

            validationCallback.validate(receivedMessage, context);
        } else {
            Message controlMessage = createControlMessage(context, messageType);
            if (StringUtils.hasText(controlMessage.getName())) {
                context.getMessageStore().storeMessage(controlMessage.getName(), receivedMessage);
            } else {
                context.getMessageStore().storeMessage(context.getMessageStore().constructMessageName(this, getOrCreateEndpoint(context)), receivedMessage);
            }

            if (!CollectionUtils.isEmpty(validators)) {
                for (MessageValidator<? extends ValidationContext> messageValidator : validators) {
                    messageValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);
                }

                if (validators.parallelStream()
                                .map(Object::getClass)
                                .noneMatch(DefaultMessageHeaderValidator.class::isAssignableFrom)) {
                    MessageValidator defaultMessageHeaderValidator = context.getMessageValidatorRegistry().getDefaultMessageHeaderValidator();
                    if (defaultMessageHeaderValidator != null) {
                        defaultMessageHeaderValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);
                    }
                }
            } else {
                List<MessageValidator<? extends ValidationContext>> validators =
                        context.getMessageValidatorRegistry().findMessageValidators(messageType, receivedMessage);

                if (validators.isEmpty()) {
                    if (controlMessage.getPayload() instanceof String &&
                            StringUtils.hasText(controlMessage.getPayload(String.class))) {
                        throw new CitrusRuntimeException(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));
                    } else if (validationContexts.stream().anyMatch(item -> JsonPathMessageValidationContext.class.isAssignableFrom(item.getClass())
                            || XpathMessageValidationContext.class.isAssignableFrom(item.getClass())
                            || ScriptValidationContext.class.isAssignableFrom(item.getClass()))) {
                        throw new CitrusRuntimeException(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));
                    } else {
                        log.warn(String.format("Unable to find proper message validator for message type '%s' and validation contexts '%s'", messageType, validationContexts));
                    }
                }

                for (MessageValidator<? extends ValidationContext> messageValidator : validators) {
                    messageValidator.validateMessage(receivedMessage, controlMessage, context, validationContexts);
                }
            }
        }
    }
1373122
private Set<String> validatePathAndRetrievePathParams(ValidationHelper helper, Context context, String pathStr) {
        String pathToCheck = pathStr;
        Set<String> pathParameters = new HashSet<String>();

        while (pathToCheck.contains("{")) {
            if (!pathToCheck.contains("}")) {
                final String message = Tr.formatMessage(tc, "pathItemInvalidFormat", pathStr);
                helper.addValidationEvent(new ValidationEvent(ValidationEvent.Severity.ERROR, context.getLocation(), message));
                return pathParameters;
            }
            int firstIndex = pathToCheck.indexOf("{");
            int lastIndex = pathToCheck.indexOf("}");

            if (firstIndex > lastIndex) {
                final String message = Tr.formatMessage(tc, "pathItemInvalidFormat", pathStr);
                helper.addValidationEvent(new ValidationEvent(ValidationEvent.Severity.ERROR, context.getLocation(), message));
                return pathParameters;
            }

            String parameter = pathToCheck.substring(firstIndex + 1, lastIndex);

            if (parameter.isEmpty() || parameter.contains("{") || parameter.contains("/")) {
                final String message = Tr.formatMessage(tc, "pathItemInvalidFormat", pathStr);
                helper.addValidationEvent(new ValidationEvent(ValidationEvent.Severity.ERROR, context.getLocation(), message));
                return pathParameters;
            }

            pathParameters.add(parameter);
            pathToCheck = pathToCheck.substring(lastIndex + 1);
        }

        if (pathToCheck.contains("}")) {
            final String message = Tr.formatMessage(tc, "pathItemInvalidFormat", pathStr);
            helper.addValidationEvent(new ValidationEvent(ValidationEvent.Severity.ERROR, context.getLocation(), message));
            return pathParameters;
        }

        return pathParameters;
    }
881204
private void findErrorMessages(FacesContext context) {
        if (context.getMessageList().isEmpty() || context.isValidationFailed()) {
            return;
        }
        for (FacesMessage msg : context.getMessageList()) {
            if (msg.getSeverity().equals(FacesMessage.SEVERITY_ERROR) || msg.getSeverity().equals(FacesMessage.SEVERITY_FATAL)) {
                validationFailed(context);
                break;
            }
        }
    }
1194624
public String getValidationScript(TestContext context) {
        try {
            if (validationScriptResourcePath != null) {
                return context.replaceDynamicContentInString(FileUtils.readToString(FileUtils.getFileResource(validationScriptResourcePath, context),
                        Charset.forName(context.replaceDynamicContentInString(validationScriptResourceCharset))));
            } else if (validationScript != null) {
                return context.replaceDynamicContentInString(validationScript);
            } else {
                return "";
            }
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to load validation script resource", e);
        }
    }
1113344
private XpathMessageValidationContext getXPathMessageValidationContext(Element messageElement, XmlMessageValidationContext parentContext) {
        XpathMessageValidationContext context = new XpathMessageValidationContext();
        
        parseXPathValidationElements(messageElement, context);

        context.setControlNamespaces(parentContext.getControlNamespaces());
        context.setNamespaces(parentContext.getNamespaces());
        context.setIgnoreExpressions(parentContext.getIgnoreExpressions());
        context.setSchema(parentContext.getSchema());
        context.setSchemaRepository(parentContext.getSchemaRepository());
        context.setSchemaValidation(parentContext.isSchemaValidationEnabled());
        context.setDTDResource(parentContext.getDTDResource());

        return context;
    }
454937
public void setValidationEmails(java.util.Collection<String> validationEmails) {
        if (validationEmails == null) {
            this.validationEmails = null;
            return;
        }

        this.validationEmails = new java.util.ArrayList<String>(validationEmails);
    }
733143
public ValidationResult validateConfiguration(@Nonnull AnalysisContext analysisContext) {
        ValidationResult validation = ValidationResult.success();

        // even though we're not using the extensions much during validation and we actually don't run any analysis
        // at all, let's just use the same method for instantiating the extensions as during the analysis even though we
        // actually don't need the extensions classified by their type.
        AnalysisResult.Extensions exts = prepareAnalysis(analysisContext);
        validation = validate(analysisContext, validation, exts);

        return validation;
    }
256125
private void parseXPathValidationElements(Element messageElement, XpathMessageValidationContext context) {
        //check for validate elements, these elements can either have script, xpath or namespace validation information
        //for now we only handle xpath validation
        Map<String, Object> validateXpathExpressions = new HashMap<>();

        List<?> validateElements = DomUtils.getChildElementsByTagName(messageElement, "validate");
        if (validateElements.size() > 0) {
            for (Iterator<?> iter = validateElements.iterator(); iter.hasNext();) {
                Element validateElement = (Element) iter.next();
                extractXPathValidateExpressions(validateElement, validateXpathExpressions);
            }

            context.setXpathExpressions(validateXpathExpressions);
        }
    }