606d00b39b82e0dd1aae8c001675075712d6a056
[dcaegen2/services/sdk.git] /
1 /*
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
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.impl;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.anyString;
26 import static org.mockito.BDDMockito.given;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.verify;
29
30 import com.google.gson.JsonObject;
31 import java.net.InetSocketAddress;
32 import org.junit.jupiter.api.Test;
33 import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
34 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.adapters.CloudHttpClient;
35 import reactor.core.publisher.Mono;
36
37 /**
38  * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
39  * @since February 2019
40  */
41 class CbsClientImplTest {
42     private final CloudHttpClient httpClient = mock(CloudHttpClient.class);
43
44     @Test
45     void shouldFetchUsingProperUrl() {
46         // given
47         InetSocketAddress cbsAddress = InetSocketAddress.createUnresolved("cbshost", 6969);
48         String serviceName = "dcaegen2-ves-collector";
49         final CbsClientImpl cut = CbsClientImpl.create(httpClient, cbsAddress, serviceName);
50         final JsonObject httpResponse = new JsonObject();
51         given(httpClient.get(anyString(), any(RequestDiagnosticContext.class), any(Class.class))).willReturn(Mono.just(httpResponse));
52         RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create();
53
54         // when
55         final JsonObject result = cut.get(diagnosticContext).block();
56
57         // then
58         final String expectedUrl = "http://cbshost:6969/service_component/dcaegen2-ves-collector";
59         verify(httpClient).get(expectedUrl, diagnosticContext, JsonObject.class);
60         assertThat(result).isSameAs(httpResponse);
61     }
62 }