diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-11-15 13:45:44 +0100 |
---|---|---|
committer | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-11-27 09:42:57 +0100 |
commit | 4aa75b58a490b07ccff713f4c1548a2a755904ef (patch) | |
tree | e42ec47c1f65dba14932c241028717c192c6cfe8 /hv-collector-core | |
parent | 0573df820926986dd19ac9a82943bd5b5eda450d (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].*"
Change-Id: I784f13c0a35a25beca29f4ae756df3586ddddd5b
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-976
Diffstat (limited to 'hv-collector-core')
3 files changed, 35 insertions, 5 deletions
diff --git a/hv-collector-core/pom.xml b/hv-collector-core/pom.xml index a893dad6..5a098cca 100644 --- a/hv-collector-core/pom.xml +++ b/hv-collector-core/pom.xml @@ -33,7 +33,7 @@ <parent> <groupId>org.onap.dcaegen2.collectors.hv-ves</groupId> <artifactId>ves-hv-collector</artifactId> - <version>1.0.1-SNAPSHOT</version> + <version>1.0.2-SNAPSHOT</version> <relativePath>..</relativePath> </parent> 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..05221e45 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,5 @@ 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..872e67ef 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({ @@ -96,5 +93,36 @@ internal object MessageValidatorTest : Spek({ assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse() } } + + on("ves hv message including header.vesEventListenerVersion with non-string major part") { + val commonHeader = commonHeader(vesEventListenerVersion = "sample-version") + val rawMessageBytes = vesEventBytes(commonHeader) + + + it("should not accept message header") { + val vesMessage = VesMessage(commonHeader, rawMessageBytes) + assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse() + } + } + + on("ves hv message including header.vesEventListenerVersion with major part != 7") { + val commonHeader = commonHeader(vesEventListenerVersion = "1.2.3") + val rawMessageBytes = vesEventBytes(commonHeader) + + it("should not accept message header") { + val vesMessage = VesMessage(commonHeader, rawMessageBytes) + assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse() + } + } + + on("ves hv message including header.vesEventListenerVersion with minor part not starting with a digit") { + val commonHeader = commonHeader(vesEventListenerVersion = "7.test") + val rawMessageBytes = vesEventBytes(commonHeader) + + it("should not accept message header") { + val vesMessage = VesMessage(commonHeader, rawMessageBytes) + assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse() + } + } } }) |