aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/cbs-client/src/test
diff options
context:
space:
mode:
authorPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2019-02-26 15:08:37 +0100
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2019-02-27 08:09:11 +0100
commit4b1062c01ea444f429ca7c51153c2cea5692ed80 (patch)
treee91d33a0550fec77ac219054dcdc4358f8c89376 /rest-services/cbs-client/src/test
parentddfb652b619c7e42d84b11930d0453663df63d0b (diff)
CBS lookup algorithm
Implement CBS lookup algorithm as docummented on https://wiki.onap.org/display/DW/MicroServices+Onboarding+in+ONAP#MicroServicesOnboardinginONAP-CodesnippettofetchconfigurationfromConfigbindingservice Change-Id: Ib465c5fd44b853ba46e152259744dbdd775872a0 Issue-ID: DCAEGEN2-1233 Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'rest-services/cbs-client/src/test')
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvPropertiesTest.java37
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java94
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProviderTest.java6
-rw-r--r--rest-services/cbs-client/src/test/resources/consul_cbs_service.json23
4 files changed, 157 insertions, 3 deletions
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvPropertiesTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvPropertiesTest.java
new file mode 100644
index 00000000..b48543d2
--- /dev/null
+++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/EnvPropertiesTest.java
@@ -0,0 +1,37 @@
+/*
+ * ============LICENSE_START====================================
+ * DCAEGEN2-SERVICES-SDK
+ * =========================================================
+ * Copyright (C) 2019 Nokia. 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.api;
+
+
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
+ * @since February 2019
+ */
+class EnvPropertiesTest {
+ @Test
+ void fromEnvironmentShouldFailWhenEnvVariablesAreMissing() {
+ assertThatExceptionOfType(NullPointerException.class).isThrownBy(EnvProperties::fromEnvironment);
+ }
+} \ 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/impl/CbsLookupTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java
new file mode 100644
index 00000000..e7513852
--- /dev/null
+++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsLookupTest.java
@@ -0,0 +1,94 @@
+/*
+ * ============LICENSE_START====================================
+ * DCAEGEN2-SERVICES-SDK
+ * =========================================================
+ * Copyright (C) 2019 Nokia. 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.impl;
+
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import java.io.InputStreamReader;
+import java.net.InetSocketAddress;
+import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.ImmutableEnvProperties;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.adapters.CloudHttpClient;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+/**
+ * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
+ * @since February 2019
+ */
+class CbsLookupTest {
+
+ private final EnvProperties env = ImmutableEnvProperties.builder()
+ .cbsName("cbs-service")
+ .consulHost("consul.local")
+ .consulPort(8050)
+ .appName("whatever").build();
+ private final CloudHttpClient httpClient = mock(CloudHttpClient.class);
+ private final CbsLookup cut = new CbsLookup(httpClient);
+
+ @Test
+ void lookupShouldReturnValidConfiguration() {
+ // given
+ givenConsulResponse(parseResource("/consul_cbs_service.json").getAsJsonArray());
+
+ // when
+ final InetSocketAddress result = cut.lookup(env).block();
+
+ // then
+ assertThat(result.getHostString()).isEqualTo("config-binding-service");
+ assertThat(result.getPort()).isEqualTo(10000);
+ }
+
+ @Test
+ void lookupShouldReturnEmptyResultWhenServiceArrayIsEmpty() {
+ // given
+ givenConsulResponse(new JsonArray());
+
+ // when
+ final Mono<InetSocketAddress> result = cut.lookup(env);
+
+ // then
+ StepVerifier.create(result).verifyComplete();
+ }
+
+ private JsonElement parseResource(String resource) {
+ return new JsonParser().parse(new InputStreamReader(CbsLookupTest.class.getResourceAsStream(resource)));
+ }
+
+ private void givenConsulResponse(JsonArray jsonArray) {
+ final String url = "http://"
+ + env.consulHost()
+ + ":"
+ + env.consulPort()
+ + "/v1/catalog/service/"
+ + env.cbsName();
+ given(httpClient.callHttpGet(url, JsonArray.class))
+ .willReturn(Mono.just(jsonArray));
+ }
+
+} \ 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
index 5d6ef6bc..4e8782b6 100644
--- 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
@@ -27,9 +27,9 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.CloudHttpClient;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.EnvProperties;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.ImmutableEnvProperties;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.ImmutableEnvProperties;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.adapters.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.EnvProperties;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
diff --git a/rest-services/cbs-client/src/test/resources/consul_cbs_service.json b/rest-services/cbs-client/src/test/resources/consul_cbs_service.json
new file mode 100644
index 00000000..49b1df20
--- /dev/null
+++ b/rest-services/cbs-client/src/test/resources/consul_cbs_service.json
@@ -0,0 +1,23 @@
+[
+ {
+ "Address": "10.42.102.75",
+ "CreateIndex": 1097,
+ "Datacenter": "dc1",
+ "ID": "2a69de1b-4c2d-a958-5058-639acc926fde",
+ "ModifyIndex": 1097,
+ "Node": "dcae-bootstrap",
+ "NodeMeta": {
+ "consul-network-segment": ""
+ },
+ "ServiceAddress": "config-binding-service",
+ "ServiceEnableTagOverride": false,
+ "ServiceID": "dcae-cbs0",
+ "ServiceName": "config_binding_service",
+ "ServicePort": 10000,
+ "ServiceTags": [],
+ "TaggedAddresses": {
+ "lan": "10.42.102.75",
+ "wan": "10.42.102.75"
+ }
+ }
+]