From 9400913cfaab43916ca3345e1708c0e6b6264616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Tue, 17 Oct 2023 15:35:55 +0200 Subject: [PATCH] test: Add VssSpecification tests --- .../vsscore/model/VssSpecificationTest.kt | 16 ++++++- .../eclipse/kuksa/vsscore/model/VssVehicle.kt | 45 +++++++++++++++---- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssSpecificationTest.kt b/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssSpecificationTest.kt index 8bed685b..6611a4af 100644 --- a/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssSpecificationTest.kt +++ b/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssSpecificationTest.kt @@ -27,15 +27,27 @@ class VssSpecificationTest : BehaviorSpec({ `when`("finding the whole heritage") { val heritage = vssVehicle.heritage then("it should return all possible heirs") { - heritage shouldBe listOf(vssVehicle.driver, vssVehicle.body, vssVehicle.driver.heartRate) + heritage shouldBe listOf( + vssVehicle.driver, + vssVehicle.passenger, + vssVehicle.body, + vssVehicle.driver.heartRate, + vssVehicle.passenger.heartRate, + ) } } `when`("finding a heritage line") { - val heritageLine = vssVehicle.findHeritageLine(VssHeartRate()) + val heritageLine = vssVehicle.findHeritageLine(VssDriver.VssHeartRate()) then("it should return the correct line") { heritageLine shouldBe listOf(vssVehicle.driver, vssVehicle.driver.heartRate) } } + `when`("finding specific properties") { + val properties = vssVehicle.findProperties(VssDriver.VssHeartRate::class) + then("it should return all VssProperties which fit the class") { + properties.size shouldBe 2 + } + } `when`("getting the variable name") { val variableName = vssVehicle.variableName then("it should be correct") { diff --git a/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssVehicle.kt b/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssVehicle.kt index 3c668342..a28835b2 100644 --- a/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssVehicle.kt +++ b/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssVehicle.kt @@ -25,6 +25,7 @@ import kotlin.reflect.KClass data class VssVehicle( val driver: VssDriver = VssDriver(), + val passenger: VssPassenger = VssPassenger(), val body: VssBody = VssBody(), override val uuid: String = "Vehicle", override val vssPath: String = "Vehicle", @@ -33,7 +34,7 @@ data class VssVehicle( override val comment: String = "", ) : VssSpecification { override val children: Set - get() = setOf(driver, body) + get() = setOf(driver, passenger, body) } data class VssBody( @@ -59,16 +60,42 @@ data class VssDriver( get() = setOf(heartRate) override val parentClass: KClass<*> get() = VssVehicle::class + + data class VssHeartRate( + override val uuid: String = "Driver HeartRate", + override val vssPath: String = "Vehicle.Driver.HeartRate", + override val description: String = "Heart rate of the driver.", + override val type: String = "sensor", + override val comment: String = "", + override val value: Int = 100, + ) : VssProperty { + override val parentClass: KClass<*> + get() = VssDriver::class + } } -data class VssHeartRate( - override val uuid: String = "HeartRate", - override val vssPath: String = "Vehicle.Driver.HeartRate", - override val description: String = "Heart rate of the driver.", - override val type: String = "sensor", +data class VssPassenger( + val heartRate: VssHeartRate = VssHeartRate(), + override val uuid: String = "Passenger", + override val vssPath: String = "Vehicle.Passenger", + override val description: String = "Passenger data", + override val type: String = "branch", override val comment: String = "", - override val value: Int = 100, -) : VssProperty { +) : VssSpecification { + override val children: Set + get() = setOf(heartRate) override val parentClass: KClass<*> - get() = VssDriver::class + get() = VssVehicle::class + + data class VssHeartRate( + override val uuid: String = "Passenger HeartRate", + override val vssPath: String = "Vehicle.Passenger.HeartRate", + override val description: String = "Heart rate of the Passenger.", + override val type: String = "sensor", + override val comment: String = "", + override val value: Int = 80, + ) : VssProperty { + override val parentClass: KClass<*> + get() = VssPassenger::class + } }