summaryrefslogtreecommitdiffstats
path: root/restapi-call-node/provider/src/test/java
diff options
context:
space:
mode:
authorGaurav Agrawal <gaurav.agrawal@huawei.com>2017-09-20 12:43:42 +0530
committerGaurav Agrawal <gaurav.agrawal@huawei.com>2017-09-20 12:43:42 +0530
commit72e394582ceeb86e35d2c5cb34b244b38ae5659f (patch)
treefed5e0395ea15d35e48f77a52677abec726a0a03 /restapi-call-node/provider/src/test/java
parentba209b4de55c56e5c427e3389518966f2c896661 (diff)
Refinements and test additions to XmlParser
Changes includes 1) Added validation for invalid length 2) Added testcases to test length Change-Id: Iefd56ca470382be139f185fdf84b6c0de0fa99f6 Issue-Id: CCSDK-100 Signed-off-by: Gaurav Agrawal <gaurav.agrawal@huawei.com>
Diffstat (limited to 'restapi-call-node/provider/src/test/java')
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java
index e8567d591..c6bf4a8b9 100644
--- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java
+++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java
@@ -21,6 +21,9 @@
package jtest.org.onap.ccsdk.sli.plugins.restapicall;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
@@ -31,6 +34,7 @@ import java.util.Map;
import java.util.Set;
import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.plugins.restapicall.XmlParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,6 +66,48 @@ public class TestXmlParser {
in.close();
}
+ @Test
+ public void testValidLength() throws Exception {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml"))
+ );
+ StringBuilder b = new StringBuilder();
+ String line;
+ while ((line = in.readLine()) != null)
+ b.append(line).append('\n');
+
+ Set<String> listNameList = new HashSet<String>();
+ listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
+ listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
+
+ Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
+
+ assertThat(mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[5]"), is("SET_RESET_LP"));
+ assertThat(mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport[0]"), is("SET_BVOIP_IN"));
+
+ logProperties(mm);
+ in.close();
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testInvalidLength() throws Exception {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(ClassLoader.getSystemResourceAsStream("invalidlength.xml"))
+ );
+ StringBuilder b = new StringBuilder();
+ String line;
+ while ((line = in.readLine()) != null)
+ b.append(line).append('\n');
+
+ Set<String> listNameList = new HashSet<String>();
+ listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
+ listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
+
+ Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
+ logProperties(mm);
+ in.close();
+ }
+
private void logProperties(Map<String, String> mm) {
List<String> ll = new ArrayList<>();
for (Object o : mm.keySet())