diff options
Diffstat (limited to 'appc-adapters/appc-chef-adapter')
3 files changed, 103 insertions, 9 deletions
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java index 69b57f7ce..4a4081e5c 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java @@ -416,10 +416,7 @@ public class ChefAdapterImpl implements ChefAdapter { JSONObject jsonConfig = new JSONObject(allConfigData); String contextData = fetchContextData(key, jsonConfig); - RequestContext rc = new RequestContext(ctx); - rc.isAlive(); - SvcLogicContext svcLogic = rc.getSvcLogicContext(); - svcLogic.setAttribute(dgContext, contextData); + ctx.setAttribute(dgContext, contextData); } private String fetchContextData(String key, JSONObject jsonConfig) { @@ -443,10 +440,7 @@ public class ChefAdapterImpl implements ChefAdapter { String string2 = params.get("String2"); String dgContext = params.get("dgContext"); String contextData = string1 + string2; - RequestContext rc = new RequestContext(ctx); - rc.isAlive(); - SvcLogicContext svcLogic = rc.getSvcLogicContext(); - svcLogic.setAttribute(dgContext, contextData); + ctx.setAttribute(dgContext, contextData); } /** 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 |