@@ -36,6 +36,8 @@ import io.kotest.matchers.shouldNotBe
36
36
import org.cyclonedx.parsers.JsonParser
37
37
import org.cyclonedx.parsers.XmlParser
38
38
39
+ import org.ossreviewtoolkit.model.Identifier
40
+ import org.ossreviewtoolkit.model.OrtResult
39
41
import org.ossreviewtoolkit.plugins.reporters.cyclonedx.CycloneDxReporter.Companion.REPORT_BASE_FILENAME
40
42
import org.ossreviewtoolkit.reporter.ORT_RESULT
41
43
import org.ossreviewtoolkit.reporter.ORT_RESULT_WITH_ILLEGAL_COPYRIGHTS
@@ -94,6 +96,30 @@ class CycloneDxReporterFunTest : WordSpec({
94
96
}
95
97
}
96
98
99
+ " create the expected XML file with authors" {
100
+ val expectedBom = readResource("/cyclonedx-reporter-expected-result-with-authors.xml")
101
+
102
+ val ortResult = ORT_RESULT .withAuthors(
103
+ packageId = Identifier ("NPM :@ort:license-file:1.0"),
104
+ authors = setOf("Author One ", "Author Two ")
105
+ )
106
+
107
+ val bomFileResults = CycloneDxReporterFactory .create(
108
+ singleBom = true,
109
+ outputFileFormats = listOf("xml")
110
+ ).generateReport(ReporterInput (ortResult), outputDir)
111
+
112
+ bomFileResults.shouldBeSingleton {
113
+ it shouldBeSuccess { bomFile ->
114
+ bomFile shouldBe aFile()
115
+ bomFile shouldNotBe emptyFile()
116
+
117
+ val actualBom = bomFile.readText().patchCycloneDxResult().normalizeLineBreaks()
118
+ actualBom shouldBe expectedBom
119
+ }
120
+ }
121
+ }
122
+
97
123
" the expected XML file even if some copyrights contain non printable characters" {
98
124
val bomFileResults = CycloneDxReporterFactory .create(
99
125
singleBom = true,
@@ -224,6 +250,26 @@ class CycloneDxReporterFunTest : WordSpec({
224
250
}
225
251
})
226
252
253
+ /* *
254
+ * Add [authors] to the [package][packageId].
255
+ */
256
+ private fun OrtResult.withAuthors (packageId : Identifier , authors : Set <String >): OrtResult =
257
+ analyzer?.let { analyzer ->
258
+ copy(
259
+ analyzer = analyzer.copy(
260
+ result = analyzer.result.copy(
261
+ packages = analyzer.result.packages.map { pkg ->
262
+ if (pkg.id == packageId) {
263
+ pkg.copy(authors = authors)
264
+ } else {
265
+ pkg
266
+ }
267
+ }.toSet()
268
+ )
269
+ )
270
+ )
271
+ } ? : this
272
+
227
273
private fun String.patchCycloneDxResult (): String =
228
274
replaceFirst(
229
275
""" urn:uuid:[a-f0-9]{8}(?:-[a-f0-9]{4}){4}[a-f0-9]{8}""" .toRegex(),
0 commit comments