diff options
author | Filip Krzywka <filip.krzywka@nokia.com> | 2018-09-11 14:45:53 +0200 |
---|---|---|
committer | Filip Krzywka <filip.krzywka@nokia.com> | 2018-09-17 11:53:34 +0000 |
commit | eb766269ca42c91a985797c15fdaa9de255b904e (patch) | |
tree | b87975976b9d579a256ef031f75fa46f2897c67f /hv-collector-ves-message-generator/src/test | |
parent | 6bc7018f650ad67301d4d9dbdbc5ae5c05753841 (diff) |
Align with latest HV-VES proto definition
- excluded measurements proto files from build to keep them
reference-only
Change-Id: I8c6de20eeeb1b9f8cd2ae4e865de368afe55cc91
Issue-ID: DCAEGEN2-775
Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
Diffstat (limited to 'hv-collector-ves-message-generator/src/test')
4 files changed, 113 insertions, 127 deletions
diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/CommonEventHeaderParserTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/CommonEventHeaderParserTest.kt index c16459ce..ce394cc1 100644 --- a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/CommonEventHeaderParserTest.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/CommonEventHeaderParserTest.kt @@ -27,8 +27,9 @@ 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.domain.VesEventDomain.STATE_CHANGE import org.onap.dcae.collectors.veshv.tests.utils.commonHeader -import org.onap.ves.VesEventV5 +import org.onap.ves.VesEventOuterClass.CommonEventHeader import java.io.ByteArrayInputStream import javax.json.Json import kotlin.test.fail @@ -40,7 +41,7 @@ class CommonEventHeaderParserTest : Spek({ given("valid header in JSON format") { val commonEventHeader = commonHeader( - domain = VesEventV5.VesEvent.CommonEventHeader.Domain.STATE_CHANGE, + domain = STATE_CHANGE, id = "sample-event-id") val json = JsonFormat.printer().print(commonEventHeader).byteInputStream() @@ -75,7 +76,7 @@ class CommonEventHeaderParserTest : Spek({ } }) -fun assertFailed(result: Option<VesEventV5.VesEvent.CommonEventHeader>) = +fun assertFailed(result: Option<CommonEventHeader>) = result.fold({}, { fail() }) fun jsonObject(json: ByteArrayInputStream) = Json.createReader(json).readObject()
\ No newline at end of file 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 f13a33bf..ea3d094a 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,15 +30,15 @@ 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.domain.VesEventDomain.HVMEAS +import org.onap.dcae.collectors.veshv.domain.VesEventDomain.FAULT +import org.onap.dcae.collectors.veshv.domain.VesEventDomain.HEARTBEAT 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 -import org.onap.ves.VesEventV5.VesEvent -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain.FAULT -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain.HEARTBEAT -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain.HVRANMEAS +import org.onap.ves.VesEventOuterClass.CommonEventHeader +import org.onap.ves.VesEventOuterClass.VesEvent import reactor.test.test /** @@ -54,7 +54,7 @@ object MessageGeneratorImplTest : Spek({ val limit = 1000L generator .createMessageFlux(listOf(MessageParameters( - commonHeader(HVRANMEAS), + commonHeader(HVMEAS), MessageType.VALID ))) .take(limit) @@ -67,7 +67,7 @@ object MessageGeneratorImplTest : Spek({ it("should create message flux of specified size") { generator .createMessageFlux(listOf(MessageParameters( - commonHeader(HVRANMEAS), + commonHeader(HVMEAS), MessageType.VALID, 5 ))) @@ -88,7 +88,7 @@ object MessageGeneratorImplTest : Spek({ .assertNext { assertThat(it.isValid()).isTrue() assertThat(it.payloadSize).isLessThan(PayloadWireFrameMessage.MAX_PAYLOAD_SIZE) - assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT) + assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT.name) } .verifyComplete() } @@ -98,7 +98,7 @@ object MessageGeneratorImplTest : Spek({ generator .createMessageFlux(listOf(MessageParameters( - commonHeader(HVRANMEAS), + commonHeader(HVMEAS), MessageType.TOO_BIG_PAYLOAD, 1 ))) @@ -106,7 +106,7 @@ object MessageGeneratorImplTest : Spek({ .assertNext { assertThat(it.isValid()).isTrue() assertThat(it.payloadSize).isGreaterThan(PayloadWireFrameMessage.MAX_PAYLOAD_SIZE) - assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HVRANMEAS) + assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HVMEAS.name) } .verifyComplete() } @@ -115,7 +115,7 @@ object MessageGeneratorImplTest : Spek({ it("should create flux of messages with invalid payload") { generator .createMessageFlux(listOf(MessageParameters( - commonHeader(HVRANMEAS), + commonHeader(HVMEAS), MessageType.INVALID_GPB_DATA, 1 ))) @@ -133,7 +133,7 @@ object MessageGeneratorImplTest : Spek({ it("should create flux of messages with invalid version") { generator .createMessageFlux(listOf(MessageParameters( - commonHeader(HVRANMEAS), + commonHeader(HVMEAS), MessageType.INVALID_WIRE_FRAME, 1 ))) @@ -141,7 +141,7 @@ object MessageGeneratorImplTest : Spek({ .assertNext { assertThat(it.isValid()).isFalse() assertThat(it.payloadSize).isLessThan(PayloadWireFrameMessage.MAX_PAYLOAD_SIZE) - assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HVRANMEAS) + assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HVMEAS.name) assertThat(it.versionMajor).isNotEqualTo(PayloadWireFrameMessage.SUPPORTED_VERSION_MINOR) } .verifyComplete() @@ -160,7 +160,7 @@ object MessageGeneratorImplTest : Spek({ assertThat(it.isValid()).isTrue() assertThat(it.payloadSize).isLessThan(PayloadWireFrameMessage.MAX_PAYLOAD_SIZE) assertThat(extractHvRanMeasFields(it.payload).size()).isEqualTo(MessageGenerator.FIXED_PAYLOAD_SIZE) - assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT) + assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT.name) } .verifyComplete() } @@ -170,7 +170,7 @@ object MessageGeneratorImplTest : Spek({ it("should create concatenated flux of messages") { val singleFluxSize = 5L val messageParameters = listOf( - MessageParameters(commonHeader(HVRANMEAS), MessageType.VALID, singleFluxSize), + MessageParameters(commonHeader(HVMEAS), MessageType.VALID, singleFluxSize), MessageParameters(commonHeader(FAULT), MessageType.TOO_BIG_PAYLOAD, singleFluxSize), MessageParameters(commonHeader(HEARTBEAT), MessageType.VALID, singleFluxSize) ) @@ -178,17 +178,17 @@ object MessageGeneratorImplTest : Spek({ .test() .assertNext { assertThat(it.payloadSize).isLessThan(PayloadWireFrameMessage.MAX_PAYLOAD_SIZE) - assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HVRANMEAS) + assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HVMEAS.name) } .expectNextCount(singleFluxSize - 1) .assertNext { assertThat(it.payloadSize).isGreaterThan(PayloadWireFrameMessage.MAX_PAYLOAD_SIZE) - assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT) + assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT.name) } .expectNextCount(singleFluxSize - 1) .assertNext { assertThat(it.payloadSize).isLessThan(PayloadWireFrameMessage.MAX_PAYLOAD_SIZE) - assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HEARTBEAT) + assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HEARTBEAT.name) } .expectNextCount(singleFluxSize - 1) .verifyComplete() @@ -197,10 +197,10 @@ object MessageGeneratorImplTest : Spek({ } }) -fun extractCommonEventHeader(bytes: ByteData): CommonEventHeader { - return VesEvent.parseFrom(bytes.unsafeAsArray()).commonEventHeader -} +fun extractCommonEventHeader(bytes: ByteData): CommonEventHeader = + VesEvent.parseFrom(bytes.unsafeAsArray()).commonEventHeader + + +fun extractHvRanMeasFields(bytes: ByteData): ByteString = + VesEvent.parseFrom(bytes.unsafeAsArray()).hvMeasFields -fun extractHvRanMeasFields(bytes: ByteData): ByteString { - return VesEvent.parseFrom(bytes.unsafeAsArray()).hvRanMeasFields -} diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/PayloadGeneratorTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/PayloadGeneratorTest.kt index 3695ca4d..2b41e290 100644 --- a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/PayloadGeneratorTest.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/PayloadGeneratorTest.kt @@ -26,50 +26,27 @@ import org.assertj.core.api.Assertions.assertThat import org.jetbrains.spek.api.dsl.on import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator -private const val DEFAULT_MEASUREMENTS_NUMBER = 2 -private const val DEFAULT_COUNTERS_NUMBER = 2 - -private val uriRegex = """sample/uri(\d+)""".toRegex() - object PayloadGeneratorTest : Spek({ given("payload factory object") { val payloadGenerator = PayloadGenerator() - on("two generated payloads") { - val generatedPayload0 = payloadGenerator.generatePayload() - val generatedPayload1 = payloadGenerator.generatePayload() - it("URIs should have different names") { - val matchResult0 = uriRegex.find(generatedPayload0.getPmObject(0).uri)!!.value - val matchResult1 = uriRegex.find(generatedPayload1.getPmObject(0).uri)!!.value - assertThat(matchResult0 != matchResult1).isTrue() - } - } + on("raw payload generation") { + val size = 100 + val generatedPayload = payloadGenerator.generateRawPayload(size) - on("call with default parameters") { - val generatedPayload = payloadGenerator.generatePayload() - it("should contain default numbers of measurements") { - assertThat(generatedPayload.getPmObject(0).hvRanMeasCount).isEqualTo(DEFAULT_MEASUREMENTS_NUMBER) - } - it("should contain default numbers of counters in measurement") { - assertThat(generatedPayload.getPmObject(0).getHvRanMeas(0).counterSubidCount).isEqualTo(DEFAULT_COUNTERS_NUMBER) + it("should generate sequence of zeros") { + assertThat(generatedPayload.size()).isEqualTo(size) + assertThat(generatedPayload.toByteArray()).isEqualTo(ByteArray(size)) } } - on("call with specified parameters") { - val numOfCountPerMeas: Long = 5 - val numOfMeasPerObject = 10 - val generatedPayload = payloadGenerator.generatePayload(numOfCountPerMeas, numOfMeasPerObject) - it("should contain specified number of measurements") { - assertThat(generatedPayload.getPmObject(0).hvRanMeasCount).isEqualTo(numOfMeasPerObject) - } - it("measurement should contain specified number of counters") { - assertThat(generatedPayload.getPmObject(0).hvRanMeasList - .filter { numOfCountPerMeas.toInt() == it.counterSubidCount } - .size) - .isEqualTo(numOfMeasPerObject) + on("two generated payloads") { + val generatedPayload0 = payloadGenerator.generatePayload() + val generatedPayload1 = payloadGenerator.generatePayload() + it("should be different") { + assertThat(generatedPayload0 != generatedPayload1).isTrue() } - } } }) diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/parameters.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/parameters.kt index 88550603..45e936a6 100644 --- a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/parameters.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/parameters.kt @@ -21,73 +21,81 @@ package org.onap.dcae.collectors.veshv.ves.message.generator.impl.impl import javax.json.Json -private const val validMessageParameters = "[\n" + - " {\n" + - " \"commonEventHeader\": {\n" + - " \"version\": \"sample-version\",\n" + - " \"domain\": \"HVRANMEAS\",\n" + - " \"sequence\": 1,\n" + - " \"priority\": 1,\n" + - " \"eventId\": \"sample-event-id\",\n" + - " \"eventName\": \"sample-event-name\",\n" + - " \"eventType\": \"sample-event-type\",\n" + - " \"startEpochMicrosec\": 120034455,\n" + - " \"lastEpochMicrosec\": 120034455,\n" + - " \"nfNamingCode\": \"sample-nf-naming-code\",\n" + - " \"nfcNamingCode\": \"sample-nfc-naming-code\",\n" + - " \"reportingEntityId\": \"sample-reporting-entity-id\",\n" + - " \"reportingEntityName\": \"sample-reporting-entity-name\",\n" + - " \"sourceId\": \"sample-source-id\",\n" + - " \"sourceName\": \"sample-source-name\"\n" + - " },\n" + - " \"messageType\": \"VALID\",\n" + - " \"messagesAmount\": 25000\n" + - " },\n" + - " {\n" + - " \"commonEventHeader\": {\n" + - " \"version\": \"sample-version\",\n" + - " \"domain\": \"HVRANMEAS\",\n" + - " \"sequence\": 1,\n" + - " \"priority\": 1,\n" + - " \"eventId\": \"sample-event-id\",\n" + - " \"eventName\": \"sample-event-name\",\n" + - " \"eventType\": \"sample-event-type\",\n" + - " \"startEpochMicrosec\": 120034455,\n" + - " \"lastEpochMicrosec\": 120034455,\n" + - " \"nfNamingCode\": \"sample-nf-naming-code\",\n" + - " \"nfcNamingCode\": \"sample-nfc-naming-code\",\n" + - " \"reportingEntityId\": \"sample-reporting-entity-id\",\n" + - " \"reportingEntityName\": \"sample-reporting-entity-name\",\n" + - " \"sourceId\": \"sample-source-id\",\n" + - " \"sourceName\": \"sample-source-name\"\n" + - " },\n" + - " \"messageType\": \"TOO_BIG_PAYLOAD\",\n" + - " \"messagesAmount\": 100\n" + - " }\n" + - "]" +private const val validMessageParameters = +"""[ + { + "commonEventHeader": { + "version": "sample-version", + "domain": "HVMEAS", + "sequence": 1, + "priority": 1, + "eventId": "sample-event-id", + "eventName": "sample-event-name", + "eventType": "sample-event-type", + "startEpochMicrosec": 120034455, + "lastEpochMicrosec": 120034455, + "nfNamingCode": "sample-nf-naming-code", + "nfcNamingCode": "sample-nfc-naming-code", + "reportingEntityId": "sample-reporting-entity-id", + "reportingEntityName": "sample-reporting-entity-name", + "sourceId": "sample-source-id", + "sourceName": "sample-source-name", + "vesEventListenerVersion": "another-version" + }, + "messageType": "VALID", + "messagesAmount": 25000 + }, + { + "commonEventHeader": { + "version": "sample-version", + "domain": "HVMEAS", + "sequence": 1, + "priority": 1, + "eventId": "sample-event-id", + "eventName": "sample-event-name", + "eventType": "sample-event-type", + "startEpochMicrosec": 120034455, + "lastEpochMicrosec": 120034455, + "nfNamingCode": "sample-nf-naming-code", + "nfcNamingCode": "sample-nfc-naming-code", + "reportingEntityId": "sample-reporting-entity-id", + "reportingEntityName": "sample-reporting-entity-name", + "sourceId": "sample-source-id", + "sourceName": "sample-source-name", + "vesEventListenerVersion": "another-version" + }, + "messageType": "TOO_BIG_PAYLOAD", + "messagesAmount": 100 + } + ] +""" -private const val invalidMessageParameters = "[\n" + - " {\n" + - " \"commonEventHeader\": {\n" + - " \"version\": \"sample-version\",\n" + - " \"domain\": \"HVRANMEAS\",\n" + - " \"sequence\": 1,\n" + - " \"priority\": 1,\n" + - " \"eventId\": \"sample-event-id\",\n" + - " \"eventName\": \"sample-event-name\",\n" + - " \"eventType\": \"sample-event-type\",\n" + - " \"startEpochMicrosec\": 120034455,\n" + - " \"lastEpochMicrosec\": 120034455,\n" + - " \"nfNamingCode\": \"sample-nf-naming-code\",\n" + - " \"nfcNamingCode\": \"sample-nfc-naming-code\",\n" + - " \"reportingEntityId\": \"sample-reporting-entity-id\",\n" + - " \"reportingEntityName\": \"sample-reporting-entity-name\",\n" + - " \"sourceId\": \"sample-source-id\",\n" + - " \"sourceName\": \"sample-source-name\"\n" + - " },\n" + - " \"messagesAmount\": 3\n" + - " }\n" + - "]" +private const val invalidMessageParameters = +""" + [ + { + "commonEventHeader": { + "version": "sample-version", + "domain": "HVMEAS", + "sequence": 1, + "priority": 1, + "eventId": "sample-event-id", + "eventName": "sample-event-name", + "eventType": "sample-event-type", + "startEpochMicrosec": 120034455, + "lastEpochMicrosec": 120034455, + "nfNamingCode": "sample-nf-naming-code", + "nfcNamingCode": "sample-nfc-naming-code", + "reportingEntityId": "sample-reporting-entity-id", + "reportingEntityName": "sample-reporting-entity-name", + "sourceId": "sample-source-id", + "sourceName": "sample-source-name", + "vesEventListenerVersion": "another-version" + }, + "messagesAmount": 3 + } + ] +""" fun validMessagesParametesJson() = Json .createReader(validMessageParameters.reader()) |