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 {
41 LogParserTool lp = new LogParserTool();
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);
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);
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);
70 public void testNode() {
71 CustomJsonNodeFactory c = new CustomJsonNodeFactory();
77 public void testCustomText() {
78 CustomTextNode c = new CustomTextNode("test");
83 public void testEscapeUtils() {
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);
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);
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);
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(lp, "checkDateTime", line);