Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Update to cyclonedx-core-java-9.0.2 for test runners #480

Merged
merged 13 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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