aefb7a4b3032d337b0d8051a0b585b0e9ed6bc2f
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.sdnc.config.generator.tool;
25
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31 import org.apache.commons.io.IOUtils;
32 import org.junit.Test;
33 import org.mockito.Mock;
34 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
35 import org.onap.sdnc.config.generator.pattern.TestPatternNode;
36 import org.powermock.reflect.Whitebox;
37
38 public class TestDataTool {
39
40     @Mock
41     private LogParserTool logParserTool = 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.escapeString(s);
89         EscapeUtils.escapeSql(s);
90         EscapeUtils.escapeString(st);
91         EscapeUtils.escapeString(str);
92         EscapeUtils.escapeString(strng);
93         EscapeUtils.escapeString(null);
94     }
95
96     @Test(expected = Exception.class)
97     public void testgetData() throws Exception {
98         List<String> 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 setClause = null;
109         String tableName = "dual";
110         List<String> inputArgs = null;
111         String whereClause = "123='123'";
112         DbServiceUtil.updateDB(tableName, inputArgs, whereClause, setClause);
113     }
114
115     // @Test(expected = Exception.class)
116     public void testinitDbLibService() throws Exception {
117         DbServiceUtil.initDbLibService();
118     }
119
120     @Test
121     public void testJSONTool() throws Exception {
122         String data = IOUtils.toString(
123             TestPatternNode.class.getClassLoader()
124                 .getResourceAsStream("convert/payload_cli_config.json"),
125             ConfigGeneratorConstant.STRING_ENCODING);
126         JSONTool.convertToProperties(data);
127         List<String> blockKeys = new ArrayList<String>();
128         blockKeys.add("vnf-type");
129         blockKeys.add("request-parameters");
130         JSONTool.convertToProperties(data, blockKeys);
131     }
132
133     @Test
134     public void testLogParserTool() throws Exception {
135         String data = IOUtils.toString(
136             TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
137             ConfigGeneratorConstant.STRING_ENCODING);
138         LogParserTool lpt = new LogParserTool();
139         lpt.parseErrorLog(data);
140     }
141
142     @Test
143     public void testMergeTool() throws Exception {
144         String template = "test";
145         Map<String, String> dataMap = new HashMap<String, String>();
146         MergeTool.mergeMap2TemplateData(template, dataMap);
147     }
148
149     @Test
150     public void testcheckDateTime() throws Exception {
151         String line = "2017-08-20T17:40:23.100361+00:00";
152         Whitebox.invokeMethod(logParserTool, "checkDateTime", line);
153     }
154 }