From bacba429e2dd6b3048da7e75800f5ad200952599 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Tue, 19 Feb 2019 18:06:33 +0100 Subject: Use sdk/hvves-producer in hvves/xnf-simulator Change-Id: I8f493b0edd2cbaef136a22d914ad24198bb63a7f Signed-off-by: Jakub Dudycz Issue-ID: DCAEGEN2-1253 --- .../generator/impl/raw/RawMessageGeneratorTest.kt | 66 ++++++++++++++++++ .../impl/vesevent/CommonEventHeaderParserTest.kt | 3 +- .../impl/vesevent/PayloadGeneratorTest.kt | 3 +- .../impl/vesevent/VesEventGeneratorTest.kt | 2 + .../impl/wireframe/WireFrameGeneratorTest.kt | 81 ---------------------- 5 files changed, 72 insertions(+), 83 deletions(-) create mode 100644 sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/raw/RawMessageGeneratorTest.kt delete mode 100644 sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/wireframe/WireFrameGeneratorTest.kt (limited to 'sources/hv-collector-ves-message-generator/src/test') diff --git a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/raw/RawMessageGeneratorTest.kt b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/raw/RawMessageGeneratorTest.kt new file mode 100644 index 00000000..8c8c8357 --- /dev/null +++ b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/raw/RawMessageGeneratorTest.kt @@ -0,0 +1,66 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018-2019 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.ves.message.generator.impl.raw + +import com.google.protobuf.InvalidProtocolBufferException +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.it +import org.jetbrains.spek.api.dsl.on +import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType +import org.onap.dcae.collectors.veshv.ves.message.generator.generators.RawMessageGenerator +import org.onap.ves.VesEventOuterClass +import reactor.test.test +import java.nio.ByteBuffer +import java.nio.charset.Charset + +/** + * @author Jakub Dudycz + * @since February 2019 + */ +object WireFrameGeneratorTest : Spek({ + + val maxPayloadSizeBytes = 1024 + val cut = RawMessageGenerator() + + on("message type requesting invalid GPB data ") { + it("should createVesEventGenerator flux of messages with invalid payload") { + cut + .createMessageFlux(WireFrameParameters( + WireFrameType.INVALID_GPB_DATA, 1 + )) + .test() + .assertNext { + val decodedBytes = it.array().toString(Charset.defaultCharset()) + assertThat(decodedBytes).isEqualTo("invalid vesEvent") + assertThat(it.capacity()).isLessThan(maxPayloadSizeBytes) + + Assertions.assertThatExceptionOfType(InvalidProtocolBufferException::class.java) + .isThrownBy { extractCommonEventHeader(it) } + } + .verifyComplete() + } + } +}) + +private fun extractCommonEventHeader(bytes: ByteBuffer): VesEventOuterClass.CommonEventHeader = + VesEventOuterClass.VesEvent.parseFrom(bytes).commonEventHeader diff --git a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/CommonEventHeaderParserTest.kt b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/CommonEventHeaderParserTest.kt index 04222d1e..09635afd 100644 --- a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/CommonEventHeaderParserTest.kt +++ b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/CommonEventHeaderParserTest.kt @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * dcaegen2-collectors-veshv * ================================================================================ - * Copyright (C) 2018 NOKIA + * Copyright (C) 2018-2019 NOKIA * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ 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.dcae.collectors.veshv.ves.message.generator.impl.CommonEventHeaderParser import org.onap.ves.VesEventOuterClass.CommonEventHeader import java.io.ByteArrayInputStream import javax.json.Json diff --git a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/PayloadGeneratorTest.kt b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/PayloadGeneratorTest.kt index 2d77bb9f..4558bb1a 100644 --- a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/PayloadGeneratorTest.kt +++ b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/PayloadGeneratorTest.kt @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * dcaegen2-collectors-veshv * ================================================================================ - * Copyright (C) 2018 NOKIA + * Copyright (C) 2018-2019 NOKIA * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ 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.ves.message.generator.impl.PayloadGenerator object PayloadGeneratorTest : Spek({ diff --git a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/VesEventGeneratorTest.kt b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/VesEventGeneratorTest.kt index 2f13c52e..fa99bfb6 100644 --- a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/VesEventGeneratorTest.kt +++ b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/VesEventGeneratorTest.kt @@ -28,8 +28,10 @@ import org.jetbrains.spek.api.dsl.on import org.onap.dcae.collectors.veshv.domain.VesEventDomain.FAULT import org.onap.dcae.collectors.veshv.domain.VesEventDomain.PERF3GPP import org.onap.dcae.collectors.veshv.tests.utils.commonHeader +import org.onap.dcae.collectors.veshv.ves.message.generator.generators.VesEventGenerator import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventParameters import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator import reactor.test.test /** diff --git a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/wireframe/WireFrameGeneratorTest.kt b/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/wireframe/WireFrameGeneratorTest.kt deleted file mode 100644 index f8c84c39..00000000 --- a/sources/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/wireframe/WireFrameGeneratorTest.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2010 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.ves.message.generator.impl.wireframe - -import com.google.protobuf.InvalidProtocolBufferException -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.it -import org.jetbrains.spek.api.dsl.on -import org.onap.dcae.collectors.veshv.domain.ByteData -import org.onap.dcae.collectors.veshv.domain.WireFrameMessage -import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameParameters -import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType -import org.onap.ves.VesEventOuterClass -import reactor.test.test -import kotlin.test.assertTrue - -/** - * @author Jakub Dudycz - * @since February 2019 - */ -object WireFrameGeneratorTest : Spek({ - - val maxPayloadSizeBytes = 1024 - val cut = WireFrameGenerator() - - on("message type requesting invalid GPB data ") { - it("should createVesEventGenerator flux of messages with invalid payload") { - cut - .createMessageFlux(WireFrameParameters( - WireFrameType.INVALID_GPB_DATA, 1 - )) - .test() - .assertNext { - assertTrue(it.validate().isRight()) - assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes) - Assertions.assertThatExceptionOfType(InvalidProtocolBufferException::class.java) - .isThrownBy { extractCommonEventHeader(it.payload) } - } - .verifyComplete() - } - } - - on("message type requesting invalid wire frame ") { - it("should createVesEventGenerator flux of messages with invalid version") { - cut - .createMessageFlux(WireFrameParameters( - WireFrameType.INVALID_WIRE_FRAME, 1 - )) - .test() - .assertNext { - assertTrue(it.validate().isLeft()) - assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes) - assertThat(it.versionMajor).isNotEqualTo(WireFrameMessage.SUPPORTED_VERSION_MINOR) - } - .verifyComplete() - } - } - -}) - -fun extractCommonEventHeader(bytes: ByteData): VesEventOuterClass.CommonEventHeader = - VesEventOuterClass.VesEvent.parseFrom(bytes.unsafeAsArray()).commonEventHeader -- cgit 1.2.3-korg