2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * =============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.appc.adapter.chef.impl;
22 import com.google.common.collect.ImmutableMap;
24 import org.assertj.core.api.Assertions;
25 import org.junit.Test;
26 import org.onap.appc.adapter.chef.ChefAdapter;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 public class ChefAdapterImplDataRetrieverTest {
31 private static final String KEY_PARAM = "key";
32 private static final String DG_CONTEXT_PARAM = "dgContext";
33 private static final String ALL_CONFIG_PARAM = "allConfig";
34 private static final String KEY_VALUE = "keyValue";
35 private static final String DG_CONTEXT_VALUE = "contextValue";
38 public void retrieveData_shouldSetContextData_withExtractedJsonString() {
40 Map<String, String> params = givenParamMapWithJson("{" + KEY_VALUE + ":testValue}");
41 SvcLogicContext svcLogicContext = new SvcLogicContext();
44 ChefAdapter chefAdapter = new ChefAdapterImpl();
45 chefAdapter.retrieveData(params, svcLogicContext);
48 Assertions.assertThat(svcLogicContext.getAttribute(DG_CONTEXT_VALUE)).isEqualTo("testValue");
52 public void retrieveData_shouldSetContextData_withExtractedJsonObject() {
54 Map<String, String> params = givenParamMapWithJson("{" + KEY_VALUE + ": {param : testValue} }");
55 SvcLogicContext svcLogicContext = new SvcLogicContext();
58 ChefAdapter chefAdapter = new ChefAdapterImpl();
59 chefAdapter.retrieveData(params, svcLogicContext);
62 Assertions.assertThat(svcLogicContext.getAttribute(DG_CONTEXT_VALUE)).isEqualTo("{\"param\":\"testValue\"}");
66 public void retrieveData_shouldSetContextData_withExtractedJsonArray() {
68 Map<String, String> params = givenParamMapWithJson("{" + KEY_VALUE + ": [val1, val2, val3] }");
69 SvcLogicContext svcLogicContext = new SvcLogicContext();
72 ChefAdapter chefAdapter = new ChefAdapterImpl();
73 chefAdapter.retrieveData(params, svcLogicContext);
76 Assertions.assertThat(svcLogicContext.getAttribute(DG_CONTEXT_VALUE)).isEqualTo("[\"val1\",\"val2\",\"val3\"]");
79 private Map<String, String> givenParamMapWithJson(String json) {
81 .of(KEY_PARAM, KEY_VALUE,
82 DG_CONTEXT_PARAM, DG_CONTEXT_VALUE,
83 ALL_CONFIG_PARAM, json);