1313 */
1414package org .cyclonedx .schema ;
1515
16- import org .cyclonedx .CycloneDxSchema ;
17- import org .cyclonedx .parsers .XmlParser ;
18- import org .junit .jupiter .api .DynamicTest ;
19- import org .junit .jupiter .api .TestFactory ;
2016import java .io .File ;
2117import java .util .ArrayList ;
2218import java .util .Collection ;
2319import java .util .List ;
2420
21+ import org .cyclonedx .parsers .XmlParser ;
22+ import org .cyclonedx .Version ;
23+ import org .junit .jupiter .api .DynamicTest ;
24+ import org .junit .jupiter .api .TestFactory ;
25+
2526import static org .junit .jupiter .api .Assertions .assertTrue ;
2627import static org .junit .jupiter .api .Assertions .assertFalse ;
2728
2829public class XmlSchemaVerificationTest extends BaseSchemaVerificationTest {
2930
3031 @ TestFactory
32+ /**
33+ * Generates a collection of dynamic tests based on the available XML files.
34+ *
35+ * @return Collection<DynamicTest> a collection of dynamic tests
36+ * @throws Exception if an error occurs during the generation of the dynamic tests
37+ */
3138 Collection <DynamicTest > dynamicTestsWithCollection () throws Exception {
3239 final List <String > files = getAllResources ();
3340 final List <DynamicTest > dynamicTests = new ArrayList <>();
3441 for (final String file : files ) {
3542 if (file .endsWith (".xml" )) {
36- final CycloneDxSchema . Version schemaVersion ;
43+ final Version schemaVersion ;
3744 if (file .endsWith ("-1.0.xml" )) {
38- schemaVersion = CycloneDxSchema . Version .VERSION_10 ;
45+ schemaVersion = Version .VERSION_10 ;
3946 } else if (file .endsWith ("-1.1.xml" )) {
40- schemaVersion = CycloneDxSchema . Version .VERSION_11 ;
47+ schemaVersion = Version .VERSION_11 ;
4148 } else if (file .endsWith ("-1.2.xml" )) {
42- schemaVersion = CycloneDxSchema . Version .VERSION_12 ;
49+ schemaVersion = Version .VERSION_12 ;
4350 } else if (file .endsWith ("-1.3.xml" )) {
44- schemaVersion = CycloneDxSchema . Version .VERSION_13 ;
51+ schemaVersion = Version .VERSION_13 ;
4552 } else if (file .endsWith ("-1.4.xml" )) {
46- schemaVersion = CycloneDxSchema . Version .VERSION_14 ;
53+ schemaVersion = Version .VERSION_14 ;
4754 } else if (file .endsWith ("-1.5.xml" )) {
48- schemaVersion = CycloneDxSchema .Version .VERSION_15 ;
55+ schemaVersion = Version .VERSION_15 ;
56+ } else if (file .endsWith ("-1.6.xml" )) {
57+ schemaVersion = Version .VERSION_16 ;
4958 } else {
5059 schemaVersion = null ;
5160 }
@@ -61,7 +70,15 @@ Collection<DynamicTest> dynamicTestsWithCollection() throws Exception {
6170 return dynamicTests ;
6271 }
6372
64- private boolean isValid (CycloneDxSchema .Version version , String resource ) throws Exception {
73+ /**
74+ * Validates the given XML file against the specified CycloneDX schema version.
75+ *
76+ * @param version the CycloneDX schema version to validate against
77+ * @param resource the path to the XML file to be validated
78+ * @return boolean true if the XML file is valid according to the specified schema version, false otherwise
79+ * @throws Exception if an error occurs during the validation process
80+ */
81+ private boolean isValid (Version version , String resource ) throws Exception {
6582 final File file = new File (this .getClass ().getResource (resource ).getFile ());
6683 final XmlParser parser = new XmlParser ();
6784 return parser .isValid (file , version );
0 commit comments