389e6e8a5ea6604dff5ce2df96067b6403484571
[dcaegen2/services/sdk.git] /
1 /*
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers;
22
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;
27
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;
35
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);
40
41     private final CloudConfigurationProvider provider = mock(CloudConfigurationProvider.class);
42     private final CbsClientConfiguration configuration = mock(CbsClientConfiguration.class);
43
44     private CloudConfigurationClient client;
45
46     @BeforeEach
47     void setUp() {
48         client = new CloudConfigurationClient(provider);
49         when(provider.callForServiceConfigurationReactive(any(CbsClientConfiguration.class)))
50             .thenReturn(Mono.just(CONFIGURATION_JSON_MOCK));
51     }
52
53     @Test
54     void callForServiceConfigurationReactiveWithManyParamsShouldReturnConfigurationObjectMono() {
55         StepVerifier.create(client.callForServiceConfigurationReactive("hostName", 4444, "cbsName1", "appName1"))
56             .expectSubscription()
57             .expectNext(CONFIGURATION_JSON_MOCK).verifyComplete();
58     }
59
60     @Test
61     void callForServiceConfigurationReactiveWithOneParamShouldReturnConfigurationObjectMono() {
62         StepVerifier.create(client.callForServiceConfigurationReactive(configuration))
63             .expectSubscription()
64             .expectNext(CONFIGURATION_JSON_MOCK).verifyComplete();
65     }
66
67     @Test
68     void callForServiceConfigurationWithManyParamsShouldReturnConfigurationObject() {
69         JsonObject json = client.callForServiceConfiguration("hostName", 4444, "cbsName1", "appName1");
70         assertEquals(CONFIGURATION_JSON_MOCK, json);
71     }
72
73     @Test
74     void callForServiceConfigurationWithOneParamShouldReturnConfigurationObject() {
75         JsonObject json = client.callForServiceConfiguration(configuration);
76         assertEquals(CONFIGURATION_JSON_MOCK, json);
77     }
78 }