Search in sources :

Example 1 with LoggingLSResourceResolver

use of com.helger.xml.ls.LoggingLSResourceResolver 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) {
    }
}
Also used : CollectingLSResourceResolver(com.helger.xml.ls.CollectingLSResourceResolver) LSResourceData(com.helger.xml.ls.LSResourceData) LoggingLSResourceResolver(com.helger.xml.ls.LoggingLSResourceResolver) Schema(javax.xml.validation.Schema) LoggingSAXErrorHandler(com.helger.xml.sax.LoggingSAXErrorHandler) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) PresentForCodeCoverage(com.helger.commons.annotation.PresentForCodeCoverage) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

PresentForCodeCoverage (com.helger.commons.annotation.PresentForCodeCoverage)1 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)1 IReadableResource (com.helger.commons.io.resource.IReadableResource)1 CollectingLSResourceResolver (com.helger.xml.ls.CollectingLSResourceResolver)1 LSResourceData (com.helger.xml.ls.LSResourceData)1 LoggingLSResourceResolver (com.helger.xml.ls.LoggingLSResourceResolver)1 LoggingSAXErrorHandler (com.helger.xml.sax.LoggingSAXErrorHandler)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Schema (javax.xml.validation.Schema)1 Test (org.junit.Test)1