985f295cc22ad130382433e2af4b495d254be8b5
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APP-C
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdnc.config.generator.convert;
22
23 import static org.junit.Assert.assertNotEquals;
24 import static org.junit.Assert.assertEquals;
25
26 import java.io.IOException;
27 import java.text.SimpleDateFormat;
28 import java.util.ArrayList;
29 import java.util.Date;
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import org.apache.commons.io.IOUtils;
34 import org.junit.Test;
35 import org.openecomp.sdnc.config.generator.ConfigGeneratorConstant;
36 import org.openecomp.sdnc.config.generator.convert.ConvertNode;
37 import org.openecomp.sdnc.config.generator.merge.TestMergeNode;
38
39 import com.att.eelf.configuration.EELFLogger;
40 import com.att.eelf.configuration.EELFManager;
41 import org.openecomp.sdnc.sli.SvcLogicContext;
42 import org.openecomp.sdnc.sli.SvcLogicException;
43
44 public class TestConvertNode {
45     private static final  EELFLogger log = EELFManager.getInstance().getLogger(TestConvertNode.class);
46
47 //    @Test
48     public void testPayloadParametersConfig() throws Exception {
49         SvcLogicContext ctx = new SvcLogicContext();
50         Map<String, String> inParams = new HashMap<String, String>();
51         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
52         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS, "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
53         convertJson2Context("convert/payload_parameters_config.json", inParams, ctx);
54         log.info("testPayloadParametersConfig Result: " + ctx.getAttribute("block_configuration-parameters"));
55
56     }
57
58 //@Test
59     public void testPayloadCliConfig() throws Exception {
60         SvcLogicContext ctx = new SvcLogicContext();
61         Map<String, String> inParams = new HashMap<String, String>();
62         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
63         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS, "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
64         convertJson2Context("convert/payload_cli_config.json", inParams, ctx);
65
66         log.info("testPayloadCliConfig Result: " + ctx.getAttribute("block_configuration-parameters"));
67         log.info("testPayloadCliConfig Result: " + ctx.getAttribute("block_configuration.configuration-string"));
68     }
69
70         //@Test   
71     public void testPayloadXMLConfig() throws Exception {
72         SvcLogicContext ctx = new SvcLogicContext();
73         Map<String, String> inParams = new HashMap<String, String>();
74         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
75         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS, "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
76         convertJson2Context("convert/payload_xml_config.json", inParams, ctx);
77
78         log.info("testPayloadXMLConfig Result: " + ctx.getAttribute("block_configuration-parameters"));
79         log.info("testPayloadXMLConfig Result: " + ctx.getAttribute("block_configuration.configuration-string"));
80     }
81          //@Test
82     public void testPayloadJsonConfig() throws Exception {
83         SvcLogicContext ctx = new SvcLogicContext();
84         Map<String, String> inParams = new HashMap<String, String>();
85         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
86         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS, "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
87         convertJson2Context("convert/payload_json_config.json", inParams, ctx);
88         log.info("testPayloadJsonConfig Result: " + ctx.getAttribute("block_configuration-parameters"));
89         log.info("testPayloadJsonConfig Result: " + ctx.getAttribute("block_configuration.configuration-json"));
90     }
91         //@Test
92     private void convertJson2Context(String jsonFile, Map<String, String> inParams, SvcLogicContext ctx) throws IOException, SvcLogicException {
93         ConvertNode convertNode = new ConvertNode();
94         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
95
96         String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader().getResourceAsStream(jsonFile));
97         log.info("TestConvertNode.testConvertJson2DGContext()" + jsonData);
98         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
99         convertNode.convertJson2DGContext(inParams, ctx);
100         assertEquals(ctx.getAttribute("test."+ConfigGeneratorConstant.OUTPUT_PARAM_STATUS), ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
101     }
102
103 //    @Test
104     public void testEscapeData() throws Exception {
105         SvcLogicContext ctx = new SvcLogicContext();
106         Map<String, String> inParams = new HashMap<String, String>();
107         //String unescapeData = IOUtils.toString(TestMergeNode.class.getClassLoader().getResourceAsStream("convert/escape/config_msc.txt"));
108         String unescapeData = IOUtils.toString(TestMergeNode.class.getClassLoader().getResourceAsStream("convert/escape/config_ssc.txt"));
109         //String unescapeData = IOUtils.toString(TestMergeNode.class.getClassLoader().getResourceAsStream("convert/escape/config_vdbe.xml"));
110         log.info("TestConvertNode.testEscapeData() unescapeData :"+unescapeData);
111         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
112         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA, unescapeData);
113         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_SQL);
114         ConvertNode convertNode = new ConvertNode();
115         convertNode.escapeData(inParams, ctx);
116         log.info("testEscapeData Result: " + ctx.getAttribute("test."+ConfigGeneratorConstant.OUTPUT_PARAM_ESCAPE_DATA));
117     }
118
119
120
121 //    @Test
122     public void testConvertContextToJson() throws Exception {
123         SvcLogicContext ctx = new SvcLogicContext();
124         ctx.setAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID", "200");
125         ctx.setAttribute("tmp.uploadConfigInfo.VNF-ID", "00000");
126         ctx.setAttribute("tmp.uploadConfigInfo.test[0]", "test0");
127         ctx.setAttribute("tmp.uploadConfigInfo.test[1]", "test1");
128         ctx.setAttribute("tmp.uploadConfigInfo.test[2]", "test2");
129     
130         
131         ConvertNode convertNode = new ConvertNode();
132         Map<String, String> inParams = new HashMap<String, String>();
133         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
134         inParams.put("contextKey", "tmp.uploadConfigInfo");
135
136             
137         convertNode.convertContextToJson(inParams, ctx);
138         
139         log.info("JSON CONTENT " + ctx.getAttribute("test.jsonContent"));
140         assertEquals(ctx.getAttribute("test."+ConfigGeneratorConstant.OUTPUT_PARAM_STATUS), ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
141         
142         
143             
144     }
145
146     
147     
148
149 }