1616import static org .junit .jupiter .api .Assertions .assertFalse ;
1717import static org .junit .jupiter .api .Assertions .assertTrue ;
1818
19- import java .nio .file .Path ;
20- import java .nio .file .Paths ;
2119import java .util .ArrayList ;
2220import java .util .Collection ;
2321import java .util .List ;
2422import javax .xml .XMLConstants ;
25- import javax .xml .transform .Source ;
2623import javax .xml .transform .stream .StreamSource ;
2724import javax .xml .validation .Schema ;
2825import javax .xml .validation .SchemaFactory ;
@@ -45,38 +42,26 @@ public class XmlSchemaVerificationTest extends BaseSchemaVerificationTest {
4542 private static final Schema VERSION_16 ;
4643
4744 static {
48- // Surefire sets a `basedir` system property
49- // Otherwise we assume that the project is in the current working directory (should work in IDEs)
50- Path toolsPath = Paths .get (System .getProperty ("basedir" , "." ));
51- Path schemaPath = toolsPath .resolve ("../schema" );
52- SchemaFactory factory = SchemaFactory .newInstance (XMLConstants .W3C_XML_SCHEMA_NS_URI );
53- ClassLoader cl = XmlSchemaVerificationTest .class .getClassLoader ();
5445 try {
55- VERSION_10 = factory .newSchema (
56- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.0.xsd" ))});
57- VERSION_11 = factory .newSchema (
58- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.1.xsd" ))});
59- VERSION_12 = factory .newSchema (
60- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.2.xsd" ))});
61- VERSION_13 = factory .newSchema (
62- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.3.xsd" ))});
63- VERSION_14 = factory .newSchema (
64- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.4.xsd" ))});
65- VERSION_15 = factory .newSchema (new Source [] {
66- spdxSource (), new StreamSource (schemaPath .resolve ("bom-1.5.xsd" ).toFile ())
67- });
68- VERSION_16 = factory .newSchema (new Source [] {
69- spdxSource (), new StreamSource (schemaPath .resolve ("bom-1.6.xsd" ).toFile ())
70- });
46+ SchemaFactory factory = SchemaFactory .newInstance (XMLConstants .W3C_XML_SCHEMA_NS_URI );
47+ factory .setProperty (XMLConstants .ACCESS_EXTERNAL_SCHEMA , "file" );
48+ ClassLoader cl = XmlSchemaVerificationTest .class .getClassLoader ();
49+ // Override the `schemaLocation` property in the file
50+ factory .setProperty (
51+ "http://apache.org/xml/properties/schema/external-schemaLocation" ,
52+ "http://cyclonedx.org/schema/spdx spdx.xsd" );
53+ VERSION_10 = factory .newSchema (cl .getResource ("bom-1.0.xsd" ));
54+ VERSION_11 = factory .newSchema (cl .getResource ("bom-1.1.xsd" ));
55+ VERSION_12 = factory .newSchema (cl .getResource ("bom-1.2.xsd" ));
56+ VERSION_13 = factory .newSchema (cl .getResource ("bom-1.3.xsd" ));
57+ VERSION_14 = factory .newSchema (cl .getResource ("bom-1.4.xsd" ));
58+ VERSION_15 = factory .newSchema (cl .getResource ("bom-1.5.xsd" ));
59+ VERSION_16 = factory .newSchema (cl .getResource ("bom-1.6.xsd" ));
7160 } catch (SAXException e ) {
7261 throw new IllegalStateException (e );
7362 }
7463 }
7564
76- private static Source spdxSource () {
77- return new StreamSource (XmlSchemaVerificationTest .class .getClassLoader ().getResourceAsStream ("spdx.xsd" ));
78- }
79-
8065 /**
8166 * Generates a collection of dynamic tests based on the available XML files.
8267 *
0 commit comments