diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-11-15 13:29:09 +0100 |
---|---|---|
committer | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-11-19 09:29:35 +0100 |
commit | 33ff28e3fab91baa36e954c4fd167b615e94993c (patch) | |
tree | 33ed79a9d53e9457a18f9aa355962d6f89f95f5c /hv-collector-core | |
parent | 3fdd2fe2b4f35e18998d050c632fc6de24a7e3b1 (diff) |
Fix Common Event Header fields validation
- "sequence" is no longer a required parameter,
since deafult value "0" is acceptable
- "vesEventListenerVersion" has to match the regular expression "7\.[0-9]+\.[0-9]+"
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-976
Change-Id: I2f9fd6f375ccca3255cc9e035918dc37cc97bd6a
Diffstat (limited to 'hv-collector-core')
2 files changed, 21 insertions, 5 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 a4a4374c..fb949079 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 @@ -20,6 +20,7 @@ package org.onap.dcae.collectors.veshv.impl import org.onap.dcae.collectors.veshv.domain.headerRequiredFieldDescriptors +import org.onap.dcae.collectors.veshv.domain.vesEventListenerVersionRegex import org.onap.dcae.collectors.veshv.model.VesMessage import org.onap.ves.VesEventOuterClass.CommonEventHeader @@ -32,4 +33,6 @@ internal object MessageValidator { private fun allMandatoryFieldsArePresent(header: CommonEventHeader) = headerRequiredFieldDescriptors .all { fieldDescriptor -> header.hasField(fieldDescriptor) } + .and(vesEventListenerVersionRegex.matches(header.vesEventListenerVersion)) + } 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 443dfa2f..25bd4f67 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 @@ -29,10 +29,7 @@ import org.onap.dcae.collectors.veshv.domain.VesEventDomain import org.onap.dcae.collectors.veshv.model.VesMessage import org.onap.dcae.collectors.veshv.tests.utils.commonHeader import org.onap.dcae.collectors.veshv.tests.utils.vesEventBytes - -import org.onap.ves.VesEventOuterClass.CommonEventHeader.Priority -import org.onap.ves.VesEventOuterClass.CommonEventHeader.getDefaultInstance -import org.onap.ves.VesEventOuterClass.CommonEventHeader.newBuilder +import org.onap.ves.VesEventOuterClass.CommonEventHeader.* internal object MessageValidatorTest : Spek({ @@ -91,9 +88,25 @@ internal object MessageValidatorTest : Spek({ .build() val rawMessageBytes = vesEventBytes(commonHeader) - it("should not accept not fully initialized message header ") { + it("should not accept not fully initialized message header") { + val vesMessage = VesMessage(commonHeader, rawMessageBytes) + assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse() + } + } + + on("ves hv message including header with vesEventListenerVersion field not matching required pattern") { + val commonHeader = commonHeader(vesEventListenerVersion = "1.2.3") + val commonHeader2 = commonHeader(vesEventListenerVersion = "sample-version") + + val rawMessageBytes = vesEventBytes(commonHeader) + val rawMessageBytes2 = vesEventBytes(commonHeader2) + + it("should not accept message header") { val vesMessage = VesMessage(commonHeader, rawMessageBytes) assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse() + + val vesMessage2 = VesMessage(commonHeader2, rawMessageBytes2) + assertThat(cut.isValid(vesMessage2)).describedAs("second message validation result").isFalse() } } } |