diff options
author | 2018-11-07 15:08:43 +0100 | |
---|---|---|
committer | 2018-11-15 12:51:43 +0100 | |
commit | 4d15e5a578dc2c94af2b7f1c7ad02fb44d384501 (patch) | |
tree | baad5e6314ef6d2a0f1409b0a23e0001e814f0a8 /hv-collector-core/src/test | |
parent | 3fdd2fe2b4f35e18998d050c632fc6de24a7e3b1 (diff) |
Update project and dependencies
* Changed version from 4.0.0-SNAPSHOT to 1.1.0-SNAPSHOT as per Vijay
suggestion
* Updated Reactor to BOM Californium-SR2
* Updated mockito-kotlin to 2.0.0
* Introduced some fixes to support OpenJDK 11 compilation
Change-Id: Ib25979ef50c7241a019bf98efd9759e0b8792d58
Issue-ID: DCAEGEN2-961
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'hv-collector-core/src/test')
2 files changed, 34 insertions, 55 deletions
diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt index 9a6889c8..7a1a4cdc 100644 --- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt +++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt @@ -19,9 +19,9 @@ */ package org.onap.dcae.collectors.veshv.impl.adapters -import com.nhaarman.mockito_kotlin.eq -import com.nhaarman.mockito_kotlin.mock -import com.nhaarman.mockito_kotlin.whenever +import com.nhaarman.mockitokotlin2.eq +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.whenever import org.assertj.core.api.Assertions.assertThat import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.describe diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/HttpAdapterTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/HttpAdapterTest.kt index 123d8f72..91457faf 100644 --- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/HttpAdapterTest.kt +++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/HttpAdapterTest.kt @@ -19,21 +19,15 @@ */ package org.onap.dcae.collectors.veshv.impl.adapters -import com.nhaarman.mockito_kotlin.mock -import com.nhaarman.mockito_kotlin.verify -import com.nhaarman.mockito_kotlin.whenever -import io.netty.buffer.Unpooled -import io.netty.handler.codec.http.HttpContent 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 reactor.core.publisher.Flux import reactor.core.publisher.Mono -import reactor.ipc.netty.http.client.HttpClient -import reactor.ipc.netty.http.client.HttpClientResponse +import reactor.netty.http.client.HttpClient +import reactor.netty.http.server.HttpServer import reactor.test.StepVerifier -import java.nio.charset.Charset +import reactor.test.test /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> @@ -42,66 +36,51 @@ import java.nio.charset.Charset internal object HttpAdapterTest : Spek({ describe("HttpAdapter") { - val httpClientMock: HttpClient = mock() - val httpAdapter = HttpAdapter(httpClientMock) + val httpServer = HttpServer.create() + .host("127.0.0.1") + .route { routes -> + routes.get("/url") { req, resp -> + resp.sendString(Mono.just(req.uri())) + } + } + .bindNow() + val baseUrl = "http://${httpServer.host()}:${httpServer.port()}" + val httpAdapter = HttpAdapter(HttpClient.create().baseUrl(baseUrl)) + + afterGroup { + httpServer.disposeNow() + } given("url without query params") { - val initialUrl = "http://test-url" - whenever(httpClientMock.get(initialUrl)).thenReturn(Mono.empty()) + val url = "/url" it("should not append query string") { - httpAdapter.get(initialUrl) - verify(httpClientMock).get(initialUrl) + httpAdapter.get(url).test() + .expectNext(url) + .verifyComplete() } } given("url with query params") { - val queryParams = mapOf(Pair("key", "value")) - val initialUrl = "http://test-url" - val expectedUrl = "http://test-url?key=value" - whenever(httpClientMock.get(expectedUrl)).thenReturn(Mono.empty()) - - it("should parse them to query string and append to url") { - httpAdapter.get(initialUrl, queryParams) - verify(httpClientMock).get(expectedUrl) - } - } + val queryParams = mapOf(Pair("p", "the-value")) + val url = "/url" - given("valid resource url") { - val validUrl = "http://valid-url/" - val responseContent = """{"key1": "value1", "key2": "value2"}""" - val httpResponse = createHttpResponseMock(responseContent) - whenever(httpClientMock.get(validUrl)).thenReturn(Mono.just(httpResponse)) - - it("should return response string") { - StepVerifier - .create(httpAdapter.get(validUrl)) - .expectNext(responseContent) + it("should add them as query string to the url") { + httpAdapter.get(url, queryParams).test() + .expectNext("/url?p=the-value") + .verifyComplete() } } - given("invalid resource url") { - val invalidUrl = "http://invalid-url/" - val exceptionMessage = "Test exception" - whenever(httpClientMock.get(invalidUrl)).thenReturn(Mono.error(Exception(exceptionMessage))) + given("invalid url") { + val invalidUrl = "/wtf" it("should interrupt the flux") { StepVerifier .create(httpAdapter.get(invalidUrl)) - .verifyErrorMessage(exceptionMessage) + .verifyError() } } } -}) - -fun createHttpResponseMock(content: String): HttpClientResponse { - val responseMock: HttpClientResponse = mock() - val contentMock: HttpContent = mock() - val contentByteBuff = Unpooled.copiedBuffer(content, Charset.defaultCharset()) - - whenever(responseMock.receiveContent()).thenReturn(Flux.just(contentMock)) - whenever(contentMock.content()).thenReturn(contentByteBuff) - - return responseMock -} +})
\ No newline at end of file |