From bc2c9899ae7d71d0e4a970c146a5121822913ff9 Mon Sep 17 00:00:00 2001 From: janani b Date: Mon, 8 Oct 2018 19:11:02 +0530 Subject: PUT and PATCH operation support Changes to add a additional root node to the data format req to support PUT and PATCH operations in RestconfApiCallNode Issue-ID: CCSDK-614 Change-Id: If094810861f8152a2a6d6ee86e9f81c8812b8ad6 Signed-off-by: janani b --- .../dfserializer/DataFormatSerializerTest.java | 173 ++++++++++++++++++++- .../dfserializer/DataFormatUtilsTest.java | 53 +++++-- 2 files changed, 211 insertions(+), 15 deletions(-) (limited to 'restconf-client/provider/src/test/java') 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 1185eea1c..08fa33ee7 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 @@ -42,19 +42,24 @@ import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.GET; +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_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_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; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_AUG_POST; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_PUT; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID_PUT; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_RPC; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG_AUG_POST; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG_PUT; /** @@ -102,6 +107,9 @@ public class DataFormatSerializerTest { doAnswer(dfCaptor).when(restconf).serializeRequest( any(Map.class), any(YangParameters.class), any(String.class), any(InstanceIdentifierContext.class)); + doAnswer(dfCaptor).when(restconf).updateReq( + any(String.class), any(YangParameters.class), + any(InstanceIdentifierContext.class)); } /** @@ -140,6 +148,46 @@ public class DataFormatSerializerTest { assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID)); } + /** + * Verifies encoding of parameters to JSON data format with identity-ref + * and inter-file linking for put operation-type. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToJsonIdWithPut() throws SvcLogicException { + String pre = "identity-test:test."; + SvcLogicContext ctx = createAttList(pre); + ctx.setAttribute(pre + "l", "abc"); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "put"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/identity-test:test"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID_PUT)); + } + + /** + * Verifies encoding of parameters to JSON data format with identity-ref + * and inter-file linking for patch operation-type. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToJsonIdWithPatch() throws SvcLogicException { + String pre = "identity-test:test."; + SvcLogicContext ctx = createAttList(pre); + ctx.setAttribute(pre + "l", "abc"); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "patch"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/identity-test:test"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID_PUT)); + } + /** * Verifies encoding of parameters to XML data format with identity-ref * and inter-file linking. @@ -159,6 +207,44 @@ public class DataFormatSerializerTest { assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID)); } + /** + * Verifies encoding of parameters to XML data format with identity-ref + * and inter-file linking for put operation-type. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToXmlIdWithPut() throws SvcLogicException { + String pre = "identity-test:test."; + SvcLogicContext ctx = createAttList(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "xml"); + p.put("httpMethod", "put"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/identity-test:test"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID_PUT)); + } + + /** + * Verifies encoding of parameters to XML data format with identity-ref + * and inter-file linking for patch operation-type. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToXmlIdWithPatch() throws SvcLogicException { + String pre = "identity-test:test."; + SvcLogicContext ctx = createAttList(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "xml"); + p.put("httpMethod", "patch"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/identity-test:test"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID_PUT)); + } + /** * Verifies decoding of parameters from JSON data format with identity-ref * and inter-file linking. @@ -219,6 +305,44 @@ public class DataFormatSerializerTest { assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG)); } + /** + * Verifies encoding of parameters to JSON data format with containers, + * grouping and augment for put operation-type. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToJsonYangWithPut() throws SvcLogicException { + String pre = "test-yang:cont1.cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "put"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/test-yang:cont1/cont2/cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT)); + } + + /** + * Verifies encoding of parameters to JSON data format with containers, + * grouping and augment for patch operation-type. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToJsonYangWithPatch() throws SvcLogicException { + String pre = "test-yang:cont1.cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "patch"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/test-yang:cont1/cont2/cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT)); + } + /** * Verifies encoding of parameters to JSON data format with augment as * root child. @@ -277,6 +401,44 @@ public class DataFormatSerializerTest { assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG)); } + /** + * Verifies encoding of parameters to XML data format with containers, + * grouping and augment for put operation-type + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToXmlYangWithPut() throws SvcLogicException { + String pre = "test-yang:cont1.cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "xml"); + p.put("httpMethod", "put"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/test-yang:cont1/cont2/cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT)); + } + + /** + * Verifies encoding of parameters to XML data format with containers, + * grouping and augment for patch operation-type + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToXmlYangWithPatch() throws SvcLogicException { + String pre = "test-yang:cont1.cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "xml"); + p.put("httpMethod", "put"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/test-yang:cont1/cont2/cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT)); + } + /** * Verifies encoding of parameters to XML data format with augment as * root child. @@ -369,23 +531,24 @@ public class DataFormatSerializerTest { @Test public void validateUrlParser() throws SvcLogicException { String actVal = "identity-test:test"; + String putId = "/for-put"; String url1 = "http://echo.getpostman.com/restconf/operations/" + actVal; String url2 = "http://echo.getpostman.com/restconf/data/" + actVal; String url3 = "https://echo.getpostman.com/restconf/operations/" + actVal; String url4 = "https://echo.getpostman.com/restconf/data/" + actVal + - "/for-put"; + putId; String url5 = "http://localhost:8282/restconf/operations/" + actVal; String url6 = "https://localhost:8282/restconf/operations/" + actVal; String url7 = "http://localhost:8282/restconf/data/" + actVal + - "/for-put"; + putId; 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 val1 = parseUrl(url1, POST); String val2 = parseUrl(url2, GET); - String val3 = parseUrl(url3, POST); + String val3 = parseUrl(url3, PATCH); String val4 = parseUrl(url4, PUT); String val5 = parseUrl(url5, GET); String val6 = parseUrl(url6, POST); @@ -396,10 +559,10 @@ public class DataFormatSerializerTest { assertThat(val1, is(actVal)); assertThat(val2, is(actVal)); assertThat(val3, is(actVal)); - assertThat(val4, is(actVal)); + assertThat(val4, is(actVal + putId)); assertThat(val5, is(actVal)); assertThat(val6, is(actVal)); - assertThat(val7, is(actVal)); + assertThat(val7, is(actVal + putId)); assertThat(val8, is(actVal)); assertThat(val9, is(actVal)); assertThat(val10, is(actVal)); 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 a0a154bf3..027604480 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 @@ -26,9 +26,9 @@ package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; */ public final class DataFormatUtilsTest { - static final String ENCODE_TO_JSON_ID = "{\n" + - " \"identity-test:con1\": {\n" + - " \"interfaces\": {\n" + + static final String ENCODE_TO_JSON_ID_COMMON = "\n \"interfaces\"" + + ": " + + "{\n" + " \"int-list\": [\n" + " {\n" + " \"iden\": \"optical\",\n" + @@ -61,14 +61,23 @@ public final class DataFormatUtilsTest { " ]\n" + " },\n" + " \"interface\": \"identity-types:physical\"\n" + - " },\n" + + " }"; + + static final String ENCODE_TO_JSON_ID = "{\n" + + " \"identity-test:con1\": {" + ENCODE_TO_JSON_ID_COMMON + + ",\n" + " \"identity-test:l\": \"abc\"\n" + "}"; - static final String ENCODE_TO_XML_ID = "\n" + - "\n" + - " \n" + + static final String ENCODE_TO_JSON_ID_PUT = "{\n" + + " \"identity-test:test\": {\n" + + " \"con1\": {" + addSpace(ENCODE_TO_JSON_ID_COMMON, 4) + + ",\n" + + " \"l\": \"abc\"\n" + + " }\n" + + "}"; + + static final String ENCODE_TO_XML_ID_COMMON = "\n \n" + " \n" + " optical\n" + " \n" + @@ -97,8 +106,19 @@ public final class DataFormatUtilsTest { " \n" + " \n" + " " + - "yangid:physical\n" + - "\n"; + "yangid:physical"; + + static final String ENCODE_TO_XML_ID = "\n" + + "" + + ENCODE_TO_XML_ID_COMMON + "\n\n"; + + static final String ENCODE_TO_XML_ID_PUT = "\n" + + "\n" + + " " + addSpace(ENCODE_TO_XML_ID_COMMON, 4) + + "\n \n" + + "\n"; static final String ENCODE_TO_JSON_YANG_COMMON = "\n " + "\"test-augment:cont13\": {\n" + @@ -249,6 +269,13 @@ public final class DataFormatUtilsTest { " }\n" + "}"; + static final String ENCODE_TO_JSON_YANG_PUT = "{\n" + + " \"test-yang:cont4\": {" + addSpace( + ENCODE_TO_JSON_YANG_COMMON, 4) + ",\n" + + " \"leaf10\": \"abc\"\n" + + " }\n" + + "}"; + static final String ENCODE_TO_XML_YANG_COMMON = "\n" + "\n" + @@ -290,6 +317,12 @@ public final class DataFormatUtilsTest { "" + ENCODE_TO_XML_YANG_COMMON + "\n"; + static final String ENCODE_TO_XML_YANG_PUT = "\n" + + "\n" + + " abc" + + addSpace(ENCODE_TO_XML_YANG_COMMON, 4) + "\n\n"; + static final String ENCODE_TO_XML_YANG = "\n" + "\n" + -- cgit 1.2.3-korg