2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.sdnc.config.generator.tool;
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
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;
39 public class TestDataTool {
42 private LogParserTool logParserTool = new LogParserTool();
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);
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);
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);
71 public void testNode() {
72 CustomJsonNodeFactory c = new CustomJsonNodeFactory();
78 public void testCustomText() {
79 CustomTextNode c = new CustomTextNode("test");
84 public void testEscapeUtils() {
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);
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);
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);
116 // @Test(expected = Exception.class)
117 public void testinitDbLibService() throws Exception {
118 DbServiceUtil.initDbLibService();
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);
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);
144 public void testMergeTool() throws Exception {
145 String template = "test";
146 Map<String, String> dataMap = new HashMap<String, String>();
147 MergeTool.mergeMap2TemplateData(template, dataMap);
151 public void testcheckDateTime() throws Exception {
152 String line = "2017-08-20T17:40:23.100361+00:00";
153 Whitebox.invokeMethod(logParserTool, "checkDateTime", line);