use of com.helger.xml.ls.CollectingLSResourceResolver in project ph-commons by phax.
the class XMLSchemaCacheTest method testCustom.
@Test
@SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION")
public void testCustom() {
@PresentForCodeCoverage XMLSchemaCache sc = new XMLSchemaCache(new LoggingSAXErrorHandler());
assertNotNull(sc);
final CollectingLSResourceResolver crr = new CollectingLSResourceResolver();
sc = new XMLSchemaCache(new LoggingLSResourceResolver().setWrappedResourceResolver(crr));
assertNotNull(sc);
// Valid schema
Schema aSchema = sc.getSchema(new ClassPathResource("xml/schema1.xsd"));
assertNotNull(aSchema);
assertTrue(crr.getAllRequestedResources().isEmpty());
// Valid schema (with includes)
aSchema = sc.getSchema(new ClassPathResource("xml/schema2.xsd"));
assertNotNull(aSchema);
assertEquals(1, crr.getAllRequestedResources().size());
final LSResourceData rd = crr.getAllRequestedResources().get(0);
assertEquals("http://www.w3.org/2001/XMLSchema", rd.getType());
assertEquals("http://www.example.org/schema1", rd.getNamespaceURI());
assertNull(rd.getPublicID());
assertEquals("schema1.xsd", rd.getSystemID());
assertNotNull(rd.getBaseURI());
assertTrue(rd.getBaseURI().endsWith("xml/schema2.xsd"));
// Not a schema
try {
sc.getSchema(new ClassPathResource("test1.txt"));
fail();
} catch (final IllegalArgumentException ex) {
}
// empty
try {
sc.getSchema((IReadableResource[]) null);
fail();
} catch (final NullPointerException ex) {
}
try {
sc.getSchema(new IReadableResource[0]);
fail();
} catch (final IllegalArgumentException ex) {
}
}
Aggregations