diff options
author | fkrzywka <filip.krzywka@nokia.com> | 2018-07-31 14:26:09 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-03 11:02:26 +0200 |
commit | 185bc70fa1c024e532649bea650183e05c2d3d87 (patch) | |
tree | dafcd1a21d71948d79f903380b860cca36bebb6c /hv-collector-xnf-simulator | |
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-xnf-simulator')
3 files changed, 19 insertions, 24 deletions
diff --git a/hv-collector-xnf-simulator/pom.xml b/hv-collector-xnf-simulator/pom.xml index 2a02fae1..29d557a2 100644 --- a/hv-collector-xnf-simulator/pom.xml +++ b/hv-collector-xnf-simulator/pom.xml @@ -19,8 +19,8 @@ ~ ============LICENSE_END========================================================= --> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <licenses> @@ -99,6 +99,12 @@ <version>${project.parent.version}</version> </dependency> <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>hv-collector-test-utils</artifactId> + <version>${project.parent.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>io.arrow-kt</groupId> <artifactId>arrow-effects</artifactId> </dependency> diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt index 3fb4be99..02e6ee72 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt +++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt @@ -23,6 +23,7 @@ import arrow.effects.IO import org.onap.dcae.collectors.veshv.utils.logging.Logger import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser.Companion.INSTANCE import ratpack.handling.Chain import ratpack.handling.Context import ratpack.server.RatpackServer @@ -35,7 +36,7 @@ import javax.json.Json * @since June 2018 */ internal class HttpServer(private val vesClient: XnfSimulator, - private val messageParametersParser: MessageParametersParser = MessageParametersParser.INSTANCE) { + private val messageParametersParser: MessageParametersParser = INSTANCE) { fun start(port: Int): IO<RatpackServer> = IO { RatpackServer.start { server -> diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt index e3a20c70..8749dc5b 100644 --- a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt +++ b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt @@ -19,8 +19,6 @@ */ package org.onap.dcae.collectors.veshv.main.config -import arrow.core.identity -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.describe @@ -31,6 +29,8 @@ import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration.DefaultValues import org.onap.dcae.collectors.veshv.simulators.xnf.config.SimulatorConfiguration +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 import java.nio.file.Paths import kotlin.test.assertTrue @@ -49,25 +49,13 @@ object ArgXnfSimulatorConfiurationTest : Spek({ cut = ArgXnfSimulatorConfiguration() } - fun parse(vararg cmdLine: String): SimulatorConfiguration = - 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: SimulatorConfiguration given("all parameters are present in the long form") { beforeEachTest { - result = parse("--ssl-disable", + result = cut.parseExpectingSuccess("--ssl-disable", "--listen-port", listenPort, "--ves-host", vesHost, "--ves-port", vesPort, @@ -98,7 +86,7 @@ object ArgXnfSimulatorConfiurationTest : Spek({ given("some parameters are present in the short form") { beforeEachTest { - result = parse("-p", listenPort, "-h", vesHost, "--ves-port", vesPort) + result = cut.parseExpectingSuccess("-p", listenPort, "-h", vesHost, "--ves-port", vesPort) } it("should set proper listen port") { @@ -117,7 +105,7 @@ object ArgXnfSimulatorConfiurationTest : Spek({ given("all optional parameters are absent") { beforeEachTest { - result = parse("-p", listenPort, "-h", vesHost, "-v", vesPort) + result = cut.parseExpectingSuccess("-p", listenPort, "-h", vesHost, "-v", vesPort) } on("security config") { @@ -139,7 +127,7 @@ object ArgXnfSimulatorConfiurationTest : Spek({ given("disabled ssl certs together with all other parameters") { beforeEachTest { - result = parse("--ssl-disable", + result = cut.parseExpectingSuccess("--ssl-disable", "--listen-port", listenPort, "--ves-port", "888", "--ves-host", vesHost, @@ -170,21 +158,21 @@ object ArgXnfSimulatorConfiurationTest : Spek({ describe("required parameter is absent") { given("ves port is missing") { it("should throw exception") { - assertThat(parseExpectingFailure("-p", listenPort, "-h", vesHost)) + assertThat(cut.parseExpectingFailure("-p", listenPort, "-h", vesHost)) .isInstanceOf(WrongArgumentError::class.java) } } given("ves host is missing") { it("should throw exception") { - assertThat(parseExpectingFailure("-p", listenPort, "-v", vesPort)) + assertThat(cut.parseExpectingFailure("-p", listenPort, "-v", vesPort)) .isInstanceOf(WrongArgumentError::class.java) } } given("listen port is missing") { it("should throw exception") { - assertThat(parseExpectingFailure("-h", vesHost, "-v", vesPort)) + assertThat(cut.parseExpectingFailure("-h", vesHost, "-v", vesPort)) .isInstanceOf(WrongArgumentError::class.java) } } |