aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfkrzywka <filip.krzywka@nokia.com>2018-07-31 14:26:09 +0200
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-08-03 11:02:26 +0200
commit185bc70fa1c024e532649bea650183e05c2d3d87 (patch)
treedafcd1a21d71948d79f903380b860cca36bebb6c
parent8a0e9e5d4d7613793d2804d7e16a9352e3883874 (diff)
Extract test-utils module
- removed duplicate code that was creating VesMessages and similiar objects - removed duplicate code in command line parsing tests - made minor refactorings to avoid passing unnecessary params and to be as verbose as possible in tests Closes ONAP-699 Change-Id: I2607f1f775054ae1c5f275c231895f838b415371 Signed-off-by: fkrzywka <filip.krzywka@nokia.com> Issue-ID: DCAEGEN2-601
-rw-r--r--hv-collector-core/pom.xml6
-rw-r--r--hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/wire/WireChunkDecoder.kt8
-rw-r--r--hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt54
-rw-r--r--hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/RouterTest.kt15
-rw-r--r--hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt29
-rw-r--r--hv-collector-ct/pom.xml6
-rw-r--r--hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt27
-rw-r--r--hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/VesHvSpecification.kt63
-rw-r--r--hv-collector-dcae-app-simulator/pom.xml6
-rw-r--r--hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt25
-rw-r--r--hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/ByteData.kt1
-rw-r--r--hv-collector-main/pom.xml10
-rw-r--r--hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt22
-rw-r--r--hv-collector-test-utils/pom.xml55
-rw-r--r--hv-collector-test-utils/src/main/kotlin/configurations.kt37
-rw-r--r--hv-collector-test-utils/src/main/kotlin/messages.kt (renamed from hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/messages.kt)62
-rw-r--r--hv-collector-test-utils/src/main/kotlin/vesEvents.kt65
-rw-r--r--hv-collector-ves-message-generator/pom.xml6
-rw-r--r--hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt41
-rw-r--r--hv-collector-xnf-simulator/pom.xml10
-rw-r--r--hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt3
-rw-r--r--hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt30
-rw-r--r--pom.xml1
23 files changed, 321 insertions, 261 deletions
diff --git a/hv-collector-core/pom.xml b/hv-collector-core/pom.xml
index cf99867f..06687b7d 100644
--- a/hv-collector-core/pom.xml
+++ b/hv-collector-core/pom.xml
@@ -73,6 +73,12 @@
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-test-utils</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
diff --git a/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/wire/WireChunkDecoder.kt b/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/wire/WireChunkDecoder.kt
index fbff769f..80f62d1a 100644
--- a/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/wire/WireChunkDecoder.kt
+++ b/hv-collector-core/src/main/kotlin/org/onap/dcae/collectors/veshv/impl/wire/WireChunkDecoder.kt
@@ -22,7 +22,13 @@ package org.onap.dcae.collectors.veshv.impl.wire
import arrow.effects.IO
import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufAllocator
-import org.onap.dcae.collectors.veshv.domain.*
+import org.onap.dcae.collectors.veshv.domain.WireFrameMessage
+import org.onap.dcae.collectors.veshv.domain.WireFrameDecoder
+import org.onap.dcae.collectors.veshv.domain.InvalidWireFrame
+import org.onap.dcae.collectors.veshv.domain.WireFrameDecodingError
+import org.onap.dcae.collectors.veshv.domain.MissingWireFrameBytes
+import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage
+import org.onap.dcae.collectors.veshv.domain.EndOfTransmissionMessage
import org.onap.dcae.collectors.veshv.utils.logging.Logger
import reactor.core.publisher.Flux
import reactor.core.publisher.SynchronousSink
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 eb8971c3..213f4544 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
@@ -19,17 +19,15 @@
*/
package org.onap.dcae.collectors.veshv.impl
-import com.google.protobuf.ByteString
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.domain.ByteData
-import org.onap.dcae.collectors.veshv.domain.toByteData
import org.onap.dcae.collectors.veshv.model.VesMessage
-import org.onap.ves.VesEventV5.VesEvent
-import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
+import org.onap.dcae.collectors.veshv.tests.utils.commonHeader
+import org.onap.dcae.collectors.veshv.tests.utils.vesEventBytes
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Priority
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.getDefaultInstance
@@ -37,22 +35,14 @@ import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.newBuilder
internal object MessageValidatorTest : Spek({
- fun vesMessageBytes(commonHeader: CommonEventHeader): ByteData {
- val msg = VesEvent.newBuilder()
- .setCommonEventHeader(commonHeader)
- .setHvRanMeasFields(ByteString.copyFromUtf8("high volume data"))
- .build()
- return msg.toByteData()
- }
-
given("Message validator") {
val cut = MessageValidator
on("ves hv message including header with fully initialized fields") {
- val commonHeader = createInitializedHeaderBuilder().build()
+ val commonHeader = commonHeader()
it("should accept message with fully initialized message header") {
- val vesMessage = VesMessage(commonHeader, vesMessageBytes(commonHeader))
+ val vesMessage = VesMessage(commonHeader, vesEventBytes(commonHeader))
assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isTrue()
}
@@ -60,8 +50,8 @@ internal object MessageValidatorTest : Spek({
.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))
+ val header = commonHeader(domain)
+ val vesMessage = VesMessage(header, vesEventBytes(header))
assertThat(cut.isValid(vesMessage))
.isTrue()
}
@@ -83,10 +73,8 @@ internal object MessageValidatorTest : Spek({
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))
+ val commonEventHeader = commonHeader(value)
+ val vesMessage = VesMessage(commonEventHeader, vesEventBytes(commonEventHeader))
it("should resolve validation result") {
assertThat(cut.isValid(vesMessage)).describedAs("message validation results")
@@ -102,10 +90,8 @@ internal object MessageValidatorTest : Spek({
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))
+ val commonEventHeader = commonHeader(priority = value)
+ val vesMessage = VesMessage(commonEventHeader, vesEventBytes(commonEventHeader))
it("should resolve validation result") {
assertThat(cut.isValid(vesMessage)).describedAs("message validation results")
@@ -114,7 +100,6 @@ internal object MessageValidatorTest : Spek({
}
}
-
on("ves hv message including header with not initialized fields") {
val commonHeader = newBuilder()
.setVersion("1.9")
@@ -122,11 +107,7 @@ internal object MessageValidatorTest : Spek({
.setEventId("Sample event Id")
.setSourceName("Sample Source")
.build()
- val msg = VesEvent.newBuilder()
- .setCommonEventHeader(commonHeader)
- .setHvRanMeasFields(ByteString.copyFromUtf8("high volume data !!!"))
- .build()
- val rawMessageBytes = msg.toByteData()
+ val rawMessageBytes = vesEventBytes(commonHeader)
it("should not accept not fully initialized message header ") {
val vesMessage = VesMessage(commonHeader, rawMessageBytes)
@@ -135,16 +116,3 @@ internal object MessageValidatorTest : Spek({
}
}
})
-
-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/RouterTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/RouterTest.kt
index 599a9d40..91fa7c19 100644
--- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/RouterTest.kt
+++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/RouterTest.kt
@@ -30,7 +30,7 @@ import org.onap.dcae.collectors.veshv.domain.ByteData
import org.onap.dcae.collectors.veshv.model.RoutedMessage
import org.onap.dcae.collectors.veshv.model.VesMessage
import org.onap.dcae.collectors.veshv.model.routing
-import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
+import org.onap.dcae.collectors.veshv.tests.utils.commonHeader
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain
/**
@@ -56,7 +56,7 @@ object RouterTest : Spek({
val cut = Router(config)
on("message with existing route (rtpm)") {
- val message = VesMessage(vesCommonHeaderWithDomain(Domain.HVRANMEAS), ByteData.EMPTY)
+ val message = VesMessage(commonHeader(Domain.HVRANMEAS), ByteData.EMPTY)
val result = cut.findDestination(message)
it("should have route available") {
@@ -77,7 +77,7 @@ object RouterTest : Spek({
}
on("message with existing route (trace)") {
- val message = VesMessage(vesCommonHeaderWithDomain(Domain.SYSLOG), ByteData.EMPTY)
+ val message = VesMessage(commonHeader(Domain.SYSLOG), ByteData.EMPTY)
val result = cut.findDestination(message)
it("should have route available") {
@@ -98,7 +98,7 @@ object RouterTest : Spek({
}
on("message with unknown route") {
- val message = VesMessage(vesCommonHeaderWithDomain(Domain.HEARTBEAT), ByteData.EMPTY)
+ val message = VesMessage(commonHeader(Domain.HEARTBEAT), ByteData.EMPTY)
val result = cut.findDestination(message)
it("should not have route available") {
@@ -106,9 +106,4 @@ object RouterTest : Spek({
}
}
}
-})
-
-private fun vesCommonHeaderWithDomain(domain: Domain) =
- CommonEventHeader.getDefaultInstance().toBuilder()
- .setDomain(domain)
- .build() \ No newline at end of file
+}) \ No newline at end of file
diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt
index 3f1f610e..a7d3971e 100644
--- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt
+++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt
@@ -26,10 +26,10 @@ import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.domain.ByteData
-import org.onap.dcae.collectors.veshv.domain.toByteData
import org.onap.dcae.collectors.veshv.model.VesMessage
-import org.onap.ves.VesEventV5.VesEvent
-import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
+import org.onap.dcae.collectors.veshv.tests.utils.commonHeader
+import org.onap.dcae.collectors.veshv.tests.utils.vesEventBytes
+import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain
import java.nio.charset.Charset
import kotlin.test.assertTrue
import kotlin.test.fail
@@ -41,12 +41,8 @@ internal object VesDecoderTest : Spek({
val cut = VesDecoder()
on("ves hv message bytes") {
- val commonHeader = commonEventHeader()
- val msg = VesEvent.newBuilder()
- .setCommonEventHeader(commonHeader)
- .setHvRanMeasFields(ByteString.copyFromUtf8("highvolume measurements"))
- .build()
- val rawMessageBytes = msg.toByteData()
+ val commonHeader = commonHeader(Domain.HEARTBEAT)
+ val rawMessageBytes = vesEventBytes(commonHeader, ByteString.copyFromUtf8("highvolume measurements"))
it("should decode only header and pass it on along with raw message") {
val expectedMessage = VesMessage(
@@ -76,18 +72,3 @@ private fun <A> assertFailedWithError(option: Option<A>) =
option.exists {
fail("Error expected")
}
-
-
-private fun commonEventHeader() =
- CommonEventHeader.getDefaultInstance().toBuilder()
- .setDomain(CommonEventHeader.Domain.HEARTBEAT)
- .setVersion("1.0")
- .setEventName("xyz")
- .setEventId("eventID")
- .setEventName("Sample event name")
- .setSourceName("Sample Source")
- .setPriority(CommonEventHeader.Priority.MEDIUM)
- .setStartEpochMicrosec(120034455)
- .setLastEpochMicrosec(120034459)
- .setSequence(1)
- .build()
diff --git a/hv-collector-ct/pom.xml b/hv-collector-ct/pom.xml
index 71b906cb..347bbbe0 100644
--- a/hv-collector-ct/pom.xml
+++ b/hv-collector-ct/pom.xml
@@ -69,6 +69,12 @@
<artifactId>hv-collector-xnf-simulator</artifactId>
<version>${project.parent.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-test-utils</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+
<dependency>
<groupId>io.arrow-kt</groupId>
diff --git a/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt b/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt
index 928c62fb..1e22d4c0 100644
--- a/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt
+++ b/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt
@@ -20,7 +20,6 @@
package org.onap.dcae.collectors.veshv.tests.component
import arrow.syntax.function.partially1
-import com.google.protobuf.ByteString
import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.CompositeByteBuf
@@ -33,17 +32,16 @@ import org.jetbrains.spek.api.dsl.it
import org.onap.dcae.collectors.veshv.domain.WireFrameEncoder
import org.onap.dcae.collectors.veshv.tests.fakes.CountingSink
import org.onap.dcae.collectors.veshv.tests.fakes.basicConfiguration
+import org.onap.dcae.collectors.veshv.tests.utils.commonHeader
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParameters
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType.VALID
-import org.onap.ves.VesEventV5
-import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain.HVRANMEAS
import reactor.core.publisher.Flux
import reactor.math.sum
import java.security.MessageDigest
import java.time.Duration
-import java.util.*
+import java.util.Random
import kotlin.system.measureTimeMillis
/**
@@ -64,7 +62,7 @@ object PerformanceSpecification : Spek({
val timeout = Duration.ofMinutes((1 + (runs / 2)).toLong())
val params = MessageParameters(
- commonEventHeader = createSampleCommonHeader(HVRANMEAS),
+ commonEventHeader = commonHeader(HVRANMEAS),
messageType = VALID,
amount = numMessages
)
@@ -94,7 +92,7 @@ object PerformanceSpecification : Spek({
val timeout = Duration.ofSeconds(30)
val params = MessageParameters(
- commonEventHeader = createSampleCommonHeader(HVRANMEAS),
+ commonEventHeader = commonHeader(HVRANMEAS),
messageType = VALID,
amount = numMessages
)
@@ -203,20 +201,3 @@ private fun randomlySplitTcpFrames(bb: CompositeByteBuf): Flux<ByteBuf> {
}
}
-private fun createSampleCommonHeader(domain: Domain): VesEventV5.VesEvent.CommonEventHeader = VesEventV5.VesEvent.CommonEventHeader.newBuilder()
- .setVersion("sample-version")
- .setDomain(domain)
- .setSequence(1)
- .setPriority(VesEventV5.VesEvent.CommonEventHeader.Priority.NORMAL)
- .setEventId("sample-event-id")
- .setEventName("sample-event-name")
- .setEventType("sample-event-type")
- .setStartEpochMicrosec(120034455)
- .setLastEpochMicrosec(120034455)
- .setNfNamingCode("sample-nf-naming-code")
- .setNfcNamingCode("sample-nfc-naming-code")
- .setReportingEntityId("sample-reporting-entity-id")
- .setReportingEntityName(ByteString.copyFromUtf8("sample-reporting-entity-name"))
- .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
- .setSourceName("sample-source-name")
- .build()
diff --git a/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/VesHvSpecification.kt b/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/VesHvSpecification.kt
index 5e6e666f..1f07c233 100644
--- a/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/VesHvSpecification.kt
+++ b/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/VesHvSpecification.kt
@@ -24,7 +24,13 @@ import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import org.onap.dcae.collectors.veshv.tests.fakes.*
+import org.onap.dcae.collectors.veshv.tests.utils.endOfTransmissionWireMessage
+import org.onap.dcae.collectors.veshv.tests.utils.garbageFrame
+import org.onap.dcae.collectors.veshv.tests.utils.wireFrameMessageWithInvalidPayload
+import org.onap.dcae.collectors.veshv.tests.utils.invalidWireFrame
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain
+import org.onap.dcae.collectors.veshv.tests.utils.vesWireFrameMessage
+import org.onap.dcae.collectors.veshv.tests.utils.vesMessageWithTooBigPayload
import reactor.core.publisher.Flux
import java.time.Duration
@@ -38,7 +44,10 @@ object VesHvSpecification : Spek({
describe("VES High Volume Collector") {
it("should handle multiple HV RAN events") {
val (sut, sink) = vesHvWithStoringSink()
- val messages = sut.handleConnection(sink, vesMessage(Domain.HVRANMEAS), vesMessage(Domain.HVRANMEAS))
+ val messages = sut.handleConnection(sink,
+ vesWireFrameMessage(Domain.HVRANMEAS),
+ vesWireFrameMessage(Domain.HVRANMEAS)
+ )
assertThat(messages)
.describedAs("should send all events")
@@ -47,9 +56,9 @@ object VesHvSpecification : Spek({
it("should not handle messages received from client after end-of-transmission message") {
val (sut, sink) = vesHvWithStoringSink()
- val validMessage = vesMessage(Domain.HVRANMEAS)
- val anotherValidMessage = vesMessage(Domain.HVRANMEAS)
- val endOfTransmissionMessage = endOfTransmissionMessage()
+ val validMessage = vesWireFrameMessage(Domain.HVRANMEAS)
+ val anotherValidMessage = vesWireFrameMessage(Domain.HVRANMEAS)
+ val endOfTransmissionMessage = endOfTransmissionWireMessage()
val handledEvents = sut.handleConnection(sink,
validMessage,
@@ -73,8 +82,8 @@ object VesHvSpecification : Spek({
describe("Memory management") {
it("should release memory for each handled and dropped message") {
val (sut, sink) = vesHvWithStoringSink()
- val validMessage = vesMessage(Domain.HVRANMEAS)
- val msgWithInvalidDomain = vesMessage(Domain.OTHER)
+ val validMessage = vesWireFrameMessage(Domain.HVRANMEAS)
+ val msgWithInvalidDomain = vesWireFrameMessage(Domain.OTHER)
val msgWithInvalidFrame = invalidWireFrame()
val msgWithTooBigPayload = vesMessageWithTooBigPayload(Domain.HVRANMEAS)
val expectedRefCnt = 0
@@ -100,8 +109,8 @@ object VesHvSpecification : Spek({
it("should release memory for end-of-transmission message") {
val (sut, sink) = vesHvWithStoringSink()
- val validMessage = vesMessage(Domain.HVRANMEAS)
- val endOfTransmissionMessage = endOfTransmissionMessage()
+ val validMessage = vesWireFrameMessage(Domain.HVRANMEAS)
+ val endOfTransmissionMessage = endOfTransmissionWireMessage()
val expectedRefCnt = 0
val handledEvents = sut.handleConnection(sink,
@@ -120,8 +129,8 @@ object VesHvSpecification : Spek({
it("should release memory for each message with invalid payload") {
val (sut, sink) = vesHvWithStoringSink()
- val validMessage = vesMessage(Domain.HVRANMEAS)
- val msgWithInvalidPayload = invalidVesMessage()
+ val validMessage = vesWireFrameMessage(Domain.HVRANMEAS)
+ val msgWithInvalidPayload = wireFrameMessageWithInvalidPayload()
val expectedRefCnt = 0
val handledEvents = sut.handleConnection(sink, validMessage, msgWithInvalidPayload)
@@ -139,7 +148,7 @@ object VesHvSpecification : Spek({
it("should release memory for each message with garbage frame") {
val (sut, sink) = vesHvWithStoringSink()
- val validMessage = vesMessage(Domain.HVRANMEAS)
+ val validMessage = vesWireFrameMessage(Domain.HVRANMEAS)
val msgWithGarbageFrame = garbageFrame()
val expectedRefCnt = 0
@@ -161,7 +170,7 @@ object VesHvSpecification : Spek({
it("should direct message to a topic by means of routing configuration") {
val (sut, sink) = vesHvWithStoringSink()
- val messages = sut.handleConnection(sink, vesMessage(Domain.HVRANMEAS))
+ val messages = sut.handleConnection(sink, vesWireFrameMessage(Domain.HVRANMEAS))
assertThat(messages).describedAs("number of routed messages").hasSize(1)
val msg = messages[0]
@@ -175,9 +184,9 @@ object VesHvSpecification : Spek({
sut.configurationProvider.updateConfiguration(twoDomainsToOneTopicConfiguration)
val messages = sut.handleConnection(sink,
- vesMessage(Domain.HVRANMEAS),
- vesMessage(Domain.HEARTBEAT),
- vesMessage(Domain.MEASUREMENTS_FOR_VF_SCALING))
+ vesWireFrameMessage(Domain.HVRANMEAS),
+ vesWireFrameMessage(Domain.HEARTBEAT),
+ vesWireFrameMessage(Domain.MEASUREMENTS_FOR_VF_SCALING))
assertThat(messages).describedAs("number of routed messages").hasSize(3)
@@ -194,9 +203,9 @@ object VesHvSpecification : Spek({
it("should drop message if route was not found") {
val (sut, sink) = vesHvWithStoringSink()
val messages = sut.handleConnection(sink,
- vesMessage(Domain.OTHER, "first"),
- vesMessage(Domain.HVRANMEAS, "second"),
- vesMessage(Domain.HEARTBEAT, "third"))
+ vesWireFrameMessage(Domain.OTHER, "first"),
+ vesWireFrameMessage(Domain.HVRANMEAS, "second"),
+ vesWireFrameMessage(Domain.HEARTBEAT, "third"))
assertThat(messages).describedAs("number of routed messages").hasSize(1)
@@ -228,12 +237,12 @@ object VesHvSpecification : Spek({
sut.configurationProvider.updateConfiguration(configurationWithoutRouting)
- val messages = sut.handleConnection(sink, vesMessage(Domain.HVRANMEAS))
+ val messages = sut.handleConnection(sink, vesWireFrameMessage(Domain.HVRANMEAS))
assertThat(messages).isEmpty()
sut.configurationProvider.updateConfiguration(basicConfiguration)
- val messagesAfterUpdate = sut.handleConnection(sink, vesMessage(Domain.HVRANMEAS))
+ val messagesAfterUpdate = sut.handleConnection(sink, vesWireFrameMessage(Domain.HVRANMEAS))
assertThat(messagesAfterUpdate).hasSize(1)
val message = messagesAfterUpdate[0]
@@ -248,7 +257,7 @@ object VesHvSpecification : Spek({
sut.configurationProvider.updateConfiguration(basicConfiguration)
- val messages = sut.handleConnection(sink, vesMessage(Domain.HVRANMEAS))
+ val messages = sut.handleConnection(sink, vesWireFrameMessage(Domain.HVRANMEAS))
assertThat(messages).hasSize(1)
val firstMessage = messages[0]
@@ -260,7 +269,7 @@ object VesHvSpecification : Spek({
sut.configurationProvider.updateConfiguration(configurationWithDifferentRouting)
- val messagesAfterUpdate = sut.handleConnection(sink, vesMessage(Domain.HVRANMEAS))
+ val messagesAfterUpdate = sut.handleConnection(sink, vesWireFrameMessage(Domain.HVRANMEAS))
assertThat(messagesAfterUpdate).hasSize(2)
val secondMessage = messagesAfterUpdate[1]
@@ -283,7 +292,7 @@ object VesHvSpecification : Spek({
sut.configurationProvider.updateConfiguration(configurationWithDifferentRouting)
}
}.doOnNext {
- sut.handleConnection(sink, vesMessage(Domain.HVRANMEAS))
+ sut.handleConnection(sink, vesWireFrameMessage(Domain.HVRANMEAS))
}.then().block(defaultTimeout)
@@ -314,7 +323,7 @@ object VesHvSpecification : Spek({
println("config changed")
}
}
- .map { vesMessage(Domain.HVRANMEAS) }
+ .map { vesWireFrameMessage(Domain.HVRANMEAS) }
sut.collector.handleConnection(sut.alloc, incomingMessages).block(defaultTimeout)
@@ -339,9 +348,9 @@ object VesHvSpecification : Spek({
val (sut, sink) = vesHvWithStoringSink()
val handledMessages = sut.handleConnection(sink,
- vesMessage(Domain.HVRANMEAS, "first"),
- vesMessageWithTooBigPayload(Domain.HVRANMEAS, "second"),
- vesMessage(Domain.HVRANMEAS, "third"))
+ vesWireFrameMessage(Domain.HVRANMEAS, "first"),
+ vesMessageWithTooBigPayload(Domain.HVRANMEAS),
+ vesWireFrameMessage(Domain.HVRANMEAS))
assertThat(handledMessages).hasSize(1)
assertThat(handledMessages.first().message.header.eventId).isEqualTo("first")
diff --git a/hv-collector-dcae-app-simulator/pom.xml b/hv-collector-dcae-app-simulator/pom.xml
index f3c17357..e38e3cd9 100644
--- a/hv-collector-dcae-app-simulator/pom.xml
+++ b/hv-collector-dcae-app-simulator/pom.xml
@@ -98,6 +98,12 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-test-utils</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>io.arrow-kt</groupId>
<artifactId>arrow-effects</artifactId>
</dependency>
diff --git a/hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt b/hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt
index 5ca64e3e..622a9a22 100644
--- a/hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt
+++ b/hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt
@@ -19,12 +19,13 @@
*/
package org.onap.dcae.collectors.veshv.simulators.dcaeapp.config
-import arrow.core.identity
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
+import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingFailure
+import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingSuccess
import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
@@ -39,25 +40,13 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({
cut = ArgDcaeAppSimConfiguration()
}
- fun parseExpectingSuccess(vararg cmdLine: String): DcaeAppSimConfiguration =
- cut.parse(cmdLine).fold(
- { throw AssertionError("Parsing result should be present") },
- ::identity
- )
-
- fun parseExpectingFailure(vararg cmdLine: String) =
- cut.parse(cmdLine).fold(
- ::identity,
- { throw AssertionError("parsing should have failed") }
- )
-
describe("parsing arguments") {
lateinit var result: DcaeAppSimConfiguration
given("all parameters are present in the long form") {
beforeEachTest {
- result = parseExpectingSuccess(
+ result = cut.parseExpectingSuccess(
"--listen-port", listenPort,
"--kafka-bootstrap-servers", kafkaBootstrapServers,
"--kafka-topics", kafkaTopics
@@ -83,7 +72,7 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({
given("some parameters are present in the short form") {
beforeEachTest {
- result = parseExpectingSuccess(
+ result = cut.parseExpectingSuccess(
"-p", listenPort,
"--kafka-bootstrap-servers", kafkaBootstrapServers,
"-f", kafkaTopics)
@@ -107,7 +96,7 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({
describe("required parameter is absent") {
given("kafka topics are missing") {
it("should throw exception") {
- assertThat(parseExpectingFailure(
+ assertThat(cut.parseExpectingFailure(
"-p", listenPort,
"-s", kafkaBootstrapServers
)).isInstanceOf(WrongArgumentError::class.java)
@@ -116,7 +105,7 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({
given("kafka bootstrap servers is missing") {
it("should throw exception") {
- assertThat(parseExpectingFailure(
+ assertThat(cut.parseExpectingFailure(
"-p", listenPort,
"-f", kafkaTopics
)).isInstanceOf(WrongArgumentError::class.java)
@@ -125,7 +114,7 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({
given("listen port is missing") {
it("should throw exception") {
- assertThat(parseExpectingFailure(
+ assertThat(cut.parseExpectingFailure(
"-p", kafkaTopics,
"-s", kafkaBootstrapServers
)).isInstanceOf(WrongArgumentError::class.java)
diff --git a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/ByteData.kt b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/ByteData.kt
index 2b84e3f1..38be9aee 100644
--- a/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/ByteData.kt
+++ b/hv-collector-domain/src/main/kotlin/org/onap/dcae/collectors/veshv/domain/ByteData.kt
@@ -55,4 +55,3 @@ class ByteData(private val data: ByteArray) {
}
}
-fun MessageLite.toByteData(): ByteData = ByteData(toByteArray())
diff --git a/hv-collector-main/pom.xml b/hv-collector-main/pom.xml
index dbec1def..1208e15d 100644
--- a/hv-collector-main/pom.xml
+++ b/hv-collector-main/pom.xml
@@ -19,8 +19,8 @@
~ ============LICENSE_END=========================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<licenses>
@@ -89,6 +89,12 @@
<artifactId>hv-collector-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-test-utils</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>io.arrow-kt</groupId>
diff --git a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt
index 6b111ae4..f15f7f49 100644
--- a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt
+++ b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgVesHvConfigurationTest.kt
@@ -19,7 +19,6 @@
*/
package org.onap.dcae.collectors.veshv.main
-import arrow.core.identity
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
@@ -29,6 +28,8 @@ import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
import org.onap.dcae.collectors.veshv.main.ArgVesHvConfiguration.DefaultValues
import org.onap.dcae.collectors.veshv.model.ServerConfiguration
+import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingFailure
+import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingSuccess
import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
import java.nio.file.Paths
import java.time.Duration
@@ -51,23 +52,12 @@ object ArgVesHvConfigurationTest : Spek({
cut = ArgVesHvConfiguration()
}
- fun parse(vararg cmdLine: String): ServerConfiguration =
- cut.parse(cmdLine).fold(
- { throw AssertionError("Parsing result should be present") },
- ::identity
- )
-
- fun parseExpectingFailure(vararg cmdLine: String) =
- cut.parse(cmdLine).fold(::identity) {
- throw AssertionError("parsing should have failed")
- }
-
describe("parsing arguments") {
given("all parameters are present in the long form") {
lateinit var result: ServerConfiguration
beforeEachTest {
- result = parse("--ssl-disable",
+ result = cut.parseExpectingSuccess("--ssl-disable",
"--listen-port", listenPort,
"--config-url", configurationUrl,
"--first-request-delay", firstRequestDelay,
@@ -107,7 +97,7 @@ object ArgVesHvConfigurationTest : Spek({
lateinit var result: ServerConfiguration
beforeEachTest {
- result = parse("-p", listenPort, "-c", configurationUrl, "-d", firstRequestDelay)
+ result = cut.parseExpectingSuccess("-p", listenPort, "-c", configurationUrl, "-d", firstRequestDelay)
}
it("should set proper port") {
@@ -129,7 +119,7 @@ object ArgVesHvConfigurationTest : Spek({
lateinit var result: ServerConfiguration
beforeEachTest {
- result = parse("--listen-port", listenPort)
+ result = cut.parseExpectingSuccess("--listen-port", listenPort)
}
it("should set default config url") {
@@ -167,7 +157,7 @@ object ArgVesHvConfigurationTest : Spek({
describe("required parameter is absent") {
given("listen port is missing") {
it("should throw exception") {
- assertThat(parseExpectingFailure(
+ assertThat(cut.parseExpectingFailure(
"--ssl-disable",
"--config-url", configurationUrl,
"--first-request-delay", firstRequestDelay,
diff --git a/hv-collector-test-utils/pom.xml b/hv-collector-test-utils/pom.xml
new file mode 100644
index 00000000..0d670d18
--- /dev/null
+++ b/hv-collector-test-utils/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ </license>
+ </licenses>
+
+ <parent>
+ <groupId>org.onap.dcaegen2.collectors.veshv</groupId>
+ <artifactId>ves-hv-collector</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>hv-collector-test-utils</artifactId>
+ <description>VES HighVolume Collector :: Test Utilities</description>
+
+ <properties>
+ <failIfMissingUnitTests>false</failIfMissingUnitTests>
+ <failIfMissingComponentTests>false</failIfMissingComponentTests>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>kotlin-maven-plugin</artifactId>
+ <groupId>org.jetbrains.kotlin</groupId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <groupId>org.apache.maven.plugins</groupId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-domain</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-utils</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/hv-collector-test-utils/src/main/kotlin/configurations.kt b/hv-collector-test-utils/src/main/kotlin/configurations.kt
new file mode 100644
index 00000000..57843b45
--- /dev/null
+++ b/hv-collector-test-utils/src/main/kotlin/configurations.kt
@@ -0,0 +1,37 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.tests.utils
+
+import arrow.core.identity
+import org.onap.dcae.collectors.veshv.utils.commandline.ArgBasedConfiguration
+import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
+
+
+fun <T> ArgBasedConfiguration<T>.parseExpectingSuccess(vararg cmdLine: String): T =
+ parse(cmdLine).fold(
+ { throw AssertionError("Parsing result should be present") },
+ ::identity
+ )
+
+fun <T> ArgBasedConfiguration<T>.parseExpectingFailure(vararg cmdLine: String): WrongArgumentError =
+ parse(cmdLine).fold(
+ ::identity,
+ { throw AssertionError("parsing should have failed") }
+ ) \ No newline at end of file
diff --git a/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/messages.kt b/hv-collector-test-utils/src/main/kotlin/messages.kt
index a63aa9d5..f8453c64 100644
--- a/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/messages.kt
+++ b/hv-collector-test-utils/src/main/kotlin/messages.kt
@@ -17,45 +17,44 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcae.collectors.veshv.tests.component
+package org.onap.dcae.collectors.veshv.tests.utils
import com.google.protobuf.ByteString
import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.PooledByteBufAllocator
import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage.Companion.MAX_PAYLOAD_SIZE
-import org.onap.ves.VesEventV5
-import org.onap.ves.VesEventV5.VesEvent
-import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain
-import java.util.*
+import java.util.UUID.randomUUID
+
val allocator: ByteBufAllocator = PooledByteBufAllocator.DEFAULT
-fun vesMessage(domain: Domain = Domain.OTHER, id: String = UUID.randomUUID().toString()): ByteBuf =
+private fun ByteBuf.writeValidWireFrameHeaders() {
+ writeByte(0xFF) // always 0xFF
+ writeByte(0x01) // version
+ writeByte(0x01) // content type = GPB
+}
+
+fun vesWireFrameMessage(domain: Domain = Domain.OTHER,
+ id: String = randomUUID().toString()): ByteBuf =
allocator.buffer().run {
- writeByte(0xFF) // always 0xFF
- writeByte(0x01) // version
- writeByte(0x01) // content type = GPB
+ writeValidWireFrameHeaders()
val gpb = vesEvent(domain, id).toByteString().asReadOnlyByteBuffer()
writeInt(gpb.limit()) // ves event size in bytes
writeBytes(gpb) // ves event as GPB bytes
}
-fun endOfTransmissionMessage(): ByteBuf =
+fun endOfTransmissionWireMessage(): ByteBuf =
allocator.buffer().writeByte(0xAA)
-
-fun invalidVesMessage(): ByteBuf = allocator.buffer().run {
- writeByte(0xFF) // always 0xFF
- writeByte(0x01) // version
- writeByte(0x01) // content type = GPB
+fun wireFrameMessageWithInvalidPayload(): ByteBuf = allocator.buffer().run {
+ writeValidWireFrameHeaders()
val invalidGpb = "some random data".toByteArray(Charsets.UTF_8)
writeInt(invalidGpb.size) // ves event size in bytes
writeBytes(invalidGpb)
-
}
fun garbageFrame(): ByteBuf = allocator.buffer().run {
@@ -68,38 +67,17 @@ fun invalidWireFrame(): ByteBuf = allocator.buffer().run {
writeByte(0x01) // content type = GPB
}
-fun vesMessageWithTooBigPayload(domain: Domain = Domain.OTHER, id: String = UUID.randomUUID().toString()): ByteBuf =
+fun vesMessageWithTooBigPayload(domain: Domain = Domain.DOMAIN_UNDEFINED): ByteBuf =
allocator.buffer().run {
- writeByte(0xFF) // always 0xFF
- writeByte(0x01) // version
- writeByte(0x01) // content type = GPB
+ writeValidWireFrameHeaders()
val gpb = vesEvent(
- domain,
- id,
- ByteString.copyFrom(ByteArray(MAX_PAYLOAD_SIZE))
+ domain = domain,
+ hvRanMeasFields = ByteString.copyFrom(ByteArray(MAX_PAYLOAD_SIZE))
).toByteString().asReadOnlyByteBuffer()
writeInt(gpb.limit()) // ves event size in bytes
writeBytes(gpb) // ves event as GPB bytes
}
-fun vesEvent(domain: Domain = Domain.HVRANMEAS,
- id: String = UUID.randomUUID().toString(),
- hvRanMeasFields: ByteString = ByteString.EMPTY): VesEventV5.VesEvent =
- VesEvent.newBuilder()
- .setCommonEventHeader(
- CommonEventHeader.getDefaultInstance().toBuilder()
- .setVersion("1.0")
- .setEventName("xyz")
- .setEventId(id)
- .setDomain(domain)
- .setEventName("Sample event name")
- .setSourceName("Sample Source")
- .setReportingEntityName(ByteString.copyFromUtf8("Sample byte String"))
- .setPriority(CommonEventHeader.Priority.MEDIUM)
- .setStartEpochMicrosec(120034455)
- .setLastEpochMicrosec(120034459)
- .setSequence(1))
- .setHvRanMeasFields(hvRanMeasFields)
- .build()
+
diff --git a/hv-collector-test-utils/src/main/kotlin/vesEvents.kt b/hv-collector-test-utils/src/main/kotlin/vesEvents.kt
new file mode 100644
index 00000000..6aeb6206
--- /dev/null
+++ b/hv-collector-test-utils/src/main/kotlin/vesEvents.kt
@@ -0,0 +1,65 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.tests.utils
+
+
+import com.google.protobuf.ByteString
+import com.google.protobuf.MessageLite
+import org.onap.dcae.collectors.veshv.domain.ByteData
+import org.onap.ves.VesEventV5
+import java.util.UUID.randomUUID
+
+fun vesEvent(domain: VesEventV5.VesEvent.CommonEventHeader.Domain = VesEventV5.VesEvent.CommonEventHeader.Domain.HVRANMEAS,
+ id: String = randomUUID().toString(),
+ hvRanMeasFields: ByteString = ByteString.EMPTY
+): VesEventV5.VesEvent = vesEvent(commonHeader(domain, id), hvRanMeasFields)
+
+fun vesEvent(commonEventHeader: VesEventV5.VesEvent.CommonEventHeader,
+ hvRanMeasFields: ByteString = ByteString.EMPTY): VesEventV5.VesEvent =
+ VesEventV5.VesEvent.newBuilder()
+ .setCommonEventHeader(commonEventHeader)
+ .setHvRanMeasFields(hvRanMeasFields)
+ .build()
+
+fun commonHeader(domain: VesEventV5.VesEvent.CommonEventHeader.Domain = VesEventV5.VesEvent.CommonEventHeader.Domain.HVRANMEAS,
+ id: String = randomUUID().toString(),
+ priority: VesEventV5.VesEvent.CommonEventHeader.Priority = VesEventV5.VesEvent.CommonEventHeader.Priority.NORMAL): VesEventV5.VesEvent.CommonEventHeader =
+ VesEventV5.VesEvent.CommonEventHeader.newBuilder()
+ .setVersion("sample-version")
+ .setDomain(domain)
+ .setSequence(1)
+ .setPriority(priority)
+ .setEventId(id)
+ .setEventName("sample-event-name")
+ .setEventType("sample-event-type")
+ .setStartEpochMicrosec(120034455)
+ .setLastEpochMicrosec(120034455)
+ .setNfNamingCode("sample-nf-naming-code")
+ .setNfcNamingCode("sample-nfc-naming-code")
+ .setReportingEntityId("sample-reporting-entity-id")
+ .setReportingEntityName(ByteString.copyFromUtf8("sample-reporting-entity-name"))
+ .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
+ .setSourceName("sample-source-name")
+ .build()
+
+fun vesEventBytes(commonHeader: VesEventV5.VesEvent.CommonEventHeader, byteString: ByteString = ByteString.EMPTY): ByteData =
+ vesEvent(commonHeader, byteString).toByteData()
+
+fun MessageLite.toByteData(): ByteData = ByteData(toByteArray()) \ No newline at end of file
diff --git a/hv-collector-ves-message-generator/pom.xml b/hv-collector-ves-message-generator/pom.xml
index f049d78f..7da3bb21 100644
--- a/hv-collector-ves-message-generator/pom.xml
+++ b/hv-collector-ves-message-generator/pom.xml
@@ -63,6 +63,12 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-test-utils</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt
index 1e38d46e..1b121ec4 100644
--- a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt
+++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt
@@ -30,6 +30,7 @@ import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.domain.ByteData
import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage
+import org.onap.dcae.collectors.veshv.tests.utils.commonHeader
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParameters
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType
@@ -53,7 +54,7 @@ object MessageGeneratorImplTest : Spek({
val limit = 1000L
generator
.createMessageFlux(listOf(MessageParameters(
- createSampleCommonHeader(HVRANMEAS),
+ commonHeader(HVRANMEAS),
MessageType.VALID
)))
.take(limit)
@@ -66,7 +67,7 @@ object MessageGeneratorImplTest : Spek({
it("should create message flux of specified size") {
generator
.createMessageFlux(listOf(MessageParameters(
- createSampleCommonHeader(HVRANMEAS),
+ commonHeader(HVRANMEAS),
MessageType.VALID,
5
)))
@@ -79,7 +80,7 @@ object MessageGeneratorImplTest : Spek({
it("should create flux of valid messages with given domain") {
generator
.createMessageFlux(listOf(MessageParameters(
- createSampleCommonHeader(FAULT),
+ commonHeader(FAULT),
MessageType.VALID,
1
)))
@@ -97,7 +98,7 @@ object MessageGeneratorImplTest : Spek({
generator
.createMessageFlux(listOf(MessageParameters(
- createSampleCommonHeader(HVRANMEAS),
+ commonHeader(HVRANMEAS),
MessageType.TOO_BIG_PAYLOAD,
1
)))
@@ -114,7 +115,7 @@ object MessageGeneratorImplTest : Spek({
it("should create flux of messages with invalid payload") {
generator
.createMessageFlux(listOf(MessageParameters(
- createSampleCommonHeader(HVRANMEAS),
+ commonHeader(HVRANMEAS),
MessageType.INVALID_GPB_DATA,
1
)))
@@ -132,7 +133,7 @@ object MessageGeneratorImplTest : Spek({
it("should create flux of messages with invalid version") {
generator
.createMessageFlux(listOf(MessageParameters(
- createSampleCommonHeader(HVRANMEAS),
+ commonHeader(HVRANMEAS),
MessageType.INVALID_WIRE_FRAME,
1
)))
@@ -150,7 +151,7 @@ object MessageGeneratorImplTest : Spek({
it("should create flux of valid messages with fixed payload") {
generator
.createMessageFlux(listOf(MessageParameters(
- createSampleCommonHeader(FAULT),
+ commonHeader(FAULT),
MessageType.FIXED_PAYLOAD,
1
)))
@@ -169,9 +170,9 @@ object MessageGeneratorImplTest : Spek({
it("should create concatenated flux of messages") {
val singleFluxSize = 5L
val messageParameters = listOf(
- MessageParameters(createSampleCommonHeader(HVRANMEAS), MessageType.VALID, singleFluxSize),
- MessageParameters(createSampleCommonHeader(FAULT), MessageType.TOO_BIG_PAYLOAD, singleFluxSize),
- MessageParameters(createSampleCommonHeader(HEARTBEAT), MessageType.VALID, singleFluxSize)
+ MessageParameters(commonHeader(HVRANMEAS), MessageType.VALID, singleFluxSize),
+ MessageParameters(commonHeader(FAULT), MessageType.TOO_BIG_PAYLOAD, singleFluxSize),
+ MessageParameters(commonHeader(HEARTBEAT), MessageType.VALID, singleFluxSize)
)
generator.createMessageFlux(messageParameters)
.test()
@@ -203,23 +204,3 @@ fun extractCommonEventHeader(bytes: ByteData): CommonEventHeader {
fun extractHvRanMeasFields(bytes: ByteData): ByteString {
return VesEvent.parseFrom(bytes.unsafeAsArray()).hvRanMeasFields
}
-
-private fun createSampleCommonHeader(domain: CommonEventHeader.Domain): CommonEventHeader = CommonEventHeader.newBuilder()
- .setVersion("sample-version")
- .setDomain(domain)
- .setSequence(1)
- .setPriority(CommonEventHeader.Priority.NORMAL)
- .setEventId("sample-event-id")
- .setEventName("sample-event-name")
- .setEventType("sample-event-type")
- .setStartEpochMicrosec(120034455)
- .setLastEpochMicrosec(120034455)
- .setNfNamingCode("sample-nf-naming-code")
- .setNfcNamingCode("sample-nfc-naming-code")
- .setReportingEntityId("sample-reporting-entity-id")
- .setReportingEntityName(ByteString.copyFromUtf8("sample-reporting-entity-name"))
- .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
- .setSourceName("sample-source-name")
- .build()
-
-
diff --git a/hv-collector-xnf-simulator/pom.xml b/hv-collector-xnf-simulator/pom.xml
index 2a02fae1..29d557a2 100644
--- a/hv-collector-xnf-simulator/pom.xml
+++ b/hv-collector-xnf-simulator/pom.xml
@@ -19,8 +19,8 @@
~ ============LICENSE_END=========================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<licenses>
@@ -99,6 +99,12 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>hv-collector-test-utils</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>io.arrow-kt</groupId>
<artifactId>arrow-effects</artifactId>
</dependency>
diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt
index 3fb4be99..02e6ee72 100644
--- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt
+++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt
@@ -23,6 +23,7 @@ import arrow.effects.IO
import org.onap.dcae.collectors.veshv.utils.logging.Logger
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser
+import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser.Companion.INSTANCE
import ratpack.handling.Chain
import ratpack.handling.Context
import ratpack.server.RatpackServer
@@ -35,7 +36,7 @@ import javax.json.Json
* @since June 2018
*/
internal class HttpServer(private val vesClient: XnfSimulator,
- private val messageParametersParser: MessageParametersParser = MessageParametersParser.INSTANCE) {
+ private val messageParametersParser: MessageParametersParser = INSTANCE) {
fun start(port: Int): IO<RatpackServer> = IO {
RatpackServer.start { server ->
diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt
index e3a20c70..8749dc5b 100644
--- a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt
+++ b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt
@@ -19,8 +19,6 @@
*/
package org.onap.dcae.collectors.veshv.main.config
-import arrow.core.identity
-import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
@@ -31,6 +29,8 @@ import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration
import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration.DefaultValues
import org.onap.dcae.collectors.veshv.simulators.xnf.config.SimulatorConfiguration
+import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingFailure
+import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingSuccess
import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
import java.nio.file.Paths
import kotlin.test.assertTrue
@@ -49,25 +49,13 @@ object ArgXnfSimulatorConfiurationTest : Spek({
cut = ArgXnfSimulatorConfiguration()
}
- fun parse(vararg cmdLine: String): SimulatorConfiguration =
- cut.parse(cmdLine).fold(
- { throw AssertionError("Parsing result should be present") },
- ::identity
- )
-
- fun parseExpectingFailure(vararg cmdLine: String) =
- cut.parse(cmdLine).fold(
- ::identity,
- { throw AssertionError("parsing should have failed") }
- )
-
describe("parsing arguments") {
lateinit var result: SimulatorConfiguration
given("all parameters are present in the long form") {
beforeEachTest {
- result = parse("--ssl-disable",
+ result = cut.parseExpectingSuccess("--ssl-disable",
"--listen-port", listenPort,
"--ves-host", vesHost,
"--ves-port", vesPort,
@@ -98,7 +86,7 @@ object ArgXnfSimulatorConfiurationTest : Spek({
given("some parameters are present in the short form") {
beforeEachTest {
- result = parse("-p", listenPort, "-h", vesHost, "--ves-port", vesPort)
+ result = cut.parseExpectingSuccess("-p", listenPort, "-h", vesHost, "--ves-port", vesPort)
}
it("should set proper listen port") {
@@ -117,7 +105,7 @@ object ArgXnfSimulatorConfiurationTest : Spek({
given("all optional parameters are absent") {
beforeEachTest {
- result = parse("-p", listenPort, "-h", vesHost, "-v", vesPort)
+ result = cut.parseExpectingSuccess("-p", listenPort, "-h", vesHost, "-v", vesPort)
}
on("security config") {
@@ -139,7 +127,7 @@ object ArgXnfSimulatorConfiurationTest : Spek({
given("disabled ssl certs together with all other parameters") {
beforeEachTest {
- result = parse("--ssl-disable",
+ result = cut.parseExpectingSuccess("--ssl-disable",
"--listen-port", listenPort,
"--ves-port", "888",
"--ves-host", vesHost,
@@ -170,21 +158,21 @@ object ArgXnfSimulatorConfiurationTest : Spek({
describe("required parameter is absent") {
given("ves port is missing") {
it("should throw exception") {
- assertThat(parseExpectingFailure("-p", listenPort, "-h", vesHost))
+ assertThat(cut.parseExpectingFailure("-p", listenPort, "-h", vesHost))
.isInstanceOf(WrongArgumentError::class.java)
}
}
given("ves host is missing") {
it("should throw exception") {
- assertThat(parseExpectingFailure("-p", listenPort, "-v", vesPort))
+ assertThat(cut.parseExpectingFailure("-p", listenPort, "-v", vesPort))
.isInstanceOf(WrongArgumentError::class.java)
}
}
given("listen port is missing") {
it("should throw exception") {
- assertThat(parseExpectingFailure("-h", vesHost, "-v", vesPort))
+ assertThat(cut.parseExpectingFailure("-h", vesHost, "-v", vesPort))
.isInstanceOf(WrongArgumentError::class.java)
}
}
diff --git a/pom.xml b/pom.xml
index 27461bed..25400ef3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,7 @@
<module>hv-collector-utils</module>
<module>hv-collector-ves-message-generator</module>
<module>hv-collector-xnf-simulator</module>
+ <module>hv-collector-test-utils</module>
</modules>
<properties>