diff options
author | kjaniak <kornel.janiak@nokia.com> | 2018-07-25 14:02:27 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-03 09:55:19 +0200 |
commit | efceaa86a2fc3eb22b9e30bafd08c0fb6ad2a783 (patch) | |
tree | a56fc159369f44fec5be42d776285c867e81bf66 /hv-collector-core | |
parent | fc6ab3e5fee2bc3e607848caa665b166d6f38dd6 (diff) |
Enable UNDEFINED option in commonHeader GPB schema
Closes ONAP-655
Change-Id: I6fc830d2b8c7bdd726f306a6fbf7e979f39e03f0
Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Issue-ID: DCAEGEN2-601
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() |