diff options
author | 2018-07-31 14:26:09 +0200 | |
---|---|---|
committer | 2018-08-03 11:02:26 +0200 | |
commit | 185bc70fa1c024e532649bea650183e05c2d3d87 (patch) | |
tree | dafcd1a21d71948d79f903380b860cca36bebb6c /hv-collector-ves-message-generator/src | |
parent | 8a0e9e5d4d7613793d2804d7e16a9352e3883874 (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
Diffstat (limited to 'hv-collector-ves-message-generator/src')
-rw-r--r-- | hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt | 41 |
1 files changed, 11 insertions, 30 deletions
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() - - |