diff --git a/kpi-calculator/core/src/test/kotlin/de/fraunhofer/iem/kpiCalculator/core/KpiCalculatorTest.kt b/kpi-calculator/core/src/test/kotlin/de/fraunhofer/iem/kpiCalculator/core/KpiCalculatorTest.kt index e80a516b4d8d090495d02419c9fcc726df5b38ab..1d829a9f6e3a4b9c111b68ada988bc2138c8d872 100644 --- a/kpi-calculator/core/src/test/kotlin/de/fraunhofer/iem/kpiCalculator/core/KpiCalculatorTest.kt +++ b/kpi-calculator/core/src/test/kotlin/de/fraunhofer/iem/kpiCalculator/core/KpiCalculatorTest.kt @@ -193,4 +193,57 @@ class KpiCalculatorTest { fail() } } + + @Test + fun calculateAggregationKpisIncompleteMixedKindsNested() { + val rawValueKpis = listOf( + RawValueKpi(kind = KpiId.VULNERABILITY_SCORE, score = 80), + RawValueKpi(kind = KpiId.VULNERABILITY_SCORE, score = 90), + ) + + val root = KpiNode( + kpiId = KpiId.ROOT, strategyType = KpiStrategyId.AGGREGATION_STRATEGY, children = listOf( + KpiEdge( + target = KpiNode( + kpiId = KpiId.MAXIMAL_VULNERABILITY, + strategyType = KpiStrategyId.MAXIMUM_STRATEGY, + children = listOf( + KpiEdge( + target = KpiNode( + kpiId = KpiId.VULNERABILITY_SCORE, + strategyType = KpiStrategyId.RAW_VALUE_STRATEGY, + children = listOf() + ), + weight = 1.0 + ), + ) + ), + weight = 0.5 + ), + KpiEdge( + target = KpiNode( + kpiId = KpiId.SAST_USAGE, + strategyType = KpiStrategyId.RAW_VALUE_STRATEGY, + children = listOf() + ), + weight = 0.5 + ) + ) + ) + val hierarchy = KpiHierarchy.create(root) + + val res = KpiCalculator.calculateKpis(hierarchy, rawValueKpis) + val result = res.rootNode.kpiResult + + if (result is KpiCalculationResult.Incomplete) { + assertEquals(90, result.score) + val sastResult = res.rootNode.children.find { it.target.kpiId == KpiId.SAST_USAGE } ?: fail() + assertEquals(0.0, sastResult.actualWeight) + val vulnerabilityEdges = res.rootNode.children.filter { it.target.kpiId == KpiId.MAXIMAL_VULNERABILITY } + assertEquals(vulnerabilityEdges.first().actualWeight, 1.0) + assertEquals(vulnerabilityEdges.first().plannedWeight, 0.5) + } else { + fail() + } + } }