2 * ============LICENSE_START====================================
3 * DCAEGEN2-SERVICES-SDK
4 * =========================================================
5 * Copyright (C) 2019 Nokia. All rights reserved.
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=====================================
21 package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl;
23 import static org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.DummyHttpServer.sendResource;
24 import static org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.DummyHttpServer.sendString;
26 import com.google.gson.JsonObject;
27 import java.time.Duration;
28 import org.junit.jupiter.api.AfterAll;
29 import org.junit.jupiter.api.BeforeAll;
30 import org.junit.jupiter.api.Test;
31 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient;
32 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFactory;
33 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties;
34 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.ImmutableEnvProperties;
35 import reactor.core.publisher.Mono;
36 import reactor.test.StepVerifier;
39 * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
40 * @since February 2019
42 class CbsClientImplIT {
44 private static final String CONSUL_RESP = "[\n"
46 + " \"ServiceAddress\": \"HOST\",\n"
47 + " \"ServiceName\": \"the_cbs\",\n"
48 + " \"ServicePort\": PORT\n"
51 private static final String RES_CONFIG = "/sample_config.json";
52 private static DummyHttpServer server;
56 server = DummyHttpServer.start(routes ->
57 routes.get("/v1/catalog/service/the_cbs", (req, resp) -> sendString(resp, lazyConsulResponse()))
58 .get("/service_component/dcae-component", (req, resp) -> sendResource(resp, RES_CONFIG)));
62 static void tearDown() {
67 void testCbsClient() {
69 final EnvProperties env = ImmutableEnvProperties.builder()
70 .appName("dcae-component")
72 .consulHost(server.host())
73 .consulPort(server.port())
75 final Mono<CbsClient> sut = CbsClientFactory.createCbsClient(env);
78 final Mono<JsonObject> result = sut.flatMap(CbsClient::get);
81 StepVerifier.create(result.map(obj -> obj.get("keystore.path").getAsString()))
82 .expectNext("/var/run/security/keystore.p12")
84 .verify(Duration.ofSeconds(5));
87 private static Mono<String> lazyConsulResponse() {
88 return Mono.just(CONSUL_RESP)
89 .map(CbsClientImplIT::processConsulResponseTemplate);
92 private static String processConsulResponseTemplate(String resp) {
93 return resp.replaceAll("HOST", server.host())
94 .replaceAll("PORT", Integer.toString(server.port()));