2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modification Copyright (C) 2018 IBM.
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.generator.convert;
28 import static org.junit.Assert.assertEquals;
29 import java.io.IOException;
30 import java.util.HashMap;
32 import org.apache.commons.io.IOUtils;
33 import org.junit.Test;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
37 import org.onap.sdnc.config.generator.merge.TestMergeNode;
38 import org.powermock.reflect.Whitebox;
39 import com.att.eelf.configuration.EELFLogger;
40 import com.att.eelf.configuration.EELFManager;
42 public class TestConvertNode {
43 private static final EELFLogger log =
44 EELFManager.getInstance().getLogger(TestConvertNode.class);
46 @Test(expected = Exception.class)
47 public void testPayloadParametersConfig() throws Exception {
48 SvcLogicContext ctx = new SvcLogicContext();
49 Map<String, String> inParams = new HashMap<String, String>();
50 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
51 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
52 "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
53 convertJson2Context("convert/payload_parameters_config.json", inParams, ctx);
54 Whitebox.invokeMethod("convertJson2Context", "convert/payload_parameters_config.json",
56 log.info("testPayloadParametersConfig Result: "
57 + ctx.getAttribute("block_configuration-parameters"));
61 public void testPayloadCliConfig() throws Exception {
62 SvcLogicContext ctx = new SvcLogicContext();
63 Map<String, String> inParams = new HashMap<String, String>();
64 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
65 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
66 "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
67 convertJson2Context("convert/payload_cli_config.json", inParams, ctx);
68 log.info("testPayloadCliConfig Result: "
69 + ctx.getAttribute("block_configuration-parameters"));
70 log.info("testPayloadCliConfig Result: "
71 + ctx.getAttribute("block_configuration.configuration-string"));
74 @Test(expected = Exception.class)
75 public void testPayloadXMLConfig() throws Exception {
76 SvcLogicContext ctx = new SvcLogicContext();
77 Map<String, String> inParams = new HashMap<String, String>();
78 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
79 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
80 "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
81 convertJson2Context("convert/payload_xml_config.json", inParams, ctx);
83 log.info("testPayloadXMLConfig Result: "
84 + ctx.getAttribute("block_configuration-parameters"));
85 log.info("testPayloadXMLConfig Result: "
86 + ctx.getAttribute("block_configuration.configuration-string"));
89 @Test(expected = Exception.class)
90 public void testPayloadJsonConfig() throws Exception {
91 SvcLogicContext ctx = new SvcLogicContext();
92 Map<String, String> inParams = new HashMap<String, String>();
93 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
94 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
95 "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
96 convertJson2Context("convert/payload_json_config.json", inParams, ctx);
97 log.info("testPayloadJsonConfig Result: "
98 + ctx.getAttribute("block_configuration-parameters"));
99 log.info("testPayloadJsonConfig Result: "
100 + ctx.getAttribute("block_configuration.configuration-json"));
103 private void convertJson2Context(String jsonFile, Map<String, String> inParams,
104 SvcLogicContext ctx) throws IOException, SvcLogicException {
105 ConvertNode convertNode = new ConvertNode();
106 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
107 String jsonData = IOUtils
108 .toString(TestMergeNode.class.getClassLoader().getResourceAsStream(jsonFile));
109 log.info("TestConvertNode.testConvertJson2DGContext()" + jsonData);
110 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
111 convertNode.convertJson2DGContext(inParams, ctx);
112 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
113 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
116 @Test(expected = Exception.class)
117 public void testEscapeData() throws Exception {
118 SvcLogicContext ctx = new SvcLogicContext();
119 Map<String, String> inParams = new HashMap<String, String>();
120 String unescapeData = IOUtils.toString(TestMergeNode.class.getClassLoader()
121 .getResourceAsStream("convert/escape/config_ssc.txt"));
122 log.info("TestConvertNode.testEscapeData() unescapeData :" + unescapeData);
123 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
124 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA, unescapeData);
125 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE,
126 ConfigGeneratorConstant.DATA_TYPE_SQL);
127 ConvertNode convertNode = new ConvertNode();
128 convertNode.escapeData(inParams, ctx);
129 log.info("testEscapeData Result: "
130 + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_ESCAPE_DATA));
134 public void testConvertContextToJson() throws Exception {
135 SvcLogicContext ctx = new SvcLogicContext();
136 ctx.setAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID", "200");
137 ctx.setAttribute("tmp.uploadConfigInfo.VNF-ID", "00000");
138 ctx.setAttribute("tmp.uploadConfigInfo.test[0]", "test0");
139 ctx.setAttribute("tmp.uploadConfigInfo.test[1]", "test1");
140 ctx.setAttribute("tmp.uploadConfigInfo.test[2]", "test2");
141 ConvertNode convertNode = new ConvertNode();
142 Map<String, String> inParams = new HashMap<String, String>();
143 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
144 inParams.put("contextKey", "tmp.uploadConfigInfo");
145 convertNode.convertContextToJson(inParams, ctx);
146 log.info("JSON CONTENT " + ctx.getAttribute("test.jsonContent"));
147 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
148 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
152 @Test(expected = Exception.class)
153 public void testunEscapeData() throws Exception {
154 ConvertNode convertNode = new ConvertNode();
155 Map<String, String> inParams = new HashMap<String, String>();
156 SvcLogicContext ctx = new SvcLogicContext();
157 log.trace("Received unEscapeData call with params : " + inParams);
158 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "tmp");
159 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA, "//");
160 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, "String");
161 convertNode.unEscapeData(inParams, ctx);
166 public void testEscapeDataForValidUnescapeDataString() throws Exception {
167 SvcLogicContext ctx = new SvcLogicContext();
168 Map<String, String> inParams = new HashMap<String, String>();
169 String unescapeData = "testUnescapeData";
170 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
171 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA, unescapeData);
172 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE,
173 ConfigGeneratorConstant.DATA_TYPE_SQL);
174 ConvertNode convertNode = new ConvertNode();
175 convertNode.escapeData(inParams, ctx);
176 assertEquals(unescapeData, ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_ESCAPE_DATA));