From 185bc70fa1c024e532649bea650183e05c2d3d87 Mon Sep 17 00:00:00 2001 From: fkrzywka Date: Tue, 31 Jul 2018 14:26:09 +0200 Subject: 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 Issue-ID: DCAEGEN2-601 --- hv-collector-dcae-app-simulator/pom.xml | 6 ++++++ .../config/ArgDcaeAppSimulatorConfigurationTest.kt | 25 ++++++---------------- 2 files changed, 13 insertions(+), 18 deletions(-) (limited to 'hv-collector-dcae-app-simulator') diff --git a/hv-collector-dcae-app-simulator/pom.xml b/hv-collector-dcae-app-simulator/pom.xml index f3c17357..e38e3cd9 100644 --- a/hv-collector-dcae-app-simulator/pom.xml +++ b/hv-collector-dcae-app-simulator/pom.xml @@ -97,6 +97,12 @@ hv-collector-ves-message-generator ${project.parent.version} + + ${project.parent.groupId} + hv-collector-test-utils + ${project.parent.version} + test + io.arrow-kt arrow-effects diff --git a/hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt b/hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt index 5ca64e3e..622a9a22 100644 --- a/hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt +++ b/hv-collector-dcae-app-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/config/ArgDcaeAppSimulatorConfigurationTest.kt @@ -19,12 +19,13 @@ */ package org.onap.dcae.collectors.veshv.simulators.dcaeapp.config -import arrow.core.identity import org.assertj.core.api.Assertions.assertThat 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.tests.utils.parseExpectingFailure +import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingSuccess import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError @@ -39,25 +40,13 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({ cut = ArgDcaeAppSimConfiguration() } - fun parseExpectingSuccess(vararg cmdLine: String): DcaeAppSimConfiguration = - cut.parse(cmdLine).fold( - { throw AssertionError("Parsing result should be present") }, - ::identity - ) - - fun parseExpectingFailure(vararg cmdLine: String) = - cut.parse(cmdLine).fold( - ::identity, - { throw AssertionError("parsing should have failed") } - ) - describe("parsing arguments") { lateinit var result: DcaeAppSimConfiguration given("all parameters are present in the long form") { beforeEachTest { - result = parseExpectingSuccess( + result = cut.parseExpectingSuccess( "--listen-port", listenPort, "--kafka-bootstrap-servers", kafkaBootstrapServers, "--kafka-topics", kafkaTopics @@ -83,7 +72,7 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({ given("some parameters are present in the short form") { beforeEachTest { - result = parseExpectingSuccess( + result = cut.parseExpectingSuccess( "-p", listenPort, "--kafka-bootstrap-servers", kafkaBootstrapServers, "-f", kafkaTopics) @@ -107,7 +96,7 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({ describe("required parameter is absent") { given("kafka topics are missing") { it("should throw exception") { - assertThat(parseExpectingFailure( + assertThat(cut.parseExpectingFailure( "-p", listenPort, "-s", kafkaBootstrapServers )).isInstanceOf(WrongArgumentError::class.java) @@ -116,7 +105,7 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({ given("kafka bootstrap servers is missing") { it("should throw exception") { - assertThat(parseExpectingFailure( + assertThat(cut.parseExpectingFailure( "-p", listenPort, "-f", kafkaTopics )).isInstanceOf(WrongArgumentError::class.java) @@ -125,7 +114,7 @@ internal class ArgDcaeAppSimulatorConfigurationTest : Spek({ given("listen port is missing") { it("should throw exception") { - assertThat(parseExpectingFailure( + assertThat(cut.parseExpectingFailure( "-p", kafkaTopics, "-s", kafkaBootstrapServers )).isInstanceOf(WrongArgumentError::class.java) -- cgit 1.2.3-korg