
org.mockserver.matchers.XmlSchemaMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-core Show documentation
Show all versions of mockserver-core Show documentation
Functionality used by all MockServer modules for matching and expectations
package org.mockserver.matchers;
import org.mockserver.validator.xmlschema.XmlSchemaValidator;
/**
* See http://xml-schema.org/
*
* @author jamesdbloom
*/
public class XmlSchemaMatcher extends BodyMatcher {
private String schema;
private XmlSchemaValidator xmlSchemaValidator;
public XmlSchemaMatcher(String schema) {
this.schema = schema;
xmlSchemaValidator = new XmlSchemaValidator(schema);
}
protected String[] fieldsExcludedFromEqualsAndHashCode() {
return new String[]{"logger", "xmlSchemaValidator"};
}
public boolean matches(String matched) {
boolean result = false;
try {
String validation = xmlSchemaValidator.isValid(matched);
result = validation.isEmpty();
if (!result) {
logger.trace("Failed to perform XML match \"{}\" with schema \"{}\" because {}", matched, this.schema, validation);
}
} catch (Exception e) {
logger.trace("Failed to perform XML match \"{}\" with schema \"{}\" because {}", matched, this.schema, e.getMessage());
}
return reverseResultIfNot(result);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy