aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers
diff options
context:
space:
mode:
Diffstat (limited to 'rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers')
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationClientTest.java78
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java135
2 files changed, 213 insertions, 0 deletions
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationClientTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationClientTest.java
new file mode 100644
index 00000000..389e6e8a
--- /dev/null
+++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/CloudConfigurationClientTest.java
@@ -0,0 +1,78 @@
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 2020 Nokia Intellectual Property. 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.providers;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+class CloudConfigurationClientTest {
+ private static final String CONFIGURATION_MOCK = "{\"test\":1}";
+ private static final JsonObject CONFIGURATION_JSON_MOCK = new Gson()
+ .fromJson(CONFIGURATION_MOCK, JsonObject.class);
+
+ private final CloudConfigurationProvider provider = mock(CloudConfigurationProvider.class);
+ private final CbsClientConfiguration configuration = mock(CbsClientConfiguration.class);
+
+ private CloudConfigurationClient client;
+
+ @BeforeEach
+ void setUp() {
+ client = new CloudConfigurationClient(provider);
+ when(provider.callForServiceConfigurationReactive(any(CbsClientConfiguration.class)))
+ .thenReturn(Mono.just(CONFIGURATION_JSON_MOCK));
+ }
+
+ @Test
+ void callForServiceConfigurationReactiveWithManyParamsShouldReturnConfigurationObjectMono() {
+ StepVerifier.create(client.callForServiceConfigurationReactive("hostName", 4444, "cbsName1", "appName1"))
+ .expectSubscription()
+ .expectNext(CONFIGURATION_JSON_MOCK).verifyComplete();
+ }
+
+ @Test
+ void callForServiceConfigurationReactiveWithOneParamShouldReturnConfigurationObjectMono() {
+ StepVerifier.create(client.callForServiceConfigurationReactive(configuration))
+ .expectSubscription()
+ .expectNext(CONFIGURATION_JSON_MOCK).verifyComplete();
+ }
+
+ @Test
+ void callForServiceConfigurationWithManyParamsShouldReturnConfigurationObject() {
+ JsonObject json = client.callForServiceConfiguration("hostName", 4444, "cbsName1", "appName1");
+ assertEquals(CONFIGURATION_JSON_MOCK, json);
+ }
+
+ @Test
+ void callForServiceConfigurationWithOneParamShouldReturnConfigurationObject() {
+ JsonObject json = client.callForServiceConfiguration(configuration);
+ assertEquals(CONFIGURATION_JSON_MOCK, json);
+ }
+} \ 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/providers/ReactiveCloudConfigurationProviderTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java
new file mode 100644
index 00000000..de0870d0
--- /dev/null
+++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java
@@ -0,0 +1,135 @@
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 2018-2019 NOKIA Intellectual Property. 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.providers;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import java.io.IOException;
+import java.util.List;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+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.RxHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.streams.gson.GsonUtils;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsClientConfiguration;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+/**
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 11/15/18
+ */
+class ReactiveCloudConfigurationProviderTest {
+
+ private static final Gson gson = new Gson();
+ private static final String CONFIGURATION_MOCK = "{\"test\":1}";
+ private static final JsonObject CONFIGURATION_JSON_MOCK = gson
+ .fromJson(CONFIGURATION_MOCK, JsonObject.class);
+
+ private final RxHttpClient httpClient = mock(RxHttpClient.class);
+ private final JsonArray configBindingService = GsonUtils.readObjectArrayFromResource("/sample_config_binding_service.json");
+
+ private CbsClientConfiguration cbsClientConfiguration = ImmutableCbsClientConfiguration.builder()
+ .appName("dcae-prh")
+ .cbsName("config-binding-service")
+ .consulHost("consul")
+ .consulPort(8500)
+ .build();
+
+ private HttpResponse response;
+ private ReactiveCloudConfigurationProvider provider;
+
+ ReactiveCloudConfigurationProviderTest() throws IOException {
+ }
+
+
+ @BeforeEach
+ void setUp() {
+ response = mock(HttpResponse.class);
+ provider = new ReactiveCloudConfigurationProvider(httpClient);
+ }
+
+ @Test
+ void shouldReturnPrhConfiguration(){
+ //when
+ when(httpClient.call(any(HttpRequest.class))).thenReturn(Mono.just(response));
+ when(response.bodyAsJson(JsonArray.class)).thenReturn(configBindingService);
+ when(response.bodyAsJson(JsonObject.class)).thenReturn(CONFIGURATION_JSON_MOCK);
+
+
+ //then
+ StepVerifier.create(provider.callForServiceConfigurationReactive(cbsClientConfiguration))
+ .expectSubscription()
+ .expectNext(CONFIGURATION_JSON_MOCK).verifyComplete();
+ }
+
+ @Test
+ void shouldRequestCorrectUrl(){
+ // given
+ String consulRequestUrl = "http://consul:8500/v1/catalog/service/config-binding-service";
+ String configRequestUrl = "http://config-binding-service:10000/service_component/dcae-prh";
+
+ //when
+ when(httpClient.call(any(HttpRequest.class))).thenReturn(Mono.just(response));
+ when(response.bodyAsJson(JsonArray.class)).thenReturn(configBindingService);
+ when(response.bodyAsJson(JsonObject.class)).thenReturn(CONFIGURATION_JSON_MOCK);
+
+
+ //then
+ StepVerifier.create(provider.callForServiceConfigurationReactive(cbsClientConfiguration))
+ .expectSubscription()
+ .expectNext(CONFIGURATION_JSON_MOCK).verifyComplete();
+
+
+ ArgumentCaptor<HttpRequest> httpReq = ArgumentCaptor
+ .forClass(HttpRequest.class);
+ verify(httpClient, times(2)).call(httpReq.capture());
+
+ List<HttpRequest> allRequests = httpReq.getAllValues();
+ assertThat(allRequests.get(0).url()).isEqualTo(consulRequestUrl);
+ assertThat(allRequests.get(1).url()).isEqualTo(configRequestUrl);
+ }
+
+ @Test
+ void shouldReturnMonoErrorWhenConsuleDoesntHaveConfigBindingServiceEntry() {
+ // given
+ JsonArray emptyArray = gson.fromJson("[]", JsonArray.class);
+
+ //when
+ when(httpClient.call(any(HttpRequest.class))).thenReturn(Mono.just(response));
+ when(response.bodyAsJson(JsonArray.class)).thenReturn(emptyArray);
+
+
+ //then
+ StepVerifier.create(provider.callForServiceConfigurationReactive(cbsClientConfiguration))
+ .expectSubscription()
+ .expectError(IllegalStateException.class).verify();
+ }
+} \ No newline at end of file