diff options
Diffstat (limited to 'hv-collector-core')
3 files changed, 61 insertions, 20 deletions
diff --git a/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt b/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt index 4586d30c..543d7dc6 100644 --- a/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt +++ b/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt @@ -27,11 +27,11 @@ internal object MessageValidator { private val requiredFieldDescriptors = listOf( "version", "eventName", - // "domain", TODO to be restored back when GPB schema will include default value + "domain", "eventId", "sourceName", "reportingEntityName", - // "priority", TODO to be restored back when GPB schema will include default value + "priority", "startEpochMicrosec", "lastEpochMicrosec", "sequence") diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt index a2a26b31..eb8971c3 100644 --- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt +++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt @@ -49,18 +49,7 @@ internal object MessageValidatorTest : Spek({ val cut = MessageValidator on("ves hv message including header with fully initialized fields") { - val commonHeader = newBuilder() - .setVersion("1.9") - .setEventName("Sample event name") - .setDomain(Domain.HVRANMEAS) - .setEventId("Sample event Id") - .setSourceName("Sample Source") - .setReportingEntityName(ByteString.copyFromUtf8("Sample byte String")) - .setPriority(Priority.MEDIUM) - .setStartEpochMicrosec(120034455) - .setLastEpochMicrosec(120034459) - .setSequence(2) - .build() + val commonHeader = createInitializedHeaderBuilder().build() it("should accept message with fully initialized message header") { val vesMessage = VesMessage(commonHeader, vesMessageBytes(commonHeader)) @@ -68,9 +57,9 @@ internal object MessageValidatorTest : Spek({ } Domain.values() - .filter { it != Domain.UNRECOGNIZED } - .forEach {domain -> - it("should accept message with $domain domain"){ + .filter { (it != Domain.UNRECOGNIZED && it != Domain.DOMAIN_UNDEFINED) } + .forEach { domain -> + it("should accept message with $domain domain") { val header = newBuilder(commonHeader).setDomain(domain).build() val vesMessage = VesMessage(header, vesMessageBytes(header)) assertThat(cut.isValid(vesMessage)) @@ -87,6 +76,45 @@ internal object MessageValidatorTest : Spek({ } + val domainTestCases = mapOf( + Domain.DOMAIN_UNDEFINED to false, + Domain.FAULT to true + ) + + domainTestCases.forEach { value, expectedResult -> + on("ves hv message including header with domain $value") { + val commonEventHeader = createInitializedHeaderBuilder() + .setDomain(value) + .build() + val vesMessage = VesMessage(commonEventHeader, vesMessageBytes(commonEventHeader)) + + it("should resolve validation result") { + assertThat(cut.isValid(vesMessage)).describedAs("message validation results") + .isEqualTo(expectedResult) + } + } + } + + val priorityTestCases = mapOf( + Priority.PRIORITY_UNDEFINED to false, + Priority.HIGH to true + ) + + priorityTestCases.forEach { value, expectedResult -> + on("ves hv message including header with priority $value") { + val commonEventHeader = createInitializedHeaderBuilder() + .setPriority(value) + .build() + val vesMessage = VesMessage(commonEventHeader, vesMessageBytes(commonEventHeader)) + + it("should resolve validation result") { + assertThat(cut.isValid(vesMessage)).describedAs("message validation results") + .isEqualTo(expectedResult) + } + } + } + + on("ves hv message including header with not initialized fields") { val commonHeader = newBuilder() .setVersion("1.9") @@ -106,4 +134,17 @@ internal object MessageValidatorTest : Spek({ } } } -})
\ No newline at end of file +}) + +private fun createInitializedHeaderBuilder(): CommonEventHeader.Builder = + newBuilder() + .setVersion("1.9") + .setEventName("Sample event name") + .setDomain(Domain.HVRANMEAS) + .setEventId("Sample event Id") + .setSourceName("Sample Source") + .setReportingEntityName(ByteString.copyFromUtf8("Sample byte String")) + .setPriority(Priority.MEDIUM) + .setStartEpochMicrosec(120034455) + .setLastEpochMicrosec(120034459) + .setSequence(2)
\ No newline at end of file diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt index 808a6fcc..f4c527a4 100644 --- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt +++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt @@ -68,11 +68,11 @@ internal object ConsulConfigurationProviderTest : Spek({ assertEquals("kafka:9093", it.kafkaBootstrapServers) val route1 = it.routing.routes[0] - assertEquals(Domain.HEARTBEAT, route1.domain) + assertEquals(Domain.FAULT, route1.domain) assertEquals("test-topic-1", route1.targetTopic) val route2 = it.routing.routes[1] - assertEquals(Domain.MEASUREMENTS_FOR_VF_SCALING, route2.domain) + assertEquals(Domain.HEARTBEAT, route2.domain) assertEquals("test-topic-2", route2.targetTopic) }.verifyComplete() |