diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-07-18 14:33:10 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-03 07:59:03 +0200 |
commit | f4a58fbdbcaaba92a4daae0e2807536c3da4c857 (patch) | |
tree | 8a1b7b9db9fe2d65d67661aee142bc0aba7e4ef1 /hv-collector-xnf-simulator | |
parent | 0d15767178ffff59009de51d3737883aa81df2a6 (diff) |
Support scenarios for continuous streaming test
Added support for below scenarios
-too big payloads
-invalid wire frames
-invalid GPB data
-unsupported domains
Changed input json for xnf simulator endpoint
Closes ONAP-500
Change-Id: I19e84a76cef501e274ea8152f3c33c95dddcaac9
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-xnf-simulator')
-rw-r--r-- | hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt | 36 |
1 files changed, 21 insertions, 15 deletions
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 08a35d42..0ab248b9 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 @@ -21,9 +21,11 @@ package org.onap.dcae.collectors.veshv.simulators.xnf.impl import arrow.effects.IO import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage -import org.onap.dcae.collectors.veshv.ves.message.generator.config.MessageParameters 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.MessageParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain import ratpack.exec.Promise import ratpack.handling.Chain import ratpack.handling.Context @@ -31,8 +33,9 @@ import ratpack.server.RatpackServer import ratpack.server.ServerConfig import reactor.core.publisher.Flux import reactor.core.scheduler.Schedulers +import java.nio.charset.Charset import javax.json.Json -import javax.json.JsonObject +import javax.json.JsonArray /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> @@ -47,7 +50,6 @@ internal class HttpServer(private val vesClient: XnfSimulator) { } } - private fun configureHandlers(chain: Chain) { chain .post("simulator/sync") { ctx -> @@ -68,11 +70,26 @@ internal class HttpServer(private val vesClient: XnfSimulator) { private fun createMessageFlux(ctx: Context): Promise<Flux<PayloadWireFrameMessage>> { return ctx.request.body - .map { Json.createReader(it.inputStream).readObject() } + .map { Json.createReader(it.inputStream).readArray() } .map { extractMessageParameters(it) } .map { MessageGenerator.INSTANCE.createMessageFlux(it) } } + private fun extractMessageParameters(request: JsonArray): List<MessageParameters> = + try { + request + .map { it.asJsonObject() } + .map { + + val domain = Domain.valueOf(it.getString("domain")) + val messageType = MessageType.valueOf(it.getString("messageType")) + val messagesAmount = it.getJsonNumber("messagesAmount").longValue() + MessageParameters(domain, messageType, messagesAmount) + } + } catch (e: Exception) { + throw ValidationException("Validating request body failed", e) + } + private fun sendAcceptedResponse(ctx: Context) { ctx.response .status(STATUS_OK) @@ -94,17 +111,6 @@ internal class HttpServer(private val vesClient: XnfSimulator) { .toString()) } - private fun extractMessageParameters(request: JsonObject): MessageParameters = - try { - val commonEventHeader = MessageGenerator.INSTANCE - .parseCommonHeader(request.getJsonObject("commonEventHeader")) - val messagesAmount = request.getJsonNumber("messagesAmount").longValue() - MessageParameters(commonEventHeader, messagesAmount) - } catch (e: Exception) { - throw ValidationException("Validating request body failed", e) - } - - companion object { private val logger = Logger(HttpServer::class) const val DEFAULT_PORT = 5000 |