1515import org .xml .sax .XMLReader ;
1616
1717import javax .xml .parsers .ParserConfigurationException ;
18+ import java .util .List ;
1819import java .util .stream .Stream ;
1920
2021import static org .hamcrest .MatcherAssert .assertThat ;
@@ -49,28 +50,28 @@ void shouldValidateXmlSuccessfullyAgainstSchema(String xmlToValidateResource) th
4950 }
5051 }
5152
52- static Stream <Pair <String , String >> invalidSchemaDocProvider () {
53+ static Stream <Pair <String , List < String > >> invalidSchemaDocProvider () {
5354 return Stream .of (
5455 Pair .of ("schema-validation/simpledoc-invalid-schemaloc-https-badprefix.xml" ,
55- "'https' access is not allowed due to restriction set by the accessExternalSchema property" ),
56+ List . of ( "'https'" , " accessExternalSchema" ) ),
5657 Pair .of ("schema-validation/simpledoc-invalid-schemaloc-https-notfound.xml" ,
57- "'https' access is not allowed due to restriction set by the accessExternalSchema property" ),
58+ List . of ( "'https'" , " accessExternalSchema" ) ),
5859 Pair .of ("schema-validation/simpledoc-invalid-schemaloc-file.xml" ,
59- "'file' access is not allowed due to restriction set by the accessExternalSchema property" ),
60+ List . of ( "'file'" , " accessExternalSchema" ) ),
6061 Pair .of ("schema-validation/simpledoc-invalid-schemaloc-ambiguous-uri.xml" ,
61- "'file' access is not allowed due to restriction set by the accessExternalSchema property." )
62+ List . of ( "'file'" , " accessExternalSchema" ) )
6263 );
6364 }
6465
6566 @ ParameterizedTest
6667 @ MethodSource ("invalidSchemaDocProvider" )
67- void shouldFailValidationWhenUnableToFindExternalSchema (Pair <String , String > test ) throws Exception {
68+ void shouldFailValidationWhenUnableToFindExternalSchema (Pair <String , List < String > > test ) throws Exception {
6869 try (AutoCloseableInputSource simple = fromResource ("schema-validation/simple.xsd" );
6970 AutoCloseableInputSource irrelevant = fromResource ("schema-validation/irrelevant.xsd" );
7071 AutoCloseableInputSource toValidate = fromResource (test .getLeft ())) {
7172
7273 Throwable t = assertThrows (SAXException .class , () -> withDefaultReader (simple , irrelevant ).parse (toValidate ));
73- assertThat (t .getMessage (), containsString (test . getRight ( )));
74+ test . getRight (). forEach ( msg -> assertThat (t .getMessage (), containsString (msg )));
7475 }
7576 }
7677
@@ -81,7 +82,7 @@ void shouldFailValidationWhenDocIsInvalidForSchema() throws Exception {
8182 AutoCloseableInputSource toValidate = fromResource ("schema-validation/simpledoc-invalid-no-schemaloc-bad-content.xml" )) {
8283
8384 Throwable t = assertThrows (SAXException .class , () -> withDefaultReader (simple , irrelevant ).parse (toValidate ));
84- assertThat (t .getMessage (), containsString ("Invalid content was found starting with element " ));
85+ assertThat (t .getMessage (), containsString ("cvc-complex-type.2.4.a " ));
8586 }
8687 }
8788
@@ -90,7 +91,8 @@ void shouldFailValidationWhenNoRegisteredSchemas() throws Exception {
9091 try (AutoCloseableInputSource toValidate = fromResource ("schema-validation/simpledoc-valid-no-schemaloc.xml" )) {
9192
9293 Throwable t = assertThrows (SAXException .class , () -> withDefaultReader ().parse (toValidate ));
93- assertThat (t .getMessage (), containsString ("Cannot find the declaration of element 'items'." ));
94+ assertThat (t .getMessage (), containsString ("cvc-elt.1.a" ));
95+ assertThat (t .getMessage (), containsString ("'items'" ));
9496 }
9597 }
9698
@@ -100,7 +102,8 @@ void shouldFailValidationWhenNoRelevantSchemas() throws Exception {
100102 AutoCloseableInputSource toValidate = fromResource ("schema-validation/simpledoc-valid-no-schemaloc.xml" )) {
101103
102104 Throwable t = assertThrows (SAXException .class , () -> withDefaultReader (irrelevant ).parse (toValidate ));
103- assertThat (t .getMessage (), containsString ("Cannot find the declaration of element 'items'." ));
105+ assertThat (t .getMessage (), containsString ("cvc-elt.1.a" ));
106+ assertThat (t .getMessage (), containsString ("'items'" ));
104107 }
105108 }
106109
0 commit comments