2  * ============LICENSE_START=======================================================
 
   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
 
  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  * ============LICENSE_END=========================================================
 
  24 package org.onap.sdnc.config.generator.tool;
 
  26 import java.io.IOException;
 
  27 import java.util.ArrayList;
 
  28 import java.util.HashMap;
 
  29 import java.util.List;
 
  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;
 
  38 public class TestDataTool {
 
  41     private LogParserTool logParserTool = 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.escapeString(s);
 
  89         EscapeUtils.escapeSql(s);
 
  90         EscapeUtils.escapeString(st);
 
  91         EscapeUtils.escapeString(str);
 
  92         EscapeUtils.escapeString(strng);
 
  93         EscapeUtils.escapeString(null);
 
  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);
 
 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);
 
 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()
 
 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);
 
 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);
 
 143     public void testMergeTool() throws Exception {
 
 144         String template = "test";
 
 145         Map<String, String> dataMap = new HashMap<String, String>();
 
 146         MergeTool.mergeMap2TemplateData(template, dataMap);
 
 150     public void testcheckDateTime() throws Exception {
 
 151         String line = "2017-08-20T17:40:23.100361+00:00";
 
 152         Whitebox.invokeMethod(logParserTool, "checkDateTime", line);