-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix relationshipTest, add it to the solver, correct path in conversionTests #27
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.spdx.toolsJavaSolver; | ||
|
||
public enum TestCaseName { | ||
|
||
GENERATION_MINIMAL("generationMinimalTest"), | ||
GENERATION_BASELINE_SBOM("generationBaselineSbomTest"), | ||
GENERATION_DOCUMENT("generationDocumentTest"), | ||
GENERATION_PACKAGE("generationPackageTest"), | ||
GENERATION_FILE("generationFileTest"), | ||
GENERATION_SNIPPET("generationSnippetTest"), | ||
GENERATION_LICENSE("generationLicenseTest"), | ||
GENERATION_RELATIONSHIP("generationRelationshipTest"), | ||
GENERATION_EXTRACTED_LICENSE_INFO("generationExtractedLicenseInfoTest"); | ||
|
||
private final String fullName; | ||
|
||
TestCaseName(String name) { | ||
this.fullName = name; | ||
} | ||
|
||
public String getFullName() { | ||
return this.fullName; | ||
} | ||
|
||
public static TestCaseName fromString(String str) { | ||
for (var testCaseName : TestCaseName.values()){ | ||
if (testCaseName.getFullName().equals(str)){ | ||
return testCaseName; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown test case name: " + str); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.spdx.toolsJavaSolver.generationTestCases; | ||
|
||
import org.spdx.library.InvalidSPDXAnalysisException; | ||
import org.spdx.library.model.SpdxDocument; | ||
import org.spdx.library.model.enumerations.RelationshipType; | ||
import org.spdx.library.model.license.LicenseInfoFactory; | ||
|
||
import java.util.List; | ||
|
||
public class GenerationRelationshipTestCase { | ||
|
||
public static SpdxDocument buildDocument() throws InvalidSPDXAnalysisException { | ||
var document = GenerationUtil.createSpdxDocumentWithBasicInfo("Relationship test document"); | ||
|
||
var modelStore = document.getModelStore(); | ||
var documentUri = document.getDocumentUri(); | ||
|
||
var sha1Checksum = GenerationUtil.createSha1Checksum(modelStore, documentUri); | ||
|
||
var concludedLicense = LicenseInfoFactory.parseSPDXLicenseString("LGPL-2.0-only"); | ||
|
||
var fileA = document.createSpdxFile("SPDXRef-fileA", "./fileA.c", concludedLicense, | ||
List.of(), "Copyright 2022 some person", sha1Checksum) | ||
.build(); | ||
|
||
var fileB = document.createSpdxFile("SPDXRef-fileB", "./fileB.c", concludedLicense, | ||
List.of(), "Copyright 2022 some person", sha1Checksum) | ||
.build(); | ||
|
||
document.getDocumentDescribes().add(fileA); | ||
document.getDocumentDescribes().add(fileB); | ||
|
||
for (var relationshipType : RelationshipType.values()) { | ||
if (relationshipType == RelationshipType.MISSING) { | ||
continue; | ||
} | ||
fileB.addRelationship( | ||
document.createRelationship( | ||
fileA, relationshipType, String.format("comment on %s", relationshipType.name()))); | ||
|
||
} | ||
|
||
return document; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.spdx.toolsJavaSolver.generationTestCases; | ||
|
||
import org.spdx.jacksonstore.MultiFormatStore; | ||
import org.spdx.library.InvalidSPDXAnalysisException; | ||
import org.spdx.library.ModelCopyManager; | ||
import org.spdx.library.Version; | ||
import org.spdx.library.model.Checksum; | ||
import org.spdx.library.model.SpdxDocument; | ||
import org.spdx.library.model.SpdxModelFactory; | ||
import org.spdx.library.model.enumerations.ChecksumAlgorithm; | ||
import org.spdx.storage.IModelStore; | ||
import org.spdx.storage.simple.InMemSpdxStore; | ||
|
||
import java.util.List; | ||
|
||
public class GenerationUtil { | ||
|
||
static Checksum createSha1Checksum(IModelStore modelStore, String documentUri) throws InvalidSPDXAnalysisException { | ||
return Checksum.create(modelStore, documentUri, ChecksumAlgorithm.SHA1, "d6a770ba38583ed4bb4525bd96e50461655d2758"); | ||
} | ||
Comment on lines
+18
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it funny that we are always generating a hardcoded checksum value 😂 . But it's fine for the time being, as long as the actual value is irrelevant |
||
|
||
static SpdxDocument createSpdxDocumentWithBasicInfo(String documentName) throws InvalidSPDXAnalysisException { | ||
var modelStore = new MultiFormatStore(new InMemSpdxStore(), MultiFormatStore.Format.XML, MultiFormatStore.Verbose.COMPACT); | ||
var documentUri = "https://some.namespace"; | ||
var copyManager = new ModelCopyManager(); | ||
|
||
var document = SpdxModelFactory.createSpdxDocument(modelStore, documentUri, copyManager); | ||
|
||
var creationInfo = document.createCreationInfo( | ||
List.of("Tool: test-tool"), "2022-01-01T00:00:00Z"); | ||
|
||
document.setCreationInfo(creationInfo); | ||
document.setSpecVersion(Version.TWO_POINT_THREE_VERSION); | ||
document.setName(documentName); | ||
|
||
return document; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package org.spdx.testbed; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import lombok.Builder; | ||
import org.spdx.testbed.util.Comparisons; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
@Builder | ||
public class TestResult { | ||
Boolean success; | ||
|
||
@Builder.Default | ||
Map<String, Comparisons.Tuple<?>> differences = Collections.emptyMap(); | ||
ArrayNode differences = (new ObjectMapper()).createArrayNode(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't create a new object mapper every time we need one. I created #28 to cover this, may require a little bit of thought |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a side remark (no need to change this): This could be done quite elegantly with a stream, using one
filter
to ignore theMISSING
type and then aforEach