2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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=========================================================
21 package org.openecomp.sdnc.config.generator.convert;
23 import static org.junit.Assert.assertEquals;
24 import java.io.IOException;
25 import java.util.HashMap;
27 import org.apache.commons.io.IOUtils;
28 import org.junit.Test;
29 import org.openecomp.sdnc.config.generator.ConfigGeneratorConstant;
30 import org.openecomp.sdnc.config.generator.merge.TestMergeNode;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.powermock.reflect.Whitebox;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
37 public class TestConvertNode {
39 private static final EELFLogger log = EELFManager.getInstance().getLogger(TestConvertNode.class);
40 @Test(expected = Exception.class)
41 public void testPayloadParametersConfig() throws Exception {
42 SvcLogicContext ctx = new SvcLogicContext();
43 Map<String, String> inParams = new HashMap<String, String>();
44 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
45 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
46 "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
47 convertJson2Context("convert/payload_parameters_config.json", inParams, ctx);
48 Whitebox.invokeMethod("convertJson2Context", "convert/payload_parameters_config.json", inParams, ctx);
49 log.info("testPayloadParametersConfig Result: " + ctx.getAttribute("block_configuration-parameters"));
53 public void testPayloadCliConfig() throws Exception {
54 SvcLogicContext ctx = new SvcLogicContext();
55 Map<String, String> inParams = new HashMap<String, String>();
56 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
57 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
58 "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
59 convertJson2Context("convert/payload_cli_config.json", inParams, ctx);
60 log.info("testPayloadCliConfig Result: " + ctx.getAttribute("block_configuration-parameters"));
61 log.info("testPayloadCliConfig Result: " + ctx.getAttribute("block_configuration.configuration-string"));
64 @Test(expected = Exception.class)
65 public void testPayloadXMLConfig() throws Exception {
66 SvcLogicContext ctx = new SvcLogicContext();
67 Map<String, String> inParams = new HashMap<String, String>();
68 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
69 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
70 "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
71 convertJson2Context("convert/payload_xml_config.json", inParams, ctx);
72 log.info("testPayloadXMLConfig Result: " + ctx.getAttribute("block_configuration-parameters"));
73 log.info("testPayloadXMLConfig Result: " + ctx.getAttribute("block_configuration.configuration-string"));
76 @Test(expected = Exception.class)
77 public void testPayloadJsonConfig() throws Exception {
78 SvcLogicContext ctx = new SvcLogicContext();
79 Map<String, String> inParams = new HashMap<String, String>();
80 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
81 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
82 "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
83 convertJson2Context("convert/payload_json_config.json", inParams, ctx);
84 log.info("testPayloadJsonConfig Result: " + ctx.getAttribute("block_configuration-parameters"));
85 log.info("testPayloadJsonConfig Result: " + ctx.getAttribute("block_configuration.configuration-json"));
88 private void convertJson2Context(String jsonFile, Map<String, String> inParams, SvcLogicContext ctx)
89 throws IOException, SvcLogicException {
90 ConvertNode convertNode = new ConvertNode();
91 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
92 String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader().getResourceAsStream(jsonFile));
93 log.info("TestConvertNode.testConvertJson2DGContext()" + jsonData);
94 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
95 convertNode.convertJson2DGContext(inParams, ctx);
96 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
97 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
100 @Test(expected = Exception.class)
101 public void testEscapeData() throws Exception {
102 SvcLogicContext ctx = new SvcLogicContext();
103 Map<String, String> inParams = new HashMap<String, String>();
104 String unescapeData = IOUtils
105 .toString(TestMergeNode.class.getClassLoader().getResourceAsStream("convert/escape/config_ssc.txt"));
106 log.info("TestConvertNode.testEscapeData() unescapeData :" + unescapeData);
107 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
108 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA, unescapeData);
109 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_SQL);
110 ConvertNode convertNode = new ConvertNode();
111 convertNode.escapeData(inParams, ctx);
112 log.info("testEscapeData Result: "
113 + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_ESCAPE_DATA));
117 public void testConvertContextToJson() throws Exception {
118 SvcLogicContext ctx = new SvcLogicContext();
119 ctx.setAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID", "200");
120 ctx.setAttribute("tmp.uploadConfigInfo.VNF-ID", "00000");
121 ctx.setAttribute("tmp.uploadConfigInfo.test[0]", "test0");
122 ctx.setAttribute("tmp.uploadConfigInfo.test[1]", "test1");
123 ctx.setAttribute("tmp.uploadConfigInfo.test[2]", "test2");
124 ConvertNode convertNode = new ConvertNode();
125 Map<String, String> inParams = new HashMap<String, String>();
126 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
127 inParams.put("contextKey", "tmp.uploadConfigInfo");
128 convertNode.convertContextToJson(inParams, ctx);
129 log.info("JSON CONTENT " + ctx.getAttribute("test.jsonContent"));
130 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
131 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
134 @Test(expected = Exception.class)
135 public void testunEscapeData() throws Exception {
136 ConvertNode convertNode = new ConvertNode();
137 Map<String, String> inParams = new HashMap<String, String>();
138 SvcLogicContext ctx = new SvcLogicContext();
139 log.trace("Received unEscapeData call with params : " + inParams);
140 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "tmp");
141 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA, "//");
142 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, "String");
143 convertNode.unEscapeData(inParams, ctx);