6e1d525c211e04766eec8612f8196b251b756451
[appc.git] / appc-config / appc-config-generator / provider / src / test / java / org / onap / sdnc / config / generator / tool / TestDataTool.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.sdnc.config.generator.tool;
26
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32 import org.apache.commons.io.IOUtils;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
36 import org.onap.sdnc.config.generator.pattern.TestPatternNode;
37 import org.powermock.reflect.Whitebox;
38
39 public class TestDataTool {
40     @Mock
41     LogParserTool lp = new LogParserTool();
42
43     @Test
44     public void testCheckData() throws IOException {
45         String data = IOUtils.toString(
46                 TestPatternNode.class.getClassLoader()
47                         .getResourceAsStream("convert/payload_cli_config.json"),
48                 ConfigGeneratorConstant.STRING_ENCODING);
49         CheckDataTool.checkData(data);
50     }
51
52     @Test
53     public void testIsJSON() throws IOException {
54         String data = IOUtils.toString(
55                 TestPatternNode.class.getClassLoader()
56                         .getResourceAsStream("convert/payload_cli_config.json"),
57                 ConfigGeneratorConstant.STRING_ENCODING);
58         CheckDataTool.isJSON(data);
59     }
60
61     @Test
62     public void testIsXML() throws IOException {
63         String data = IOUtils.toString(
64                 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
65                 ConfigGeneratorConstant.STRING_ENCODING);
66         CheckDataTool.isXML(data);
67     }
68
69     @Test
70     public void testNode() {
71         CustomJsonNodeFactory c = new CustomJsonNodeFactory();
72         String text = "test";
73         c.textNode(text);
74     }
75
76     @Test
77     public void testCustomText() {
78         CustomTextNode c = new CustomTextNode("test");
79         c.toString();
80     }
81
82     @Test
83     public void testEscapeUtils() {
84         String s = "test\\";
85         String st = "test\"test";
86         String str = "test\'" + "test";
87         String strng = "test\0";
88         EscapeUtils.escapeSQL(s);
89         EscapeUtils.escapeSql(s);
90         EscapeUtils.escapeSQL(st);
91         EscapeUtils.escapeSQL(str);
92         EscapeUtils.escapeSQL(strng);
93         EscapeUtils.escapeSQL(null);
94     }
95
96     // @Test(expected = Exception.class)
97     public void testgetData() throws Exception {
98         ArrayList argList = null;
99         String schema = "sdnctl";
100         String tableName = "dual";
101         String getselectData = "123";
102         String getDataClasue = "123='123'";
103         DbServiceUtil.getData(tableName, argList, schema, getselectData, getDataClasue);
104     }
105
106     // @Test(expected = Exception.class)
107     public void testupdateDB() throws Exception {
108         String setCluase = null;
109         String schema = "sdnctl";
110         String tableName = "dual";
111         ArrayList inputArgs = null;
112         String whereClause = "123='123'";
113         DbServiceUtil.updateDB(tableName, inputArgs, schema, whereClause, setCluase);
114     }
115
116     // @Test(expected = Exception.class)
117     public void testinitDbLibService() throws Exception {
118         DbServiceUtil.initDbLibService();
119     }
120
121     @Test
122     public void testJSONTool() throws Exception {
123         String data = IOUtils.toString(
124                 TestPatternNode.class.getClassLoader()
125                         .getResourceAsStream("convert/payload_cli_config.json"),
126                 ConfigGeneratorConstant.STRING_ENCODING);
127         JSONTool.convertToProperties(data);
128         List<String> blockKeys = new ArrayList<String>();
129         blockKeys.add("vnf-type");
130         blockKeys.add("request-parameters");
131         JSONTool.convertToProperties(data, blockKeys);
132     }
133
134     @Test
135     public void testLogParserTool() throws Exception {
136         String data = IOUtils.toString(
137                 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
138                 ConfigGeneratorConstant.STRING_ENCODING);
139         LogParserTool lpt = new LogParserTool();
140         lpt.parseErrorLog(data);
141     }
142
143     @Test
144     public void testMergeTool() throws Exception {
145         String template = "test";
146         Map<String, String> dataMap = new HashMap<String, String>();
147         MergeTool.mergeMap2TemplateData(template, dataMap);
148     }
149
150     @Test
151     public void testcheckDateTime() throws Exception {
152         String line = "2017-08-20T17:40:23.100361+00:00";
153         Whitebox.invokeMethod(lp, "checkDateTime", line);
154     }
155 }