summaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test')
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java85
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java17
2 files changed, 101 insertions, 1 deletions
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java
new file mode 100644
index 000000000..1f447a4ff
--- /dev/null
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplDataRetrieverTest.java
@@ -0,0 +1,85 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 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.appc.adapter.chef.impl;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+import org.onap.appc.adapter.chef.ChefAdapter;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+public class ChefAdapterImplDataRetrieverTest {
+
+ private static final String KEY_PARAM = "key";
+ private static final String DG_CONTEXT_PARAM = "dgContext";
+ private static final String ALL_CONFIG_PARAM = "allConfig";
+ private static final String KEY_VALUE = "keyValue";
+ private static final String DG_CONTEXT_VALUE = "contextValue";
+
+ @Test
+ public void retrieveData_shouldSetContextData_withExtractedJsonString() {
+ // GIVEN
+ Map<String, String> params = givenParamMapWithJson("{" + KEY_VALUE + ":testValue}");
+ SvcLogicContext svcLogicContext = new SvcLogicContext();
+
+ // WHEN
+ ChefAdapter chefAdapter = new ChefAdapterImpl();
+ chefAdapter.retrieveData(params, svcLogicContext);
+
+ // THEN
+ Assertions.assertThat(svcLogicContext.getAttribute(DG_CONTEXT_VALUE)).isEqualTo("testValue");
+ }
+
+ @Test
+ public void retrieveData_shouldSetContextData_withExtractedJsonObject() {
+ // GIVEN
+ Map<String, String> params = givenParamMapWithJson("{" + KEY_VALUE + ": {param : testValue} }");
+ SvcLogicContext svcLogicContext = new SvcLogicContext();
+
+ // WHEN
+ ChefAdapter chefAdapter = new ChefAdapterImpl();
+ chefAdapter.retrieveData(params, svcLogicContext);
+
+ // THEN
+ Assertions.assertThat(svcLogicContext.getAttribute(DG_CONTEXT_VALUE)).isEqualTo("{\"param\":\"testValue\"}");
+ }
+
+ @Test
+ public void retrieveData_shouldSetContextData_withExtractedJsonArray() {
+ // GIVEN
+ Map<String, String> params = givenParamMapWithJson("{" + KEY_VALUE + ": [val1, val2, val3] }");
+ SvcLogicContext svcLogicContext = new SvcLogicContext();
+
+ // WHEN
+ ChefAdapter chefAdapter = new ChefAdapterImpl();
+ chefAdapter.retrieveData(params, svcLogicContext);
+
+ // THEN
+ Assertions.assertThat(svcLogicContext.getAttribute(DG_CONTEXT_VALUE)).isEqualTo("[\"val1\",\"val2\",\"val3\"]");
+ }
+
+ private Map<String, String> givenParamMapWithJson(String json) {
+ return ImmutableMap
+ .of(KEY_PARAM, KEY_VALUE,
+ DG_CONTEXT_PARAM, DG_CONTEXT_VALUE,
+ ALL_CONFIG_PARAM, json);
+ }
+} \ No newline at end of file
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java
index c4c3e3089..df8326782 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java
@@ -39,10 +39,10 @@ public class ChefAdapterImplTest {
public void nodeObjectBuilder_shouldBuildJsonNodeObject_forPassedParams_andAddToSvcLogicContext() {
// GIVEN
Map<String, String> params = givenInputParams();
+ SvcLogicContext svcLogicContext = new SvcLogicContext();
// WHEN
ChefAdapter chefAdapter = new ChefAdapterImpl();
- SvcLogicContext svcLogicContext = new SvcLogicContext();
chefAdapter.nodeObejctBuilder(params, svcLogicContext);
// THEN
@@ -78,4 +78,19 @@ public class ChefAdapterImplTest {
expectedJson.put("chef_environment", "testChefEnvVal");
return expectedJson.toString();
}
+
+ @Test
+ public void combineStrings_shouldConcatenateTwoParamStrings_andSetThemInSvcContext() {
+ // GIVEN
+ Map<String, String> params = ImmutableMap
+ .of("dgContext", "contextValue", "String1", "paramString1", "String2", "paramString2");
+ SvcLogicContext svcLogicContext = new SvcLogicContext();
+
+ // WHEN
+ ChefAdapter chefAdapter = new ChefAdapterImpl();
+ chefAdapter.combineStrings(params, svcLogicContext);
+
+ // THEN
+ assertThat(svcLogicContext.getAttribute("contextValue")).isEqualTo("paramString1paramString2");
+ }
} \ No newline at end of file