-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(opossum reporter): migrate serialization to kotlinx
Migrates the OpossumReporter plugin away from Jackson serialization to use kotlinx serialization. To get properly typed data structures for serialization the previous untyped Map<*, *> are substituted by properly typed data classes. This leads to the creation of an OpossumInputCreator class that holds intermediate data structures needed for processing of the Reporter input. Signed-off-by: alexzurbonsen <[email protected]>
- Loading branch information
1 parent
9103ac2
commit 7b1a948
Showing
4 changed files
with
258 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,17 @@ | |
|
||
package org.ossreviewtoolkit.plugins.reporters.opossum | ||
|
||
import com.fasterxml.jackson.databind.json.JsonMapper | ||
import kotlinx.serialization.json.Json | ||
|
||
import io.kotest.core.TestConfiguration | ||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.engine.spec.tempdir | ||
import io.kotest.matchers.sequences.shouldContain | ||
import io.kotest.matchers.collections.shouldContain | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.shouldContain | ||
import kotlinx.serialization.json.jsonArray | ||
import kotlinx.serialization.json.jsonObject | ||
import kotlinx.serialization.json.jsonPrimitive | ||
|
||
import org.ossreviewtoolkit.model.OrtResult | ||
import org.ossreviewtoolkit.plugins.api.PluginConfig | ||
|
@@ -45,15 +48,24 @@ class OpossumReporterFunTest : WordSpec({ | |
} | ||
|
||
"create a parseable result and contain some expected values" { | ||
with(JsonMapper().readTree(reportStr)) { | ||
isObject shouldBe true | ||
get("metadata").get("projectId").asText() shouldBe "0" | ||
get("attributionBreakpoints").size() shouldBe 4 | ||
get("externalAttributionSources").size() shouldBe 7 | ||
get("resourcesToAttributions").fieldNames().asSequence() shouldContain | ||
"/analyzer/src/funTest/assets/projects/synthetic/gradle/lib/build.gradle/" + | ||
"compile/org.apache.commons/[email protected]/dependencies/org.apache.commons/[email protected]" | ||
} | ||
val json = Json.parseToJsonElement(reportStr).jsonObject | ||
|
||
json["metadata"]?.jsonObject?.get("projectId")?.jsonPrimitive?.content shouldBe "0" | ||
json["resources"]?.jsonObject?.size shouldBe 2 | ||
json["attributionBreakpoints"]?.jsonArray?.size shouldBe 4 | ||
json["externalAttributionSources"]?.jsonObject?.size shouldBe 7 | ||
json["frequentLicenses"]?.jsonArray?.size shouldBe 666 | ||
json["resourcesToAttributions"]?.jsonObject?.size shouldBe 13 | ||
|
||
val resourceRoots = json["resources"]?.jsonObject?.keys ?: emptySet() | ||
resourceRoots shouldBe setOf("analyzer", "project") | ||
val projectResource = json["resources"]?.jsonObject?.get("project") | ||
projectResource?.jsonObject?.size shouldBe 5 | ||
projectResource?.jsonObject?.get("file.kt")?.jsonPrimitive?.content shouldBe "1" | ||
|
||
val resourcePaths = json["resourcesToAttributions"]?.jsonObject?.keys ?: emptySet() | ||
resourcePaths shouldContain "/analyzer/src/funTest/assets/projects/synthetic/gradle/lib/build.gradle/" + | ||
"compile/org.apache.commons/[email protected]/dependencies/org.apache.commons/[email protected]" | ||
} | ||
} | ||
}) | ||
|
Oops, something went wrong.