From 1f762430d37bd8b3599700ea872e0dc79a9e21d0 Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Mon, 25 Nov 2024 00:27:15 +0100 Subject: [PATCH] test(plugins): Simplify creating plugin instances Use the convenience function introduced in the previous commit to simplify the creation of plugin instances in tests. Signed-off-by: Martin Nonnenmacher --- .../osv/src/funTest/kotlin/OsvFunTest.kt | 3 +- .../funTest/kotlin/VulnerableCodeFunTest.kt | 9 +-- ...lyDefinedPackageCurationProviderFunTest.kt | 5 +- ...OrtConfigPackageCurationProviderFunTest.kt | 3 +- .../kotlin/DocBookTemplateReporterFunTest.kt | 3 +- .../kotlin/HtmlTemplateReporterFunTest.kt | 3 +- .../kotlin/ManPageTemplateReporterFunTest.kt | 3 +- .../kotlin/PdfTemplateReporterFunTest.kt | 13 +-- .../kotlin/CycloneDxReporterFunTest.kt | 80 +++++++++---------- .../kotlin/EvaluatedModelReporterFunTest.kt | 40 ++++------ .../funTest/kotlin/OpossumReporterFunTest.kt | 4 +- .../src/test/kotlin/OpossumReporterTest.kt | 6 +- .../funTest/kotlin/WebAppReporterFunTest.kt | 3 +- 13 files changed, 76 insertions(+), 99 deletions(-) diff --git a/plugins/advisors/osv/src/funTest/kotlin/OsvFunTest.kt b/plugins/advisors/osv/src/funTest/kotlin/OsvFunTest.kt index ace5d0484a4da..2722276f19c09 100644 --- a/plugins/advisors/osv/src/funTest/kotlin/OsvFunTest.kt +++ b/plugins/advisors/osv/src/funTest/kotlin/OsvFunTest.kt @@ -33,7 +33,6 @@ import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.Package import org.ossreviewtoolkit.model.readValue import org.ossreviewtoolkit.model.utils.toPurl -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.utils.test.getAssetFile class OsvFunTest : StringSpec({ @@ -89,7 +88,7 @@ class OsvFunTest : StringSpec({ private fun identifierToPackage(id: String): Package = Identifier(id).let { Package.EMPTY.copy(id = it, purl = it.toPurl()) } -private fun createOsv(): Osv = OsvFactory().create(PluginConfig()) +private fun createOsv(): Osv = OsvFactory.create() private fun Map.patchTimes(): Map = mapValues { (_, advisorResult) -> diff --git a/plugins/advisors/vulnerable-code/src/funTest/kotlin/VulnerableCodeFunTest.kt b/plugins/advisors/vulnerable-code/src/funTest/kotlin/VulnerableCodeFunTest.kt index 1ee1aa4bb9c90..e1ef63ca18a00 100644 --- a/plugins/advisors/vulnerable-code/src/funTest/kotlin/VulnerableCodeFunTest.kt +++ b/plugins/advisors/vulnerable-code/src/funTest/kotlin/VulnerableCodeFunTest.kt @@ -29,12 +29,11 @@ import io.kotest.matchers.shouldBe import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.Package import org.ossreviewtoolkit.model.utils.toPurl -import org.ossreviewtoolkit.plugins.api.PluginConfig class VulnerableCodeFunTest : WordSpec({ "Vulnerable Go packages" should { "return findings for QUIC" { - val vc = VulnerableCodeFactory().create(PluginConfig()) + val vc = VulnerableCodeFactory.create() val id = Identifier("Go::github.com/quic-go/quic-go:0.40.0") val pkg = Package.EMPTY.copy(id, purl = id.toPurl()) @@ -60,7 +59,7 @@ class VulnerableCodeFunTest : WordSpec({ "Vulnerable Maven packages" should { "return findings for Guava" { - val vc = VulnerableCodeFactory().create(PluginConfig()) + val vc = VulnerableCodeFactory.create() val id = Identifier("Maven:com.google.guava:guava:19.0") val pkg = Package.EMPTY.copy(id, purl = id.toPurl()) @@ -86,7 +85,7 @@ class VulnerableCodeFunTest : WordSpec({ } "return findings for Commons-Compress" { - val vc = VulnerableCodeFactory().create(PluginConfig()) + val vc = VulnerableCodeFactory.create() val id = Identifier("Maven:org.apache.commons:commons-compress:1.23.0") val pkg = Package.EMPTY.copy(id, purl = id.toPurl()) @@ -112,7 +111,7 @@ class VulnerableCodeFunTest : WordSpec({ "Vulnerable NPM packages" should { "return findings for Elliptic" { - val vc = VulnerableCodeFactory().create(PluginConfig()) + val vc = VulnerableCodeFactory.create() val id = Identifier("NPM::elliptic:6.5.7") val pkg = Package.EMPTY.copy(id, purl = id.toPurl()) diff --git a/plugins/package-curation-providers/clearly-defined/src/funTest/kotlin/ClearlyDefinedPackageCurationProviderFunTest.kt b/plugins/package-curation-providers/clearly-defined/src/funTest/kotlin/ClearlyDefinedPackageCurationProviderFunTest.kt index ee9d6e0621781..58231d6b9b059 100644 --- a/plugins/package-curation-providers/clearly-defined/src/funTest/kotlin/ClearlyDefinedPackageCurationProviderFunTest.kt +++ b/plugins/package-curation-providers/clearly-defined/src/funTest/kotlin/ClearlyDefinedPackageCurationProviderFunTest.kt @@ -31,12 +31,11 @@ import kotlin.time.Duration.Companion.seconds import org.ossreviewtoolkit.clients.clearlydefined.ClearlyDefinedService.Server import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.Package -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.utils.spdx.toSpdx class ClearlyDefinedPackageCurationProviderFunTest : WordSpec({ "The production server" should { - val provider = ClearlyDefinedPackageCurationProviderFactory().create(PluginConfig()) + val provider = ClearlyDefinedPackageCurationProviderFactory.create() "return an existing curation for the javax.servlet-api Maven package" { val packages = createPackagesFromIds("Maven:javax.servlet:javax.servlet-api:3.1.0") @@ -93,7 +92,7 @@ class ClearlyDefinedPackageCurationProviderFunTest : WordSpec({ } "be retrieved for packages without a namespace" { - val provider = ClearlyDefinedPackageCurationProviderFactory().create(PluginConfig()) + val provider = ClearlyDefinedPackageCurationProviderFactory.create() val packages = createPackagesFromIds("NPM::acorn:0.6.0") withRetry { diff --git a/plugins/package-curation-providers/ort-config/src/funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt b/plugins/package-curation-providers/ort-config/src/funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt index 0aaeebf649217..ef8d5b8330ab6 100644 --- a/plugins/package-curation-providers/ort-config/src/funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt +++ b/plugins/package-curation-providers/ort-config/src/funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt @@ -26,10 +26,9 @@ import io.kotest.matchers.shouldNot import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.Package -import org.ossreviewtoolkit.plugins.api.PluginConfig class OrtConfigPackageCurationProviderFunTest : StringSpec({ - fun createProvider() = OrtConfigPackageCurationProviderFactory().create(PluginConfig()) + fun createProvider() = OrtConfigPackageCurationProviderFactory.create() "The provider succeeds to return known curations for packages" { val azureCore = Identifier("NuGet:Azure:Core:1.22.0") diff --git a/plugins/reporters/asciidoc/src/funTest/kotlin/DocBookTemplateReporterFunTest.kt b/plugins/reporters/asciidoc/src/funTest/kotlin/DocBookTemplateReporterFunTest.kt index 8a338c082dcbe..c4318a89eeca6 100644 --- a/plugins/reporters/asciidoc/src/funTest/kotlin/DocBookTemplateReporterFunTest.kt +++ b/plugins/reporters/asciidoc/src/funTest/kotlin/DocBookTemplateReporterFunTest.kt @@ -25,7 +25,6 @@ import io.kotest.matchers.should import java.time.LocalDate -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.reporter.ORT_RESULT import org.ossreviewtoolkit.reporter.ReporterInput import org.ossreviewtoolkit.utils.test.getAssetFile @@ -35,7 +34,7 @@ class DocBookTemplateReporterFunTest : StringSpec({ "DocBook report is created from default template" { val expectedResultFile = getAssetFile("docbook-template-reporter-expected-result.xml") - val reportContent = DocBookTemplateReporterFactory().create(PluginConfig()) + val reportContent = DocBookTemplateReporterFactory.create() .generateReport(ReporterInput(ORT_RESULT), tempdir()) .single().getOrThrow().readText() diff --git a/plugins/reporters/asciidoc/src/funTest/kotlin/HtmlTemplateReporterFunTest.kt b/plugins/reporters/asciidoc/src/funTest/kotlin/HtmlTemplateReporterFunTest.kt index 9d33016156e94..5e1ab4289b327 100644 --- a/plugins/reporters/asciidoc/src/funTest/kotlin/HtmlTemplateReporterFunTest.kt +++ b/plugins/reporters/asciidoc/src/funTest/kotlin/HtmlTemplateReporterFunTest.kt @@ -23,7 +23,6 @@ import io.kotest.core.spec.style.StringSpec import io.kotest.engine.spec.tempdir import io.kotest.matchers.shouldBe -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.reporter.ORT_RESULT import org.ossreviewtoolkit.reporter.ReporterInput import org.ossreviewtoolkit.utils.test.getAssetFile @@ -33,7 +32,7 @@ class HtmlTemplateReporterFunTest : StringSpec({ "HTML report is created from default template" { val expectedResultFile = getAssetFile("html-template-reporter-expected-result.html") - val reporter = HtmlTemplateReporterFactory().create(PluginConfig()) + val reporter = HtmlTemplateReporterFactory.create() val reportContent = reporter.generateReport(ReporterInput(ORT_RESULT), tempdir()) .single().getOrThrow().readText() diff --git a/plugins/reporters/asciidoc/src/funTest/kotlin/ManPageTemplateReporterFunTest.kt b/plugins/reporters/asciidoc/src/funTest/kotlin/ManPageTemplateReporterFunTest.kt index 10caa486f0c5a..dbfa9d19a3cc9 100644 --- a/plugins/reporters/asciidoc/src/funTest/kotlin/ManPageTemplateReporterFunTest.kt +++ b/plugins/reporters/asciidoc/src/funTest/kotlin/ManPageTemplateReporterFunTest.kt @@ -25,7 +25,6 @@ import io.kotest.matchers.should import java.time.LocalDate -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.reporter.ORT_RESULT import org.ossreviewtoolkit.reporter.ReporterInput import org.ossreviewtoolkit.utils.test.getAssetFile @@ -34,7 +33,7 @@ import org.ossreviewtoolkit.utils.test.matchExpectedResult class ManPageTemplateReporterFunTest : StringSpec({ "ManPage report is created from default template" { val expectedResultFile = getAssetFile("manpage-template-reporter-expected-result.1") - val reporter = ManPageTemplateReporterFactory().create(PluginConfig()) + val reporter = ManPageTemplateReporterFactory.create() val reportContent = reporter.generateReport(ReporterInput(ORT_RESULT), tempdir()) .single().getOrThrow().readText() diff --git a/plugins/reporters/asciidoc/src/funTest/kotlin/PdfTemplateReporterFunTest.kt b/plugins/reporters/asciidoc/src/funTest/kotlin/PdfTemplateReporterFunTest.kt index 94b0944133c3f..f45690af7d523 100644 --- a/plugins/reporters/asciidoc/src/funTest/kotlin/PdfTemplateReporterFunTest.kt +++ b/plugins/reporters/asciidoc/src/funTest/kotlin/PdfTemplateReporterFunTest.kt @@ -29,15 +29,13 @@ import io.kotest.matchers.result.shouldBeSuccess import io.kotest.matchers.should import io.kotest.matchers.shouldBe -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.reporter.ORT_RESULT import org.ossreviewtoolkit.reporter.ORT_RESULT_WITH_VULNERABILITIES import org.ossreviewtoolkit.reporter.ReporterInput -import org.ossreviewtoolkit.utils.common.Options class PdfTemplateReporterFunTest : StringSpec({ "The report is created successfully from an existing result and default template" { - val reportFileResults = createReporter().generateReport(ReporterInput(ORT_RESULT), tempdir()) + val reportFileResults = PdfTemplateReporterFactory.create().generateReport(ReporterInput(ORT_RESULT), tempdir()) reportFileResults.shouldBeSingleton { it shouldBeSuccess { reportFile -> @@ -54,20 +52,20 @@ class PdfTemplateReporterFunTest : StringSpec({ "Report generation is aborted when path to non-existing PDF theme file is given" { shouldThrow { - createReporter(mapOf("pdf.theme.file" to "dummy.file")) + PdfTemplateReporterFactory.create(pdfThemeFile = "dummy.file") .generateReport(ReporterInput(ORT_RESULT), tempdir()) } } "Report generation is aborted when a non-existent PDF fonts directory is given" { shouldThrow { - createReporter(mapOf("pdf.fonts.dir" to "fake.path")) + PdfTemplateReporterFactory.create(pdfFontsDir = "fake.path") .generateReport(ReporterInput(ORT_RESULT), tempdir()) } } "Advisor reports are generated if the result contains an advisor section" { - val reportFileResults = createReporter().generateReport( + val reportFileResults = PdfTemplateReporterFactory.create().generateReport( ReporterInput(ORT_RESULT_WITH_VULNERABILITIES), tempdir() ) @@ -76,6 +74,3 @@ class PdfTemplateReporterFunTest : StringSpec({ reportFileNames.shouldContainAll("AsciiDoc_vulnerability_report.pdf", "AsciiDoc_defect_report.pdf") } }) - -private fun createReporter(options: Options = emptyMap()) = - PdfTemplateReporterFactory().create(PluginConfig(options = options)) diff --git a/plugins/reporters/cyclonedx/src/funTest/kotlin/CycloneDxReporterFunTest.kt b/plugins/reporters/cyclonedx/src/funTest/kotlin/CycloneDxReporterFunTest.kt index 1667f2d05e7cc..2dbcd16cd6a36 100644 --- a/plugins/reporters/cyclonedx/src/funTest/kotlin/CycloneDxReporterFunTest.kt +++ b/plugins/reporters/cyclonedx/src/funTest/kotlin/CycloneDxReporterFunTest.kt @@ -33,19 +33,14 @@ import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import java.io.File - import org.cyclonedx.parsers.JsonParser import org.cyclonedx.parsers.XmlParser -import org.ossreviewtoolkit.model.OrtResult -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.plugins.reporters.cyclonedx.CycloneDxReporter.Companion.REPORT_BASE_FILENAME import org.ossreviewtoolkit.reporter.ORT_RESULT import org.ossreviewtoolkit.reporter.ORT_RESULT_WITH_ILLEGAL_COPYRIGHTS import org.ossreviewtoolkit.reporter.ORT_RESULT_WITH_VULNERABILITIES import org.ossreviewtoolkit.reporter.ReporterInput -import org.ossreviewtoolkit.utils.common.Options import org.ossreviewtoolkit.utils.common.normalizeLineBreaks import org.ossreviewtoolkit.utils.test.getAssetAsString @@ -53,16 +48,12 @@ class CycloneDxReporterFunTest : WordSpec({ val defaultSchemaVersion = DEFAULT_SCHEMA_VERSION.versionString val outputDir = tempdir() - fun generateReport(result: OrtResult, options: Options): List> = - CycloneDxReporterFactory().create(PluginConfig(options)).generateReport(ReporterInput(result), outputDir) - "BOM generation with single option" should { - val optionSingle = mapOf("single.bom" to "true") - "create just one file" { - val jsonOptions = optionSingle + mapOf("output.file.formats" to "json") - - val bomFileResults = generateReport(ORT_RESULT, jsonOptions) + val bomFileResults = CycloneDxReporterFactory.create( + singleBom = true, + outputFileFormats = listOf("json") + ).generateReport(ReporterInput(ORT_RESULT), outputDir) bomFileResults.shouldBeSingleton { it shouldBeSuccess outputDir.resolve("$REPORT_BASE_FILENAME.json") @@ -70,9 +61,10 @@ class CycloneDxReporterFunTest : WordSpec({ } "be valid XML according to schema version $defaultSchemaVersion" { - val xmlOptions = optionSingle + mapOf("output.file.formats" to "xml") - - val bomFileResults = generateReport(ORT_RESULT, xmlOptions) + val bomFileResults = CycloneDxReporterFactory.create( + singleBom = true, + outputFileFormats = listOf("xml") + ).generateReport(ReporterInput(ORT_RESULT), outputDir) bomFileResults.shouldBeSingleton { it shouldBeSuccess { bomFile -> @@ -85,9 +77,11 @@ class CycloneDxReporterFunTest : WordSpec({ "create the expected XML file" { val expectedBom = getAssetAsString("cyclonedx-reporter-expected-result.xml") - val xmlOptions = optionSingle + mapOf("output.file.formats" to "xml") - val bomFileResults = generateReport(ORT_RESULT_WITH_VULNERABILITIES, xmlOptions) + val bomFileResults = CycloneDxReporterFactory.create( + singleBom = true, + outputFileFormats = listOf("xml") + ).generateReport(ReporterInput(ORT_RESULT_WITH_VULNERABILITIES), outputDir) bomFileResults.shouldBeSingleton { it shouldBeSuccess { bomFile -> @@ -101,9 +95,10 @@ class CycloneDxReporterFunTest : WordSpec({ } "the expected XML file even if some copyrights contain non printable characters" { - val xmlOptions = optionSingle + mapOf("output.file.formats" to "xml") - - val bomFileResults = generateReport(ORT_RESULT_WITH_ILLEGAL_COPYRIGHTS, xmlOptions) + val bomFileResults = CycloneDxReporterFactory.create( + singleBom = true, + outputFileFormats = listOf("xml") + ).generateReport(ReporterInput(ORT_RESULT_WITH_ILLEGAL_COPYRIGHTS), outputDir) bomFileResults.shouldBeSingleton { it shouldBeSuccess { bomFile -> @@ -114,9 +109,10 @@ class CycloneDxReporterFunTest : WordSpec({ } "be valid JSON according to schema version $defaultSchemaVersion" { - val jsonOptions = optionSingle + mapOf("output.file.formats" to "json") - - val bomFileResults = generateReport(ORT_RESULT_WITH_VULNERABILITIES, jsonOptions) + val bomFileResults = CycloneDxReporterFactory.create( + singleBom = true, + outputFileFormats = listOf("json") + ).generateReport(ReporterInput(ORT_RESULT_WITH_VULNERABILITIES), outputDir) bomFileResults.shouldBeSingleton { it shouldBeSuccess { bomFile -> @@ -129,9 +125,11 @@ class CycloneDxReporterFunTest : WordSpec({ "create the expected JSON file" { val expectedBom = getAssetAsString("cyclonedx-reporter-expected-result.json") - val jsonOptions = optionSingle + mapOf("output.file.formats" to "json") - val bomFileResults = generateReport(ORT_RESULT_WITH_VULNERABILITIES, jsonOptions) + val bomFileResults = CycloneDxReporterFactory.create( + singleBom = true, + outputFileFormats = listOf("json") + ).generateReport(ReporterInput(ORT_RESULT_WITH_VULNERABILITIES), outputDir) bomFileResults.shouldBeSingleton { it shouldBeSuccess { bomFile -> @@ -146,22 +144,22 @@ class CycloneDxReporterFunTest : WordSpec({ } "BOM generation with multi option" should { - val optionMulti = mapOf("single.bom" to "false") - "create one file per project" { - val jsonOptions = optionMulti + mapOf("output.file.formats" to "json") - - val bomFileResults = generateReport(ORT_RESULT_WITH_VULNERABILITIES, jsonOptions) + val bomFileResults = CycloneDxReporterFactory.create( + singleBom = false, + outputFileFormats = listOf("json") + ).generateReport(ReporterInput(ORT_RESULT_WITH_VULNERABILITIES), outputDir) bomFileResults shouldHaveSize 2 bomFileResults.forAll { it.shouldBeSuccess() } } "generate valid XML files according to schema version $defaultSchemaVersion" { - val xmlOptions = optionMulti + mapOf("output.file.formats" to "xml") - val (bomFileResultWithFindings, bomFileResultWithoutFindings) = - generateReport(ORT_RESULT_WITH_VULNERABILITIES, xmlOptions).also { + CycloneDxReporterFactory.create( + singleBom = false, + outputFileFormats = listOf("xml") + ).generateReport(ReporterInput(ORT_RESULT_WITH_VULNERABILITIES), outputDir).also { it shouldHaveSize 2 } @@ -179,10 +177,11 @@ class CycloneDxReporterFunTest : WordSpec({ } "generate valid JSON files according to schema version $defaultSchemaVersion" { - val jsonOptions = optionMulti + mapOf("output.file.formats" to "json") - val (bomFileResultWithFindings, bomFileResultWithoutFindings) = - generateReport(ORT_RESULT_WITH_VULNERABILITIES, jsonOptions).also { + CycloneDxReporterFactory.create( + singleBom = false, + outputFileFormats = listOf("json") + ).generateReport(ReporterInput(ORT_RESULT_WITH_VULNERABILITIES), outputDir).also { it shouldHaveSize 2 } @@ -200,10 +199,11 @@ class CycloneDxReporterFunTest : WordSpec({ } "generate expected JSON files" { - val jsonOptions = optionMulti + mapOf("output.file.formats" to "json") - val (bomFileResultWithFindings, bomFileResultWithoutFindings) = - generateReport(ORT_RESULT, jsonOptions).also { + CycloneDxReporterFactory.create( + singleBom = false, + outputFileFormats = listOf("json") + ).generateReport(ReporterInput(ORT_RESULT), outputDir).also { it shouldHaveSize 2 } diff --git a/plugins/reporters/evaluated-model/src/funTest/kotlin/EvaluatedModelReporterFunTest.kt b/plugins/reporters/evaluated-model/src/funTest/kotlin/EvaluatedModelReporterFunTest.kt index ecfe20f6cae5e..4ff82e3b6f31d 100644 --- a/plugins/reporters/evaluated-model/src/funTest/kotlin/EvaluatedModelReporterFunTest.kt +++ b/plugins/reporters/evaluated-model/src/funTest/kotlin/EvaluatedModelReporterFunTest.kt @@ -19,57 +19,51 @@ package org.ossreviewtoolkit.plugins.reporters.evaluatedmodel -import io.kotest.core.TestConfiguration import io.kotest.core.spec.style.WordSpec import io.kotest.engine.spec.tempdir import io.kotest.matchers.shouldBe -import org.ossreviewtoolkit.model.FileFormat import org.ossreviewtoolkit.model.OrtResult -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.reporter.ReporterInput import org.ossreviewtoolkit.utils.common.normalizeLineBreaks import org.ossreviewtoolkit.utils.test.getAssetAsString import org.ossreviewtoolkit.utils.test.readOrtResult class EvaluatedModelReporterFunTest : WordSpec({ + fun EvaluatedModelReporter.generateReport(ortResult: OrtResult) = + generateReport( + input = ReporterInput( + ortResult = ortResult, + howToFixTextProvider = { "Some how to fix text." } + ), + outputDir = tempdir() + ).single().getOrThrow().readText().normalizeLineBreaks() + "EvaluatedModelReporter" should { "create the expected JSON output" { val expectedResult = getAssetAsString("evaluated-model-reporter-test-expected-output.json") val ortResult = readOrtResult("src/funTest/assets/reporter-test-input.yml") - generateReport(ortResult) shouldBe expectedResult + EvaluatedModelReporterFactory.create().generateReport(ortResult) shouldBe expectedResult } "create the expected YAML output" { val expectedResult = getAssetAsString("evaluated-model-reporter-test-expected-output.yml") val ortResult = readOrtResult("src/funTest/assets/reporter-test-input.yml") - val options = mapOf(EvaluatedModelReporter.OPTION_OUTPUT_FILE_FORMATS to FileFormat.YAML.fileExtension) - generateReport(ortResult, options) shouldBe expectedResult + EvaluatedModelReporterFactory.create( + outputFileFormats = listOf("yml") + ).generateReport(ortResult) shouldBe expectedResult } "create the expected YAML output with dependency tree de-duplication enabled" { val expectedResult = getAssetAsString("evaluated-model-reporter-test-deduplicate-expected-output.yml") val ortResult = readOrtResult("src/funTest/assets/reporter-test-input.yml") - val options = mapOf( - EvaluatedModelReporter.OPTION_OUTPUT_FILE_FORMATS to FileFormat.YAML.fileExtension, - EvaluatedModelReporter.OPTION_DEDUPLICATE_DEPENDENCY_TREE to "true" - ) - generateReport(ortResult, options) shouldBe expectedResult + EvaluatedModelReporterFactory.create( + outputFileFormats = listOf("yml"), + deduplicateDependencyTree = true + ).generateReport(ortResult) shouldBe expectedResult } } }) - -private fun TestConfiguration.generateReport(ortResult: OrtResult, options: Map = emptyMap()): String { - val input = ReporterInput( - ortResult = ortResult, - howToFixTextProvider = { "Some how to fix text." } - ) - - val outputDir = tempdir() - - return EvaluatedModelReporterFactory().create(PluginConfig(options)).generateReport(input, outputDir) - .single().getOrThrow().readText().normalizeLineBreaks() -} diff --git a/plugins/reporters/opossum/src/funTest/kotlin/OpossumReporterFunTest.kt b/plugins/reporters/opossum/src/funTest/kotlin/OpossumReporterFunTest.kt index ea7f36c05b6b1..2a41e07eb9c7e 100644 --- a/plugins/reporters/opossum/src/funTest/kotlin/OpossumReporterFunTest.kt +++ b/plugins/reporters/opossum/src/funTest/kotlin/OpossumReporterFunTest.kt @@ -29,7 +29,6 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import org.ossreviewtoolkit.model.OrtResult -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.reporter.ReporterInput import org.ossreviewtoolkit.utils.common.normalizeLineBreaks import org.ossreviewtoolkit.utils.common.unpackZip @@ -62,8 +61,7 @@ private fun TestConfiguration.generateReport(ortResult: OrtResult): String { val input = ReporterInput(ortResult) val outputDir = tempdir() - OpossumReporterFactory().create(PluginConfig()) - .generateReport(input, outputDir).single().getOrThrow().unpackZip(outputDir) + OpossumReporterFactory.create().generateReport(input, outputDir).single().getOrThrow().unpackZip(outputDir) return outputDir.resolve("input.json").readText() } diff --git a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt index c46ffeefdbb38..1b46e4485de1c 100644 --- a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt +++ b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt @@ -58,7 +58,6 @@ import org.ossreviewtoolkit.model.VcsType import org.ossreviewtoolkit.model.config.AnalyzerConfiguration import org.ossreviewtoolkit.model.config.ScopeExclude import org.ossreviewtoolkit.model.config.ScopeExcludeReason -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.reporter.ReporterInput import org.ossreviewtoolkit.utils.spdx.toSpdx import org.ossreviewtoolkit.utils.test.scannerRunOf @@ -103,7 +102,7 @@ class OpossumReporterTest : WordSpec({ "generateOpossumInput()" should { val result = createOrtResult() - val opossumInput = OpossumReporterFactory().create(PluginConfig()).generateOpossumInput(ReporterInput(result)) + val opossumInput = OpossumReporterFactory.create().generateOpossumInput(ReporterInput(result)) "create input that is somehow valid" { opossumInput shouldNotBeNull { @@ -233,8 +232,7 @@ class OpossumReporterTest : WordSpec({ "generateOpossumInput() with excluded scopes" should { val result = createOrtResult().setScopeExcludes("devDependencies") - val opossumInputWithExcludedScopes = - OpossumReporterFactory().create(PluginConfig()).generateOpossumInput(ReporterInput(result)) + val opossumInputWithExcludedScopes = OpossumReporterFactory.create().generateOpossumInput(ReporterInput(result)) val fileListWithExcludedScopes = opossumInputWithExcludedScopes.resources.toFileList() "exclude scopes" { diff --git a/plugins/reporters/web-app/src/funTest/kotlin/WebAppReporterFunTest.kt b/plugins/reporters/web-app/src/funTest/kotlin/WebAppReporterFunTest.kt index 4074d59b1d077..3b7fad75d8a1a 100644 --- a/plugins/reporters/web-app/src/funTest/kotlin/WebAppReporterFunTest.kt +++ b/plugins/reporters/web-app/src/funTest/kotlin/WebAppReporterFunTest.kt @@ -26,7 +26,6 @@ import io.kotest.matchers.longs.beInRange import io.kotest.matchers.result.shouldBeSuccess import io.kotest.matchers.should -import org.ossreviewtoolkit.plugins.api.PluginConfig import org.ossreviewtoolkit.reporter.ReporterInput import org.ossreviewtoolkit.utils.test.getAssetFile import org.ossreviewtoolkit.utils.test.readOrtResult @@ -37,7 +36,7 @@ class WebAppReporterFunTest : WordSpec({ val ortResult = readOrtResult(getAssetFile("scan-result-for-synthetic-gradle-lib.yml")) val outputDir = tempdir() - val reportFileResults = WebAppReporterFactory().create(PluginConfig()) + val reportFileResults = WebAppReporterFactory.create() .generateReport(ReporterInput(ortResult), outputDir) reportFileResults.shouldBeSingleton {