Skip to content

Commit

Permalink
tests: Update to cyclonedx-core-java-9.0.2 for test runners (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkowalleck authored Jun 13, 2024
2 parents 491e813 + fa50287 commit 7c630cc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<lib.commons.lang3.version>3.6</lib.commons.lang3.version>
<lib.commons.text.version>1.12.0</lib.commons.text.version>
<lib.unirest.version>1.4.9</lib.unirest.version>
<lib.cyclonedx.core.java.version>8.0.3</lib.cyclonedx.core.java.version>
<lib.cyclonedx.core.java.version>9.0.2</lib.cyclonedx.core.java.version>
</properties>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
*/
package org.cyclonedx.schema;

import org.cyclonedx.CycloneDxSchema;
import org.cyclonedx.parsers.JsonParser;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.cyclonedx.parsers.JsonParser;
import org.cyclonedx.Version;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

Expand All @@ -33,15 +34,15 @@ Collection<DynamicTest> dynamicTestsWithCollection() throws Exception {
final List<DynamicTest> dynamicTests = new ArrayList<>();
for (final String file: files) {
if (file.endsWith(".json")) {
final CycloneDxSchema.Version schemaVersion;
final Version schemaVersion;
if (file.endsWith("-1.2.json")) {
schemaVersion = CycloneDxSchema.Version.VERSION_12;
schemaVersion = Version.VERSION_12;
} else if (file.endsWith("-1.3.json")) {
schemaVersion = CycloneDxSchema.Version.VERSION_13;
schemaVersion = Version.VERSION_13;
} else if (file.endsWith("-1.4.json")) {
schemaVersion = CycloneDxSchema.Version.VERSION_14;
schemaVersion = Version.VERSION_14;
} else if (file.endsWith("-1.5.json")) {
schemaVersion = CycloneDxSchema.Version.VERSION_15;
schemaVersion = Version.VERSION_15;
} else {
schemaVersion = null;
}
Expand All @@ -57,7 +58,7 @@ Collection<DynamicTest> dynamicTestsWithCollection() throws Exception {
return dynamicTests;
}

private boolean isValidJson(CycloneDxSchema.Version version, String resource) throws Exception {
private boolean isValidJson(Version version, String resource) throws Exception {
final File file = new File(this.getClass().getResource(resource).getFile());
final JsonParser parser = new JsonParser();
return parser.isValid(file, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,46 @@
*/
package org.cyclonedx.schema;

import org.cyclonedx.CycloneDxSchema;
import org.cyclonedx.parsers.XmlParser;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.cyclonedx.parsers.XmlParser;
import org.cyclonedx.Version;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class XmlSchemaVerificationTest extends BaseSchemaVerificationTest {

@TestFactory
/**
* Generates a collection of dynamic tests based on the available XML files.
*
* @return Collection<DynamicTest> a collection of dynamic tests
* @throws Exception if an error occurs during the generation of the dynamic tests
*/
Collection<DynamicTest> dynamicTestsWithCollection() throws Exception {
final List<String> files = getAllResources();
final List<DynamicTest> dynamicTests = new ArrayList<>();
for (final String file: files) {
if (file.endsWith(".xml")) {
final CycloneDxSchema.Version schemaVersion;
final Version schemaVersion;
if (file.endsWith("-1.0.xml")) {
schemaVersion = CycloneDxSchema.Version.VERSION_10;
schemaVersion = Version.VERSION_10;
} else if (file.endsWith("-1.1.xml")) {
schemaVersion = CycloneDxSchema.Version.VERSION_11;
schemaVersion = Version.VERSION_11;
} else if (file.endsWith("-1.2.xml")) {
schemaVersion = CycloneDxSchema.Version.VERSION_12;
schemaVersion = Version.VERSION_12;
} else if (file.endsWith("-1.3.xml")) {
schemaVersion = CycloneDxSchema.Version.VERSION_13;
schemaVersion = Version.VERSION_13;
} else if (file.endsWith("-1.4.xml")) {
schemaVersion = CycloneDxSchema.Version.VERSION_14;
schemaVersion = Version.VERSION_14;
} else if (file.endsWith("-1.5.xml")) {
schemaVersion = CycloneDxSchema.Version.VERSION_15;
schemaVersion = Version.VERSION_15;
} else {
schemaVersion = null;
}
Expand All @@ -61,7 +68,15 @@ Collection<DynamicTest> dynamicTestsWithCollection() throws Exception {
return dynamicTests;
}

private boolean isValid(CycloneDxSchema.Version version, String resource) throws Exception {
/**
* Validates the given XML file against the specified CycloneDX schema version.
*
* @param version the CycloneDX schema version to validate against
* @param resource the path to the XML file to be validated
* @return boolean true if the XML file is valid according to the specified schema version, false otherwise
* @throws Exception if an error occurs during the validation process
*/
private boolean isValid(Version version, String resource) throws Exception {
final File file = new File(this.getClass().getResource(resource).getFile());
final XmlParser parser = new XmlParser();
return parser.isValid(file, version);
Expand Down

0 comments on commit 7c630cc

Please sign in to comment.