diff options
Diffstat (limited to 'restconf-client/provider/src/test/java')
5 files changed, 1403 insertions, 172 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 08fa33ee7..45e8eb3f1 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 @@ -20,6 +20,9 @@ package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; +import java.util.HashMap; +import java.util.Map; + import org.junit.Before; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; @@ -31,9 +34,6 @@ import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode; import org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiCallNode; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; -import java.util.HashMap; -import java.util.Map; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.mockito.Matchers.any; @@ -136,7 +136,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToJsonId() throws SvcLogicException { - String pre = "identity-test:test."; + String pre = "identity-test_test."; SvcLogicContext ctx = createAttList(pre); ctx.setAttribute(pre + "l", "abc"); p.put("dirPath", "src/test/resources"); @@ -156,7 +156,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToJsonIdWithPut() throws SvcLogicException { - String pre = "identity-test:test."; + String pre = "identity-test_test."; SvcLogicContext ctx = createAttList(pre); ctx.setAttribute(pre + "l", "abc"); p.put("dirPath", "src/test/resources"); @@ -176,7 +176,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToJsonIdWithPatch() throws SvcLogicException { - String pre = "identity-test:test."; + String pre = "identity-test_test."; SvcLogicContext ctx = createAttList(pre); ctx.setAttribute(pre + "l", "abc"); p.put("dirPath", "src/test/resources"); @@ -196,7 +196,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToXmlId() throws SvcLogicException { - String pre = "identity-test:test."; + String pre = "identity-test_test."; SvcLogicContext ctx = createAttList(pre); p.put("dirPath", "src/test/resources"); p.put("format", "xml"); @@ -215,7 +215,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToXmlIdWithPut() throws SvcLogicException { - String pre = "identity-test:test."; + String pre = "identity-test_test."; SvcLogicContext ctx = createAttList(pre); p.put("dirPath", "src/test/resources"); p.put("format", "xml"); @@ -234,7 +234,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToXmlIdWithPatch() throws SvcLogicException { - String pre = "identity-test:test."; + String pre = "identity-test_test."; SvcLogicContext ctx = createAttList(pre); p.put("dirPath", "src/test/resources"); p.put("format", "xml"); @@ -255,7 +255,7 @@ public class DataFormatSerializerTest { public void decodeToJsonId() throws SvcLogicException { createMockForDecode(ENCODE_TO_JSON_ID); SvcLogicContext ctx = new SvcLogicContext(); - String pre = "identity-test:test."; + String pre = "identity-test_test."; p.put("dirPath", "src/test/resources"); p.put("format", "json"); p.put("httpMethod", "get"); @@ -276,7 +276,7 @@ public class DataFormatSerializerTest { public void decodeToXmlId() throws SvcLogicException { createMockForDecode(ENCODE_TO_XML_ID); SvcLogicContext ctx = new SvcLogicContext(); - String pre = "identity-test:test."; + String pre = "identity-test_test."; p.put("dirPath", "src/test/resources"); p.put("format", "xml"); p.put("httpMethod", "get"); @@ -294,7 +294,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToJsonYang() throws SvcLogicException { - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; SvcLogicContext ctx = createAttListYang(pre); p.put("dirPath", "src/test/resources"); p.put("format", "json"); @@ -313,7 +313,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToJsonYangWithPut() throws SvcLogicException { - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; SvcLogicContext ctx = createAttListYang(pre); p.put("dirPath", "src/test/resources"); p.put("format", "json"); @@ -332,7 +332,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToJsonYangWithPatch() throws SvcLogicException { - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; SvcLogicContext ctx = createAttListYang(pre); p.put("dirPath", "src/test/resources"); p.put("format", "json"); @@ -351,7 +351,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToJsonWithAugAsRootChild() throws SvcLogicException { - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; SvcLogicContext ctx = createAttListYang(pre); p.put("dirPath", "src/test/resources"); p.put("format", "json"); @@ -372,7 +372,7 @@ public class DataFormatSerializerTest { public void decodeToJsonYang() throws SvcLogicException { createMockForDecode(ENCODE_TO_JSON_YANG); SvcLogicContext ctx = new SvcLogicContext(); - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; p.put("dirPath", "src/test/resources"); p.put("format", "json"); p.put("httpMethod", "get"); @@ -390,7 +390,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToXmlYang() throws SvcLogicException { - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; SvcLogicContext ctx = createAttListYang(pre); p.put("dirPath", "src/test/resources"); p.put("format", "xml"); @@ -409,7 +409,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToXmlYangWithPut() throws SvcLogicException { - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; SvcLogicContext ctx = createAttListYang(pre); p.put("dirPath", "src/test/resources"); p.put("format", "xml"); @@ -428,7 +428,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToXmlYangWithPatch() throws SvcLogicException { - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; SvcLogicContext ctx = createAttListYang(pre); p.put("dirPath", "src/test/resources"); p.put("format", "xml"); @@ -447,7 +447,7 @@ public class DataFormatSerializerTest { */ @Test public void encodeToXmlWithAugAsRootChild() throws SvcLogicException { - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; SvcLogicContext ctx = createAttListYang(pre); p.put("dirPath", "src/test/resources"); p.put("format", "xml"); @@ -468,7 +468,7 @@ public class DataFormatSerializerTest { public void decodeToXmlYang() throws SvcLogicException { createMockForDecode(ENCODE_TO_XML_YANG); SvcLogicContext ctx = new SvcLogicContext(); - String pre = "test-yang:cont1.cont2."; + String pre = "test-yang_cont1.cont2."; p.put("dirPath", "src/test/resources"); p.put("format", "xml"); p.put("httpMethod", "get"); @@ -487,8 +487,8 @@ public class DataFormatSerializerTest { @Test public void codecToJsonRpc() throws SvcLogicException { createMockForDecode(DECODE_FROM_JSON_RPC); - String inPre = "test-yang:create-sfc.input."; - String outPre = "test-yang:create-sfc.output."; + String inPre = "test-yang_create-sfc.input."; + String outPre = "test-yang_create-sfc.output."; SvcLogicContext ctx = createAttListRpc(inPre); p.put("dirPath", "src/test/resources"); p.put("format", "json"); @@ -509,8 +509,8 @@ public class DataFormatSerializerTest { @Test public void codecToXmlRpc() throws SvcLogicException { createMockForDecode(DECODE_FROM_XML_RPC); - String inPre = "test-yang:create-sfc.input."; - String outPre = "test-yang:create-sfc.output."; + String inPre = "test-yang_create-sfc.input."; + String outPre = "test-yang_create-sfc.output."; SvcLogicContext ctx = createAttListRpc(inPre); p.put("dirPath", "src/test/resources"); p.put("format", "xml"); @@ -650,21 +650,21 @@ public class DataFormatSerializerTest { ctx.setAttribute(pre + "leaf12", "abc"); ctx.setAttribute(pre + "ll5[0]", "abc"); ctx.setAttribute(pre + "ll5[1]", "abc"); - ctx.setAttribute(pre + "cont4.test-augment:cont5.leaf13", "true"); - ctx.setAttribute(pre + "cont4.test-augment:list7[0].leaf14", "test"); - ctx.setAttribute(pre + "cont4.test-augment:list7[1].leaf14", "create"); - ctx.setAttribute(pre + "cont4.test-augment:leaf15", "abc"); - ctx.setAttribute(pre + "cont4.test-augment:ll6[0]", "unbounded"); - ctx.setAttribute(pre + "cont4.test-augment:ll6[1]", "8"); - ctx.setAttribute(pre + "cont4.test-augment:cont13.cont12.leaf26", + ctx.setAttribute(pre + "cont4.test-augment_cont5.leaf13", "true"); + ctx.setAttribute(pre + "cont4.test-augment_list7[0].leaf14", "test"); + ctx.setAttribute(pre + "cont4.test-augment_list7[1].leaf14", "create"); + ctx.setAttribute(pre + "cont4.test-augment_leaf15", "abc"); + ctx.setAttribute(pre + "cont4.test-augment_ll6[0]", "unbounded"); + ctx.setAttribute(pre + "cont4.test-augment_ll6[1]", "8"); + ctx.setAttribute(pre + "cont4.test-augment_cont13.cont12.leaf26", "abc"); - ctx.setAttribute(pre + "cont4.test-augment:cont13.list9[0].leaf27", + ctx.setAttribute(pre + "cont4.test-augment_cont13.list9[0].leaf27", "abc"); - ctx.setAttribute(pre + "cont4.test-augment:cont13.list9[1].leaf27", + ctx.setAttribute(pre + "cont4.test-augment_cont13.list9[1].leaf27", "abc"); - ctx.setAttribute(pre + "cont4.test-augment:cont13.leaf28", "abc"); - ctx.setAttribute(pre + "cont4.test-augment:cont13.ll9[0]", "abc"); - ctx.setAttribute(pre + "cont4.test-augment:cont13.ll9[1]", "abc"); + ctx.setAttribute(pre + "cont4.test-augment_cont13.leaf28", "abc"); + ctx.setAttribute(pre + "cont4.test-augment_cont13.ll9[0]", "abc"); + ctx.setAttribute(pre + "cont4.test-augment_cont13.ll9[1]", "abc"); return ctx; } @@ -785,29 +785,29 @@ public class DataFormatSerializerTest { assertThat(ctx.getAttribute(pre + "leaf12"), is("abc")); assertThat(ctx.getAttribute(pre + "ll5[0]"), is("abc")); assertThat(ctx.getAttribute(pre + "ll5[1]"), is("abc")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont5.leaf13"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont5.leaf13"), is("true")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:list7[0].leaf14"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_list7[0].leaf14"), is("test")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:list7[1].leaf14"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_list7[1].leaf14"), is("create")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:leaf15"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_leaf15"), is("abc")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:ll6[0]"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_ll6[0]"), is("unbounded")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:ll6[1]"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_ll6[1]"), is("8")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13" + + assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13" + ".cont12.leaf26"), is("abc")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.list9[0]" + + assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.list9[0]" + ".leaf27"), is("abc")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.list9[1]" + + assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.list9[1]" + ".leaf27"), is("abc")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.leaf28"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.leaf28"), is("abc")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.ll9[0]"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.ll9[0]"), is("abc")); - assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.ll9[1]"), + assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.ll9[1]"), is("abc")); } 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 027604480..a7814e10e 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 @@ -121,7 +121,11 @@ public final class DataFormatUtilsTest { "</test>\n"; static final String ENCODE_TO_JSON_YANG_COMMON = "\n " + - "\"test-augment:cont13\": {\n" + + "\"test-augment:ll6\": [\n" + + " \"unbounded\",\n" + + " \"8\"\n" + + " ],\n" + + " \"test-augment:cont13\": {\n" + " \"ll9\": [\n" + " \"abc\",\n" + " \"abc\"\n" + @@ -148,10 +152,6 @@ public final class DataFormatUtilsTest { " }\n" + " ],\n" + " \"test-augment:leaf15\": \"abc\",\n" + - " \"test-augment:ll6\": [\n" + - " \"unbounded\",\n" + - " \"8\"\n" + - " ],\n" + " \"test-augment:cont5\": {\n" + " \"leaf13\": \"true\"\n" + " }"; @@ -277,6 +277,10 @@ public final class DataFormatUtilsTest { "}"; static final String ENCODE_TO_XML_YANG_COMMON = "\n" + + "<ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" + + "ment\">unbounded</ll6>\n" + + "<ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" + + "ment\">8</ll6>\n" + "<cont13 xmlns=\"urn:opendaylight:params:xml:ns:yang:" + "augment\">\n" + " <ll9>abc</ll9>\n" + @@ -302,10 +306,6 @@ public final class DataFormatUtilsTest { "</list7>\n" + "<leaf15 xmlns=\"urn:opendaylight:params:xml:ns:yang:" + "augment\">abc</leaf15>\n" + - "<ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" + - "ment\">unbounded</ll6>\n" + - "<ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" + - "ment\">8</ll6>\n" + "<cont5 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" + "ugment\">\n" + " <leaf13>true</leaf13>\n" + @@ -557,8 +557,8 @@ public final class DataFormatUtilsTest { * @param i number of space * @return space appended string */ - private static String addSpace(String req, int i) { - StringBuilder space = new StringBuilder(""); + public static String addSpace(String req, int i) { + StringBuilder space = new StringBuilder(); for (int sp = 0; sp < i; sp++) { space = space.append(" "); } diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/IdentifierValidationTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/IdentifierValidationTest.java new file mode 100644 index 000000000..1109d426c --- /dev/null +++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/IdentifierValidationTest.java @@ -0,0 +1,762 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.plugins.restapicall.HttpResponse; +import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode; +import org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiCallNode; +import org.opendaylight.restconf.common.context.InstanceIdentifierContext; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doAnswer; +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.yangserializers.dfserializer.IdentifierValidationUtilsTest.DECODE_FROM_JSON_RPC_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.DECODE_FROM_XML_RPC_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_RPC_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_WITH_AUG_PATH; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_YANG_AUG_POST_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_YANG_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_YANG_PUT_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_XML_RPC_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_XML_YANG_AUG_POST_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_XML_YANG_ID; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_XML_YANG_PUT_ID; + +/** + * Unit test cases for identifier validation test. + */ +public class IdentifierValidationTest { + + private Map<String, String> p; + + private RestconfApiCallNode restconf; + + private RestapiCallNode restApi; + + private DfCaptor dfCaptor; + + /** + * Sets up the pre-requisite for each test case. + * + * @throws SvcLogicException when test case fails + */ + @Before + public void setUp() throws SvcLogicException { + p = new HashMap<>(); + p.put("restapiUser", "user1"); + p.put("restapiPassword", "abc123"); + p.put("responsePrefix", "response"); + p.put("skipSending", "true"); + restApi = new RestapiCallNode(); + restconf = mock(RestconfApiCallNode.class); + dfCaptor = new DfCaptor(); + createMethodMocks(); + } + + /** + * Creates method mocks using mockito for RestconfApiCallNode class. + * + * @throws SvcLogicException when test case fails + */ + private void createMethodMocks() throws SvcLogicException { + doReturn(restApi).when(restconf).getRestapiCallNode(); + doCallRealMethod().when(restconf).sendRequest( + any(Map.class), any(SvcLogicContext.class)); + doCallRealMethod().when(restconf).sendRequest( + any(Map.class), any(SvcLogicContext.class), any(Integer.class)); + 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)); + } + + /** + * Creates mock using mockito with input data for decoding. + * + * @param decodeData input data + * @throws SvcLogicException when test case fails + */ + private void createMockForDecode(String decodeData) + throws SvcLogicException { + doReturn(decodeData).when(restconf).getResponse( + any(SvcLogicContext.class), any(YangParameters.class), + any(String.class), any(HttpResponse.class)); + doCallRealMethod().when(restconf).serializeResponse( + any(YangParameters.class), any(String.class), any(String.class), + any(InstanceIdentifierContext.class)); + } + + /** + * Verifies encoding of parameters to JSON data format with containers, + * grouping and augment. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToJsonYang() throws SvcLogicException { + String pre = "test_name_of_the_module_name_of_the_cont1.name_" + + "of_the_cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "post"); + p.put("restapiUrl", "http://echo.getpostman.com/restconf/operati" + + "ons/test_name_of_the_module:name_of_the_cont1"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_ID)); + } + + /** + * Verifies encoding of parameters with augment in the URL. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToJsonYangWithAugUrl() throws SvcLogicException { + String pre = "test_name_of_the_module_name_of_the_cont1.name_" + + "of_the_cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "post"); + p.put("restapiUrl", "http://echo.getpostman.com/restconf/operati" + + "ons/test_name_of_the_module:name_of_the_cont1/name_of_t" + + "he_cont2/name_of_the_cont4/test_augment_1_for_module:na" + + "me_of_the_cont5"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_WITH_AUG_PATH)); + } + + /** + * 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_name_of_the_module_name_of_the_cont1.name_of_the_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_name_of_the_module:name_of" + + "_the_cont1/name_of_the_cont2/name_of_the_cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT_ID)); + } + + /** + * 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_name_of_the_module_name_of_the_cont1.name_o" + + "f_the_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_name_of_the_module:name_of_" + + "the_cont1/name_of_the_cont2/name_of_the_cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT_ID)); + } + + /** + * Verifies encoding of parameters to JSON data format with augment as + * root child. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToJsonWithAugAsRootChild() throws SvcLogicException { + String pre = "test_name_of_the_module_name_of_the_cont1.name_of_" + + "the_cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "post"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/test_name_of_the_module:name_of_" + + "the_cont1/name_of_the_cont2/name_of_the_cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_AUG_POST_ID)); + } + + /** + * Verifies decoding of parameters from JSON data format with containers, + * grouping and augment. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void decodeToJsonYang() throws SvcLogicException { + createMockForDecode(ENCODE_TO_JSON_YANG_ID); + SvcLogicContext ctx = new SvcLogicContext(); + String pre = "test_name_of_the_module_name_of_the_cont1.name_" + + "of_the_cont2."; + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "get"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/test_name_of_the_module:name" + + "_of_the_cont1"); + restconf.sendRequest(p, ctx); + verifyAttListYang(ctx, pre); + } + + /** + * Verifies encoding of parameters to XML data format with containers, + * grouping and augment. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToXmlYang() throws SvcLogicException { + String pre = "test_name_of_the_module_name_of_the_cont1.name_of" + + "_the_cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "xml"); + p.put("httpMethod", "post"); + p.put("restapiUrl", "http://echo.getpostman.com/restconf/operations/" + + "test_name_of_the_module:name_of_the_cont1"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_ID)); + } + + /** + * 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_name_of_the_module_name_of_the_cont1.name_" + + "of_the_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_name_of_the_module:name_of_the_cont1/name_of_the_cont2" + + "/name_of_the_cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT_ID)); + } + + /** + * 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_name_of_the_module_name_of_the_cont1.name_of" + + "_the_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/operation" + + "s/test_name_of_the_module:name_of_the_cont1/name_of_the_c" + + "ont2/name_of_the_cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT_ID)); + } + + /** + * Verifies encoding of parameters to XML data format with augment as + * root child. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToXmlWithAugAsRootChild() throws SvcLogicException { + String pre = "test_name_of_the_module_name_of_the_cont1.name_of_the" + + "_cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "xml"); + p.put("httpMethod", "post"); + p.put("restapiUrl", "http://echo.getpostman.com/restconf/operations/" + + "test_name_of_the_module:name_of_the_cont1/name_of_the_cont2" + + "/name_of_the_cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_AUG_POST_ID)); + } + + /** + * Verifies decoding of parameters from XML data format with containers, + * grouping and augment. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void decodeToXmlYang() throws SvcLogicException { + createMockForDecode(ENCODE_TO_XML_YANG_ID); + SvcLogicContext ctx = new SvcLogicContext(); + String pre = "test_name_of_the_module_name_of_the_cont1.name_of_" + + "the_cont2."; + p.put("dirPath", "src/test/resources"); + p.put("format", "xml"); + p.put("httpMethod", "get"); + p.put("restapiUrl", "http://echo.getpostman.com/restconf/operation" + + "s/test_name_of_the_module:name_of_the_cont1"); + restconf.sendRequest(p, ctx); + verifyAttListYang(ctx, pre); + } + + /** + * Verifies encoding of and decoding from, JSON respectively for data + * format with containers, grouping and augment. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void codecToJsonRpc() throws SvcLogicException { + createMockForDecode(DECODE_FROM_JSON_RPC_ID); + String inPre = "test_name_of_the_module_name_of_the_create-sfc.input."; + String outPre = "test_name_of_the_module_name_of_the_create-sfc" + + ".output."; + SvcLogicContext ctx = createAttListRpc(inPre); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "post"); + p.put("restapiUrl", "http://echo.getpostman.com/restconf/operations" + + "/test_name_of_the_module:name_of_the_create-sfc"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_RPC_ID)); + verifyAttListRpc(ctx, outPre); + } + + /** + * Verifies encoding of and decoding from, XML respectively for data + * format with containers, grouping and augment. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void codecToXmlRpc() throws SvcLogicException { + createMockForDecode(DECODE_FROM_XML_RPC_ID); + String inPre = "test_name_of_the_module_name_of_the_create-sfc.input."; + String outPre = "test_name_of_the_module_name_of_the_create-sfc.output."; + SvcLogicContext ctx = createAttListRpc(inPre); + p.put("dirPath", "src/test/resources"); + p.put("format", "xml"); + p.put("httpMethod", "post"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/test_name_of_the_module" + + ":name_of_the_create-sfc"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_RPC_ID)); + verifyAttListRpc(ctx, outPre); + } + + /** + * Creates attribute list for encoding JSON or XML with container, + * grouping and augmented YANG file. + * + * @param pre prefix + * @return service logic context + */ + private SvcLogicContext createAttListYang(String pre) { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute(pre + "name_of_the_cont3.name_of_the_leaf" + + "10", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_leaf1" + + "", "true"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_leaf2" + + "", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_leaf3" + + "", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "ll1[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "ll1[1]", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "ll2[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "ll2[1]", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "cont4.name_of_the_leaf11", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "list4[0].name_of_the_leaf8", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "list4[1].name_of_the_leaf8", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "list5[0].name_of_the_leaf9", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" + + "list5[1].name_of_the_leaf9", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "leaf1", "true"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "leaf2", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "leaf3", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "ll1[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "ll1[1]", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "ll2[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "ll2[1]", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "cont4.name_of_the_leaf11", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "list4[0].name_of_the_leaf8", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "list4[1].name_of_the_leaf8", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "list5[0].name_of_the_leaf9", "abc"); + ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" + + "list5[1].name_of_the_leaf9", "abc"); + ctx.setAttribute(pre + "name_of_the_list2[0].name_of_the_" + + "leaf4", "abc"); + ctx.setAttribute(pre + "name_of_the_list2[1].name_of_the_" + + "leaf4", "abc"); + ctx.setAttribute(pre + "name_of_the_leaf5", "abc"); + ctx.setAttribute(pre + "name_of_the_leaf6", "abc"); + ctx.setAttribute(pre + "name_of_the_ll3[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_ll3[1]", "abc"); + ctx.setAttribute(pre + "name_of_the_ll4[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_ll4[1]", "abc"); + ctx.setAttribute(pre + "name_of_the_cont4.name_of_the_leaf10", + "abc"); + ctx.setAttribute(pre + "name_of_the_list6[0].name_of_the_leaf11", + "abc"); + ctx.setAttribute(pre + "name_of_the_list6[1].name_of_the_leaf11", + "abc"); + ctx.setAttribute(pre + "name_of_the_leaf12", "abc"); + ctx.setAttribute(pre + "name_of_the_ll5[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_ll5[1]", "abc"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" + + "module_name_of_the_cont5.name_of_the_leaf13", + "true"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" + + "module_name_of_the_list7[0].name_of_the" + + "_leaf14", "test"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" + + "module_name_of_the_list7[1].name_of_the" + + "_leaf14", "create"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" + + "module_name_of_the_leaf15", "abc"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" + + "module_name_of_the_ll6[0]", + "unbounded"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" + + "_module_name_of_the_ll6[1]", "8"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" + + "_module_name_of_the_cont13.name_of_the_" + + "cont12.name_of_the_leaf26", + "abc"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" + + "module_name_of_the_cont13.name_of_the_" + + "list9[0].name_of_the_leaf27", + "abc"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" + + "_module_name_of_the_cont13.name_of_the_" + + "list9[1].name_of_the_leaf27", + "abc"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" + + "_module_name_of_the_cont13.name_of_the_" + + "leaf28", "abc"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" + + "_module_name_of_the_cont13.name_of_the_" + + "ll9[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" + + "_module_name_of_the_cont13.name_of_the_" + + "ll9[1]", "abc"); + return ctx; + } + + /** + * Creates attribute list for encoding JSON or XML with RPC YANG file. + * + * @param pre prefix + * @return service logic context + */ + private SvcLogicContext createAttListRpc(String pre) { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute(pre + "name_of_the_cont14.name_of_the_leaf28", + "abc"); + ctx.setAttribute(pre + "name_of_the_list10[0].name_of_the_leaf29", + "abc"); + ctx.setAttribute(pre + "name_of_the_list10[1].name_of_the_leaf29", + "abc"); + ctx.setAttribute(pre + "name_of_the_leaf30", "abc"); + ctx.setAttribute(pre + "name_of_the_ll10[0]", "abc"); + ctx.setAttribute(pre + "name_of_the_ll10[1]", "abc"); + ctx.setAttribute(pre + "name_of_the_cont15.name_of_the_leaf31", + "abc"); + ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_list9[0]" + + ".name_of_the_leaf27", "abc"); + ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_list9[1]" + + ".name_of_the_leaf27", "abc"); + ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_leaf28", + "abc"); + ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_ll9[0]", + "abc"); + ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_ll9[1]", + "abc"); + return ctx; + } + + /** + * Verifies the attribute list for decoding from JSON or XML with + * container, grouping and augmented file. + * + * @param ctx service logic context + * @param pre prefix + */ + private void verifyAttListYang(SvcLogicContext ctx, String pre) { + assertThat(ctx.getAttribute(pre + "name_of_the_cont3.name_of" + + "_the_leaf10"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" + + "_of_the_leaf1"), is("true")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" + + "_of_the_leaf2"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" + + "_of_the_leaf3"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" + + "_of_the_ll1[0]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" + + "_of_the_ll1[1]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" + + "_of_the_ll2[0]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" + + "_of_the_ll2[1]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" + + "_of_the_cont4.name_of_the_leaf11"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name_of" + + "_the_list4[0].name_of_the_leaf8"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name_of" + + "_the_list4[1].name_of_the_leaf8"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name_of" + + "_the_list5[0].name_of_the_leaf9"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name_of" + + "_the_list5[1].name_of_the_leaf9"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_leaf1"), is("true")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_leaf2"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_leaf3"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_ll1[0]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_ll1[1]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_ll2[0]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_ll2[1]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_cont4.name_of_the_leaf11"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_list4[0].name_of_the_leaf8"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_list4[1].name_of_the_leaf8"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_list5[0].name_of_the_leaf9"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" + + "_the_list5[1].name_of_the_leaf9"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list2[0].name_of" + + "_the_leaf4"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list2[1].name_of" + + "_the_leaf4"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_leaf5"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_leaf6"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_ll3[0]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_ll3[1]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_ll4[0]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_ll4[1]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.name_of" + + "_the_leaf10"), is( "abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list6[0].name_of" + + "_the_leaf11"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list6[1].name_of" + + "_the_leaf11"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_leaf12"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_ll5[0]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_ll5[1]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_cont5.name_of_the_leaf13"), + is("true")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_list7[0].name_of_the_leaf14"), + is("test")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_list7[1].name_of_the_leaf14"), + is("create")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_leaf15"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_ll6[0]"), + is("unbounded")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_ll6[1]"), + is("8")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_cont13" + + ".name_of_the_cont12.name_of_" + + "the_leaf26"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_cont13.name_of_the_list9[0]" + + ".name_of_the_leaf27"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_cont13.name_of_the_list9[1]" + + ".name_of_the_leaf27"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_cont13.name_of_the_leaf28"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_cont13.name_of_the_ll9[0]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" + + "augment_1_for_module_name_of_" + + "the_cont13.name_of_the_ll9[1]"), + is("abc")); + } + + /** + * Verifies the attribute list for decoding from JSON or XML with + * RPC YANG file. + * + * @param ctx service logic context + * @param pre prefix + */ + private void verifyAttListRpc(SvcLogicContext ctx, String pre) { + assertThat(ctx.getAttribute(pre + "name_of_the_cont16.name_of_" + + "the_leaf32"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list11[0].name" + + "_of_the_leaf33"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_list11[1].name" + + "_of_the_leaf33"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_leaf34"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_ll11[0]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_ll11[1]"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont17.name_of_" + + "the_leaf35"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" + + "the_cont12.name_of_the_leaf26"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" + + "the_list9[0].name_of_the_leaf27"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" + + "the_list9[1].name_of_the_leaf27"), + is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" + + "the_ll9[0]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" + + "the_ll9[1]"), is("abc")); + assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" + + "the_leaf28"), is("abc")); + } + + /** + * Captures the data format messages by mocking it, which can be used in + * testing the value. + * + * @param <String> capturing data format + */ + public class DfCaptor<String> implements Answer { + + private String result; + + /** + * Returns the captured data format message. + * + * @return data format message. + */ + public String getResult() { + return result; + } + + @Override + public String answer(InvocationOnMock invocationOnMock) + throws Throwable { + result = (String) invocationOnMock.callRealMethod(); + return result; + } + } + +} diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/IdentifierValidationUtilsTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/IdentifierValidationUtilsTest.java new file mode 100644 index 000000000..a866f1c4a --- /dev/null +++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/IdentifierValidationUtilsTest.java @@ -0,0 +1,469 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer; + +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.addSpace; + +/** + * Unit test case utilities for identifier validation and restconf api + * call node. + */ +public final class IdentifierValidationUtilsTest { + + static final String ENCODE_TO_JSON_YANG_COMMON_ID = "\n " + + "\"test_augment_1_for_module:name_of_the_ll6\": [\n" + + " \"unbounded\",\n" + + " \"8\"\n" + + " ],\n" + + " \"test_augment_1_for_module:name_of_the_cont13\": {\n" + + " \"name_of_the_cont12\": {\n" + + " \"name_of_the_leaf26\": \"abc\"\n" + + " },\n" + + " \"name_of_the_ll9\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_leaf28\": \"abc\",\n" + + " \"name_of_the_list9\": [\n" + + " {\n" + + " \"name_of_the_leaf27\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf27\": \"abc\"\n" + + " }\n" + + " ]\n" + + " },\n" + + " \"test_augment_1_for_module:name_of_the_list7\": [\n" + + " {\n" + + " \"name_of_the_leaf14\": \"test\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf14\": \"create\"\n" + + " }\n" + + " ],\n" + + " \"test_augment_1_for_module:name_of_the_leaf15\": \"abc\",\n" + + " \"test_augment_1_for_module:name_of_the_cont5\": {\n" + + " \"name_of_the_leaf13\": \"true\"\n" + + " }"; + + static final String ENCODE_TO_JSON_YANG_AUG_POST_ID = "{\n" + + " \"test_name_of_the_module:name_of_the_leaf10\": \"abc\"," + + ENCODE_TO_JSON_YANG_COMMON_ID + "\n}"; + + static final String ENCODE_TO_JSON_YANG_ID = "{\n" + + " \"test_name_of_the_module:name_of_the_cont2\": {\n" + + " \"name_of_the_ll4\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_leaf5\": \"abc\",\n" + + " \"name_of_the_list6\": [\n" + + " {\n" + + " \"name_of_the_leaf11\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf11\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_ll5\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_ll3\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_leaf6\": \"abc\",\n" + + " \"name_of_the_cont3\": {\n" + + " \"name_of_the_leaf10\": \"abc\"\n" + + " },\n" + + " \"name_of_the_list2\": [\n" + + " {\n" + + " \"name_of_the_leaf4\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf4\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_list1\": [\n" + + " {\n" + + " \"name_of_the_ll2\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_list5\": [\n" + + " {\n" + + " \"name_of_the_leaf9\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf9\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_list4\": [\n" + + " {\n" + + " \"name_of_the_leaf8\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf8\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_leaf1\": \"true\",\n" + + " \"name_of_the_leaf3\": \"abc\",\n" + + " \"name_of_the_leaf2\": \"abc\",\n" + + " \"name_of_the_cont4\": {\n" + + " \"name_of_the_leaf11\": \"abc\"\n" + + " },\n" + + " \"name_of_the_ll1\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"name_of_the_ll2\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_list5\": [\n" + + " {\n" + + " \"name_of_the_leaf9\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf9\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_list4\": [\n" + + " {\n" + + " \"name_of_the_leaf8\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf8\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_leaf1\": \"true\",\n" + + " \"name_of_the_leaf3\": \"abc\",\n" + + " \"name_of_the_leaf2\": \"abc\",\n" + + " \"name_of_the_cont4\": {\n" + + " \"name_of_the_leaf11\": \"abc\"\n" + + " },\n" + + " \"name_of_the_ll1\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"name_of_the_cont4\": {\n" + + " \"name_of_the_leaf10\": \"abc\"," + + addSpace(ENCODE_TO_JSON_YANG_COMMON_ID,8) + "\n" + + " },\n" + + " \"name_of_the_leaf12\": \"abc\"\n" + + " }\n" + + "}"; + + static final String ENCODE_TO_JSON_WITH_AUG_PATH = "{\n" + + " \"test_augment_1_for_module:name_of_the_leaf13\": \"true\"\n" + + "}"; + + static final String ENCODE_TO_JSON_YANG_PUT_ID = "{\n" + + " \"test_name_of_the_module:name_of_the_cont4\": {" + addSpace( + ENCODE_TO_JSON_YANG_COMMON_ID, 4) + ",\n" + + " \"name_of_the_leaf10\": \"abc\"\n" + + " }\n" + + "}"; + + static final String ENCODE_TO_XML_YANG_COMMON_ID = "\n" + + "<name_of_the_ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:" + + "test:augment:name\">unbounded</name_of_the_ll6>\n" + + "<name_of_the_ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:" + + "test:augment:name\">8</name_of_the_ll6>\n" + + "<name_of_the_cont13 xmlns=\"urn:opendaylight:params:xml:ns:ya" + + "ng:test:augment:name\">\n" + + " <name_of_the_cont12>\n" + + " <name_of_the_leaf26>abc</name_of_the_leaf26>\n" + + " </name_of_the_cont12>\n" + + " <name_of_the_ll9>abc</name_of_the_ll9>\n" + + " <name_of_the_ll9>abc</name_of_the_ll9>\n" + + " <name_of_the_leaf28>abc</name_of_the_leaf28>\n" + + " <name_of_the_list9>\n" + + " <name_of_the_leaf27>abc</name_of_the_leaf27>\n" + + " </name_of_the_list9>\n" + + " <name_of_the_list9>\n" + + " <name_of_the_leaf27>abc</name_of_the_leaf27>\n" + + " </name_of_the_list9>\n" + + "</name_of_the_cont13>\n" + + "<name_of_the_list7 xmlns=\"urn:opendaylight:params:xml:ns:yan" + + "g:test:augment:name\">\n" + + " <name_of_the_leaf14>test</name_of_the_leaf14>\n" + + "</name_of_the_list7>\n" + + "<name_of_the_list7 xmlns=\"urn:opendaylight:params:xml:ns:yan" + + "g:test:augment:name\">\n" + + " <name_of_the_leaf14>create</name_of_the_leaf14>\n" + + "</name_of_the_list7>\n" + + "<name_of_the_leaf15 xmlns=\"urn:opendaylight:params:xml:ns:ya" + + "ng:test:augment:name\">abc</name_of_the_leaf15>\n" + + "<name_of_the_cont5 xmlns=\"urn:opendaylight:params:xml:ns:yan" + + "g:test:augment:name\">\n" + + " <name_of_the_leaf13>true</name_of_the_leaf13>\n" + + "</name_of_the_cont5>"; + + static final String ENCODE_TO_XML_YANG_AUG_POST_ID = "<?xml version=\"1" + + ".0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + + "<name_of_the_leaf10 xmlns=\"urn:opendaylight:params:xml:ns:yan" + + "g:test:name\">abc</name_of_the_leaf10>" + + ENCODE_TO_XML_YANG_COMMON_ID + "\n"; + + static final String ENCODE_TO_XML_YANG_PUT_ID = "<?xml version=\"1.0\" " + + "encoding=\"UTF-8\" standalone=\"no\"?>\n" + + "<name_of_the_cont4 xmlns=\"urn:opendaylight:params:xml:ns:yang" + + ":test:name\">\n" + + " <name_of_the_leaf10>abc</name_of_the_leaf10>" + + addSpace(ENCODE_TO_XML_YANG_COMMON_ID, 4) + "\n</name_of_the_co" + + "nt4>\n"; + + static final String ENCODE_TO_XML_YANG_ID= "<?xml version=\"1.0\" " + + "encoding=\"UTF-8\" standalone=\"no\"?>\n" + + "<name_of_the_cont2 xmlns=\"urn:opendaylight:params:xml:ns:yan" + + "g:test:name\">\n" + + " <name_of_the_ll4>abc</name_of_the_ll4>\n" + + " <name_of_the_ll4>abc</name_of_the_ll4>\n" + + " <name_of_the_leaf5>abc</name_of_the_leaf5>\n" + + " <name_of_the_list6>\n" + + " <name_of_the_leaf11>abc</name_of_the_leaf11>\n" + + " </name_of_the_list6>\n" + + " <name_of_the_list6>\n" + + " <name_of_the_leaf11>abc</name_of_the_leaf11>\n" + + " </name_of_the_list6>\n" + + " <name_of_the_ll5>abc</name_of_the_ll5>\n" + + " <name_of_the_ll5>abc</name_of_the_ll5>\n" + + " <name_of_the_ll3>abc</name_of_the_ll3>\n" + + " <name_of_the_ll3>abc</name_of_the_ll3>\n" + + " <name_of_the_leaf6>abc</name_of_the_leaf6>\n" + + " <name_of_the_cont3>\n" + + " <name_of_the_leaf10>abc</name_of_the_leaf10>\n" + + " </name_of_the_cont3>\n" + + " <name_of_the_list2>\n" + + " <name_of_the_leaf4>abc</name_of_the_leaf4>\n" + + " </name_of_the_list2>\n" + + " <name_of_the_list2>\n" + + " <name_of_the_leaf4>abc</name_of_the_leaf4>\n" + + " </name_of_the_list2>\n" + + " <name_of_the_list1>\n" + + " <name_of_the_ll2>abc</name_of_the_ll2>\n" + + " <name_of_the_ll2>abc</name_of_the_ll2>\n" + + " <name_of_the_list5>\n" + + " <name_of_the_leaf9>abc</name_of_the_leaf9>\n" + + " </name_of_the_list5>\n" + + " <name_of_the_list5>\n" + + " <name_of_the_leaf9>abc</name_of_the_leaf9>\n" + + " </name_of_the_list5>\n" + + " <name_of_the_list4>\n" + + " <name_of_the_leaf8>abc</name_of_the_leaf8>\n" + + " </name_of_the_list4>\n" + + " <name_of_the_list4>\n" + + " <name_of_the_leaf8>abc</name_of_the_leaf8>\n" + + " </name_of_the_list4>\n" + + " <name_of_the_leaf1>true</name_of_the_leaf1>\n" + + " <name_of_the_leaf3>abc</name_of_the_leaf3>\n" + + " <name_of_the_leaf2>abc</name_of_the_leaf2>\n" + + " <name_of_the_cont4>\n" + + " <name_of_the_leaf11>abc</name_of_the_leaf11>\n" + + " </name_of_the_cont4>\n" + + " <name_of_the_ll1>abc</name_of_the_ll1>\n" + + " <name_of_the_ll1>abc</name_of_the_ll1>\n" + + " </name_of_the_list1>\n" + + " <name_of_the_list1>\n" + + " <name_of_the_ll2>abc</name_of_the_ll2>\n" + + " <name_of_the_ll2>abc</name_of_the_ll2>\n" + + " <name_of_the_list5>\n" + + " <name_of_the_leaf9>abc</name_of_the_leaf9>\n" + + " </name_of_the_list5>\n" + + " <name_of_the_list5>\n" + + " <name_of_the_leaf9>abc</name_of_the_leaf9>\n" + + " </name_of_the_list5>\n" + + " <name_of_the_list4>\n" + + " <name_of_the_leaf8>abc</name_of_the_leaf8>\n" + + " </name_of_the_list4>\n" + + " <name_of_the_list4>\n" + + " <name_of_the_leaf8>abc</name_of_the_leaf8>\n" + + " </name_of_the_list4>\n" + + " <name_of_the_leaf1>true</name_of_the_leaf1>\n" + + " <name_of_the_leaf3>abc</name_of_the_leaf3>\n" + + " <name_of_the_leaf2>abc</name_of_the_leaf2>\n" + + " <name_of_the_cont4>\n" + + " <name_of_the_leaf11>abc</name_of_the_leaf11>\n" + + " </name_of_the_cont4>\n" + + " <name_of_the_ll1>abc</name_of_the_ll1>\n" + + " <name_of_the_ll1>abc</name_of_the_ll1>\n" + + " </name_of_the_list1>\n" + + " <name_of_the_cont4>\n" + + " <name_of_the_leaf10>abc</name_of_the_leaf10>" + + addSpace(ENCODE_TO_XML_YANG_COMMON_ID, 8) + "\n" + + " </name_of_the_cont4>\n" + + " <name_of_the_leaf12>abc</name_of_the_leaf12>\n" + + "</name_of_the_cont2>\n"; + + static final String ENCODE_TO_JSON_RPC_ID = "{\n" + + " \"test_name_of_the_module:input\": {\n" + + " \"name_of_the_cont14\": {\n" + + " \"name_of_the_leaf28\": \"abc\"\n" + + " },\n" + + " \"name_of_the_cont13\": {\n" + + " \"name_of_the_ll9\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_leaf28\": \"abc\",\n" + + " \"name_of_the_list9\": [\n" + + " {\n" + + " \"name_of_the_leaf27\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf27\": \"abc\"\n" + + " }\n" + + " ]\n" + + " },\n" + + " \"name_of_the_leaf30\": \"abc\",\n" + + " \"name_of_the_ll10\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_list10\": [\n" + + " {\n" + + " \"name_of_the_leaf29\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf29\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_cont15\": {\n" + + " \"name_of_the_leaf31\": \"abc\"\n" + + " }\n" + + " }\n" + + "}"; + + static final String DECODE_FROM_JSON_RPC_ID = "{\n" + + " \"test_name_of_the_module:output\": {\n" + + " \"name_of_the_cont16\": {\n" + + " \"name_of_the_leaf32\": \"abc\"\n" + + " },\n" + + " \"name_of_the_list11\": [\n" + + " {\n" + + " \"name_of_the_leaf33\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf33\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_leaf34\": \"abc\",\n" + + " \"name_of_the_ll11\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_cont17\": {\n" + + " \"name_of_the_leaf35\": \"abc\"\n" + + " },\n" + + " \"name_of_the_cont13\": {\n" + + " \"name_of_the_cont12\": {\n" + + " \"name_of_the_leaf26\": \"abc\"\n" + + " },\n" + + " \"name_of_the_list9\": [\n" + + " {\n" + + " \"name_of_the_leaf27\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"name_of_the_leaf27\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"name_of_the_ll9\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"name_of_the_leaf28\": \"abc\"\n" + + " }\n" + + " }\n" + + "}"; + + static final String ENCODE_TO_XML_RPC_ID = "<?xml version=\"1.0\" " + + "encoding=\"UTF-8\" standalone=\"no\"?>\n" + + "<input xmlns=\"urn:opendaylight:params:xml:ns:yang:test:name\"" + + ">\n" + + " <name_of_the_cont14>\n" + + " <name_of_the_leaf28>abc</name_of_the_leaf28>\n" + + " </name_of_the_cont14>\n" + + " <name_of_the_cont13>\n" + + " <name_of_the_ll9>abc</name_of_the_ll9>\n" + + " <name_of_the_ll9>abc</name_of_the_ll9>\n" + + " <name_of_the_leaf28>abc</name_of_the_leaf28>\n" + + " <name_of_the_list9>\n" + + " <name_of_the_leaf27>abc</name_of_the_leaf27>\n" + + " </name_of_the_list9>\n" + + " <name_of_the_list9>\n" + + " <name_of_the_leaf27>abc</name_of_the_leaf27>\n" + + " </name_of_the_list9>\n" + + " </name_of_the_cont13>\n" + + " <name_of_the_leaf30>abc</name_of_the_leaf30>\n" + + " <name_of_the_ll10>abc</name_of_the_ll10>\n" + + " <name_of_the_ll10>abc</name_of_the_ll10>\n" + + " <name_of_the_list10>\n" + + " <name_of_the_leaf29>abc</name_of_the_leaf29>\n" + + " </name_of_the_list10>\n" + + " <name_of_the_list10>\n" + + " <name_of_the_leaf29>abc</name_of_the_leaf29>\n" + + " </name_of_the_list10>\n" + + " <name_of_the_cont15>\n" + + " <name_of_the_leaf31>abc</name_of_the_leaf31>\n" + + " </name_of_the_cont15>\n" + + "</input>\n"; + + static final String DECODE_FROM_XML_RPC_ID = "<?xml version=\"1.0\" " + + "encoding=\"UTF-8\" standalone=\"no\"?>\n" + + "<output xmlns=\"urn:opendaylight:params:xml:ns:yang:test:name" + + "\">\n" + + " <name_of_the_cont16>\n" + + " <name_of_the_leaf32>abc</name_of_the_leaf32>\n" + + " </name_of_the_cont16>\n" + + " <name_of_the_list11>\n" + + " <name_of_the_leaf33>abc</name_of_the_leaf33>\n" + + " </name_of_the_list11>\n" + + " <name_of_the_list11>\n" + + " <name_of_the_leaf33>abc</name_of_the_leaf33>\n" + + " </name_of_the_list11>\n" + + " <name_of_the_leaf34>abc</name_of_the_leaf34>\n" + + " <name_of_the_ll11>abc</name_of_the_ll11>\n" + + " <name_of_the_ll11>abc</name_of_the_ll11>\n" + + " <name_of_the_cont17>\n" + + " <name_of_the_leaf35>abc</name_of_the_leaf35>\n" + + " </name_of_the_cont17>\n" + + " <name_of_the_cont13>\n" + + " <name_of_the_cont12>\n" + + " <name_of_the_leaf26>abc</name_of_the_leaf26>\n" + + " </name_of_the_cont12>\n" + + " <name_of_the_list9>\n" + + " <name_of_the_leaf27>abc</name_of_the_leaf27>\n" + + " </name_of_the_list9>\n" + + " <name_of_the_list9>\n" + + " <name_of_the_leaf27>abc</name_of_the_leaf27>\n" + + " </name_of_the_list9>\n" + + " <name_of_the_ll9>abc</name_of_the_ll9>\n" + + " <name_of_the_ll9>abc</name_of_the_ll9>\n" + + " <name_of_the_leaf28>abc</name_of_the_leaf28>\n" + + " </name_of_the_cont13>\n" + + "</output>"; +} diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesSerializerTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesSerializerTest.java index dc0da6f7c..c3a6b4ea8 100644 --- a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesSerializerTest.java +++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesSerializerTest.java @@ -19,15 +19,6 @@ */ package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer; -import org.junit.Before; -import org.junit.Test; - -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.opendaylight.restconf.common.context.InstanceIdentifierContext; -import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; - import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; @@ -37,6 +28,14 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.opendaylight.restconf.common.context.InstanceIdentifierContext; +import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertTrue; @@ -53,39 +52,39 @@ public final class PropertiesSerializerTest { public void testBasicConstructs() throws SvcLogicException { String uri = "test-yang:cont1/cont2"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont1.cont2.cont3.leaf10", "abc"); - params.put("test-yang:cont1.cont2.list1[0].leaf1", "abc"); - params.put("test-yang:cont1.cont2.list1[0].leaf2", "abc"); - params.put("test-yang:cont1.cont2.list1[0].leaf3", "abc"); - params.put("test-yang:cont1.cont2.list1[0].ll1[0]", "abc"); - params.put("test-yang:cont1.cont2.list1[0].ll1[1]", "abc"); - params.put("test-yang:cont1.cont2.list1[0].ll2[0]", "abc"); - params.put("test-yang:cont1.cont2.list1[0].ll2[1]", "abc"); - params.put("test-yang:cont1.cont2.list1[0].cont4.leaf11", "abc"); - params.put("test-yang:cont1.cont2.list1[0].list4[0].leaf8", "abc"); - params.put("test-yang:cont1.cont2.list1[0].list4[1].leaf8", "abc"); - params.put("test-yang:cont1.cont2.list1[0].list5[0].leaf9", "abc"); - params.put("test-yang:cont1.cont2.list1[0].list5[1].leaf9", "abc"); - params.put("test-yang:cont1.cont2.list1[1].leaf1", "abc"); - params.put("test-yang:cont1.cont2.list1[1].leaf2", "abc"); - params.put("test-yang:cont1.cont2.list1[1].leaf3", "abc"); - params.put("test-yang:cont1.cont2.list1[1].ll1[0]", "abc"); - params.put("test-yang:cont1.cont2.list1[1].ll1[1]", "abc"); - params.put("test-yang:cont1.cont2.list1[1].ll2[0]", "abc"); - params.put("test-yang:cont1.cont2.list1[1].ll2[1]", "abc"); - params.put("test-yang:cont1.cont2.list1[1].cont4.leaf11", "abc"); - params.put("test-yang:cont1.cont2.list1[1].list4[0].leaf8", "abc"); - params.put("test-yang:cont1.cont2.list1[1].list4[1].leaf8", "abc"); - params.put("test-yang:cont1.cont2.list1[1].list5[0].leaf9", "abc"); - params.put("test-yang:cont1.cont2.list1[1].list5[1].leaf9", "abc"); - params.put("test-yang:cont1.cont2.list2[0].leaf4", "abc"); - params.put("test-yang:cont1.cont2.list2[1].leaf4", "abc"); - params.put("test-yang:cont1.cont2.leaf5", "abc"); - params.put("test-yang:cont1.cont2.leaf6", "abc"); - params.put("test-yang:cont1.cont2.ll3[0]", "abc"); - params.put("test-yang:cont1.cont2.ll3[1]", "abc"); - params.put("test-yang:cont1.cont2.ll4[0]", "abc"); - params.put("test-yang:cont1.cont2.ll4[1]", "abc"); + params.put("test-yang_cont1.cont2.cont3.leaf10", "abc"); + params.put("test-yang_cont1.cont2.list1[0].leaf1", "abc"); + params.put("test-yang_cont1.cont2.list1[0].leaf2", "abc"); + params.put("test-yang_cont1.cont2.list1[0].leaf3", "abc"); + params.put("test-yang_cont1.cont2.list1[0].ll1[0]", "abc"); + params.put("test-yang_cont1.cont2.list1[0].ll1[1]", "abc"); + params.put("test-yang_cont1.cont2.list1[0].ll2[0]", "abc"); + params.put("test-yang_cont1.cont2.list1[0].ll2[1]", "abc"); + params.put("test-yang_cont1.cont2.list1[0].cont4.leaf11", "abc"); + params.put("test-yang_cont1.cont2.list1[0].list4[0].leaf8", "abc"); + params.put("test-yang_cont1.cont2.list1[0].list4[1].leaf8", "abc"); + params.put("test-yang_cont1.cont2.list1[0].list5[0].leaf9", "abc"); + params.put("test-yang_cont1.cont2.list1[0].list5[1].leaf9", "abc"); + params.put("test-yang_cont1.cont2.list1[1].leaf1", "abc"); + params.put("test-yang_cont1.cont2.list1[1].leaf2", "abc"); + params.put("test-yang_cont1.cont2.list1[1].leaf3", "abc"); + params.put("test-yang_cont1.cont2.list1[1].ll1[0]", "abc"); + params.put("test-yang_cont1.cont2.list1[1].ll1[1]", "abc"); + params.put("test-yang_cont1.cont2.list1[1].ll2[0]", "abc"); + params.put("test-yang_cont1.cont2.list1[1].ll2[1]", "abc"); + params.put("test-yang_cont1.cont2.list1[1].cont4.leaf11", "abc"); + params.put("test-yang_cont1.cont2.list1[1].list4[0].leaf8", "abc"); + params.put("test-yang_cont1.cont2.list1[1].list4[1].leaf8", "abc"); + params.put("test-yang_cont1.cont2.list1[1].list5[0].leaf9", "abc"); + params.put("test-yang_cont1.cont2.list1[1].list5[1].leaf9", "abc"); + params.put("test-yang_cont1.cont2.list2[0].leaf4", "abc"); + params.put("test-yang_cont1.cont2.list2[1].leaf4", "abc"); + params.put("test-yang_cont1.cont2.leaf5", "abc"); + params.put("test-yang_cont1.cont2.leaf6", "abc"); + params.put("test-yang_cont1.cont2.ll3[0]", "abc"); + params.put("test-yang_cont1.cont2.ll3[1]", "abc"); + params.put("test-yang_cont1.cont2.ll4[0]", "abc"); + params.put("test-yang_cont1.cont2.ll4[1]", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -283,18 +282,18 @@ public final class PropertiesSerializerTest { public void testAugment() throws SvcLogicException { String uri = "test-yang:cont1/cont2"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont1.cont2.cont4.leaf10", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:cont5.leaf13", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:list7[0].leaf14", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:list7[1].leaf14", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:leaf15", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:ll6[0]", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:ll6[1]", "abc"); - params.put("test-yang:cont1.cont2.list6[0].leaf11", "abc"); - params.put("test-yang:cont1.cont2.list6[1].leaf11", "abc"); - params.put("test-yang:cont1.cont2.leaf12", "abc"); - params.put("test-yang:cont1.cont2.ll5[0]", "abc"); - params.put("test-yang:cont1.cont2.ll5[1]", "abc"); + params.put("test-yang_cont1.cont2.cont4.leaf10", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_cont5.leaf13", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_list7[0].leaf14", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_list7[1].leaf14", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_leaf15", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_ll6[0]", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_ll6[1]", "abc"); + params.put("test-yang_cont1.cont2.list6[0].leaf11", "abc"); + params.put("test-yang_cont1.cont2.list6[1].leaf11", "abc"); + params.put("test-yang_cont1.cont2.leaf12", "abc"); + params.put("test-yang_cont1.cont2.ll5[0]", "abc"); + params.put("test-yang_cont1.cont2.ll5[1]", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -397,12 +396,12 @@ public final class PropertiesSerializerTest { public void testChoiceCase1() throws SvcLogicException { String uri = "test-yang:cont8"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont8.cont6.leaf16", "abc"); - params.put("test-yang:cont8.list8[0].leaf18", "abc"); - params.put("test-yang:cont8.list8[1].leaf18", "abc"); - params.put("test-yang:cont8.leaf19", "abc"); - params.put("test-yang:cont8.ll7[0]", "abc"); - params.put("test-yang:cont8.ll7[1]", "abc"); + params.put("test-yang_cont8.cont6.leaf16", "abc"); + params.put("test-yang_cont8.list8[0].leaf18", "abc"); + params.put("test-yang_cont8.list8[1].leaf18", "abc"); + params.put("test-yang_cont8.leaf19", "abc"); + params.put("test-yang_cont8.ll7[0]", "abc"); + params.put("test-yang_cont8.ll7[1]", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -459,9 +458,9 @@ public final class PropertiesSerializerTest { public void testChoiceCase2() throws SvcLogicException { String uri = "test-yang:cont9"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont9.leaf20", "abc"); - params.put("test-yang:cont9.ll8[0]", "abc"); - params.put("test-yang:cont9.cont11.leaf25", "abc"); + params.put("test-yang_cont9.leaf20", "abc"); + params.put("test-yang_cont9.ll8[0]", "abc"); + params.put("test-yang_cont9.cont11.leaf25", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -499,7 +498,7 @@ public final class PropertiesSerializerTest { public void testChoiceCase3() throws SvcLogicException { String uri = "test-yang:cont8/cont6"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont8.cont6.test-augment:leaf21", "abc"); + params.put("test-yang_cont8.cont6.test-augment_leaf21", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -538,10 +537,10 @@ public final class PropertiesSerializerTest { public void testGrouping() throws SvcLogicException { String uri = "test-yang:cont13"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont13.cont12.leaf26", "abc"); - params.put("test-yang:cont13.list9[0].leaf27", "abc"); - params.put("test-yang:cont13.leaf28", "abc"); - params.put("test-yang:cont13.ll9[0]", "abc"); + params.put("test-yang_cont13.cont12.leaf26", "abc"); + params.put("test-yang_cont13.list9[0].leaf27", "abc"); + params.put("test-yang_cont13.leaf28", "abc"); + params.put("test-yang_cont13.ll9[0]", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -587,11 +586,11 @@ public final class PropertiesSerializerTest { public void testGrouping2() throws SvcLogicException { String uri = "test-yang:cont9/cont11"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont9.cont11.leaf25", "abc"); - params.put("test-yang:cont9.cont11.cont13.cont12.leaf26", "abc"); - params.put("test-yang:cont9.cont11.cont13.list9[0].leaf27", "abc"); - params.put("test-yang:cont9.cont11.cont13.leaf28", "abc"); - params.put("test-yang:cont9.cont11.cont13.ll9[0]", "abc"); + params.put("test-yang_cont9.cont11.leaf25", "abc"); + params.put("test-yang_cont9.cont11.cont13.cont12.leaf26", "abc"); + params.put("test-yang_cont9.cont11.cont13.list9[0].leaf27", "abc"); + params.put("test-yang_cont9.cont11.cont13.leaf28", "abc"); + params.put("test-yang_cont9.cont11.cont13.ll9[0]", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer( @@ -642,10 +641,10 @@ public final class PropertiesSerializerTest { public void testGrouping3() throws SvcLogicException { String uri = "test-augment:cont13"; Map<String, String> params = new HashMap<>(); - params.put("test-augment:cont13.cont12.leaf26", "abc"); - params.put("test-augment:cont13.list9[0].leaf27", "abc"); - params.put("test-augment:cont13.leaf28", "abc"); - params.put("test-augment:cont13.ll9[0]", "abc"); + params.put("test-augment_cont13.cont12.leaf26", "abc"); + params.put("test-augment_cont13.list9[0].leaf27", "abc"); + params.put("test-augment_cont13.leaf28", "abc"); + params.put("test-augment_cont13.ll9[0]", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer( @@ -693,10 +692,10 @@ public final class PropertiesSerializerTest { public void testGrouping4() throws SvcLogicException { String uri = "test-yang:cont1/cont2/cont4"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.cont12.leaf26", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0].leaf27", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.leaf28", "abc"); - params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9[0]", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.cont12.leaf26", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.list9[0].leaf27", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.leaf28", "abc"); + params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.ll9[0]", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -755,16 +754,16 @@ public final class PropertiesSerializerTest { public void testRpcInput() throws SvcLogicException { String uri = "test-yang:create-sfc"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:create-sfc.input.cont14.leaf28", "abc"); - params.put("test-yang:create-sfc.input.list10[0].leaf29", "abc"); - params.put("test-yang:create-sfc.input.leaf30", "abc"); - params.put("test-yang:create-sfc.input.ll10[0]", "abc"); - params.put("test-yang:create-sfc.input.cont15.leaf31", "abc"); - params.put("test-yang:create-sfc.input.cont13.cont12.leaf26", "abc"); - params.put("test-yang:create-sfc.input.cont13.list9[0].leaf27", "abc"); - params.put("test-yang:create-sfc.input.cont13.leaf28", "abc"); - params.put("test-yang:create-sfc.input.cont13.ll9[0]", "abc"); - params.put("test-yang:create-sfc.input.test-augment:leaf36", "abc"); + params.put("test-yang_create-sfc.input.cont14.leaf28", "abc"); + params.put("test-yang_create-sfc.input.list10[0].leaf29", "abc"); + params.put("test-yang_create-sfc.input.leaf30", "abc"); + params.put("test-yang_create-sfc.input.ll10[0]", "abc"); + params.put("test-yang_create-sfc.input.cont15.leaf31", "abc"); + params.put("test-yang_create-sfc.input.cont13.cont12.leaf26", "abc"); + params.put("test-yang_create-sfc.input.cont13.list9[0].leaf27", "abc"); + params.put("test-yang_create-sfc.input.cont13.leaf28", "abc"); + params.put("test-yang_create-sfc.input.cont13.ll9[0]", "abc"); + params.put("test-yang_create-sfc.input.test-augment_leaf36", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -869,16 +868,16 @@ public final class PropertiesSerializerTest { public void testRpcOutput() throws SvcLogicException { String uri = "test-yang:create-sfc"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:create-sfc.output.cont16.leaf32", "abc"); - params.put("test-yang:create-sfc.output.list11[0].leaf33", "abc"); - params.put("test-yang:create-sfc.output.leaf34", "abc"); - params.put("test-yang:create-sfc.output.ll11[0]", "abc"); - params.put("test-yang:create-sfc.output.cont17.leaf35", "abc"); - params.put("test-yang:create-sfc.output.cont13.cont12.leaf26", "abc"); - params.put("test-yang:create-sfc.output.cont13.list9[0].leaf27", "abc"); - params.put("test-yang:create-sfc.output.cont13.leaf28", "abc"); - params.put("test-yang:create-sfc.output.cont13.ll9[0]", "abc"); - params.put("test-yang:create-sfc.output.test-augment:leaf37", "abc"); + params.put("test-yang_create-sfc.output.cont16.leaf32", "abc"); + params.put("test-yang_create-sfc.output.list11[0].leaf33", "abc"); + params.put("test-yang_create-sfc.output.leaf34", "abc"); + params.put("test-yang_create-sfc.output.ll11[0]", "abc"); + params.put("test-yang_create-sfc.output.cont17.leaf35", "abc"); + params.put("test-yang_create-sfc.output.cont13.cont12.leaf26", "abc"); + params.put("test-yang_create-sfc.output.cont13.list9[0].leaf27", "abc"); + params.put("test-yang_create-sfc.output.cont13.leaf28", "abc"); + params.put("test-yang_create-sfc.output.cont13.ll9[0]", "abc"); + params.put("test-yang_create-sfc.output.test-augment_leaf37", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -983,10 +982,10 @@ public final class PropertiesSerializerTest { public void testContainerSameName() throws SvcLogicException { String uri = "test-yang:cont18"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont18.cont18.list12[0].list12[0].leaf36", "abc"); - params.put("test-yang:cont18.cont18.list12[0].leaf36", "hi"); - params.put("test-yang:cont18.cont18.list12[1].list12[0].leaf36", "xyz"); - params.put("test-yang:cont18.cont18.list12[1].list12[1].leaf36", "hey!"); + params.put("test-yang_cont18.cont18.list12[0].list12[0].leaf36", "abc"); + params.put("test-yang_cont18.cont18.list12[0].leaf36", "hi"); + params.put("test-yang_cont18.cont18.list12[1].list12[0].leaf36", "xyz"); + params.put("test-yang_cont18.cont18.list12[1].list12[1].leaf36", "hey!"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -1055,9 +1054,9 @@ public final class PropertiesSerializerTest { public void testPropertiesWithoutSchema() throws SvcLogicException { String uri = "test-yang:cont18"; Map<String, String> params = new HashMap<>(); - params.put("test-yang:cont18.leaf40", "abc"); + params.put("test-yang_cont18.leaf40", "abc"); params.put("leaf41", "hi"); - params.put("test-yang:cont18.leaf41", "abc"); + params.put("test-yang_cont18.leaf41", "abc"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); @@ -1075,11 +1074,12 @@ public final class PropertiesSerializerTest { public void testIdentityRef() throws SvcLogicException { String uri = "identity-test:test"; Map<String, String> params = new HashMap<>(); - params.put("identity-test:test.con1.interface", "identity-types:physical"); - params.put("identity-test:test.con1.interfaces.int-list[0].iden", "identity-test:Giga"); - params.put("identity-test:test.con1.interfaces.int-list[0].available.ll[0]", "identity-types:Loopback"); - params.put("identity-test:test.con1.interfaces.int-list[0].available.leaf1", "identity-types-second:Ethernet"); - params.put("identity-test:test.con1.interfaces.int-list[0].available.leaf2", "identity-types-second:iden2"); + params.put("identity-test_test.con1.interface", "identity-types" + + ":physical"); + params.put("identity-test_test.con1.interfaces.int-list[0].iden", "identity-test:Giga"); + params.put("identity-test_test.con1.interfaces.int-list[0].available.ll[0]", "identity-types:Loopback"); + params.put("identity-test_test.con1.interfaces.int-list[0].available.leaf1", "identity-types-second:Ethernet"); + params.put("identity-test_test.con1.interfaces.int-list[0].available.leaf2", "identity-types-second:iden2"); InstanceIdentifierContext<?> iCtx = ParserIdentifier .toInstanceIdentifier(uri, context, null); |