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.openecomp.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.openecomp.sdnc.config.generator.ConfigGeneratorConstant;
36 import org.openecomp.sdnc.config.generator.pattern.TestPatternNode;
37 import org.openecomp.sdnc.config.generator.tool.CheckDataTool;
38 import org.powermock.reflect.Whitebox;
40 public class TestDataTool {
42 LogParserTool lp = new LogParserTool();
45 public void testCheckData() throws IOException {
46 String data = IOUtils.toString(
47 TestPatternNode.class.getClassLoader().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().getResourceAsStream("convert/payload_cli_config.json"),
56 ConfigGeneratorConstant.STRING_ENCODING);
57 CheckDataTool.isJSON(data);
61 public void testIsXML() throws IOException {
62 String data = IOUtils.toString(
63 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
64 ConfigGeneratorConstant.STRING_ENCODING);
65 CheckDataTool.isXML(data);
69 public void testNode() {
70 CustomJsonNodeFactory c = new CustomJsonNodeFactory();
76 public void testCustomText() {
77 CustomTextNode c = new CustomTextNode("test");
82 public void testEscapeUtils() {
84 String st = "test\"test";
85 String str = "test\'" + "test";
86 String strng = "test\0";
87 EscapeUtils.escapeSQL(s);
88 EscapeUtils.escapeSql(s);
89 EscapeUtils.escapeSQL(st);
90 EscapeUtils.escapeSQL(str);
91 EscapeUtils.escapeSQL(strng);
92 EscapeUtils.escapeSQL(null);
95 // @Test(expected = Exception.class)
96 public void testgetData() throws Exception {
97 ArrayList argList = null;
98 String schema = "sdnctl";
99 String tableName = "dual";
100 String getselectData = "123";
101 String getDataClasue = "123='123'";
102 DbServiceUtil.getData(tableName, argList, schema, getselectData, getDataClasue);
105 // @Test(expected = Exception.class)
106 public void testupdateDB() throws Exception {
107 String setCluase = null;
108 String schema = "sdnctl";
109 String tableName = "dual";
110 ArrayList inputArgs = null;
111 String whereClause = "123='123'";
112 DbServiceUtil.updateDB(tableName, inputArgs, schema, whereClause, setCluase);
115 // @Test(expected = Exception.class)
116 public void testinitDbLibService() throws Exception {
117 DbServiceUtil.initDbLibService();
121 public void testJSONTool() throws Exception {
122 String data = IOUtils.toString(
123 TestPatternNode.class.getClassLoader().getResourceAsStream("convert/payload_cli_config.json"),
124 ConfigGeneratorConstant.STRING_ENCODING);
125 JSONTool.convertToProperties(data);
126 List<String> blockKeys = new ArrayList<String>();
127 blockKeys.add("vnf-type");
128 blockKeys.add("request-parameters");
129 JSONTool.convertToProperties(data, blockKeys);
133 public void testLogParserTool() throws Exception {
134 String data = IOUtils.toString(
135 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
136 ConfigGeneratorConstant.STRING_ENCODING);
137 LogParserTool lpt = new LogParserTool();
138 lpt.parseErrorLog(data);
142 public void testMergeTool() throws Exception {
143 String template = "test";
144 Map<String, String> dataMap = new HashMap<String, String>();
145 MergeTool.mergeMap2TemplateData(template, dataMap);
149 public void testcheckDateTime() throws Exception {
150 String line = "2017-08-20T17:40:23.100361+00:00";
151 Whitebox.invokeMethod(lp, "checkDateTime", line);