diff options
author | fkrzywka <filip.krzywka@nokia.com> | 2018-07-31 14:22:59 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-03 10:50:43 +0200 |
commit | 63f1796ec022705504742a5bd1700f9e20c33540 (patch) | |
tree | 63473c3fdbff6c0bc7a7606d26cb2dc8be5a1de4 /hv-collector-ves-message-generator/src/test | |
parent | d76905b9c98ec32f17bb9568ff80c04068aa213e (diff) |
Move MessageParametersParser
To avoid dependency of utilities module on modules other than domain
Change-Id: I90ef8640a86501315d84848118d3e748aafd095c
Signed-off-by: fkrzywka <filip.krzywka@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-ves-message-generator/src/test')
2 files changed, 162 insertions, 0 deletions
diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageParametersParserTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageParametersParserTest.kt new file mode 100644 index 00000000..92561995 --- /dev/null +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageParametersParserTest.kt @@ -0,0 +1,64 @@ +/* + * ============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.ves.message.generator.impl.impl + +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.assertThatExceptionOfType +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.ves.message.generator.impl.MessageParametersParserImpl.ParsingException +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.MessageParametersParserImpl + +private const val EXPECTED_MESSAGES_AMOUNT = 25000L + +/** + * @author Jakub Dudycz <jakub.dudycz@nokia.com> + * @since July 2018 + */ +object MessageParametersParserTest : Spek({ + describe("Messages parameters parser") { + val messageParametersParser = MessageParametersParserImpl() + + given("parameters json array") { + on("valid parameters json") { + it("should parse MessagesParameters object successfully") { + val result = messageParametersParser.parse(validMessagesParametesJson()) + + assertThat(result).isNotNull + assertThat(result).hasSize(2) + val firstMessage = result.first() + assertThat(firstMessage.messageType).isEqualTo(MessageType.VALID) + assertThat(firstMessage.amount).isEqualTo(EXPECTED_MESSAGES_AMOUNT) + } + } + on("invalid parameters json") { + it("should throw exception") { + assertThatExceptionOfType(ParsingException::class.java).isThrownBy { + messageParametersParser.parse(invalidMessagesParametesJson()) + } + } + } + } + } +}) 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 new file mode 100644 index 00000000..88550603 --- /dev/null +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/parameters.kt @@ -0,0 +1,98 @@ +/* + * ============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.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 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" + + "]" + +fun validMessagesParametesJson() = Json + .createReader(validMessageParameters.reader()) + .readArray() + +fun invalidMessagesParametesJson() = Json + .createReader(invalidMessageParameters.reader()) + .readArray() |