Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/improve schema resolving dom xml message validator #1000

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class XmlSchemaValidation implements SchemaValidator<XmlMessageValidation
private final TransformerFactory transformerFactory = TransformerFactory.newInstance();

/**
* Validate message with a XML schema.
* Validate message with an XML schema.
*
* @param message
* @param context
Expand Down Expand Up @@ -153,4 +153,4 @@ protected void validateDTD(Resource dtdResource, Message receivedMessage) {
public boolean supportsMessageType(String messageType, Message message) {
return "XML".equals(messageType) || (message != null && IsXmlPredicate.getInstance().test(message.getPayload(String.class)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.citrusframework.validation.script.ScriptValidationContext;
import org.citrusframework.validation.xml.schema.XmlSchemaValidation;
import org.citrusframework.xml.XsdSchemaRepository;
import org.citrusframework.xml.schema.XsdSchemaCollection;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.xsd.SimpleXsdSchema;
Expand Down Expand Up @@ -414,6 +415,50 @@ public void validateNoSchemaRepositoryAtAll() throws SAXException, IOException,
validator.validateXMLSchema(message, context, new XmlMessageValidationContext());
}

@Test
public void validateSchemaWithSchemaImport() throws SAXException, IOException, ParserConfigurationException {
Message message = new DefaultMessage("<sampleRequest xmlns:ns='http://citrusframework.org/SampleService/Message'>"
+ "<command>Cm123456789</command>"
+ "<message>FOO</message>"
+ "</sampleRequest>");

XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
schemaRepository.setName("schemaRepository");

XsdSchemaCollection schemaCollection = new XsdSchemaCollection();
schemaCollection.setSchemas(List.of("org/citrusframework/validation/SampleMessage.xsd", "org/citrusframework/validation/SampleTypes.xsd"));
schemaCollection.initialize();
schemaCollection.afterPropertiesSet();

schemaRepository.getSchemas().add(schemaCollection);

context.getReferenceResolver().bind("schemaRepository", schemaRepository);

validator.validateXMLSchema(message, context, new XmlMessageValidationContext());
}

@Test
public void validateSchemaWithSchemaImportAndWildcard() throws ParserConfigurationException, IOException, SAXException {
Message message = new DefaultMessage("<sampleRequest xmlns:ns='http://citrusframework.org/SampleService/Message'>"
+ "<command>Cm123456789</command>"
+ "<message>FOO</message>"
+ "</sampleRequest>");

XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
schemaRepository.setName("schemaRepository");

XsdSchemaCollection schemaCollection = new XsdSchemaCollection();
schemaCollection.setSchemas(List.of("org/citrusframework/validation/Sample*.xsd"));
schemaCollection.initialize();
schemaCollection.afterPropertiesSet();

schemaRepository.getSchemas().add(schemaCollection);

context.getReferenceResolver().bind("schemaRepository", schemaRepository);

validator.validateXMLSchema(message, context, new XmlMessageValidationContext());
}

@Test(expectedExceptions = {ValidationException.class})
public void validateXMLSchemaError() throws SAXException, IOException, ParserConfigurationException {
Message message = new DefaultMessage("<message xmlns='http://citrusframework.org/test'>"
Expand Down
Loading