summaryrefslogtreecommitdiffstats
path: root/hv-collector-utils
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-07-26 11:49:45 +0200
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2018-08-03 10:15:25 +0200
commita2d874fd73825b254a3e0be81cff57a5c3e1d9d7 (patch)
treeb8d90cf0c3acf46de5be92e64c8da97c969d9df4 /hv-collector-utils
parentf738ede42e619f1a5c13671cb560224aa639f1db (diff)
DCAE APP simulator rework
- Extract message parameters parsing logic to standalone class in utils - Make DCAE APP simulator store whole received messages history - Add validation endpoint - Add new messege type: FIXED_PAYLOAD Closes ONAP-686 Change-Id: I865804716ad5e46a7503a8eee70cfe9ac75a6c1e Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com> Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-utils')
-rw-r--r--hv-collector-utils/pom.xml13
-rw-r--r--hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt6
-rw-r--r--hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt9
-rw-r--r--hv-collector-utils/src/test/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParserTest.kt63
-rw-r--r--hv-collector-utils/src/test/kotlin/org/onap/dcae/collectors/veshv/utils/messages/parameters.kt98
5 files changed, 172 insertions, 17 deletions
diff --git a/hv-collector-utils/pom.xml b/hv-collector-utils/pom.xml
index d0e44932..39097c10 100644
--- a/hv-collector-utils/pom.xml
+++ b/hv-collector-utils/pom.xml
@@ -61,19 +61,10 @@
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
- <artifactId>hv-collector-domain</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.parent.groupId}</groupId>
<artifactId>hv-collector-ves-message-generator</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
- <groupId>org.glassfish</groupId>
- <artifactId>javax.json</artifactId>
- </dependency>
- <dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
@@ -98,6 +89,10 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.glassfish</groupId>
+ <artifactId>javax.json</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.nhaarman</groupId>
<artifactId>mockito-kotlin</artifactId>
</dependency>
diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt
index 9c873a0f..c00ce68d 100644
--- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt
+++ b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt
@@ -54,20 +54,16 @@ abstract class ArgBasedConfiguration<T>(private val parser: CommandLineParser) {
protected abstract fun getConfiguration(cmdLine: CommandLine): Option<T>
- protected fun CommandLine.intValue(cmdLineOpt: CommandLineOption, default: Int): Int =
- intValue(cmdLineOpt).getOrElse { default }
-
protected fun CommandLine.longValue(cmdLineOpt: CommandLineOption, default: Long): Long =
longValue(cmdLineOpt).getOrElse { default }
protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption, default: String): String =
optionValue(cmdLineOpt).getOrElse { default }
-
protected fun CommandLine.intValue(cmdLineOpt: CommandLineOption): Option<Int> =
optionValue(cmdLineOpt).map(String::toInt)
- protected fun CommandLine.longValue(cmdLineOpt: CommandLineOption): Option<Long> =
+ private fun CommandLine.longValue(cmdLineOpt: CommandLineOption): Option<Long> =
optionValue(cmdLineOpt).map(String::toLong)
protected fun CommandLine.stringValue(cmdLineOpt: CommandLineOption): Option<String> =
diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt
index 24c2cbfa..1621ba59 100644
--- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt
+++ b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt
@@ -35,14 +35,17 @@ class MessageParametersParser(
request
.map { it.asJsonObject() }
.map {
- val commonEventHeader = commonEventHeaderParser.parse(it.getJsonObject("commonEventHeader"))
+ val commonEventHeader = commonEventHeaderParser
+ .parse(it.getJsonObject("commonEventHeader"))
val messageType = MessageType.valueOf(it.getString("messageType"))
- val messagesAmount = it.getJsonNumber("messagesAmount").longValue()
+ val messagesAmount = it.getJsonNumber("messagesAmount")?.longValue()
+ ?: throw ParsingException("\"messagesAmount\" could not be parsed from message.",
+ NullPointerException())
MessageParameters(commonEventHeader, messageType, messagesAmount)
}
} catch (e: Exception) {
throw ParsingException("Parsing request body failed", e)
}
- internal class ParsingException(message: String?, cause: Exception) : Exception(message, cause)
+ internal class ParsingException(message: String, cause: Exception) : Exception(message, cause)
}
diff --git a/hv-collector-utils/src/test/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParserTest.kt b/hv-collector-utils/src/test/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParserTest.kt
new file mode 100644
index 00000000..ec628a2a
--- /dev/null
+++ b/hv-collector-utils/src/test/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParserTest.kt
@@ -0,0 +1,63 @@
+/*
+ * ============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.utils.messages
+
+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.utils.messages.MessageParametersParser.ParsingException
+import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType
+
+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 = MessageParametersParser()
+
+ 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-utils/src/test/kotlin/org/onap/dcae/collectors/veshv/utils/messages/parameters.kt b/hv-collector-utils/src/test/kotlin/org/onap/dcae/collectors/veshv/utils/messages/parameters.kt
new file mode 100644
index 00000000..f6a3a15b
--- /dev/null
+++ b/hv-collector-utils/src/test/kotlin/org/onap/dcae/collectors/veshv/utils/messages/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.utils.messages
+
+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()