Reputation: 31
I am trying to validate an XML response retrieved from RestAssured with a list of XSDs which are referenced within.
I tried
given().param(...).when().get(URL).then().assertThat().body(matchesXsd(xsd))
This works if I have one XSDs file which contains all schema definitions but how can I have multiple XSDs? These XSDs are also referenced within themselves. Also, all XSDs are local to the project.
I tried Rest-Assured XSD References Other XSDs and Validate an XML File Against Multiple Schema Definitions and few more but they were either irrelevant to my goal or didn't work for me.
Upvotes: 2
Views: 980
Reputation: 31
I solved it by:
given().param(...).when().get(URL).then().assertThat().body(matchesXsd(getSystemResourceAsStream("parent.xsd")).using(new ClasspathResourceResolver()));
ClasspathResourceResolver resolves all references from parent XSD.
and
`
public class ClasspathResourceResolver implements LSResourceResolver {
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
InputStream resource = getSystemResourceAsStream(systemId);
return new DOMInputImpl(publicId, systemId, baseURI, resource, null);
}
}
`
Upvotes: 1