Use MessageValidator in VesMessage class 23/58723/1
authorJakub Dudycz <jdudycz@nokia.com>
Wed, 11 Jul 2018 10:24:15 +0000 (12:24 +0200)
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>
Thu, 2 Aug 2018 12:36:43 +0000 (14:36 +0200)
Closes ONAP-493
Change-Id: I15b5f0f1052865aa29ffa103bef2368bd94021e8
Signed-off-by: Jakub Dudycz <jdudycz@nokia.com>
Issue-ID: DCAEGEN2-601

hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/factory/CollectorFactory.kt
hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidator.kt
hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/VesHvCollector.kt
hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/model/VesMessage.kt
hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt

index 1bde6a1..b52f959 100644 (file)
@@ -25,7 +25,6 @@ import org.onap.dcae.collectors.veshv.boundary.ConfigurationProvider
 import org.onap.dcae.collectors.veshv.boundary.Metrics
 import org.onap.dcae.collectors.veshv.boundary.SinkProvider
 import org.onap.dcae.collectors.veshv.domain.WireFrameDecoder
-import org.onap.dcae.collectors.veshv.impl.MessageValidator
 import org.onap.dcae.collectors.veshv.impl.Router
 import org.onap.dcae.collectors.veshv.impl.VesDecoder
 import org.onap.dcae.collectors.veshv.impl.VesHvCollector
@@ -57,7 +56,6 @@ class CollectorFactory(val configuration: ConfigurationProvider,
         return VesHvCollector(
                 wireChunkDecoderSupplier = { alloc -> WireChunkDecoder(WireFrameDecoder(), alloc) },
                 protobufDecoder = VesDecoder(),
-                messageValidator = MessageValidator(),
                 router = Router(config.routing),
                 sink = sinkProvider(config),
                 metrics = metrics)
index 3f355e3..8d10a40 100644 (file)
@@ -22,7 +22,7 @@ package org.onap.dcae.collectors.veshv.impl
 import org.onap.dcae.collectors.veshv.model.VesMessage
 import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
 
-internal class MessageValidator {
+internal object MessageValidator {
 
     val requiredFieldDescriptors = listOf(
             "version",
@@ -35,7 +35,7 @@ internal class MessageValidator {
             "startEpochMicrosec",
             "lastEpochMicrosec",
             "sequence")
-    .map { fieldName -> CommonEventHeader.getDescriptor().findFieldByName(fieldName)}
+            .map { fieldName -> CommonEventHeader.getDescriptor().findFieldByName(fieldName) }
 
     fun isValid(message: VesMessage): Boolean {
         return allMandatoryFieldsArePresent(message.header)
index 511ccf3..2a07b9b 100644 (file)
@@ -45,7 +45,6 @@ import java.util.function.BiConsumer
 internal class VesHvCollector(
         private val wireChunkDecoderSupplier: (ByteBufAllocator) -> WireChunkDecoder,
         private val protobufDecoder: VesDecoder,
-        private val messageValidator: MessageValidator,
         private val router: Router,
         private val sink: Sink,
         private val metrics: Metrics) : Collector {
@@ -56,7 +55,7 @@ internal class VesHvCollector(
                         .transform { decodeWireFrame(it, wireDecoder) }
                         .filter(PayloadWireFrameMessage::isValid)
                         .transform(::decodePayload)
-                        .filter(messageValidator::isValid)
+                        .filter(VesMessage::isValid)
                         .transform(::routeMessage)
                         .doOnTerminate { releaseBuffersMemory(wireDecoder) }
                         .onErrorResume(::handleErrors)
index 03c53e1..03996fd 100644 (file)
 package org.onap.dcae.collectors.veshv.model
 
 import org.onap.dcae.collectors.veshv.domain.ByteData
+import org.onap.dcae.collectors.veshv.impl.MessageValidator
 import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
 
 /**
  * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
  * @since May 2018
  */
-data class VesMessage(val header: CommonEventHeader, val rawMessage: ByteData)
+data class VesMessage(val header: CommonEventHeader, val rawMessage: ByteData) {
+    fun isValid(): Boolean = MessageValidator.isValid(this)
+}
index 4d1b879..a2a26b3 100644 (file)
@@ -46,7 +46,7 @@ internal object MessageValidatorTest : Spek({
     }
 
     given("Message validator") {
-        val cut = MessageValidator()
+        val cut = MessageValidator
 
         on("ves hv message including header with fully initialized fields") {
             val commonHeader = newBuilder()