diff options
author | Michal Kabaj <michal.kabaj@nokia.com> | 2018-03-05 13:42:17 +0100 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-03-06 17:11:29 +0000 |
commit | caece93b98a0c7ad1ae762ff1f29571e1bca8e0f (patch) | |
tree | 032919c6f5030cc369d18f0bd89291a732b98516 /appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test | |
parent | e5d914ebeabeb375a56744221fbbff9b6ec996ff (diff) |
ChefAdapterImpl JUnits
-Added unit testcases for retrieveData method - extracted new test class
-Added unit test for combineStrings method
Change-Id: I8adcc9d2dc17e4ebf305fc2a8139095d5841a445
Issue-ID: APPC-437
Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
Diffstat (limited to 'appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test')
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 |