Skip to content

Commit

Permalink
Fix after code review
Browse files Browse the repository at this point in the history
Signed-off-by: CatalinStratu <catalinstratu45@gmail.com>
  • Loading branch information
CatalinStratu committed Jan 2, 2023
1 parent d773abf commit 42b322c
Showing 1 changed file with 119 additions and 119 deletions.
238 changes: 119 additions & 119 deletions rdfloader/parser2v2/parse_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
// pads the content with the enclosing rdf:RDF tag
func wrapIntoTemplate(content string) string {
header := `<rdf:RDF
xmlns:spdx="http://spdx.org/rdf/terms#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#"
xmlns:doap="http://usefulinc.com/ns/doap#"
xmlns:j.0="http://www.w3.org/2009/pointers#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">`
xmlns:spdx="http://spdx.org/rdf/terms#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#"
xmlns:doap="http://usefulinc.com/ns/doap#"
xmlns:j.0="http://www.w3.org/2009/pointers#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">`
footer := `</rdf:RDF>`
return header + content + footer
}
Expand All @@ -49,13 +49,13 @@ func Test_rdfParser2_2_getArtifactFromNode(t *testing.T) {
// TestCase 1: artifactOf without project URI
rdfParser, err := parserFromBodyContent(
`<spdx:File>
<spdx:artifactOf>
<doap:Project>
<doap:homepage>http://www.openjena.org/</doap:homepage>
<doap:name>Jena</doap:name>
</doap:Project>
</spdx:artifactOf>
</spdx:File>`)
<spdx:artifactOf>
<doap:Project>
<doap:homepage>http://www.openjena.org/</doap:homepage>
<doap:name>Jena</doap:name>
</doap:Project>
</spdx:artifactOf>
</spdx:File>`)
if err != nil {
t.Errorf("unexpected error while parsing a valid example: %v", err)
}
Expand All @@ -78,13 +78,13 @@ func Test_rdfParser2_2_getArtifactFromNode(t *testing.T) {
// TestCase 2: artifactOf with a Project URI
rdfParser, err = parserFromBodyContent(
`<spdx:File>
<spdx:artifactOf>
<doap:Project rdf:about="http://subversion.apache.org/doap.rdf">
<doap:homepage>http://www.openjena.org/</doap:homepage>
<doap:name>Jena</doap:name>
</doap:Project>
</spdx:artifactOf>
</spdx:File>`)
<spdx:artifactOf>
<doap:Project rdf:about="http://subversion.apache.org/doap.rdf">
<doap:homepage>http://www.openjena.org/</doap:homepage>
<doap:name>Jena</doap:name>
</doap:Project>
</spdx:artifactOf>
</spdx:File>`)
if err != nil {
t.Errorf("unexpected error while parsing a valid example: %v", err)
}
Expand All @@ -101,14 +101,14 @@ func Test_rdfParser2_2_getArtifactFromNode(t *testing.T) {
// TestCase 3: artifactOf with unknown predicate
rdfParser, err = parserFromBodyContent(
`<spdx:File>
<spdx:artifactOf>
<doap:Project rdf:about="http://subversion.apache.org/doap.rdf">
<doap:homepage>http://www.openjena.org/</doap:homepage>
<doap:name>Jena</doap:name>
<doap:invalidTag rdf:ID="invalid"/>
</doap:Project>
</spdx:artifactOf>
</spdx:File>`)
<spdx:artifactOf>
<doap:Project rdf:about="http://subversion.apache.org/doap.rdf">
<doap:homepage>http://www.openjena.org/</doap:homepage>
<doap:name>Jena</doap:name>
<doap:invalidTag rdf:ID="invalid"/>
</doap:Project>
</spdx:artifactOf>
</spdx:File>`)
if err != nil {
t.Errorf("unexpected error while parsing a valid example: %v", err)
}
Expand Down Expand Up @@ -196,11 +196,11 @@ func Test_setFileIdentifier(t *testing.T) {
func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) {
// TestCase 1: md5 checksum
parser, _ := parserFromBodyContent(`
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_md5" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_md5" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
checksumNode := gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject
file := &v2_2.File{}
err := parser.setFileChecksumFromNode(file, checksumNode)
Expand All @@ -227,11 +227,11 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) {

// TestCase 2: valid sha1 checksum
parser, _ = parserFromBodyContent(`
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject
file = &v2_2.File{}
err = parser.setFileChecksumFromNode(file, checksumNode)
Expand All @@ -257,11 +257,11 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) {

// TestCase 3: valid sha256 checksum
parser, _ = parserFromBodyContent(`
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha256" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha256" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject
file = &v2_2.File{}
err = parser.setFileChecksumFromNode(file, checksumNode)
Expand Down Expand Up @@ -300,11 +300,11 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) {

// TestCase 5: invalid checksum algorithm
parser, _ = parserFromBodyContent(`
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_md43" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_md43" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject
file = &v2_2.File{}
err = parser.setFileChecksumFromNode(file, checksumNode)
Expand All @@ -314,11 +314,11 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) {

// TestCase 6: valid checksum algorithm which is invalid for file (like md4, md6, sha384, etc.)
parser, _ = parserFromBodyContent(`
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha2000" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha2000" />
<spdx:checksumValue>d2356e0fe1c0b85285d83c6b2ad51b5f</spdx:checksumValue>
</spdx:Checksum>
`)
checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject
file = &v2_2.File{}
err = parser.setFileChecksumFromNode(file, checksumNode)
Expand All @@ -340,10 +340,10 @@ func Test_rdfParser2_2_getFileFromNode(t *testing.T) {

// TestCase 2: invalid fileType
parser, _ = parserFromBodyContent(`
<spdx:File rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#SPDXRef-item177">
<spdx:fileType rdf:resource="http://spdx.org/rdf/terms#source"/>
</spdx:File>
`)
<spdx:File rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#SPDXRef-item177">
<spdx:fileType rdf:resource="http://spdx.org/rdf/terms#source"/>
</spdx:File>
`)
fileNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_FILE)[0].Subject
_, err = parser.getFileFromNode(fileNode)
if err == nil {
Expand Down Expand Up @@ -398,10 +398,10 @@ func Test_rdfParser2_2_getFileFromNode(t *testing.T) {

// TestCase 6: invalid file dependency
parser, _ = parserFromBodyContent(`
<spdx:File rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#SPDXRef-item177">
<spdx:fileDependency rdf:resource="http://spdx.org/spdxdocs/spdx-example#CommonsLangSrc"/>
</spdx:File>
`)
<spdx:File rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#SPDXRef-item177">
<spdx:fileDependency rdf:resource="http://spdx.org/spdxdocs/spdx-example#CommonsLangSrc"/>
</spdx:File>
`)
fileNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_FILE)[0].Subject
_, err = parser.getFileFromNode(fileNode)
if err == nil {
Expand Down Expand Up @@ -454,10 +454,10 @@ func Test_rdfParser2_2_getFileFromNode(t *testing.T) {

// TestCase 9: invalid licenseInfoInFile.
parser, _ = parserFromBodyContent(`
<spdx:File rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#SPDXRef-item177">
<spdx:licenseInfoInFile rdf:resource="http://spdx.org/licenses/DC0-1.0" />
</spdx:File>
`)
<spdx:File rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#SPDXRef-item177">
<spdx:licenseInfoInFile rdf:resource="http://spdx.org/licenses/DC0-1.0" />
</spdx:File>
`)
fileNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_FILE)[0].Subject
_, err = parser.getFileFromNode(fileNode)
if err == nil {
Expand Down Expand Up @@ -519,65 +519,65 @@ func Test_rdfParser2_2_getFileFromNode(t *testing.T) {

// TestCase 12: checking if recursive dependencies are resolved.
parser, _ = parserFromBodyContent(`
<spdx:File rdf:about="#SPDXRef-ParentFile">
<spdx:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
<spdx:fileDependency>
<spdx:File rdf:about="#SPDXRef-ChildFile">
<spdx:fileDependency>
<spdx:File rdf:about="#SPDXRef-ParentFile">
<spdx:fileName>ParentFile</spdx:fileName>
</spdx:File>
</spdx:fileDependency>
</spdx:File>
</spdx:fileDependency>
</spdx:File>
`)
<spdx:File rdf:about="#SPDXRef-ParentFile">
<spdx:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
<spdx:fileDependency>
<spdx:File rdf:about="#SPDXRef-ChildFile">
<spdx:fileDependency>
<spdx:File rdf:about="#SPDXRef-ParentFile">
<spdx:fileName>ParentFile</spdx:fileName>
</spdx:File>
</spdx:fileDependency>
</spdx:File>
</spdx:fileDependency>
</spdx:File>
`)
fileNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_FILE)[0].Subject
file, err = parser.getFileFromNode(fileNode)

// TestCase 11: all valid attribute and it's values.
parser, _ = parserFromBodyContent(`
<spdx:File rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#SPDXRef-item177">
<spdx:fileName>time-1.9/ChangeLog</spdx:fileName>
<spdx:name/>
<spdx:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
<spdx:checksum>
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1" />
<spdx:checksumValue>0a3a0e1ab72b7c132f5021c538a7a3ea6d539bcd</spdx:checksumValue>
</spdx:Checksum>
</spdx:checksum>
<spdx:licenseConcluded rdf:resource="http://spdx.org/rdf/terms#noassertion" />
<spdx:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#NOASSERTION" />
<spdx:licenseComments>no comments</spdx:licenseComments>
<spdx:copyrightText>from spdx file</spdx:copyrightText>
<spdx:artifactOf>
<doap:Project>
<doap:homepage>http://www.openjena.org/</doap:homepage>
<doap:name>Jena</doap:name>
</doap:Project>
</spdx:artifactOf>
<rdfs:comment>no comments</rdfs:comment>
<spdx:noticeText rdf:resource="http://spdx.org/rdf/terms#noassertion"/>
<spdx:fileContributor>Some Organization</spdx:fileContributor>
<spdx:fileDependency rdf:resource="http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#SPDXRef-CommonsLangSrc"/>
<spdx:attributionText>attribution text</spdx:attributionText>
<spdx:annotation>
<spdx:Annotation>
<spdx:annotationDate>2011-01-29T18:30:22Z</spdx:annotationDate>
<rdfs:comment>File level annotation copied from a spdx document</rdfs:comment>
<spdx:annotator>Person: File Commenter</spdx:annotator>
<spdx:annotationType rdf:resource="http://spdx.org/rdf/terms#annotationType_other"/>
</spdx:Annotation>
</spdx:annotation>
<spdx:relationship>
<spdx:Relationship>
<spdx:relationshipType rdf:resource="http://spdx.org/rdf/terms#relationshipType_contains"/>
<spdx:relatedSpdxElement rdf:resource="http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#SPDXRef-Package"/>
</spdx:Relationship>
</spdx:relationship>
</spdx:File>
`)
<spdx:File rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#SPDXRef-item177">
<spdx:fileName>time-1.9/ChangeLog</spdx:fileName>
<spdx:name/>
<spdx:fileType rdf:resource="http://spdx.org/rdf/terms#fileType_source"/>
<spdx:checksum>
<spdx:Checksum>
<spdx:algorithm rdf:resource="http://spdx.org/rdf/terms#checksumAlgorithm_sha1" />
<spdx:checksumValue>0a3a0e1ab72b7c132f5021c538a7a3ea6d539bcd</spdx:checksumValue>
</spdx:Checksum>
</spdx:checksum>
<spdx:licenseConcluded rdf:resource="http://spdx.org/rdf/terms#noassertion" />
<spdx:licenseInfoInFile rdf:resource="http://spdx.org/rdf/terms#NOASSERTION" />
<spdx:licenseComments>no comments</spdx:licenseComments>
<spdx:copyrightText>from spdx file</spdx:copyrightText>
<spdx:artifactOf>
<doap:Project>
<doap:homepage>http://www.openjena.org/</doap:homepage>
<doap:name>Jena</doap:name>
</doap:Project>
</spdx:artifactOf>
<rdfs:comment>no comments</rdfs:comment>
<spdx:noticeText rdf:resource="http://spdx.org/rdf/terms#noassertion"/>
<spdx:fileContributor>Some Organization</spdx:fileContributor>
<spdx:fileDependency rdf:resource="http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#SPDXRef-CommonsLangSrc"/>
<spdx:attributionText>attribution text</spdx:attributionText>
<spdx:annotation>
<spdx:Annotation>
<spdx:annotationDate>2011-01-29T18:30:22Z</spdx:annotationDate>
<rdfs:comment>File level annotation copied from a spdx document</rdfs:comment>
<spdx:annotator>Person: File Commenter</spdx:annotator>
<spdx:annotationType rdf:resource="http://spdx.org/rdf/terms#annotationType_other"/>
</spdx:Annotation>
</spdx:annotation>
<spdx:relationship>
<spdx:Relationship>
<spdx:relationshipType rdf:resource="http://spdx.org/rdf/terms#relationshipType_contains"/>
<spdx:relatedSpdxElement rdf:resource="http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#SPDXRef-Package"/>
</spdx:Relationship>
</spdx:relationship>
</spdx:File>
`)
fileNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_FILE)[0].Subject
file, err = parser.getFileFromNode(fileNode)
if err != nil {
Expand Down

0 comments on commit 42b322c

Please sign in to comment.