2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.impl.adapters
22 import org.jetbrains.spek.api.Spek
23 import org.jetbrains.spek.api.dsl.describe
24 import org.jetbrains.spek.api.dsl.given
25 import org.jetbrains.spek.api.dsl.it
26 import org.onap.dcae.collectors.veshv.impl.adapters.HttpAdapter.Companion.INVOCATION_ID_HEADER
27 import reactor.core.publisher.Mono
28 import reactor.netty.http.client.HttpClient
29 import reactor.netty.http.server.HttpServer
30 import reactor.test.StepVerifier
31 import reactor.test.test
35 * @author Jakub Dudycz <jakub.dudycz@nokia.com>
38 internal object HttpAdapterTest : Spek({
39 describe("HttpAdapter") {
41 val httpServer = HttpServer.create()
44 routes.get("/url") { req, resp ->
45 resp.sendString(Mono.just(req.uri()))
47 routes.get("/inv-id") { req, resp ->
48 resp.sendString(Mono.just(req.requestHeaders()[INVOCATION_ID_HEADER]))
52 val baseUrl = "http://${httpServer.host()}:${httpServer.port()}"
53 val httpAdapter = HttpAdapter(HttpClient.create().baseUrl(baseUrl))
56 httpServer.disposeNow()
59 given("url without query params") {
61 val invocationId = UUID.randomUUID()
63 it("should not append query string") {
64 httpAdapter.get(url, invocationId).test()
69 it("should pass invocation id") {
70 httpAdapter.get("/inv-id", invocationId).test()
71 .expectNext(invocationId.toString())
76 given("url with query params") {
77 val queryParams = mapOf(Pair("p", "the-value"))
79 val invocationId = UUID.randomUUID()
81 it("should add them as query string to the url") {
82 httpAdapter.get(url, invocationId, queryParams).test()
83 .expectNext("/url?p=the-value")
87 it("should pass invocation id") {
88 httpAdapter.get("/inv-id", invocationId, queryParams).test()
89 .expectNext(invocationId.toString())
94 given("invalid url") {
95 val invalidUrl = "/wtf"
96 val invocationId = UUID.randomUUID()
98 it("should interrupt the flux") {
100 .create(httpAdapter.get(invalidUrl, invocationId))