2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications Copyright (C) 2018 IBM.
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.generator.tool;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
33 import org.apache.commons.io.IOUtils;
34 import org.junit.Test;
35 import org.mockito.Mock;
36 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
37 import org.onap.sdnc.config.generator.pattern.TestPatternNode;
38 import org.powermock.reflect.Whitebox;
39 import static org.junit.Assert.assertEquals;
41 public class TestDataTool {
44 private LogParserTool logParserTool = new LogParserTool();
47 public void testCheckData() throws IOException {
48 String data = IOUtils.toString(
49 TestPatternNode.class.getClassLoader()
50 .getResourceAsStream("convert/payload_cli_config.json"),
51 ConfigGeneratorConstant.STRING_ENCODING);
52 CheckDataTool.checkData(data);
56 public void testIsJSON() throws IOException {
57 String data = IOUtils.toString(
58 TestPatternNode.class.getClassLoader()
59 .getResourceAsStream("convert/payload_cli_config.json"),
60 ConfigGeneratorConstant.STRING_ENCODING);
61 CheckDataTool.isJSON(data);
65 public void testIsXML() throws IOException {
66 String data = IOUtils.toString(
67 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
68 ConfigGeneratorConstant.STRING_ENCODING);
69 CheckDataTool.isXML(data);
73 public void testNode() {
74 CustomJsonNodeFactory c = new CustomJsonNodeFactory();
80 public void testCustomText() {
81 CustomTextNode c = new CustomTextNode("test");
86 public void testEscapeUtils() {
88 String st = "test\"test";
89 String str = "test\'" + "test";
90 String strng = "test\0";
91 EscapeUtils.escapeString(s);
92 EscapeUtils.escapeSql(s);
93 EscapeUtils.escapeString(st);
94 EscapeUtils.escapeString(str);
95 EscapeUtils.escapeString(strng);
96 EscapeUtils.escapeString(null);
99 @Test(expected = Exception.class)
100 public void testgetData() throws Exception {
101 List<String> argList = null;
102 String schema = "sdnctl";
103 String tableName = "dual";
104 String getselectData = "123";
105 String getDataClasue = "123='123'";
106 DbServiceUtil.getData(tableName, argList, schema, getselectData, getDataClasue);
109 @Test(expected = Exception.class)
110 public void testupdateDB() throws Exception {
111 String setClause = null;
112 String tableName = "dual";
113 List<String> inputArgs = null;
114 String whereClause = "123='123'";
115 DbServiceUtil.updateDB(tableName, inputArgs, whereClause, setClause);
118 // @Test(expected = Exception.class)
119 public void testinitDbLibService() throws Exception {
120 DbServiceUtil.initDbLibService();
124 public void testJSONTool() throws Exception {
125 String data = IOUtils.toString(
126 TestPatternNode.class.getClassLoader()
127 .getResourceAsStream("convert/payload_cli_config.json"),
128 ConfigGeneratorConstant.STRING_ENCODING);
129 JSONTool.convertToProperties(data);
130 List<String> blockKeys = new ArrayList<String>();
131 blockKeys.add("vnf-type");
132 blockKeys.add("request-parameters");
133 JSONTool.convertToProperties(data, blockKeys);
137 public void testLogParserTool() throws Exception {
138 String data = IOUtils.toString(
139 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
140 ConfigGeneratorConstant.STRING_ENCODING);
141 LogParserTool lpt = new LogParserTool();
142 lpt.parseErrorLog(data);
146 public void testMergeTool() throws Exception {
147 String template = "test";
148 Map<String, String> dataMap = new HashMap<String, String>();
149 MergeTool.mergeMap2TemplateData(template, dataMap);
153 public void testcheckDateTime() throws Exception {
154 String line = "2017-08-20T17:40:23.100361+00:00";
155 Whitebox.invokeMethod(logParserTool, "checkDateTime", line);
159 public void testCheckDataForInvalidXml()
161 String data="<xml><configuration</configuration>";
162 assertEquals(ConfigGeneratorConstant.DATA_TYPE_TEXT,CheckDataTool.checkData(data));
166 public void testCheckDataForValidXml()
168 String data="<xml><configuration></configuration></xml>";
169 assertEquals(ConfigGeneratorConstant.DATA_TYPE_XML,CheckDataTool.checkData(data));