aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-core/src/test
diff options
context:
space:
mode:
authorFilip Krzywka <filip.krzywka@nokia.com>2018-11-29 11:58:40 +0100
committerFilip Krzywka <filip.krzywka@nokia.com>2018-12-04 13:31:17 +0100
commitd632aef8303701a1802f817c3d6fdcd4064c32b2 (patch)
tree70614ef073f437810beea848c9f9a81189b794d8 /sources/hv-collector-core/src/test
parentdde383a2aa75f94c26d7949665b79cc95486a223 (diff)
Harmonize logging and add new logs
- corrected docker-compose consul url Change-Id: I78df868e0dd51008ef39d01553e6a0a3b8273a54 Issue-ID: DCAEGEN2-1003 Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
Diffstat (limited to 'sources/hv-collector-core/src/test')
-rw-r--r--sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt109
-rw-r--r--sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt9
2 files changed, 98 insertions, 20 deletions
diff --git a/sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt b/sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt
index 3090042d..60bd767b 100644
--- a/sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt
+++ b/sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/MessageValidatorTest.kt
@@ -19,21 +19,29 @@
*/
package org.onap.dcae.collectors.veshv.impl
+import arrow.core.Either.Companion.left
+import arrow.core.Either.Companion.right
+import com.nhaarman.mockitokotlin2.doReturn
+import com.nhaarman.mockitokotlin2.mock
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.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.domain.ByteData
+import org.onap.dcae.collectors.veshv.domain.InvalidMajorVersion
import org.onap.dcae.collectors.veshv.domain.VesEventDomain
+import org.onap.dcae.collectors.veshv.domain.WireFrameMessage
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.*
+import kotlin.test.assertTrue
internal object MessageValidatorTest : Spek({
- given("Message validator") {
+ describe("Message validator") {
val cut = MessageValidator
on("ves hv message including header with fully initialized fields") {
@@ -41,29 +49,35 @@ internal object MessageValidatorTest : Spek({
it("should accept message with fully initialized message header") {
val vesMessage = VesMessage(commonHeader, vesEventBytes(commonHeader))
- assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isTrue()
+ with(cut) {
+ assertThat(vesMessage.isValid()).describedAs("message validation result").isTrue()
+ }
}
- VesEventDomain.values()
- .forEach { domain ->
- it("should accept message with $domain domain") {
- val header = commonHeader(domain)
- val vesMessage = VesMessage(header, vesEventBytes(header))
- assertThat(cut.isValid(vesMessage))
- .isTrue()
- }
+ VesEventDomain.values().forEach { domain ->
+ it("should accept message with $domain domain") {
+ val header = commonHeader(domain)
+ val vesMessage = VesMessage(header, vesEventBytes(header))
+ with(cut) {
+ assertThat(vesMessage.isValid()).describedAs("message validation result").isTrue()
}
+ }
+ }
}
on("ves hv message bytes") {
val vesMessage = VesMessage(getDefaultInstance(), ByteData.EMPTY)
it("should not accept message with default header") {
- assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
+ with(cut) {
+ assertThat(vesMessage.isValid()).describedAs("message validation result").isFalse()
+ }
}
}
val priorityTestCases = mapOf(
Priority.PRIORITY_NOT_PROVIDED to false,
+ Priority.LOW to true,
+ Priority.MEDIUM to true,
Priority.HIGH to true
)
@@ -73,8 +87,10 @@ internal object MessageValidatorTest : Spek({
val vesMessage = VesMessage(commonEventHeader, vesEventBytes(commonEventHeader))
it("should resolve validation result") {
- assertThat(cut.isValid(vesMessage)).describedAs("message validation results")
- .isEqualTo(expectedResult)
+ with(cut) {
+ assertThat(vesMessage.isValid()).describedAs("message validation results")
+ .isEqualTo(expectedResult)
+ }
}
}
}
@@ -90,7 +106,9 @@ internal object MessageValidatorTest : Spek({
it("should not accept not fully initialized message header") {
val vesMessage = VesMessage(commonHeader, rawMessageBytes)
- assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
+ with(cut) {
+ assertThat(vesMessage.isValid()).describedAs("message validation result").isFalse()
+ }
}
}
@@ -101,7 +119,9 @@ internal object MessageValidatorTest : Spek({
it("should not accept message header") {
val vesMessage = VesMessage(commonHeader, rawMessageBytes)
- assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
+ with(cut) {
+ assertThat(vesMessage.isValid()).describedAs("message validation result").isFalse()
+ }
}
}
@@ -111,7 +131,10 @@ internal object MessageValidatorTest : Spek({
it("should not accept message header") {
val vesMessage = VesMessage(commonHeader, rawMessageBytes)
- assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
+
+ with(cut) {
+ assertThat(vesMessage.isValid()).describedAs("message validation result").isFalse()
+ }
}
}
@@ -121,8 +144,60 @@ internal object MessageValidatorTest : Spek({
it("should not accept message header") {
val vesMessage = VesMessage(commonHeader, rawMessageBytes)
- assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
+
+ with(cut) {
+ assertThat(vesMessage.isValid()).describedAs("message validation result").isFalse()
+ }
+ }
+ }
+
+ describe("validating messages and converting to Either of string for validation result") {
+ given("WireFrameMessage") {
+ on("valid message as input") {
+ val wireFrameMessage = WireFrameMessage("lets pretend it's valid".toByteArray())
+ val mockedWireFrameMessage = mock<WireFrameMessage> {
+ on { validate() } doReturn right(wireFrameMessage)
+ }
+
+ it("should be right") {
+ assertTrue(cut.validateFrameMessage(mockedWireFrameMessage).isRight())
+ }
+ }
+
+ on("invalid message as input") {
+ val mockedWireFrameMessage = mock<WireFrameMessage> {
+ on { validate() } doReturn left(InvalidMajorVersion(99))
+ }
+
+ it("should be left") {
+ assertTrue(cut.validateFrameMessage(mockedWireFrameMessage).isLeft())
+ }
+ }
}
+
+ given("VesEvent") {
+ with(cut) {
+ on("valid message as input") {
+ val commonHeader = commonHeader()
+ val rawMessageBytes = vesEventBytes(commonHeader)
+ val vesMessage = VesMessage(commonHeader, rawMessageBytes)
+
+ it("should be right") {
+ assertTrue(validateProtobufMessage(vesMessage).isRight())
+ }
+ }
+ }
+ on("invalid message as input") {
+ val commonHeader = newBuilder().build()
+ val rawMessageBytes = vesEventBytes(commonHeader)
+ val vesMessage = VesMessage(commonHeader, rawMessageBytes)
+
+ it("should be left") {
+ assertTrue(cut.validateProtobufMessage(vesMessage).isLeft())
+ }
+ }
+ }
+
}
}
})
diff --git a/sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt b/sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt
index 8950a557..cdee92c9 100644
--- a/sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt
+++ b/sources/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/VesDecoderTest.kt
@@ -20,6 +20,8 @@
package org.onap.dcae.collectors.veshv.impl
import arrow.core.Option
+import arrow.core.Try
+import arrow.core.success
import com.google.protobuf.ByteString
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
@@ -30,6 +32,7 @@ import org.onap.dcae.collectors.veshv.domain.VesEventDomain.HEARTBEAT
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 reactor.test.test
import java.nio.charset.Charset
import kotlin.test.assertTrue
import kotlin.test.fail
@@ -68,7 +71,7 @@ internal object VesDecoderTest : Spek({
}
})
-private fun <A> assertFailedWithError(option: Option<A>) =
- option.exists {
+private fun <A> assertFailedWithError(t: Try<A>) =
+ t.exists {
fail("Error expected")
- }
+ } \ No newline at end of file