@@ -21,134 +21,115 @@ package org.eclipse.apoapsis.ortserver.workers.scanner
2121
2222import io.kotest.core.spec.style.StringSpec
2323import io.kotest.matchers.collections.shouldBeEmpty
24- import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
24+ import io.kotest.matchers.collections.shouldContain
2525import io.kotest.matchers.nulls.shouldBeNull
2626import io.kotest.matchers.shouldBe
2727
28- import io.mockk.every
2928import io.mockk.mockk
3029
31- import java.time.Instant
30+ import org.eclipse.apoapsis.ortserver.shared.orttestdata.OrtTestData
3231
33- import org.ossreviewtoolkit.model.ArtifactProvenance
34- import org.ossreviewtoolkit.model.Hash
3532import org.ossreviewtoolkit.model.Identifier
36- import org.ossreviewtoolkit.model.LicenseFinding
3733import org.ossreviewtoolkit.model.OrtResult
38- import org.ossreviewtoolkit.model.RemoteArtifact
39- import org.ossreviewtoolkit.model.ScanResult
40- import org.ossreviewtoolkit.model.ScanSummary
41- import org.ossreviewtoolkit.model.ScannerDetails
42- import org.ossreviewtoolkit.model.ScannerRun
43- import org.ossreviewtoolkit.model.TextLocation
34+ import org.ossreviewtoolkit.model.config.CopyrightGarbage
35+ import org.ossreviewtoolkit.model.config.LicenseFilePatterns
4436import org.ossreviewtoolkit.model.licenses.DefaultLicenseInfoProvider
4537import org.ossreviewtoolkit.model.licenses.LicenseInfoResolver
4638
4739class LicenseComputationTest : StringSpec ({
48- " computeDetectedLicenses should aggregate licenses across multiple provenances " {
49- val id = Identifier (" Maven ", "com.example", "test-pkg", "1.0")
40+ " computeDetectedLicenses returns curated licenses using OrtTestData " {
41+ val id = OrtTestData .pkgIdentifier
5042
51- val provenance1 = ArtifactProvenance (
52- sourceArtifact = RemoteArtifact (
53- url = "https://example.com/pkg1.jar",
54- hash = Hash .NONE
55- )
56- )
57- val provenance2 = ArtifactProvenance (
58- sourceArtifact = RemoteArtifact (
59- url = "https://example.com/pkg2.jar",
60- hash = Hash .NONE
61- )
62- )
43+ val ortResult = OrtTestData .result
6344
64- val scanResult1 = ScanResult (
65- provenance = provenance1,
66- scanner = ScannerDetails ("scanner1", "1.0", ""),
67- summary = ScanSummary (
68- startTime = Instant .now(),
69- endTime = Instant .now(),
70- licenseFindings = setOf(
71- LicenseFinding ("MIT ", TextLocation ("file1.txt", 1)),
72- LicenseFinding ("Apache -2.0", TextLocation ("file2.txt", 1))
73- )
74- )
45+ val resolver = LicenseInfoResolver (
46+ provider = DefaultLicenseInfoProvider (ortResult),
47+ copyrightGarbage = CopyrightGarbage (),
48+ addAuthorsToCopyrights = false,
49+ archiver = mockk(relaxed = true),
50+ licenseFilePatterns = LicenseFilePatterns .DEFAULT
7551 )
7652
77- val scanResult2 = ScanResult (
78- provenance = provenance2,
79- scanner = ScannerDetails ("scanner2", "1.0", ""),
80- summary = ScanSummary (
81- startTime = Instant .now(),
82- endTime = Instant .now(),
83- licenseFindings = setOf(
84- LicenseFinding ("Apache -2.0", TextLocation ("file3.txt", 1)),
85- LicenseFinding ("GPL -3.0", TextLocation ("file4.txt", 1))
53+ val result = computeDetectedLicenses(resolver, id)
54+
55+ result shouldContain " LicenseRef-detected1-concluded"
56+ result shouldContain " LicenseRef-detected2"
57+ result shouldContain " LicenseRef-detected3"
58+ }
59+
60+ " computeDetectedLicenses returns all detected licenses when no curations exist" {
61+ val id = OrtTestData .pkgIdentifier
62+
63+ val ortResult = OrtTestData .result.copy(
64+ repository = OrtTestData .repository.copy(
65+ config = OrtTestData .repository.config.copy(
66+ packageConfigurations = emptyList()
8667 )
68+ ),
69+ resolvedConfiguration = OrtTestData .resolvedConfiguration.copy(
70+ packageConfigurations = emptyList()
8771 )
8872 )
8973
90- val scannerRun = mockk<ScannerRun >(relaxed = true) {
91- every { getAllScanResults() } returns mapOf(id to listOf(scanResult1, scanResult2))
92- }
74+ val resolver = LicenseInfoResolver (
75+ provider = DefaultLicenseInfoProvider (ortResult),
76+ copyrightGarbage = CopyrightGarbage (),
77+ addAuthorsToCopyrights = false,
78+ archiver = mockk(relaxed = true),
79+ licenseFilePatterns = LicenseFilePatterns .DEFAULT
80+ )
9381
94- val result = computeDetectedLicenses(scannerRun , id)
82+ val result = computeDetectedLicenses(resolver , id)
9583
96- result shouldContainExactlyInAnyOrder setOf("MIT ", "Apache -2.0", "GPL -3.0")
84+ result shouldContain " LicenseRef-detected1"
85+ result shouldContain " LicenseRef-detected2"
86+ result shouldContain " LicenseRef-detected3"
87+ result shouldContain " LicenseRef-detected-excluded"
9788 }
9889
99- " computeDetectedLicenses should return empty set when no scan results exist " {
90+ " computeDetectedLicenses returns empty set when no scan results for id " {
10091 val id = Identifier ("Maven ", "com.example", "no-scan-pkg", "1.0")
10192
102- val scannerRun = mockk<ScannerRun >(relaxed = true) {
103- every { getAllScanResults() } returns emptyMap()
104- }
93+ val ortResult = OrtResult .EMPTY
10594
106- val result = computeDetectedLicenses(scannerRun, id)
95+ val resolver = LicenseInfoResolver (
96+ provider = DefaultLicenseInfoProvider (ortResult),
97+ copyrightGarbage = CopyrightGarbage (),
98+ addAuthorsToCopyrights = false,
99+ archiver = mockk(relaxed = true),
100+ licenseFilePatterns = LicenseFilePatterns .DEFAULT
101+ )
102+
103+ val result = computeDetectedLicenses(resolver, id)
107104
108105 result.shouldBeEmpty()
109106 }
110107
111- " computeDetectedLicenses should deduplicate licenses across provenances" {
112- val id = Identifier ("NPM ", "@example", "lib", "2.0")
113-
114- val provenance = ArtifactProvenance (
115- sourceArtifact = RemoteArtifact (
116- url = "https://example.com/lib.tgz",
117- hash = Hash .NONE
118- )
119- )
120-
121- val scanResult1 = ScanResult (
122- provenance = provenance,
123- scanner = ScannerDetails ("scanner1", "1.0", ""),
124- summary = ScanSummary (
125- startTime = Instant .now(),
126- endTime = Instant .now(),
127- licenseFindings = setOf(
128- LicenseFinding ("MIT ", TextLocation ("a.txt", 1))
108+ " computeDetectedLicenses deduplicates licenses across provenances" {
109+ val ortResult = OrtTestData .result.copy(
110+ repository = OrtTestData .repository.copy(
111+ config = OrtTestData .repository.config.copy(
112+ packageConfigurations = emptyList()
129113 )
114+ ),
115+ resolvedConfiguration = OrtTestData .resolvedConfiguration.copy(
116+ packageConfigurations = emptyList()
130117 )
131118 )
119+ val id = OrtTestData .pkgIdentifier
132120
133- val scanResult2 = ScanResult (
134- provenance = provenance,
135- scanner = ScannerDetails ("scanner2", "1.0", ""),
136- summary = ScanSummary (
137- startTime = Instant .now(),
138- endTime = Instant .now(),
139- licenseFindings = setOf(
140- LicenseFinding ("MIT ", TextLocation ("b.txt", 1))
141- )
142- )
121+ val resolver = LicenseInfoResolver (
122+ provider = DefaultLicenseInfoProvider (ortResult),
123+ copyrightGarbage = CopyrightGarbage (),
124+ addAuthorsToCopyrights = false,
125+ archiver = mockk(relaxed = true),
126+ licenseFilePatterns = LicenseFilePatterns .DEFAULT
143127 )
144128
145- val scannerRun = mockk<ScannerRun >(relaxed = true) {
146- every { getAllScanResults() } returns mapOf(id to listOf(scanResult1, scanResult2))
147- }
148-
149- val result = computeDetectedLicenses(scannerRun, id)
129+ val result = computeDetectedLicenses(resolver, id)
150130
151- result shouldBe setOf("MIT ")
131+ val licenseCounts = result.groupingBy { it }.eachCount()
132+ licenseCounts.values.all { it == 1 } shouldBe true
152133 }
153134
154135 " computeEffectiveLicense should return null when no license info is available" {
@@ -157,10 +138,10 @@ class LicenseComputationTest : StringSpec({
157138 val ortResult = OrtResult .EMPTY
158139 val resolver = LicenseInfoResolver (
159140 provider = DefaultLicenseInfoProvider (ortResult),
160- copyrightGarbage = org.ossreviewtoolkit.model.config. CopyrightGarbage (),
141+ copyrightGarbage = CopyrightGarbage (),
161142 addAuthorsToCopyrights = false,
162143 archiver = mockk(relaxed = true),
163- licenseFilePatterns = org.ossreviewtoolkit.model.config. LicenseFilePatterns .DEFAULT
144+ licenseFilePatterns = LicenseFilePatterns .DEFAULT
164145 )
165146
166147 val result = computeEffectiveLicense(resolver, id)
0 commit comments