2 * ============LICENSE_START=======================================================
3 * DCAEGEN2-SERVICES-SDK
4 * ================================================================================
5 * Copyright (C) 2020 Nokia Intellectual Property. 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.providers;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
28 import com.google.gson.Gson;
29 import com.google.gson.JsonObject;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
33 import reactor.core.publisher.Mono;
34 import reactor.test.StepVerifier;
36 class CloudConfigurationClientTest {
37 private static final String CONFIGURATION_MOCK = "{\"test\":1}";
38 private static final JsonObject CONFIGURATION_JSON_MOCK = new Gson()
39 .fromJson(CONFIGURATION_MOCK, JsonObject.class);
41 private final CloudConfigurationProvider provider = mock(CloudConfigurationProvider.class);
42 private final CbsClientConfiguration configuration = mock(CbsClientConfiguration.class);
44 private CloudConfigurationClient client;
48 client = new CloudConfigurationClient(provider);
49 when(provider.callForServiceConfigurationReactive(any(CbsClientConfiguration.class)))
50 .thenReturn(Mono.just(CONFIGURATION_JSON_MOCK));
54 void callForServiceConfigurationReactiveWithManyParamsShouldReturnConfigurationObjectMono() {
55 StepVerifier.create(client.callForServiceConfigurationReactive("hostName", 4444, "cbsName1", "appName1"))
57 .expectNext(CONFIGURATION_JSON_MOCK).verifyComplete();
61 void callForServiceConfigurationReactiveWithOneParamShouldReturnConfigurationObjectMono() {
62 StepVerifier.create(client.callForServiceConfigurationReactive(configuration))
64 .expectNext(CONFIGURATION_JSON_MOCK).verifyComplete();
68 void callForServiceConfigurationWithManyParamsShouldReturnConfigurationObject() {
69 JsonObject json = client.callForServiceConfiguration("hostName", 4444, "cbsName1", "appName1");
70 assertEquals(CONFIGURATION_JSON_MOCK, json);
74 void callForServiceConfigurationWithOneParamShouldReturnConfigurationObject() {
75 JsonObject json = client.callForServiceConfiguration(configuration);
76 assertEquals(CONFIGURATION_JSON_MOCK, json);