aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-generator
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2018-11-30 14:12:38 +0000
committerTakamune Cho <takamune.cho@att.com>2018-12-03 10:15:03 +0000
commit210cbe9bec048b0e54afabd9bbb72ce5ca019a88 (patch)
tree8f238cb323e4de81d46a366dab24cfb78e2a1e23 /appc-config/appc-config-generator
parentde9d4887aabda45b805e744d2f4f1ec2dc6cf40d (diff)
Fix for APPC-1264
Fixed broken unit tests. Improved unit testing and increased line and branch coverage. Deleted unused and duplicated files used in tests. Issue-ID: APPC-1264 Change-Id: Idea7d46f4a6c9c591617fb973a8d33e5275e4579 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-config/appc-config-generator')
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/convert/TestConvertNode.java274
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java108
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/pattern/TestPatternNode.java37
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/reader/TestReaderNode.java33
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java58
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/transform/TestXSLTTransformerNode.java26
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/writer/TestFileWriterNode.java4
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_ssc.txt0
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_vdbe.xml22
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/convert/payload_json_config.json19
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/convert/payload_template_config.json19
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/convert/payload_xml_config.json19
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/merge/blank.json (renamed from appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_msc.txt)0
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/merge/complex/vdbe_data.json19
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/merge/complex/vdbe_template.xml22
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/merge/valid.json1
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/merge/valid.xml1
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/merge/vdbe_data.json19
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/merge/vdbe_template.xml22
-rw-r--r--appc-config/appc-config-generator/provider/src/test/resources/writer/testcvaas.json1
20 files changed, 298 insertions, 406 deletions
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/convert/TestConvertNode.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/convert/TestConvertNode.java
index c9cdad7fa..107165f22 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/convert/TestConvertNode.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/convert/TestConvertNode.java
@@ -27,15 +27,18 @@ package org.onap.sdnc.config.generator.convert;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
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.Mockito;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
import org.onap.sdnc.config.generator.merge.TestMergeNode;
-import org.powermock.reflect.Whitebox;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -43,187 +46,212 @@ public class TestConvertNode {
private static final EELFLogger log =
EELFManager.getInstance().getLogger(TestConvertNode.class);
- @Test(expected = Exception.class)
- public void testPayloadParametersConfig() throws Exception {
+ private ConvertNode convertNode = new ConvertNode();
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void testConvertJson2DGContextFailure() throws SvcLogicException, IOException {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
- "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "Y");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("A JSONObject text must begin with '{'");
convertJson2Context("convert/payload_parameters_config.json", inParams, ctx);
- Whitebox.invokeMethod("convertJson2Context", "convert/payload_parameters_config.json",
- inParams, ctx);
- log.info("testPayloadParametersConfig Result: "
- + ctx.getAttribute("block_configuration-parameters"));
}
@Test
- public void testPayloadCliConfig() throws Exception {
+ public void testConvertJson2DGContextSuccess() throws SvcLogicException, IOException {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
"configuration-parameters,configuration.configuration-json,configuration.configuration-string");
convertJson2Context("convert/payload_cli_config.json", inParams, ctx);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
log.info("testPayloadCliConfig Result: "
+ ctx.getAttribute("block_configuration-parameters"));
log.info("testPayloadCliConfig Result: "
+ ctx.getAttribute("block_configuration.configuration-string"));
}
- @Test(expected = Exception.class)
- public void testPayloadXMLConfig() throws Exception {
+ @Test
+ public void testEscapeDataForJsonDataType() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
- "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
- convertJson2Context("convert/payload_xml_config.json", inParams, ctx);
-
- log.info("testPayloadXMLConfig Result: "
- + ctx.getAttribute("block_configuration-parameters"));
- log.info("testPayloadXMLConfig Result: "
- + ctx.getAttribute("block_configuration.configuration-string"));
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA,"{}");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_JSON);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
+ convertNode.escapeData(inParams, ctx);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
- @Test(expected = Exception.class)
- public void testPayloadJsonConfig() throws Exception {
+ @Test
+ public void testEscapeDataForXMLDataType() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_IS_ESCAPED, "N");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_BLOCK_KEYS,
- "configuration-parameters,configuration.configuration-json,configuration.configuration-string");
- convertJson2Context("convert/payload_json_config.json", inParams, ctx);
- log.info("testPayloadJsonConfig Result: "
- + ctx.getAttribute("block_configuration-parameters"));
- log.info("testPayloadJsonConfig Result: "
- + ctx.getAttribute("block_configuration.configuration-json"));
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA,"<>");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_XML);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ convertNode.escapeData(inParams, ctx);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
- private void convertJson2Context(String jsonFile, Map<String, String> inParams,
- SvcLogicContext ctx) throws IOException, SvcLogicException {
- ConvertNode convertNode = new ConvertNode();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
- String jsonData = IOUtils
- .toString(TestMergeNode.class.getClassLoader().getResourceAsStream(jsonFile));
- log.info("TestConvertNode.testConvertJson2DGContext()" + jsonData);
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
- convertNode.convertJson2DGContext(inParams, ctx);
- assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
+ @Test
+ public void testEscapeDataForSQLDataType() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA,"SHOW TABLES;");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_SQL);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ convertNode.escapeData(inParams, ctx);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
- @Test(expected = Exception.class)
- public void testEscapeData() throws Exception {
+ @Test
+ public void testEscapeDataForUnsupportedDataType() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
- String unescapeData = IOUtils.toString(TestMergeNode.class.getClassLoader()
- .getResourceAsStream("convert/escape/config_ssc.txt"));
- log.info("TestConvertNode.testEscapeData() unescapeData :" + unescapeData);
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA, unescapeData);
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE,
- ConfigGeneratorConstant.DATA_TYPE_SQL);
- ConvertNode convertNode = new ConvertNode();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA,"lorum ipsem");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_TEXT);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Datatype (dataType) param value (TEXT)is not supported for escapeData conversion.");
convertNode.escapeData(inParams, ctx);
- log.info("testEscapeData Result: "
- + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_ESCAPE_DATA));
}
@Test
- public void testConvertContextToJson() throws Exception {
+ public void testUnescapeDataForJsonDataType() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
- ctx.setAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID", "200");
- ctx.setAttribute("tmp.uploadConfigInfo.VNF-ID", "00000");
- ctx.setAttribute("tmp.uploadConfigInfo.test[0]", "test0");
- ctx.setAttribute("tmp.uploadConfigInfo.test[1]", "test1");
- ctx.setAttribute("tmp.uploadConfigInfo.test[2]", "test2");
- ConvertNode convertNode = new ConvertNode();
Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA,"{}");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_JSON);
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
- inParams.put("contextKey", "tmp.uploadConfigInfo");
- convertNode.convertContextToJson(inParams, ctx);
- log.info("JSON CONTENT " + ctx.getAttribute("test.jsonContent"));
- assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
-
+ convertNode.unEscapeData(inParams, ctx);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
- @Test(expected = Exception.class)
- public void testunEscapeData() throws Exception {
- ConvertNode convertNode = new ConvertNode();
- Map<String, String> inParams = new HashMap<String, String>();
+ @Test
+ public void testUnescapeDataForXMLDataType() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
- log.trace("Received unEscapeData call with params : " + inParams);
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "tmp");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA, "//");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, "String");
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA,"<>");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_XML);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
convertNode.unEscapeData(inParams, ctx);
-
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
-
- @Test(expected = SvcLogicException.class)
- public void testunEscapeDataForInvalidDataType() throws Exception {
- ConvertNode convertNode = new ConvertNode();
- Map<String, String> inParams = new HashMap<String, String>();
+
+ @Test
+ public void testUnescapeDataForUnsupportedDataType() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "tmp");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA, "//");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, "TXT");
- convertNode.escapeData(inParams, ctx);
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA,"lorum ipsem");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_TEXT);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Datatype (dataType) param value (TEXT)is not supported for unEscapeData conversion.");
+ convertNode.unEscapeData(inParams, ctx);
+ }
+ @Test
+ public void testUnescapeDataForNoDataSent() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_TEXT);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Escape (escapeData) param is missing for escapeData conversion.");
+ convertNode.unEscapeData(inParams, ctx);
}
-
- @Test(expected = SvcLogicException.class)
- public void testunEscapeDataForEmptyDataType() throws Exception {
- ConvertNode convertNode = new ConvertNode();
+
+ @Test
+ public void testUnescapeDataForNoDataTypeSent() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA,"lorum ipsem");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Datatype (dataType)param is missing for escapeData conversion.");
+ convertNode.unEscapeData(inParams, ctx);
+ }
+
+ @Test
+ public void testEscapeDataForNoDataSent() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "tmp");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA, "//");
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, ConfigGeneratorConstant.DATA_TYPE_TEXT);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Unescape (unEscapeData) param is missing for escapeData conversion.");
convertNode.escapeData(inParams, ctx);
-
}
-
+
@Test
- public void testEscapeDataForValidUnescapeDataString() throws Exception {
+ public void testEscapeDataForNoDataTypeSent() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
- String unescapeData = "testUnescapeData";
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA, unescapeData);
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE,
- ConfigGeneratorConstant.DATA_TYPE_SQL);
- ConvertNode convertNode = new ConvertNode();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA,"lorum ipsem");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Datatype (dataType)param is missing for escapeData conversion.");
convertNode.escapeData(inParams, ctx);
- assertEquals(unescapeData, ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_ESCAPE_DATA));
}
-
- @Test
- public void testunEscapeDataForJsonDataType() throws Exception {
+
+ @Test
+ public void testConvertContextToJson() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID", "200");
+ ctx.setAttribute("tmp.uploadConfigInfo.VNF-ID", "00000");
+ ctx.setAttribute("tmp.uploadConfigInfo.test[0]", "test0");
+ ctx.setAttribute("tmp.uploadConfigInfo.test[1]", "test1");
+ ctx.setAttribute("tmp.uploadConfigInfo.test[2]", "test2");
ConvertNode convertNode = new ConvertNode();
Map<String, String> inParams = new HashMap<String, String>();
- SvcLogicContext ctx = new SvcLogicContext();
- log.trace("Received unEscapeData call with params : " + inParams);
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "tmp");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA, "//");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, "JSON");
- convertNode.unEscapeData(inParams, ctx);
- assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute("tmp." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
-
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
+ inParams.put("contextKey", "tmp.uploadConfigInfo");
+ convertNode.convertContextToJson(inParams, ctx);
+ log.info("JSON CONTENT " + ctx.getAttribute("test.jsonContent"));
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
-
+
@Test
- public void testunEscapeDataForXmlDataType() throws Exception {
+ public void testConvertContextToJsonFailure() throws Exception {
+ SvcLogicContext ctx = Mockito.spy(new SvcLogicContext());
+ Mockito.doThrow(new NullPointerException("Mock Exception")).when(ctx).getAttributeKeySet();
+ ctx.setAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID", "200");
+ ctx.setAttribute("tmp.uploadConfigInfo.VNF-ID", "00000");
+ ctx.setAttribute("tmp.uploadConfigInfo.test[0]", "test0");
+ ctx.setAttribute("tmp.uploadConfigInfo.test[1]", "test1");
+ ctx.setAttribute("tmp.uploadConfigInfo.test[2]", null);
ConvertNode convertNode = new ConvertNode();
Map<String, String> inParams = new HashMap<String, String>();
- SvcLogicContext ctx = new SvcLogicContext();
- log.trace("Received unEscapeData call with params : " + inParams);
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "tmp");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_ESCAPE_DATA, "//");
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE, "XML");
- convertNode.unEscapeData(inParams, ctx);
- assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute("tmp." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ inParams.put("contextKey", "tmp.uploadConfigInfo");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Mock Exception");
+ convertNode.convertContextToJson(inParams, ctx);
+ }
+
+ private void convertJson2Context(String jsonFile, Map<String, String> inParams,
+ SvcLogicContext ctx) throws IOException, SvcLogicException {
+ ConvertNode convertNode = new ConvertNode();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
+ String jsonData = IOUtils
+ .toString(TestMergeNode.class.getClassLoader().getResourceAsStream(jsonFile),
+ StandardCharsets.UTF_8);
+ log.info("TestConvertNode.testConvertJson2DGContext()" + jsonData);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
+ convertNode.convertJson2DGContext(inParams, ctx);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
-
}
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java
index a51c603ff..85f53fb41 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/merge/TestMergeNode.java
@@ -8,6 +8,8 @@
* =============================================================================
* Modification Copyright (C) 2018 IBM.
* =============================================================================
+ * Modification 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
@@ -27,67 +29,59 @@ package org.onap.sdnc.config.generator.merge;
import static org.junit.Assert.assertEquals;
-import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
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.junit.runner.RunWith;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-@RunWith(PowerMockRunner.class)
public class TestMergeNode {
- @Test(expected = Exception.class)
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
public void testMergeJsonDataOnTemplate() throws Exception {
MergeNode mergeNode = new MergeNode();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
String jsonData = IOUtils.toString(
- TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json"));
+ TestMergeNode.class.getClassLoader().getResourceAsStream("merge/valid.json"),
+ StandardCharsets.UTF_8);
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader()
- .getResourceAsStream("merge/vdbe_template.xml"));
+ .getResourceAsStream("merge/valid.xml"), StandardCharsets.UTF_8);
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
SvcLogicContext ctx = new SvcLogicContext();
mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
- assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
-
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
-
- @Test(expected = Exception.class)
+
+ @Test
public void testMergeJsonDataOnTemplateForEmptyParamData() throws Exception {
MergeNode mergeNode = new MergeNode();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
- String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader()
- .getResourceAsStream("merge/vdbe_template.xml"));
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
SvcLogicContext ctx = new SvcLogicContext();
expectedEx.expect(SvcLogicException.class);
- expectedEx.expectMessage("Param Data is missing..");
+ expectedEx.expectMessage("JSON Data is missing");
mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
-
}
- @Rule
- public ExpectedException expectedEx = ExpectedException.none();
-
- @Test(expected = Exception.class)
+ @Test
public void testMergeJsonDataOnTemplateForEmptyTemplateData() throws Exception {
MergeNode mergeNode = new MergeNode();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
String jsonData = IOUtils.toString(
- TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json"));
+ TestMergeNode.class.getClassLoader().getResourceAsStream("merge/valid.json"),
+ StandardCharsets.UTF_8);
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
SvcLogicContext ctx = new SvcLogicContext();
expectedEx.expect(SvcLogicException.class);
@@ -95,74 +89,46 @@ public class TestMergeNode {
mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
}
-
- @Test(expected = Exception.class)
+ @Test
public void testMergeComplexJsonDataOnTemplate() throws Exception {
MergeNode mergeNode = new MergeNode();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
-
String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader()
- .getResourceAsStream("merge/complex/vdbe_data.json"));
- System.out.println("TestMergeNode.testMergeJsonComplexDataOnTemplate()" + jsonData);
+ .getResourceAsStream("merge/valid.json"), StandardCharsets.UTF_8);
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
-
- String templateData = IOUtils.toString(TestMergeNode.class.getClassLoader()
- .getResourceAsStream("merge/complex/vdbe_template.xml"));
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
-
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "merge/valid.xml");
SvcLogicContext ctx = new SvcLogicContext();
mergeNode.mergeComplexJsonDataOnTemplate(inParams, ctx);
- assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
-
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
- @Test(expected = Exception.class)
- public void testMergeJsonDataOnTemplateFile() throws Exception {
+ @Test
+ public void testMergeComplexJsonDataWithMissingJson() throws Exception {
MergeNode mergeNode = new MergeNode();
Map<String, String> inParams = new HashMap<String, String>();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
-
- String jsonData = IOUtils.toString(
- TestMergeNode.class.getClassLoader().getResourceAsStream("merge/vdbe_data.json"));
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader()
+ .getResourceAsStream("merge/blank.json"), StandardCharsets.UTF_8);
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "merge/vdbe_template.xml");
-
SvcLogicContext ctx = new SvcLogicContext();
- mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
- assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("JSON Data is missing");
+ mergeNode.mergeComplexJsonDataOnTemplate(inParams, ctx);
}
@Test
- public void testMmergeDataOnTemplate() throws SvcLogicException {
- MergeNode mergeNode = new MergeNode();
- SvcLogicContext ctx = new SvcLogicContext();
- Map<String, String> inParams = new HashMap<String, String>();
- mergeNode.mergeDataOnTemplate(inParams, ctx);
- }
-
- @Test
- public void testMmergeDataOnTemplateWithTemplateData() throws SvcLogicException, IOException {
+ public void testMergeComplexJsonDataWithMissingTemplateDataAndFile() throws Exception {
MergeNode mergeNode = new MergeNode();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
- String jsonData = "{name1:value1,name2:value2}";
+ String jsonData = IOUtils.toString(TestMergeNode.class.getClassLoader()
+ .getResourceAsStream("merge/valid.json"), StandardCharsets.UTF_8);
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_JSON_DATA, jsonData);
- String templateData = "testTemplateData";
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
- SvcLogicContext ctx = new SvcLogicContext();
- mergeNode.mergeJsonDataOnTemplate(inParams, ctx);
- assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
-
- }
-
- @Test
- public void mergeYamlDataOnTemplate() throws SvcLogicException {
- MergeNode mergeNode = new MergeNode();
SvcLogicContext ctx = new SvcLogicContext();
- Map<String, String> inParams = new HashMap<String, String>();
- mergeNode.mergeYamlDataOnTemplate(inParams, ctx);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Template data or Template file is missing");
+ mergeNode.mergeComplexJsonDataOnTemplate(inParams, ctx);
}
}
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/pattern/TestPatternNode.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/pattern/TestPatternNode.java
index 848632b31..4767d8fbc 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/pattern/TestPatternNode.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/pattern/TestPatternNode.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
@@ -29,13 +31,18 @@ import static org.junit.Assert.assertEquals;
import java.util.HashMap;
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.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
public class TestPatternNode {
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
@Test
public void parseErrorLog() throws Exception {
PatternNode patternNode = new PatternNode();
@@ -47,22 +54,19 @@ public class TestPatternNode {
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_LOG_DATA, logData);
SvcLogicContext ctx = new SvcLogicContext();
patternNode.parseErrorLog(inParams, ctx);
- assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
-
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
-
- @Test(expected= SvcLogicException.class)
+
+ @Test
public void testParseErrorLogForEmptyLogData() throws Exception {
PatternNode patternNode = new PatternNode();
Map<String, String> inParams = new HashMap<String, String>();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
- String logData = IOUtils.toString(
- TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
- ConfigGeneratorConstant.STRING_ENCODING);
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
SvcLogicContext ctx = new SvcLogicContext();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Log Data is missing");
patternNode.parseErrorLog(inParams, ctx);
-
}
@@ -71,7 +75,6 @@ public class TestPatternNode {
PatternNode patternNode = new PatternNode();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
-
String xmlData = IOUtils.toString(
TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
ConfigGeneratorConstant.STRING_ENCODING);
@@ -97,7 +100,7 @@ public class TestPatternNode {
ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
}
- @Test(expected = Exception.class)
+ @Test
public void checStringData() throws Exception {
PatternNode patternNode = new PatternNode();
Map<String, String> inParams = new HashMap<String, String>();
@@ -107,19 +110,19 @@ public class TestPatternNode {
ConfigGeneratorConstant.STRING_ENCODING);
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, stringData);
SvcLogicContext ctx = new SvcLogicContext();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Check Data is missing");
patternNode.checkDataType(inParams, ctx);
- assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
}
-
+
@Test
public void testCheckDataType() throws Exception {
PatternNode patternNode = new PatternNode();
Map<String, String> inParams = new HashMap<String, String>();
- inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, "testData");
SvcLogicContext ctx = new SvcLogicContext();
patternNode.checkDataType(inParams, ctx);
- assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
}
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/reader/TestReaderNode.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/reader/TestReaderNode.java
index 80d8cdc80..4ca246ac0 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/reader/TestReaderNode.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/reader/TestReaderNode.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * 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.
@@ -23,26 +25,45 @@
package org.onap.sdnc.config.generator.reader;
+import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.HashMap;
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.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
-import org.onap.sdnc.config.generator.merge.TestMergeNode;
public class TestReaderNode {
- @Test(expected = Exception.class)
- public void testGetFileData() throws SvcLogicException, IOException {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void testGetFileDataSuccess() throws SvcLogicException, IOException {
ReaderNode r = new ReaderNode();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_FILE_NAME,
- IOUtils.toString(TestMergeNode.class.getClassLoader()
- .getResourceAsStream("convert/payload_cli_config.json")));
+ "src/test/resources/convert/payload_cli_config.json");
+ SvcLogicContext ctx = new SvcLogicContext();
+ r.getFileData(inParams, ctx);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
+ }
+
+ @Test
+ public void testGetFileDataFailure() throws SvcLogicException, IOException {
+ ReaderNode r = new ReaderNode();
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
+ inParams.put(ConfigGeneratorConstant.INPUT_PARAM_FILE_NAME,
+ "non_existent_filename");
SvcLogicContext ctx = new SvcLogicContext();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("File 'non_existent_filename' does not exist");
r.getFileData(inParams, ctx);
}
}
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()
{
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/transform/TestXSLTTransformerNode.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/transform/TestXSLTTransformerNode.java
index 0c6e77f4b..6bf993d48 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/transform/TestXSLTTransformerNode.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/transform/TestXSLTTransformerNode.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,11 +27,14 @@
package org.onap.sdnc.config.generator.transform;
+import static org.junit.Assert.assertEquals;
import java.nio.charset.Charset;
import java.util.HashMap;
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.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
import org.onap.sdnc.config.generator.merge.TestMergeNode;
@@ -42,6 +47,9 @@ public class TestXSLTTransformerNode {
private static final EELFLogger log =
EELFManager.getInstance().getLogger(TestXSLTTransformerNode.class);
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
@Test
public void transformData() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
@@ -56,34 +64,44 @@ public class TestXSLTTransformerNode {
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA, requestData);
XSLTTransformerNode transformerNode = new XSLTTransformerNode();
transformerNode.transformData(inParams, ctx);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
log.info("transformData Result: "
+ ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_TRANSFORMED_DATA));
}
- @Test(expected=SvcLogicException.class)
+
+ @Test
public void testTransformDataForEmptyTemplateData() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA, "testRequestData");
XSLTTransformerNode transformerNode = new XSLTTransformerNode();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("In-param templateFile/templateData value is missing");
transformerNode.transformData(inParams, ctx);
}
- @Test(expected=SvcLogicException.class)
+
+ @Test
public void testTransformDataForEmptyRequestData() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
XSLTTransformerNode transformerNode = new XSLTTransformerNode();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, "testTemplateData");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("In-param requestData value is missing");
transformerNode.transformData(inParams, ctx);
}
-
- @Test(expected=SvcLogicException.class)
+
+ @Test
public void testTransformDataForEmptyRequestTemplate() throws Exception {
SvcLogicContext ctx = new SvcLogicContext();
Map<String, String> inParams = new HashMap<String, String>();
XSLTTransformerNode transformerNode = new XSLTTransformerNode();
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, "testTemplateData");
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "NO_SUCH_FILE.json");
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("File 'NO_SUCH_FILE.json' does not exist");
transformerNode.transformData(inParams, ctx);
}
}
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/writer/TestFileWriterNode.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/writer/TestFileWriterNode.java
index 0d5e7de3d..8bbc85451 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/writer/TestFileWriterNode.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/writer/TestFileWriterNode.java
@@ -46,8 +46,8 @@ public class TestFileWriterNode {
inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
SvcLogicContext ctx = new SvcLogicContext();
FileWriterNode.writeFile(inParams, ctx);
- assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
+ assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
+ ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
}
@Test(expected=SvcLogicException.class)
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_ssc.txt b/appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_ssc.txt
deleted file mode 100644
index e69de29bb..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_ssc.txt
+++ /dev/null
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_vdbe.xml b/appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_vdbe.xml
deleted file mode 100644
index 79ecfe661..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_vdbe.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- ONAP : APPC
- ================================================================================
- Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- ================================================================================
- Copyright (C) 2017 Amdocs
- =============================================================================
- 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
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- ============LICENSE_END=========================================================
- -->
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_json_config.json b/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_json_config.json
deleted file mode 100644
index a82eaf0f1..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_json_config.json
+++ /dev/null
@@ -1,19 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APP-C
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_template_config.json b/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_template_config.json
deleted file mode 100644
index a82eaf0f1..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_template_config.json
+++ /dev/null
@@ -1,19 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APP-C
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_xml_config.json b/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_xml_config.json
deleted file mode 100644
index a82eaf0f1..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/convert/payload_xml_config.json
+++ /dev/null
@@ -1,19 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APP-C
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_msc.txt b/appc-config/appc-config-generator/provider/src/test/resources/merge/blank.json
index e69de29bb..e69de29bb 100644
--- a/appc-config/appc-config-generator/provider/src/test/resources/convert/escape/config_msc.txt
+++ b/appc-config/appc-config-generator/provider/src/test/resources/merge/blank.json
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/merge/complex/vdbe_data.json b/appc-config/appc-config-generator/provider/src/test/resources/merge/complex/vdbe_data.json
deleted file mode 100644
index a82eaf0f1..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/merge/complex/vdbe_data.json
+++ /dev/null
@@ -1,19 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APP-C
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/merge/complex/vdbe_template.xml b/appc-config/appc-config-generator/provider/src/test/resources/merge/complex/vdbe_template.xml
deleted file mode 100644
index 79ecfe661..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/merge/complex/vdbe_template.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- ONAP : APPC
- ================================================================================
- Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- ================================================================================
- Copyright (C) 2017 Amdocs
- =============================================================================
- 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
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- ============LICENSE_END=========================================================
- -->
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/merge/valid.json b/appc-config/appc-config-generator/provider/src/test/resources/merge/valid.json
new file mode 100644
index 000000000..9e26dfeeb
--- /dev/null
+++ b/appc-config/appc-config-generator/provider/src/test/resources/merge/valid.json
@@ -0,0 +1 @@
+{} \ No newline at end of file
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/merge/valid.xml b/appc-config/appc-config-generator/provider/src/test/resources/merge/valid.xml
new file mode 100644
index 000000000..6787e487a
--- /dev/null
+++ b/appc-config/appc-config-generator/provider/src/test/resources/merge/valid.xml
@@ -0,0 +1 @@
+<> \ No newline at end of file
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/merge/vdbe_data.json b/appc-config/appc-config-generator/provider/src/test/resources/merge/vdbe_data.json
deleted file mode 100644
index a82eaf0f1..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/merge/vdbe_data.json
+++ /dev/null
@@ -1,19 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APP-C
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/merge/vdbe_template.xml b/appc-config/appc-config-generator/provider/src/test/resources/merge/vdbe_template.xml
deleted file mode 100644
index 79ecfe661..000000000
--- a/appc-config/appc-config-generator/provider/src/test/resources/merge/vdbe_template.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- ONAP : APPC
- ================================================================================
- Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- ================================================================================
- Copyright (C) 2017 Amdocs
- =============================================================================
- 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
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- ============LICENSE_END=========================================================
- -->
diff --git a/appc-config/appc-config-generator/provider/src/test/resources/writer/testcvaas.json b/appc-config/appc-config-generator/provider/src/test/resources/writer/testcvaas.json
new file mode 100644
index 000000000..8d1a989b0
--- /dev/null
+++ b/appc-config/appc-config-generator/provider/src/test/resources/writer/testcvaas.json
@@ -0,0 +1 @@
+{'name':'Name','role':'admin'} \ No newline at end of file