diff options
author | 2019-02-27 11:43:39 +0100 | |
---|---|---|
committer | 2019-02-27 14:43:42 +0100 | |
commit | 0c4750650a84caa64c6df79c5d4042916d529799 (patch) | |
tree | a36ff229edee0855a008c9a727aa5caaf6ecb938 /rest-services/cbs-client/src/test/java/org | |
parent | bc386bcf22a1078a9e29db3faff63667a3b5c99d (diff) |
Add MDC support to CBS client
Change-Id: Id1f1f9016b03658eca0afd0bd3bd724afc0bea96
Issue-ID: DCAEGEN2-1233
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'rest-services/cbs-client/src/test/java/org')
4 files changed, 53 insertions, 22 deletions
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java index 761cc5c1..309bb62f 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java @@ -24,14 +24,17 @@ import static org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.Dummy import static org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.DummyHttpServer.sendString; import com.google.gson.JsonObject; +import io.vavr.collection.Stream; import java.time.Duration; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFactory; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.ImmutableEnvProperties; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -41,21 +44,30 @@ import reactor.test.StepVerifier; */ class CbsClientImplIT { - private static final String CONSUL_RESP = "[\n" + private static final String CONSUL_RESPONSE = "[\n" + " {\n" + " \"ServiceAddress\": \"HOST\",\n" + " \"ServiceName\": \"the_cbs\",\n" + " \"ServicePort\": PORT\n" + " }\n" + "]\n"; - private static final String RES_CONFIG = "/sample_config.json"; + private static final String SAMPLE_CONFIG = "/sample_config.json"; + private static final String SAMPLE_CONFIG_KEY = "keystore.path"; + private static final String EXPECTED_CONFIG_VALUE = "/var/run/security/keystore.p12"; + private static EnvProperties sampleEnvironment; private static DummyHttpServer server; @BeforeAll static void setUp() { server = DummyHttpServer.start(routes -> routes.get("/v1/catalog/service/the_cbs", (req, resp) -> sendString(resp, lazyConsulResponse())) - .get("/service_component/dcae-component", (req, resp) -> sendResource(resp, RES_CONFIG))); + .get("/service_component/dcae-component", (req, resp) -> sendResource(resp, SAMPLE_CONFIG))); + sampleEnvironment = ImmutableEnvProperties.builder() + .appName("dcae-component") + .cbsName("the_cbs") + .consulHost(server.host()) + .consulPort(server.port()) + .build(); } @AfterAll @@ -64,28 +76,44 @@ class CbsClientImplIT { } @Test - void testCbsClient() { + void testCbsClientWithSingleCall() { // given - final EnvProperties env = ImmutableEnvProperties.builder() - .appName("dcae-component") - .cbsName("the_cbs") - .consulHost(server.host()) - .consulPort(server.port()) - .build(); - final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(env); + final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); + final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + + // when + final Mono<JsonObject> result = sut.flatMap(cbsClient -> cbsClient.get(diagnosticContext)); + + // then + StepVerifier.create(result.map(this::sampleConfigValue)) + .expectNext(EXPECTED_CONFIG_VALUE) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void testCbsClientWithPeriodicCall() { + // given + final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); + final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); // when - final Mono<JsonObject> result = sut.flatMap(CbsClient::get); + final Flux<JsonObject> result = sut.flatMapMany(cbsClient -> cbsClient.get(diagnosticContext, Duration.ZERO, Duration.ofMillis(10))); // then - StepVerifier.create(result.map(obj -> obj.get("keystore.path").getAsString())) - .expectNext("/var/run/security/keystore.p12") + final int itemsToTake = 5; + StepVerifier.create(result.take(itemsToTake).map(this::sampleConfigValue)) + .expectNextSequence(Stream.of(EXPECTED_CONFIG_VALUE).cycle(itemsToTake)) .expectComplete() .verify(Duration.ofSeconds(5)); } + private String sampleConfigValue(JsonObject obj) { + return obj.get(SAMPLE_CONFIG_KEY).getAsString(); + } + private static Mono<String> lazyConsulResponse() { - return Mono.just(CONSUL_RESP) + return Mono.just(CONSUL_RESPONSE) .map(CbsClientImplIT::processConsulResponseTemplate); } diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java index 65284c5f..606d00b3 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.verify; import com.google.gson.JsonObject; import java.net.InetSocketAddress; import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.adapters.CloudHttpClient; import reactor.core.publisher.Mono; @@ -47,13 +48,15 @@ class CbsClientImplTest { String serviceName = "dcaegen2-ves-collector"; final CbsClientImpl cut = CbsClientImpl.create(httpClient, cbsAddress, serviceName); final JsonObject httpResponse = new JsonObject(); - given(httpClient.callHttpGet(anyString(), any(Class.class))).willReturn(Mono.just(httpResponse)); + given(httpClient.get(anyString(), any(RequestDiagnosticContext.class), any(Class.class))).willReturn(Mono.just(httpResponse)); + RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); // when - final JsonObject result = cut.get().block(); + final JsonObject result = cut.get(diagnosticContext).block(); // then - verify(httpClient).callHttpGet("http://cbshost:6969/service_component/dcaegen2-ves-collector", JsonObject.class); + final String expectedUrl = "http://cbshost:6969/service_component/dcaegen2-ves-collector"; + verify(httpClient).get(expectedUrl, diagnosticContext, JsonObject.class); assertThat(result).isSameAs(httpResponse); } }
\ No newline at end of file diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java index e7513852..b46b958b 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java @@ -87,7 +87,7 @@ class CbsLookupTest { + env.consulPort() + "/v1/catalog/service/" + env.cbsName(); - given(httpClient.callHttpGet(url, JsonArray.class)) + given(httpClient.get(url, JsonArray.class)) .willReturn(Mono.just(jsonArray)); } diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java index 4e8782b6..3f720c37 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java @@ -67,9 +67,9 @@ class ReactiveCloudConfigurationProviderTest { // given CloudHttpClient webClient = mock(CloudHttpClient.class); when( - webClient.callHttpGet("http://consul:8500/v1/catalog/service/config-binding-service", JsonArray.class)) + webClient.get("http://consul:8500/v1/catalog/service/config-binding-service", JsonArray.class)) .thenReturn(Mono.just(configBindingServiceJson)); - when(webClient.callHttpGet("http://config-binding-service:10000/service_component/dcae-prh", JsonObject.class)) + when(webClient.get("http://config-binding-service:10000/service_component/dcae-prh", JsonObject.class)) .thenReturn(Mono.just(configurationJsonMock)); ReactiveCloudConfigurationProvider provider = new ReactiveCloudConfigurationProvider(webClient); @@ -84,7 +84,7 @@ class ReactiveCloudConfigurationProviderTest { // given CloudHttpClient webClient = mock(CloudHttpClient.class); when( - webClient.callHttpGet("http://consul:8500/v1/catalog/service/config-binding-service", JsonArray.class)) + webClient.get("http://consul:8500/v1/catalog/service/config-binding-service", JsonArray.class)) .thenReturn(Mono.just(emptyConfigBindingServiceJson)); ReactiveCloudConfigurationProvider provider = new ReactiveCloudConfigurationProvider(webClient); |