appc-config-generator-provider sonar fixes part 2
[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
41     @Mock
42     private LogParserTool logParserTool = new LogParserTool();
43
44     @Test
45     public void testCheckData() throws IOException {
46         String data = IOUtils.toString(
47             TestPatternNode.class.getClassLoader()
48                 .getResourceAsStream("convert/payload_cli_config.json"),
49             ConfigGeneratorConstant.STRING_ENCODING);
50         CheckDataTool.checkData(data);
51     }
52
53     @Test
54     public void testIsJSON() throws IOException {
55         String data = IOUtils.toString(
56             TestPatternNode.class.getClassLoader()
57                 .getResourceAsStream("convert/payload_cli_config.json"),
58             ConfigGeneratorConstant.STRING_ENCODING);
59         CheckDataTool.isJSON(data);
60     }
61
62     @Test
63     public void testIsXML() throws IOException {
64         String data = IOUtils.toString(
65             TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
66             ConfigGeneratorConstant.STRING_ENCODING);
67         CheckDataTool.isXML(data);
68     }
69
70     @Test
71     public void testNode() {
72         CustomJsonNodeFactory c = new CustomJsonNodeFactory();
73         String text = "test";
74         c.textNode(text);
75     }
76
77     @Test
78     public void testCustomText() {
79         CustomTextNode c = new CustomTextNode("test");
80         c.toString();
81     }
82
83     @Test
84     public void testEscapeUtils() {
85         String s = "test\\";
86         String st = "test\"test";
87         String str = "test\'" + "test";
88         String strng = "test\0";
89         EscapeUtils.escapeString(s);
90         EscapeUtils.escapeSql(s);
91         EscapeUtils.escapeString(st);
92         EscapeUtils.escapeString(str);
93         EscapeUtils.escapeString(strng);
94         EscapeUtils.escapeString(null);
95     }
96
97     @Test(expected = Exception.class)
98     public void testgetData() throws Exception {
99         List<String> argList = null;
100         String schema = "sdnctl";
101         String tableName = "dual";
102         String getselectData = "123";
103         String getDataClasue = "123='123'";
104         DbServiceUtil.getData(tableName, argList, schema, getselectData, getDataClasue);
105     }
106
107     @Test(expected = Exception.class)
108     public void testupdateDB() throws Exception {
109         String setClause = null;
110         String tableName = "dual";
111         List<String> inputArgs = null;
112         String whereClause = "123='123'";
113         DbServiceUtil.updateDB(tableName, inputArgs, whereClause, setClause);
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(logParserTool, "checkDateTime", line);
154     }
155 }