diff options
author | 2018-07-05 14:35:43 +0200 | |
---|---|---|
committer | 2018-08-02 12:24:04 +0200 | |
commit | a788d58f813b71644059623877aca629ab49ab74 (patch) | |
tree | ea49e72a023d1d8fe735f292628c43684fa63074 /hv-collector-core/src/test | |
parent | 72b60289c3aa91f91893193011a01ea11bee2375 (diff) |
Implement blocking consul calls
Replaced interval based requesting for consul configuration with blocking query calls
Closes ONAP-80
Change-Id: If70365bae9fde513d99b047209d085122a5df0dd
Signed-off-by: Jakub Dudycz <jdudycz@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-core/src/test')
2 files changed, 54 insertions, 27 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 dd190848..c98c97a6 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,12 +19,14 @@ */ 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.verify import com.nhaarman.mockito_kotlin.whenever import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it +import org.mockito.Mockito import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain import reactor.core.publisher.Mono import reactor.ipc.netty.http.client.HttpClient @@ -39,15 +41,16 @@ import kotlin.test.assertEquals */ internal object ConsulConfigurationProviderTest : Spek({ - val updateInterval = Duration.ofMillis(1) val httpAdapterMock: HttpAdapter = mock() + val firstRequestDelay = Duration.ofMillis(1) given("valid resource url") { val validUrl = "http://valid-url/" - val consulConfigProvider = ConsulConfigurationProvider(validUrl, updateInterval, httpAdapterMock) + val consulConfigProvider = ConsulConfigurationProvider(validUrl, httpAdapterMock, firstRequestDelay) - whenever(httpAdapterMock.get(validUrl)).thenReturn(Mono.just(constructConsulResponse())) + whenever(httpAdapterMock.get(eq(validUrl), Mockito.anyMap())) + .thenReturn(Mono.just(constructConsulResponse())) it("should use default configuration at the beginning, " + "then apply received configuration") { @@ -79,9 +82,10 @@ internal object ConsulConfigurationProviderTest : Spek({ given("invalid resource url") { val invalidUrl = "http://invalid-url/" - val consulConfigProvider = ConsulConfigurationProvider(invalidUrl, updateInterval, httpAdapterMock) + val consulConfigProvider = ConsulConfigurationProvider(invalidUrl, httpAdapterMock, firstRequestDelay) - whenever(httpAdapterMock.get(invalidUrl)).thenReturn(Mono.error(RuntimeException("Test exception"))) + whenever(httpAdapterMock.get(eq(invalidUrl), Mockito.anyMap())) + .thenReturn(Mono.error(RuntimeException("Test exception"))) it("should use default configuration at the beginning, then should interrupt the flux") { 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 79eda995..123d8f72 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 @@ -20,10 +20,12 @@ 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 @@ -32,44 +34,65 @@ import reactor.ipc.netty.http.client.HttpClient import reactor.ipc.netty.http.client.HttpClientResponse import reactor.test.StepVerifier import java.nio.charset.Charset -import kotlin.test.assertEquals /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since May 2018 */ internal object HttpAdapterTest : Spek({ - - given("valid resource url") { + describe("HttpAdapter") { val httpClientMock: HttpClient = mock() val httpAdapter = HttpAdapter(httpClientMock) - 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) + given("url without query params") { + val initialUrl = "http://test-url" + whenever(httpClientMock.get(initialUrl)).thenReturn(Mono.empty()) + + it("should not append query string") { + httpAdapter.get(initialUrl) + verify(httpClientMock).get(initialUrl) + } } - } - given("invalid resource url") { + 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()) - val httpClientMock: HttpClient = mock() - val httpAdapter = HttpAdapter(httpClientMock) - val invalidUrl = "http://invalid-url/" - val exceptionMessage = "Test exception" - whenever(httpClientMock.get(invalidUrl)).thenReturn(Mono.error(Exception(exceptionMessage))) + it("should parse them to query string and append to url") { + httpAdapter.get(initialUrl, queryParams) + verify(httpClientMock).get(expectedUrl) + } + } - it("should interrupt the flux") { - StepVerifier - .create(httpAdapter.get(invalidUrl)) - .verifyErrorMessage(exceptionMessage) + 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) + } + } + + given("invalid resource url") { + val invalidUrl = "http://invalid-url/" + val exceptionMessage = "Test exception" + whenever(httpClientMock.get(invalidUrl)).thenReturn(Mono.error(Exception(exceptionMessage))) + + it("should interrupt the flux") { + StepVerifier + .create(httpAdapter.get(invalidUrl)) + .verifyErrorMessage(exceptionMessage) + } } } + }) fun createHttpResponseMock(content: String): HttpClientResponse { |