summaryrefslogtreecommitdiffstats
path: root/restconf-client/provider/src/test/java
diff options
context:
space:
mode:
authorjanani <janani.b@huawei.com>2019-05-23 15:45:14 +0530
committerjanani <janani.b@huawei.com>2019-05-23 15:45:14 +0530
commitbea0f101d0a4c7d1fbe8cb9d4a27491ba7d66dbf (patch)
treeed3465553b1f7ac2e601171f504252d6772a8034 /restconf-client/provider/src/test/java
parent06c30ec3fa1dbdf26b7e1abce89c68e3efc632c7 (diff)
Bug fix to add anyxml node.
Anyxml node fix Change-Id: Ice40fde63ac8f589fa9358ebaf12c32247b0ae96 Issue-ID: CCSDK-1344 Signed-off-by: janani <janani.b@huawei.com>
Diffstat (limited to 'restconf-client/provider/src/test/java')
-rw-r--r--restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java132
-rw-r--r--restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java64
2 files changed, 196 insertions, 0 deletions
diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java
index 45e8eb3f1..aa1e50d6a 100644
--- a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java
+++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java
@@ -46,8 +46,10 @@ import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PATCH;
import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.POST;
import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT;
import static org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiUtils.parseUrl;
+import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_ANYXML_RESPONSE;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_JSON_RPC;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_XML_RPC;
+import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_ANYXML;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID_PUT;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_RPC;
@@ -149,6 +151,24 @@ public class DataFormatSerializerTest {
}
/**
+ * Verifies encoding of parameters to JSON data format any xml in it.
+ *
+ * @throws SvcLogicException when test case fails
+ */
+ @Test
+ public void encodeForAnyXml() throws SvcLogicException {
+ String pre = "execution-service_process.";
+ SvcLogicContext ctx = createAnyXmlAttList(pre);
+ p.put("dirPath", "src/test/resources");
+ p.put("format", "json");
+ p.put("httpMethod", "post");
+ p.put("restapiUrl", "http://echo.getpostman" +
+ ".com/api/v1/execution-service/process");
+ restconf.sendRequest(p, ctx);
+ assertThat(dfCaptor.getResult(), is(ENCODE_TO_ANYXML));
+ }
+
+ /**
* Verifies encoding of parameters to JSON data format with identity-ref
* and inter-file linking for put operation-type.
*
@@ -501,6 +521,27 @@ public class DataFormatSerializerTest {
}
/**
+ * Verifies encoding of and decoding from, JSON for ANYXML.
+ *
+ * @throws SvcLogicException when test case fails
+ */
+ @Test
+ public void codecForNormalAnyXml() throws SvcLogicException {
+ createMockForDecode(DECODE_ANYXML_RESPONSE);
+ String inPre = "execution-service_process.";
+ SvcLogicContext ctx = createAnyXmlAttList(inPre);
+ p.put("dirPath", "src/test/resources");
+ p.put("format", "json");
+ p.put("httpMethod", "post");
+ p.put("responsePrefix", "pp");
+ p.put("restapiUrl", "http://echo.getpostman" +
+ ".com/api/v1/execution-service/process");
+ restconf.sendRequest(p, ctx);
+ assertThat(dfCaptor.getResult(), is(ENCODE_TO_ANYXML));
+ verifyOutputOfAnyXml(ctx);
+ }
+
+ /**
* Verifies encoding of and decoding from, XML respectively for data
* format with containers, grouping and augment.
*
@@ -546,6 +587,12 @@ public class DataFormatSerializerTest {
String url8 = "https://localhost:8282/restconf/data/" + actVal;
String url9 = "http://182.2.61.24:2250/restconf/data/" + actVal;
String url10 = "https://182.2.61.24:2250/restconf/operations/" + actVal;
+ String url11 = "https://182.2.61.24:2250/api/v1/execution-service" +
+ "/process";
+ String url12 = "https://182.2.61.24:2250/api/v1/execution-service" +
+ "/process/payload";
+ String url13 = "https://182.2.61.24:2250/api/v1/execution-service" +
+ "/process/payload/";
String val1 = parseUrl(url1, POST);
String val2 = parseUrl(url2, GET);
String val3 = parseUrl(url3, PATCH);
@@ -556,6 +603,9 @@ public class DataFormatSerializerTest {
String val8 = parseUrl(url8, POST);
String val9 = parseUrl(url9, GET);
String val10 = parseUrl(url10, POST);
+ String val11 = parseUrl(url11, POST);
+ String val12 = parseUrl(url12, POST);
+ String val13 = parseUrl(url13, POST);
assertThat(val1, is(actVal));
assertThat(val2, is(actVal));
assertThat(val3, is(actVal));
@@ -566,6 +616,43 @@ public class DataFormatSerializerTest {
assertThat(val8, is(actVal));
assertThat(val9, is(actVal));
assertThat(val10, is(actVal));
+ assertThat(val11, is("execution-service:process"));
+ assertThat(val12, is("execution-service:process/payload"));
+ assertThat(val13, is("execution-service:process/payload/"));
+ }
+
+ /**
+ * Creates attribute list for encoding JSON or XML with ANYXML YANG
+ * file.
+ *
+ * @param pre prefix
+ * @return service logic context
+ */
+ private SvcLogicContext createAnyXmlAttList(String pre) {
+ SvcLogicContext ctx = new SvcLogicContext();
+ String pre1 = pre + "commonHeader.";
+ String pre2 = pre + "actionIdentifiers.";
+ ctx.setAttribute(pre + "isNonAppend", "true");
+ ctx.setAttribute(pre1 + "originatorId", "SDNC_DG");
+ ctx.setAttribute(pre1 + "requestId", "123456-1000");
+ ctx.setAttribute(pre1 + "subRequestId", "sub-123456-1000");
+ ctx.setAttribute(pre2 + "blueprintName",
+ "baseconfiguration");
+ ctx.setAttribute(pre2 + "blueprintVersion", "1.0.0");
+ ctx.setAttribute(pre2 + "actionName", "assign-activate");
+ ctx.setAttribute(pre2 + "mode", "sync");
+ ctx.setAttribute(pre + "payload." +
+ "template-prefix", "vDNS-test");
+ ctx.setAttribute(pre + "payload.resource-assignment-request" +
+ ".resource-assignment-properties",
+ "{\n" +
+ " \"service-instance-id\": " +
+ "\"1234\",\n" +
+ " \"vnf-id\": \"3526\",\n" +
+ " \"customer-name\": \"htipl\",\n" +
+ " \"subscriber-name\": \"huawei\"\n" +
+ " }");
+ return ctx;
}
/**
@@ -835,6 +922,51 @@ public class DataFormatSerializerTest {
}
/**
+ * Verifies the attribute list for decoding from JSON or XML with
+ * ANYXML YANG file.
+ *
+ * @param ctx service logic context
+ */
+ private void verifyOutputOfAnyXml(SvcLogicContext ctx) {
+ System.out.println(ctx.getAttribute("pp.status.eventType"));
+ assertThat(ctx.getAttribute("pp.status.eventType"), is(
+ "EVENT_COMPONENT_EXECUTED"));
+ assertThat(ctx.getAttribute("pp.actionIdentifiers.blueprintName"),
+ is("golden"));
+ assertThat(ctx.getAttribute("pp.actionIdentifiers.mode"),
+ is("sync"));
+ assertThat(ctx.getAttribute("pp.stepData.name"),
+ is("resource-assignment"));
+ assertThat(ctx.getAttribute("pp.status.message"),
+ is("success"));
+ assertThat(ctx.getAttribute("pp.commonHeader.originatorId"),
+ is("System"));
+ assertThat(ctx.getAttribute("pp.status.code"),
+ is("200"));
+ assertThat(ctx.getAttribute("pp.commonHeader.requestId"),
+ is("1234"));
+ assertThat(ctx.getAttribute("pp.commonHeader.subRequestId"),
+ is("1234-12234"));
+ assertThat(ctx.getAttribute("pp.commonHeader.timestamp"),
+ is("2019-05-18T23:42:41.658Z"));
+ assertThat(ctx.getAttribute("pp.status.timestamp"),
+ is("2019-05-18T23:42:41.950Z"));
+ assertThat(ctx.getAttribute("pp.actionIdentifiers.blueprintV" +
+ "ersion"), is("1.0.0"));
+ assertThat(ctx.getAttribute("pp.actionIdentifiers.actionName"),
+ is("resource-assignment"));
+ assertThat(ctx.getAttribute("pp.payload.resource-assignment-resp" +
+ "onse.meshed-template.vf-module-1"),
+ is("<interface>\n <description>This i" +
+ "s the Virtual Firewall entity</description>\n" +
+ " <vfw>10.0.101.20/24</vfw>\n" +
+ "</interface>"));
+ assertThat(ctx.getAttribute("pp.actionIdentifiers.actionName"),
+ is("resource-assignment"));
+ }
+
+
+ /**
* Captures the data format messages by mocking it, which can be used in
* testing the value.
*
diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java
index a7814e10e..c1bb71985 100644
--- a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java
+++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java
@@ -69,6 +69,31 @@ public final class DataFormatUtilsTest {
" \"identity-test:l\": \"abc\"\n" +
"}";
+ static final String ENCODE_TO_ANYXML = "{\n" +
+ " \"actionIdentifiers\": {\n" +
+ " \"mode\": \"sync\",\n" +
+ " \"blueprintName\": \"baseconfiguration\",\n" +
+ " \"blueprintVersion\": \"1.0.0\",\n" +
+ " \"actionName\": \"assign-activate\"\n" +
+ " },\n" +
+ " \"payload\": {\n" +
+ " \"template-prefix\": \"vDNS-test\",\n" +
+ " \"resource-assignment-request\": {\n" +
+ " \"resource-assignment-properties\": {\n" +
+ " \"service-instance-id\": \"1234\",\n" +
+ " \"vnf-id\": \"3526\",\n" +
+ " \"customer-name\": \"htipl\",\n" +
+ " \"subscriber-name\": \"huawei\"\n" +
+ " }\n" +
+ " }\n" +
+ " },\n" +
+ " \"commonHeader\": {\n" +
+ " \"subRequestId\": \"sub-123456-1000\",\n" +
+ " \"requestId\": \"123456-1000\",\n" +
+ " \"originatorId\": \"SDNC_DG\"\n" +
+ " }\n" +
+ "}";
+
static final String ENCODE_TO_JSON_ID_PUT = "{\n" +
" \"identity-test:test\": {\n" +
" \"con1\": {" + addSpace(ENCODE_TO_JSON_ID_COMMON, 4) +
@@ -485,6 +510,45 @@ public final class DataFormatUtilsTest {
" }\n" +
"}";
+ static final String DECODE_ANYXML_RESPONSE = "{\n" +
+ " \"commonHeader\": {\n" +
+ " \"timestamp\": \"2019-05-18T23:42:41.658Z\",\n" +
+ " \"originatorId\": \"System\",\n" +
+ " \"requestId\": \"1234\",\n" +
+ " \"subRequestId\": \"1234-12234\",\n" +
+ " \"flags\": null\n" +
+ " },\n" +
+ " \"actionIdentifiers\": {\n" +
+ " \"blueprintName\": \"golden\",\n" +
+ " \"blueprintVersion\": \"1.0.0\",\n" +
+ " \"actionName\": \"resource-assignment\",\n" +
+ " \"mode\": \"sync\"\n" +
+ " },\n" +
+ " \"status\": {\n" +
+ " \"code\": 200,\n" +
+ " \"eventType\": \"EVENT_COMPONENT_EXECUTED\",\n" +
+ " \"timestamp\": \"2019-05-18T23:42:41.950Z\",\n" +
+ " \"errorMessage\": null,\n" +
+ " \"message\": \"success\"\n" +
+ " },\n" +
+ " \"payload\": {\n" +
+ " \"resource-assignment-response\": {\n" +
+ " \"meshed-template\": {\n" +
+ " \"vf-module-1\": \"<interface>\\n " +
+ " <description>This is the Virtual Firewall entity</" +
+ "description>\\n <vfw>10.0.101.20/24</vfw>\\n</interface>\"\n" +
+ " }\n" +
+ " }\n" +
+ " },\n" +
+ " \"stepData\": {\n" +
+ " \"name\": \"resource-assignment\",\n" +
+ " \"properties\": {\n" +
+ " \"resource-assignment-params\": null,\n" +
+ " \"status\": null\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+
static final String ENCODE_TO_XML_RPC = "<?xml version=\"1.0\" encoding" +
"=\"UTF-8\" standalone=\"no\"?>\n" +
"<input xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +