diff options
author | 2019-03-21 14:45:50 +0100 | |
---|---|---|
committer | 2019-03-22 10:10:54 +0100 | |
commit | 9b5df83176a2e2bf20442285b01ba4cd710fb7b8 (patch) | |
tree | 8747544f91621cde2f195a2eaaebdfb1e4c83507 /rest-services/cbs-client/src/test/java/org | |
parent | 5d90e4cc1354199d4a816e14f5fc431e7ff3ad65 (diff) |
Support other CBS endpoints
Change-Id: I227a8edf6da8398ca58c47e864985dac47c5dfcd
Issue-ID: DCAEGEN2-1363
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'rest-services/cbs-client/src/test/java/org')
3 files changed, 140 insertions, 17 deletions
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsRequestsTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsRequestsTest.java new file mode 100644 index 00000000..50233d3c --- /dev/null +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsRequestsTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START==================================== + * DCAEGEN2-SERVICES-SDK + * ========================================================= + * Copyright (C) 2019 Nokia. All rights reserved. + * ========================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================== + */ + +package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; + +/** + * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> + * @since March 2019 + */ +class CbsRequestsTest { + + private final RequestDiagnosticContext diagCtx = RequestDiagnosticContext.create(); + private final String serviceName = "srv-name"; + + @Test + void getConfiguration() { + // given + final CbsRequest cut = CbsRequests.getConfiguration(diagCtx); + + // when + final String result = cut.requestPath().getForService(serviceName); + + // then + assertThat(result).isEqualTo("/service_component/srv-name"); + } + + @Test + void getByKey() { + // given + final CbsRequest cut = CbsRequests.getByKey(diagCtx, "configKey"); + + // when + final String result = cut.requestPath().getForService(serviceName); + + // then + assertThat(result).isEqualTo("/configKey/srv-name"); + } + + @Test + void getAll() { + // given + final CbsRequest cut = CbsRequests.getAll(diagCtx); + + // when + final String result = cut.requestPath().getForService(serviceName); + + // then + assertThat(result).isEqualTo("/service_component_all/srv-name"); + } +}
\ 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/CbsClientImplIT.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java index 58e1e6cb..33b09208 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 @@ -34,9 +34,11 @@ import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.test.DummyHttpServer; 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.CbsRequests; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.DataStreams; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamFromGsonParser; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamFromGsonParsers; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.RawDataStream; @@ -61,7 +63,9 @@ class CbsClientImplIT { + " \"ServicePort\": PORT\n" + " }\n" + "]\n"; - private static final String SAMPLE_CONFIG = "/sample_config.json"; + private static final String SAMPLE_CONFIG = "/sample_service_config.json"; + private static final String SAMPLE_ALL = "/sample_all.json"; + private static final String SAMPLE_KEY = "/sample_key.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; @@ -71,7 +75,10 @@ class CbsClientImplIT { 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, SAMPLE_CONFIG))); + .get("/service_component/dcae-component", (req, resp) -> sendResource(resp, SAMPLE_CONFIG)) + .get("/service_component_all/dcae-component", (req, resp) -> sendResource(resp, SAMPLE_ALL)) + .get("/sampleKey/dcae-component", (req, resp) -> sendResource(resp, SAMPLE_KEY)) + ); sampleEnvironment = ImmutableEnvProperties.builder() .appName("dcae-component") .cbsName("the_cbs") @@ -89,10 +96,10 @@ class CbsClientImplIT { void testCbsClientWithSingleCall() { // given final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); - final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + final CbsRequest request = CbsRequests.getConfiguration(RequestDiagnosticContext.create()); // when - final Mono<JsonObject> result = sut.flatMap(cbsClient -> cbsClient.get(diagnosticContext)); + final Mono<JsonObject> result = sut.flatMap(cbsClient -> cbsClient.get(request)); // then StepVerifier.create(result.map(this::sampleConfigValue)) @@ -105,11 +112,11 @@ class CbsClientImplIT { void testCbsClientWithPeriodicCall() { // given final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); - final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + final CbsRequest request = CbsRequests.getConfiguration(RequestDiagnosticContext.create()); // when final Flux<JsonObject> result = sut - .flatMapMany(cbsClient -> cbsClient.get(diagnosticContext, Duration.ZERO, Duration.ofMillis(10))); + .flatMapMany(cbsClient -> cbsClient.get(request, Duration.ZERO, Duration.ofMillis(10))); // then final int itemsToTake = 5; @@ -123,12 +130,12 @@ class CbsClientImplIT { void testCbsClientWithUpdatesCall() { // given final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); - final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + final CbsRequest request = CbsRequests.getConfiguration(RequestDiagnosticContext.create()); final Duration period = Duration.ofMillis(10); // when final Flux<JsonObject> result = sut - .flatMapMany(cbsClient -> cbsClient.updates(diagnosticContext, Duration.ZERO, period)); + .flatMapMany(cbsClient -> cbsClient.updates(request, Duration.ZERO, period)); // then final Duration timeToCollectItemsFor = period.multipliedBy(50); @@ -143,10 +150,10 @@ class CbsClientImplIT { // given final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); final StreamFromGsonParser<KafkaSink> kafkaSinkParser = StreamFromGsonParsers.kafkaSinkParser(); - final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + final CbsRequest request = CbsRequests.getConfiguration(RequestDiagnosticContext.create()); // when - final Mono<KafkaSink> result = sut.flatMap(cbsClient -> cbsClient.get(diagnosticContext)) + final Mono<KafkaSink> result = sut.flatMap(cbsClient -> cbsClient.get(request)) .map(json -> DataStreams.namedSinks(json).map(kafkaSinkParser::unsafeParse).head() ); @@ -166,13 +173,13 @@ class CbsClientImplIT { void testCbsClientWithStreamsParsingUsingSwitch() { // given final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); - final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + final CbsRequest request = CbsRequests.getConfiguration(RequestDiagnosticContext.create()); // TODO: Use these parsers below final StreamFromGsonParser<KafkaSink> kafkaSinkParser = StreamFromGsonParsers.kafkaSinkParser(); final StreamFromGsonParser<MessageRouterSink> mrSinkParser = StreamFromGsonParsers.messageRouterSinkParser(); // when - final Mono<Void> result = sut.flatMap(cbsClient -> cbsClient.get(diagnosticContext)) + final Mono<Void> result = sut.flatMap(cbsClient -> cbsClient.get(request)) .map(json -> { final Map<String, Stream<RawDataStream<JsonObject>>> sinks = DataStreams.namedSinks(json) .groupBy(RawDataStream::type); @@ -204,10 +211,10 @@ class CbsClientImplIT { // given final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); final StreamFromGsonParser<KafkaSource> kafkaSourceParser = StreamFromGsonParsers.kafkaSourceParser(); - final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + final CbsRequest request = CbsRequests.getConfiguration(RequestDiagnosticContext.create()); // when - final Mono<KafkaSource> result = sut.flatMap(cbsClient -> cbsClient.get(diagnosticContext)) + final Mono<KafkaSource> result = sut.flatMap(cbsClient -> cbsClient.get(request)) .map(json -> DataStreams.namedSources(json).map(kafkaSourceParser::unsafeParse).head() ); @@ -223,6 +230,46 @@ class CbsClientImplIT { .verify(Duration.ofSeconds(5)); } + @Test + void testCbsClientWithSingleAllRequest() { + // given + final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); + final CbsRequest request = CbsRequests.getAll(RequestDiagnosticContext.create()); + + // when + final Mono<JsonObject> result = sut.flatMap(cbsClient -> cbsClient.get(request)); + + // then + StepVerifier.create(result) + .assertNext(json -> { + assertThat(json.get("config")).isNotNull(); + assertThat(json.get("policies")).isNotNull(); + assertThat(json.get("sampleKey")).isNotNull(); + }) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + + @Test + void testCbsClientWithSingleKeyRequest() { + // given + final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(sampleEnvironment); + final CbsRequest request = CbsRequests.getByKey(RequestDiagnosticContext.create(), "sampleKey"); + + // when + final Mono<JsonObject> result = sut.flatMap(cbsClient -> cbsClient.get(request)); + + // then + StepVerifier.create(result) + .assertNext(json -> { + assertThat(json.get("key")).isNotNull(); + assertThat(json.get("key").getAsString()).isEqualTo("value"); + }) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + private String sampleConfigValue(JsonObject obj) { return obj.get(SAMPLE_CONFIG_KEY).getAsString(); } 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 339b1efa..78b79f9d 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 @@ -29,13 +29,14 @@ import static org.mockito.Mockito.verify; import com.google.gson.JsonObject; import java.net.InetSocketAddress; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpResponse; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import reactor.core.publisher.Mono; @@ -51,7 +52,7 @@ class CbsClientImplTest { // given InetSocketAddress cbsAddress = InetSocketAddress.createUnresolved("cbshost", 6969); String serviceName = "dcaegen2-ves-collector"; - final CbsClientImpl cut = CbsClientImpl.create(httpClient, cbsAddress, serviceName); + final CbsClient cut = new CbsClientImpl(httpClient, serviceName, cbsAddress); final HttpResponse httpResponse = ImmutableHttpResponse.builder() .url("http://xxx") .statusCode(200) @@ -61,7 +62,7 @@ class CbsClientImplTest { RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); // when - final JsonObject result = cut.get(diagnosticContext).block(); + final JsonObject result = cut.get(CbsRequests.getConfiguration(diagnosticContext)).block(); // then final String expectedUrl = "http://cbshost:6969/service_component/dcaegen2-ves-collector"; |