@Test
  public void testValidateReadableResource() {
    // Valid
    IResourceErrorGroup aErrors = XMLSchemaValidationHelper.validate(XSD1, XML1);
    assertNotNull(aErrors);
    assertEquals(0, aErrors.getSize());
    aErrors = XMLSchemaValidationHelper.validate(new IReadableResource[] {XSD2, XSD1}, XML1);
    assertNotNull(aErrors);
    assertEquals(0, aErrors.getSize());

    // Invalid
    aErrors = XMLSchemaValidationHelper.validate(XSD1, XML2);
    assertNotNull(aErrors);
    assertEquals(1, aErrors.getSize());
    aErrors = XMLSchemaValidationHelper.validate(new IReadableResource[] {XSD2, XSD1}, XML2);
    assertNotNull(aErrors);
    assertEquals(1, aErrors.getSize());

    try {
      // null XML not allowed
      XMLSchemaValidationHelper.validate(XSD1, (IReadableResource) null);
      fail();
    } catch (final NullPointerException ex) {
    }
    try {
      // null XML not allowed
      XMLSchemaValidationHelper.validate(
          new IReadableResource[] {XSD2, XSD1}, (IReadableResource) null);
      fail();
    } catch (final NullPointerException ex) {
    }
    try {
      // Non XML instance
      XMLSchemaValidationHelper.validate(
          new IReadableResource[] {XSD2, XSD1}, new ClassPathResource("test1.txt"));
      fail();
    } catch (final IllegalArgumentException ex) {
    }
    try {
      // Non XML XSD
      XMLSchemaValidationHelper.validate(new ClassPathResource("test1.txt"), XML1);
      fail();
    } catch (final IllegalArgumentException ex) {
    }
  }
  @Test
  public void testValidateSchemaPresent() throws SAXException {
    final Schema aSchema1 = XMLSchemaCache.getInstance().getSchema(XSD1);
    final Schema aSchema2 = XMLSchemaCache.getInstance().getSchema(XSD2, XSD1);

    // Different source type
    Document aDoc = DOMReader.readXMLDOM(XML1);
    IResourceErrorGroup aErrors = XMLSchemaValidationHelper.validate(aSchema1, new DOMSource(aDoc));
    assertNotNull(aErrors);
    assertEquals(0, aErrors.getSize());
    aErrors = XMLSchemaValidationHelper.validate(aSchema2, new DOMSource(aDoc));
    assertNotNull(aErrors);
    assertEquals(0, aErrors.getSize());

    aDoc = DOMReader.readXMLDOM(XML2);
    aErrors = XMLSchemaValidationHelper.validate(aSchema1, XML1);
    assertNotNull(aErrors);
    assertEquals(0, aErrors.getSize());
    aErrors = XMLSchemaValidationHelper.validate(aSchema2, XML1);
    assertNotNull(aErrors);
    assertEquals(0, aErrors.getSize());

    try {
      // null XML not allowed
      XMLSchemaValidationHelper.validate(aSchema1, (IReadableResource) null);
      fail();
    } catch (final NullPointerException ex) {
    }
    try {
      // null XML not allowed
      XMLSchemaValidationHelper.validate(aSchema1, (Source) null);
      fail();
    } catch (final NullPointerException ex) {
    }
    try {
      // null XML not allowed
      XMLSchemaValidationHelper.validate((Schema) null, new DOMSource(aDoc));
      fail();
    } catch (final NullPointerException ex) {
    }
  }
  @Test
  public void testValidateDOMSource() throws SAXException {
    // Different source type
    Document aDoc = DOMReader.readXMLDOM(XML1);
    IResourceErrorGroup aErrors = XMLSchemaValidationHelper.validate(XSD1, new DOMSource(aDoc));
    assertNotNull(aErrors);
    assertEquals(0, aErrors.getSize());
    aErrors =
        XMLSchemaValidationHelper.validate(
            new IReadableResource[] {XSD2, XSD1}, new DOMSource(aDoc));
    assertNotNull(aErrors);
    assertEquals(0, aErrors.getSize());

    aDoc = DOMReader.readXMLDOM(XML2);
    aErrors = XMLSchemaValidationHelper.validate(XSD1, new DOMSource(aDoc));
    assertNotNull(aErrors);
    assertEquals(1, aErrors.getSize());
    aErrors =
        XMLSchemaValidationHelper.validate(
            new IReadableResource[] {XSD2, XSD1}, new DOMSource(aDoc));
    assertNotNull(aErrors);
    assertEquals(1, aErrors.getSize());

    try {
      // null XML not allowed
      XMLSchemaValidationHelper.validate(XSD1, (Source) null);
      fail();
    } catch (final NullPointerException ex) {
    }
    try {
      // null XML not allowed
      XMLSchemaValidationHelper.validate(new IReadableResource[] {XSD2, XSD1}, (Source) null);
      fail();
    } catch (final NullPointerException ex) {
    }
  }