aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java')
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java58
1 files changed, 36 insertions, 22 deletions
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
index 3d7b7fb84..6b13d18a8 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
@@ -8,6 +8,8 @@
* =============================================================================
* Modifications Copyright (C) 2018 IBM.
* =============================================================================
+ * Modifications Copyright (C) 2018 Ericsson
+ * =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -25,21 +27,27 @@
package org.onap.sdnc.config.generator.tool;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
import org.onap.sdnc.config.generator.pattern.TestPatternNode;
-import org.powermock.reflect.Whitebox;
-import static org.junit.Assert.assertEquals;
+
public class TestDataTool {
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
@Mock
private LogParserTool logParserTool = new LogParserTool();
@@ -49,7 +57,8 @@ public class TestDataTool {
TestPatternNode.class.getClassLoader()
.getResourceAsStream("convert/payload_cli_config.json"),
ConfigGeneratorConstant.STRING_ENCODING);
- CheckDataTool.checkData(data);
+ assertEquals(ConfigGeneratorConstant.DATA_TYPE_JSON,
+ CheckDataTool.checkData(data));
}
@Test
@@ -58,7 +67,7 @@ public class TestDataTool {
TestPatternNode.class.getClassLoader()
.getResourceAsStream("convert/payload_cli_config.json"),
ConfigGeneratorConstant.STRING_ENCODING);
- CheckDataTool.isJSON(data);
+ assertEquals(true, CheckDataTool.isJSON(data));
}
@Test
@@ -66,20 +75,20 @@ public class TestDataTool {
String data = IOUtils.toString(
TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
ConfigGeneratorConstant.STRING_ENCODING);
- CheckDataTool.isXML(data);
+ assertEquals(true, CheckDataTool.isXML(data));
}
@Test
public void testNode() {
CustomJsonNodeFactory c = new CustomJsonNodeFactory();
String text = "test";
- c.textNode(text);
+ assertEquals(CustomTextNode.class, c.textNode(text).getClass());;
}
@Test
public void testCustomText() {
CustomTextNode c = new CustomTextNode("test");
- c.toString();
+ assertEquals("test",c.toString());
}
@Test
@@ -88,30 +97,31 @@ public class TestDataTool {
String st = "test\"test";
String str = "test\'" + "test";
String strng = "test\0";
- EscapeUtils.escapeString(s);
- EscapeUtils.escapeSql(s);
- EscapeUtils.escapeString(st);
- EscapeUtils.escapeString(str);
- EscapeUtils.escapeString(strng);
- EscapeUtils.escapeString(null);
+ assertEquals("test\\\\", EscapeUtils.escapeString(s));
+ assertEquals("test\"test", EscapeUtils.escapeSql(st));
+ assertEquals("test\\'test", EscapeUtils.escapeString(str));
+ assertEquals("test\\0", EscapeUtils.escapeString(strng));
+ assertEquals(null, EscapeUtils.escapeString(null));
}
- @Test(expected = Exception.class)
+ @Test
public void testgetData() throws Exception {
List<String> argList = null;
String schema = "sdnctl";
String tableName = "dual";
String getselectData = "123";
String getDataClasue = "123='123'";
+ expectedEx.expect(NullPointerException.class);
DbServiceUtil.getData(tableName, argList, schema, getselectData, getDataClasue);
}
- @Test(expected = Exception.class)
+ @Test
public void testupdateDB() throws Exception {
String setClause = null;
String tableName = "dual";
List<String> inputArgs = null;
String whereClause = "123='123'";
+ expectedEx.expect(NullPointerException.class);
DbServiceUtil.updateDB(tableName, inputArgs, whereClause, setClause);
}
@@ -130,7 +140,7 @@ public class TestDataTool {
List<String> blockKeys = new ArrayList<String>();
blockKeys.add("vnf-type");
blockKeys.add("request-parameters");
- JSONTool.convertToProperties(data, blockKeys);
+ assertEquals(HashMap.class, JSONTool.convertToProperties(data, blockKeys).getClass());
}
@Test
@@ -139,29 +149,33 @@ public class TestDataTool {
TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
ConfigGeneratorConstant.STRING_ENCODING);
LogParserTool lpt = new LogParserTool();
- lpt.parseErrorLog(data);
+ assertEquals("Did not find the string 'Starting orchestration of file backed up to /var/opt"+
+ "/MetaSwitch/orch/orch_conf.json' in the log file with timestamp within the last 5 minutes",
+ lpt.parseErrorLog(data));
}
@Test
public void testMergeTool() throws Exception {
String template = "test";
Map<String, String> dataMap = new HashMap<String, String>();
- MergeTool.mergeMap2TemplateData(template, dataMap);
+ assertEquals("test", MergeTool.mergeMap2TemplateData(template, dataMap));
}
@Test
public void testcheckDateTime() throws Exception {
- String line = "2017-08-20T17:40:23.100361+00:00";
- Whitebox.invokeMethod(logParserTool, "checkDateTime", line);
+ String line = "2017-08-20T17:40:23.100361+00:00 Error parsing orchestration file:";
+ assertEquals("Did not find the string 'Starting orchestration of file backed up to /var/opt"+
+ "/MetaSwitch/orch/orch_conf.json' in the log file with timestamp within the last 5 minutes",
+ logParserTool.parseErrorLog(line));
}
-
+
@Test
public void testCheckDataForInvalidXml()
{
String data="<xml><configuration</configuration>";
assertEquals(ConfigGeneratorConstant.DATA_TYPE_TEXT,CheckDataTool.checkData(data));
}
-
+
@Test
public void testCheckDataForValidXml()
{