2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
 
   6  * ================================================================================
 
   7  * Licensed under the Apache License, Version 2.0 (the "License");
 
   8  * you may not use this file except in compliance with the License.
 
   9  * You may obtain a copy of the License at
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software
 
  14  * distributed under the License is distributed on an "AS IS" BASIS,
 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  * See the License for the specific language governing permissions and
 
  17  * limitations under the License.
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
 
  23 import org.junit.Before;
 
  24 import org.junit.Test;
 
  25 import org.mockito.invocation.InvocationOnMock;
 
  26 import org.mockito.stubbing.Answer;
 
  27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  28 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  29 import org.onap.ccsdk.sli.plugins.restapicall.HttpResponse;
 
  30 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
 
  31 import org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiCallNode;
 
  32 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 
  34 import java.util.HashMap;
 
  37 import static org.hamcrest.MatcherAssert.assertThat;
 
  38 import static org.hamcrest.core.Is.is;
 
  39 import static org.mockito.Matchers.any;
 
  40 import static org.mockito.Mockito.doAnswer;
 
  41 import static org.mockito.Mockito.doCallRealMethod;
 
  42 import static org.mockito.Mockito.doReturn;
 
  43 import static org.mockito.Mockito.mock;
 
  44 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.GET;
 
  45 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.POST;
 
  46 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT;
 
  47 import static org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiUtils.parseUrl;
 
  48 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_JSON_RPC;
 
  49 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_XML_RPC;
 
  50 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID;
 
  51 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_RPC;
 
  52 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG;
 
  53 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_AUG_POST;
 
  54 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID;
 
  55 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_RPC;
 
  56 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG;
 
  57 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG_AUG_POST;
 
  61  * Unit test cases for data format serialization and restconf api call node.
 
  63 public class DataFormatSerializerTest {
 
  65     private Map<String, String> p;
 
  67     private RestconfApiCallNode restconf;
 
  69     private RestapiCallNode restApi;
 
  71     private DfCaptor dfCaptor;
 
  74      * Sets up the pre-requisite for each test case.
 
  76      * @throws SvcLogicException when test case fails
 
  79     public void setUp() throws SvcLogicException {
 
  81         p.put("restapiUser", "user1");
 
  82         p.put("restapiPassword", "abc123");
 
  83         p.put("responsePrefix", "response");
 
  84         p.put("skipSending", "true");
 
  85         restApi = new RestapiCallNode();
 
  86         restconf = mock(RestconfApiCallNode.class);
 
  87         dfCaptor = new DfCaptor();
 
  92      * Creates method mocks using mockito for RestconfApiCallNode class.
 
  94      * @throws SvcLogicException when test case fails
 
  96     private void createMethodMocks() throws SvcLogicException {
 
  97         doReturn(restApi).when(restconf).getRestapiCallNode();
 
  98         doCallRealMethod().when(restconf).sendRequest(
 
  99                 any(Map.class), any(SvcLogicContext.class));
 
 100         doCallRealMethod().when(restconf).sendRequest(
 
 101                 any(Map.class), any(SvcLogicContext.class), any(Integer.class));
 
 102         doAnswer(dfCaptor).when(restconf).serializeRequest(
 
 103                 any(Map.class), any(YangParameters.class), any(String.class),
 
 104                 any(InstanceIdentifierContext.class));
 
 108      * Creates mock using mockito with input data for decoding.
 
 110      * @param decodeData input data
 
 111      * @throws SvcLogicException when test case fails
 
 113     private void createMockForDecode(String decodeData)
 
 114             throws SvcLogicException {
 
 115         doReturn(decodeData).when(restconf).getResponse(
 
 116                 any(SvcLogicContext.class), any(YangParameters.class),
 
 117                 any(String.class), any(HttpResponse.class));
 
 118         doCallRealMethod().when(restconf).serializeResponse(
 
 119                 any(YangParameters.class), any(String.class), any(String.class),
 
 120                 any(InstanceIdentifierContext.class));
 
 124      * Verifies encoding of parameters to JSON data format with identity-ref
 
 125      * and inter-file linking.
 
 127      * @throws SvcLogicException when test case fails
 
 130     public void encodeToJsonId() throws SvcLogicException {
 
 131         String pre = "identity-test:test.";
 
 132         SvcLogicContext ctx = createAttList(pre);
 
 133         ctx.setAttribute(pre + "l", "abc");
 
 134         p.put("dirPath", "src/test/resources");
 
 135         p.put("format", "json");
 
 136         p.put("httpMethod", "post");
 
 137         p.put("restapiUrl", "http://echo.getpostman" +
 
 138                 ".com/restconf/operations/identity-test:test");
 
 139         restconf.sendRequest(p, ctx);
 
 140         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID));
 
 144      * Verifies encoding of parameters to XML data format with identity-ref
 
 145      * and inter-file linking.
 
 147      * @throws SvcLogicException when test case fails
 
 150     public void encodeToXmlId() throws SvcLogicException {
 
 151         String pre = "identity-test:test.";
 
 152         SvcLogicContext ctx = createAttList(pre);
 
 153         p.put("dirPath", "src/test/resources");
 
 154         p.put("format", "xml");
 
 155         p.put("httpMethod", "post");
 
 156         p.put("restapiUrl", "http://echo.getpostman" +
 
 157                 ".com/restconf/operations/identity-test:test");
 
 158         restconf.sendRequest(p, ctx);
 
 159         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID));
 
 163      * Verifies decoding of parameters from JSON data format with identity-ref
 
 164      * and inter-file linking.
 
 166      * @throws SvcLogicException when test case fails
 
 169     public void decodeToJsonId() throws SvcLogicException {
 
 170         createMockForDecode(ENCODE_TO_JSON_ID);
 
 171         SvcLogicContext ctx = new SvcLogicContext();
 
 172         String pre = "identity-test:test.";
 
 173         p.put("dirPath", "src/test/resources");
 
 174         p.put("format", "json");
 
 175         p.put("httpMethod", "get");
 
 176         p.put("restapiUrl", "http://echo.getpostman" +
 
 177                 ".com/restconf/operations/identity-test:test");
 
 178         restconf.sendRequest(p, ctx);
 
 179         assertThat(ctx.getAttribute(pre + "l"), is("abc"));
 
 180         verifyAttList(ctx, pre);
 
 184      * Verifies decoding of parameters from XML data format with identity-ref
 
 185      * and inter-file linking.
 
 187      * @throws SvcLogicException when test case fails
 
 190     public void decodeToXmlId() throws SvcLogicException {
 
 191         createMockForDecode(ENCODE_TO_XML_ID);
 
 192         SvcLogicContext ctx = new SvcLogicContext();
 
 193         String pre = "identity-test:test.";
 
 194         p.put("dirPath", "src/test/resources");
 
 195         p.put("format", "xml");
 
 196         p.put("httpMethod", "get");
 
 197         p.put("restapiUrl", "http://echo.getpostman" +
 
 198                 ".com/restconf/operations/identity-test:test");
 
 199         restconf.sendRequest(p, ctx);
 
 200         verifyAttList(ctx, pre);
 
 204      * Verifies encoding of parameters to JSON data format with containers,
 
 205      * grouping and augment.
 
 207      * @throws SvcLogicException when test case fails
 
 210     public void encodeToJsonYang() throws SvcLogicException {
 
 211         String pre = "test-yang:cont1.cont2.";
 
 212         SvcLogicContext ctx = createAttListYang(pre);
 
 213         p.put("dirPath", "src/test/resources");
 
 214         p.put("format", "json");
 
 215         p.put("httpMethod", "post");
 
 216         p.put("restapiUrl", "http://echo.getpostman" +
 
 217                 ".com/restconf/operations/test-yang:cont1");
 
 218         restconf.sendRequest(p, ctx);
 
 219         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG));
 
 223      * Verifies encoding of parameters to JSON data format with augment as
 
 226      * @throws SvcLogicException when test case fails
 
 229     public void encodeToJsonWithAugAsRootChild() throws SvcLogicException {
 
 230         String pre = "test-yang:cont1.cont2.";
 
 231         SvcLogicContext ctx = createAttListYang(pre);
 
 232         p.put("dirPath", "src/test/resources");
 
 233         p.put("format", "json");
 
 234         p.put("httpMethod", "post");
 
 235         p.put("restapiUrl", "http://echo.getpostman" +
 
 236                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
 
 237         restconf.sendRequest(p, ctx);
 
 238         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_AUG_POST));
 
 242      * Verifies decoding of parameters from JSON data format with containers,
 
 243      * grouping and augment.
 
 245      * @throws SvcLogicException when test case fails
 
 248     public void decodeToJsonYang() throws SvcLogicException {
 
 249         createMockForDecode(ENCODE_TO_JSON_YANG);
 
 250         SvcLogicContext ctx = new SvcLogicContext();
 
 251         String pre = "test-yang:cont1.cont2.";
 
 252         p.put("dirPath", "src/test/resources");
 
 253         p.put("format", "json");
 
 254         p.put("httpMethod", "get");
 
 255         p.put("restapiUrl", "http://echo.getpostman" +
 
 256                 ".com/restconf/operations/test-yang:cont1");
 
 257         restconf.sendRequest(p, ctx);
 
 258         verifyAttListYang(ctx, pre);
 
 262      * Verifies encoding of parameters to XML data format with containers,
 
 263      * grouping and augment.
 
 265      * @throws SvcLogicException when test case fails
 
 268     public void encodeToXmlYang() throws SvcLogicException {
 
 269         String pre = "test-yang:cont1.cont2.";
 
 270         SvcLogicContext ctx = createAttListYang(pre);
 
 271         p.put("dirPath", "src/test/resources");
 
 272         p.put("format", "xml");
 
 273         p.put("httpMethod", "post");
 
 274         p.put("restapiUrl", "http://echo.getpostman" +
 
 275                 ".com/restconf/operations/test-yang:cont1");
 
 276         restconf.sendRequest(p, ctx);
 
 277         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG));
 
 281      * Verifies encoding of parameters to XML data format with augment as
 
 284      * @throws SvcLogicException when test case fails
 
 287     public void encodeToXmlWithAugAsRootChild() throws SvcLogicException {
 
 288         String pre = "test-yang:cont1.cont2.";
 
 289         SvcLogicContext ctx = createAttListYang(pre);
 
 290         p.put("dirPath", "src/test/resources");
 
 291         p.put("format", "xml");
 
 292         p.put("httpMethod", "post");
 
 293         p.put("restapiUrl", "http://echo.getpostman" +
 
 294                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
 
 295         restconf.sendRequest(p, ctx);
 
 296         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_AUG_POST));
 
 300      * Verifies decoding of parameters from XML data format with containers,
 
 301      * grouping and augment.
 
 303      * @throws SvcLogicException when test case fails
 
 306     public void decodeToXmlYang() throws SvcLogicException {
 
 307         createMockForDecode(ENCODE_TO_XML_YANG);
 
 308         SvcLogicContext ctx = new SvcLogicContext();
 
 309         String pre = "test-yang:cont1.cont2.";
 
 310         p.put("dirPath", "src/test/resources");
 
 311         p.put("format", "xml");
 
 312         p.put("httpMethod", "get");
 
 313         p.put("restapiUrl", "http://echo.getpostman" +
 
 314                 ".com/restconf/operations/test-yang:cont1");
 
 315         restconf.sendRequest(p, ctx);
 
 316         verifyAttListYang(ctx, pre);
 
 320      * Verifies encoding of and decoding from, JSON respectively for data
 
 321      * format with containers, grouping and augment.
 
 323      * @throws SvcLogicException when test case fails
 
 326     public void codecToJsonRpc() throws SvcLogicException {
 
 327         createMockForDecode(DECODE_FROM_JSON_RPC);
 
 328         String inPre = "test-yang:create-sfc.input.";
 
 329         String outPre = "test-yang:create-sfc.output.";
 
 330         SvcLogicContext ctx = createAttListRpc(inPre);
 
 331         p.put("dirPath", "src/test/resources");
 
 332         p.put("format", "json");
 
 333         p.put("httpMethod", "post");
 
 334         p.put("restapiUrl", "http://echo.getpostman" +
 
 335                 ".com/restconf/operations/test-yang:create-sfc");
 
 336         restconf.sendRequest(p, ctx);
 
 337         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_RPC));
 
 338         verifyAttListRpc(ctx, outPre);
 
 342      * Verifies encoding of and decoding from, XML respectively for data
 
 343      * format with containers, grouping and augment.
 
 345      * @throws SvcLogicException when test case fails
 
 348     public void codecToXmlRpc() throws SvcLogicException {
 
 349         createMockForDecode(DECODE_FROM_XML_RPC);
 
 350         String inPre = "test-yang:create-sfc.input.";
 
 351         String outPre = "test-yang:create-sfc.output.";
 
 352         SvcLogicContext ctx = createAttListRpc(inPre);
 
 353         p.put("dirPath", "src/test/resources");
 
 354         p.put("format", "xml");
 
 355         p.put("httpMethod", "post");
 
 356         p.put("restapiUrl", "http://echo.getpostman" +
 
 357                 ".com/restconf/operations/test-yang:create-sfc");
 
 358         restconf.sendRequest(p, ctx);
 
 359         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_RPC));
 
 360         verifyAttListRpc(ctx, outPre);
 
 364      * Verifies URL parser returning path with only schema information for all
 
 367      * @throws SvcLogicException when test case fails
 
 370     public void validateUrlParser() throws SvcLogicException {
 
 371         String actVal = "identity-test:test";
 
 372         String url1 = "http://echo.getpostman.com/restconf/operations/" +
 
 374         String url2 = "http://echo.getpostman.com/restconf/data/" + actVal;
 
 375         String url3 = "https://echo.getpostman.com/restconf/operations/" +
 
 377         String url4 = "https://echo.getpostman.com/restconf/data/" + actVal +
 
 379         String url5 = "http://localhost:8282/restconf/operations/" + actVal;
 
 380         String url6 = "https://localhost:8282/restconf/operations/" + actVal;
 
 381         String url7 = "http://localhost:8282/restconf/data/" + actVal +
 
 383         String url8 = "https://localhost:8282/restconf/data/" + actVal;
 
 384         String url9 = "http://182.2.61.24:2250/restconf/data/" + actVal;
 
 385         String url10 = "https://182.2.61.24:2250/restconf/operations/" + actVal;
 
 386         String val1 = parseUrl(url1, POST);
 
 387         String val2 = parseUrl(url2, GET);
 
 388         String val3 = parseUrl(url3, POST);
 
 389         String val4 = parseUrl(url4, PUT);
 
 390         String val5 = parseUrl(url5, GET);
 
 391         String val6 = parseUrl(url6, POST);
 
 392         String val7 = parseUrl(url7, PUT);
 
 393         String val8 = parseUrl(url8, POST);
 
 394         String val9 = parseUrl(url9, GET);
 
 395         String val10 = parseUrl(url10, POST);
 
 396         assertThat(val1, is(actVal));
 
 397         assertThat(val2, is(actVal));
 
 398         assertThat(val3, is(actVal));
 
 399         assertThat(val4, is(actVal));
 
 400         assertThat(val5, is(actVal));
 
 401         assertThat(val6, is(actVal));
 
 402         assertThat(val7, is(actVal));
 
 403         assertThat(val8, is(actVal));
 
 404         assertThat(val9, is(actVal));
 
 405         assertThat(val10, is(actVal));
 
 409      * Creates attribute list for encoding JSON or XML with identity-ref YANG
 
 413      * @return service logic context
 
 415     private SvcLogicContext createAttList(String pre) {
 
 416         SvcLogicContext ctx = new SvcLogicContext();
 
 417         String pre1 = pre + "con1.interfaces.";
 
 418         ctx.setAttribute(pre + "con1.interface", "identity-types:physical");
 
 419         ctx.setAttribute(pre1 + "int-list[0].iden", "optical");
 
 420         ctx.setAttribute(pre1 + "int-list[0].available.ll[0]", "Giga");
 
 421         ctx.setAttribute(pre1 + "int-list[0].available.ll[1]",
 
 422                          "identity-types:Loopback");
 
 423         ctx.setAttribute(pre1 + "int-list[0].available.ll[2]",
 
 424                          "identity-types-second:Ethernet");
 
 425         ctx.setAttribute(pre1 + "int-list[0].available.leaf1", "58");
 
 426         ctx.setAttribute(pre1 + "int-list[0].available.leaf2",
 
 427                          "identity-types-second:iden2");
 
 429         ctx.setAttribute(pre1 + "int-list[1].iden", "214748364");
 
 430         ctx.setAttribute(pre1 + "int-list[1].available.ll[0]", "Giga");
 
 431         ctx.setAttribute(pre1 + "int-list[1].available.ll[1]",
 
 432                          "identity-types:Loopback");
 
 433         ctx.setAttribute(pre1 + "int-list[1].available.ll[2]",
 
 434                          "identity-types-second:Ethernet");
 
 435         ctx.setAttribute(pre1 + "int-list[1].available.leaf1",
 
 437         ctx.setAttribute(pre1 + "int-list[1].available.leaf2",
 
 438                          "identity-types-second:iden2");
 
 443      * Creates attribute list for encoding JSON or XML with container,
 
 444      * grouping and augmented YANG file.
 
 447      * @return service logic context
 
 449     private SvcLogicContext createAttListYang(String pre) {
 
 450         SvcLogicContext ctx = new SvcLogicContext();
 
 451         ctx.setAttribute(pre + "cont3.leaf10", "abc");
 
 452         ctx.setAttribute(pre + "list1[0].leaf1", "true");
 
 453         ctx.setAttribute(pre + "list1[0].leaf2", "abc");
 
 454         ctx.setAttribute(pre + "list1[0].leaf3", "abc");
 
 455         ctx.setAttribute(pre + "list1[0].ll1[0]", "abc");
 
 456         ctx.setAttribute(pre + "list1[0].ll1[1]", "abc");
 
 457         ctx.setAttribute(pre + "list1[0].ll2[0]", "abc");
 
 458         ctx.setAttribute(pre + "list1[0].ll2[1]", "abc");
 
 459         ctx.setAttribute(pre + "list1[0].cont4.leaf11", "abc");
 
 460         ctx.setAttribute(pre + "list1[0].list4[0].leaf8", "abc");
 
 461         ctx.setAttribute(pre + "list1[0].list4[1].leaf8", "abc");
 
 462         ctx.setAttribute(pre + "list1[0].list5[0].leaf9", "abc");
 
 463         ctx.setAttribute(pre + "list1[0].list5[1].leaf9", "abc");
 
 464         ctx.setAttribute(pre + "list1[1].leaf1", "true");
 
 465         ctx.setAttribute(pre + "list1[1].leaf2", "abc");
 
 466         ctx.setAttribute(pre + "list1[1].leaf3", "abc");
 
 467         ctx.setAttribute(pre + "list1[1].ll1[0]", "abc");
 
 468         ctx.setAttribute(pre + "list1[1].ll1[1]", "abc");
 
 469         ctx.setAttribute(pre + "list1[1].ll2[0]", "abc");
 
 470         ctx.setAttribute(pre + "list1[1].ll2[1]", "abc");
 
 471         ctx.setAttribute(pre + "list1[1].cont4.leaf11", "abc");
 
 472         ctx.setAttribute(pre + "list1[1].list4[0].leaf8", "abc");
 
 473         ctx.setAttribute(pre + "list1[1].list4[1].leaf8", "abc");
 
 474         ctx.setAttribute(pre + "list1[1].list5[0].leaf9", "abc");
 
 475         ctx.setAttribute(pre + "list1[1].list5[1].leaf9", "abc");
 
 476         ctx.setAttribute(pre + "list2[0].leaf4", "abc");
 
 477         ctx.setAttribute(pre + "list2[1].leaf4", "abc");
 
 478         ctx.setAttribute(pre + "leaf5", "abc");
 
 479         ctx.setAttribute(pre + "leaf6", "abc");
 
 480         ctx.setAttribute(pre + "ll3[0]", "abc");
 
 481         ctx.setAttribute(pre + "ll3[1]", "abc");
 
 482         ctx.setAttribute(pre + "ll4[0]", "abc");
 
 483         ctx.setAttribute(pre + "ll4[1]", "abc");
 
 484         ctx.setAttribute(pre + "cont4.leaf10", "abc");
 
 485         ctx.setAttribute(pre + "list6[0].leaf11", "abc");
 
 486         ctx.setAttribute(pre + "list6[1].leaf11", "abc");
 
 487         ctx.setAttribute(pre + "leaf12", "abc");
 
 488         ctx.setAttribute(pre + "ll5[0]", "abc");
 
 489         ctx.setAttribute(pre + "ll5[1]", "abc");
 
 490         ctx.setAttribute(pre + "cont4.test-augment:cont5.leaf13", "true");
 
 491         ctx.setAttribute(pre + "cont4.test-augment:list7[0].leaf14", "test");
 
 492         ctx.setAttribute(pre + "cont4.test-augment:list7[1].leaf14", "create");
 
 493         ctx.setAttribute(pre + "cont4.test-augment:leaf15", "abc");
 
 494         ctx.setAttribute(pre + "cont4.test-augment:ll6[0]", "unbounded");
 
 495         ctx.setAttribute(pre + "cont4.test-augment:ll6[1]", "8");
 
 496         ctx.setAttribute(pre + "cont4.test-augment:cont13.cont12.leaf26",
 
 498         ctx.setAttribute(pre + "cont4.test-augment:cont13.list9[0].leaf27",
 
 500         ctx.setAttribute(pre + "cont4.test-augment:cont13.list9[1].leaf27",
 
 502         ctx.setAttribute(pre + "cont4.test-augment:cont13.leaf28", "abc");
 
 503         ctx.setAttribute(pre + "cont4.test-augment:cont13.ll9[0]", "abc");
 
 504         ctx.setAttribute(pre + "cont4.test-augment:cont13.ll9[1]", "abc");
 
 509      * Creates attribute list for encoding JSON or XML with RPC YANG file.
 
 512      * @return service logic context
 
 514     private SvcLogicContext createAttListRpc(String pre) {
 
 515         SvcLogicContext ctx = new SvcLogicContext();
 
 516         ctx.setAttribute(pre + "cont14.leaf28", "abc");
 
 517         ctx.setAttribute(pre + "list10[0].leaf29", "abc");
 
 518         ctx.setAttribute(pre + "list10[1].leaf29", "abc");
 
 519         ctx.setAttribute(pre + "leaf30", "abc");
 
 520         ctx.setAttribute(pre + "ll10[0]", "abc");
 
 521         ctx.setAttribute(pre + "ll10[1]", "abc");
 
 522         ctx.setAttribute(pre + "cont15.leaf31", "abc");
 
 523         ctx.setAttribute(pre + "cont13.list9[0].leaf27", "abc");
 
 524         ctx.setAttribute(pre + "cont13.list9[1].leaf27", "abc");
 
 525         ctx.setAttribute(pre + "cont13.leaf28", "abc");
 
 526         ctx.setAttribute(pre + "cont13.ll9[0]", "abc");
 
 527         ctx.setAttribute(pre + "cont13.ll9[1]", "abc");
 
 532      * Verifies the attribute list for decoding from JSON or XML with
 
 533      * identity-ref YANG file.
 
 535      * @param ctx service logic context
 
 538     private void verifyAttList(SvcLogicContext ctx, String pre) {
 
 539         String pre1 = pre + "con1.interfaces.";
 
 540         assertThat(ctx.getAttribute(pre + "con1.interface"), is(
 
 541                 "identity-types:physical"));
 
 542         assertThat(ctx.getAttribute(pre + "con1.interface"), is(
 
 543                 "identity-types:physical"));
 
 544         assertThat(ctx.getAttribute(pre1 + "int-list[0].iden"), is("optical"));
 
 545         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[0]"), is(
 
 547         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[1]"), is(
 
 548                 "identity-types:Loopback"));
 
 549         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[2]"), is(
 
 550                 "identity-types-second:Ethernet"));
 
 551         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf1"), is(
 
 553         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf2"), is(
 
 554                 "identity-types-second:iden2"));
 
 556         assertThat(ctx.getAttribute(pre1 + "int-list[1].iden"), is(
 
 558         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[0]"), is(
 
 560         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[1]"), is(
 
 561                 "identity-types:Loopback"));
 
 562         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[2]"), is(
 
 563                 "identity-types-second:Ethernet"));
 
 564         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf1"), is(
 
 566         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf2"), is(
 
 567                 "identity-types-second:iden2"));
 
 571      * Verifies the attribute list for decoding from JSON or XML with
 
 572      * container, grouping and augmented file.
 
 574      * @param ctx service logic context
 
 577     private void verifyAttListYang(SvcLogicContext ctx, String pre) {
 
 578         assertThat(ctx.getAttribute(pre + "cont3.leaf10"), is("abc"));
 
 579         assertThat(ctx.getAttribute(pre + "list1[0].leaf1"), is("true"));
 
 580         assertThat(ctx.getAttribute(pre + "list1[0].leaf2"), is("abc"));
 
 581         assertThat(ctx.getAttribute(pre + "list1[0].leaf3"), is("abc"));
 
 582         assertThat(ctx.getAttribute(pre + "list1[0].ll1[0]"), is("abc"));
 
 583         assertThat(ctx.getAttribute(pre + "list1[0].ll1[1]"), is("abc"));
 
 584         assertThat(ctx.getAttribute(pre + "list1[0].ll2[0]"), is("abc"));
 
 585         assertThat(ctx.getAttribute(pre + "list1[0].ll2[1]"), is("abc"));
 
 586         assertThat(ctx.getAttribute(pre + "list1[0].cont4.leaf11"), is("abc"));
 
 587         assertThat(ctx.getAttribute(pre + "list1[0].list4[0].leaf8"),
 
 589         assertThat(ctx.getAttribute(pre + "list1[0].list4[1].leaf8"),
 
 591         assertThat(ctx.getAttribute(pre + "list1[0].list5[0].leaf9"),
 
 593         assertThat(ctx.getAttribute(pre + "list1[0].list5[1].leaf9"),
 
 595         assertThat(ctx.getAttribute(pre + "list1[1].leaf1"), is("true"));
 
 596         assertThat(ctx.getAttribute(pre + "list1[1].leaf2"), is("abc"));
 
 597         assertThat(ctx.getAttribute(pre + "list1[1].leaf3"), is("abc"));
 
 598         assertThat(ctx.getAttribute(pre + "list1[1].ll1[0]"), is("abc"));
 
 599         assertThat(ctx.getAttribute(pre + "list1[1].ll1[1]"), is("abc"));
 
 600         assertThat(ctx.getAttribute(pre + "list1[1].ll2[0]"), is("abc"));
 
 601         assertThat(ctx.getAttribute(pre + "list1[1].ll2[1]"), is("abc"));
 
 602         assertThat(ctx.getAttribute(pre + "list1[1].cont4.leaf11"), is("abc"));
 
 603         assertThat(ctx.getAttribute(pre + "list1[1].list4[0].leaf8"),
 
 605         assertThat(ctx.getAttribute(pre + "list1[1].list4[1].leaf8"),
 
 607         assertThat(ctx.getAttribute(pre + "list1[1].list5[0].leaf9"),
 
 609         assertThat(ctx.getAttribute(pre + "list1[1].list5[1].leaf9"),
 
 611         assertThat(ctx.getAttribute(pre + "list2[0].leaf4"), is("abc"));
 
 612         assertThat(ctx.getAttribute(pre + "list2[1].leaf4"), is("abc"));
 
 613         assertThat(ctx.getAttribute(pre + "leaf5"), is("abc"));
 
 614         assertThat(ctx.getAttribute(pre + "leaf6"), is("abc"));
 
 615         assertThat(ctx.getAttribute(pre + "ll3[0]"), is("abc"));
 
 616         assertThat(ctx.getAttribute(pre + "ll3[1]"), is("abc"));
 
 617         assertThat(ctx.getAttribute(pre + "ll4[0]"), is("abc"));
 
 618         assertThat(ctx.getAttribute(pre + "ll4[1]"), is("abc"));
 
 619         assertThat(ctx.getAttribute(pre + "cont4.leaf10"), is( "abc"));
 
 620         assertThat(ctx.getAttribute(pre + "list6[0].leaf11"), is("abc"));
 
 621         assertThat(ctx.getAttribute(pre + "list6[1].leaf11"), is("abc"));
 
 622         assertThat(ctx.getAttribute(pre + "leaf12"), is("abc"));
 
 623         assertThat(ctx.getAttribute(pre + "ll5[0]"), is("abc"));
 
 624         assertThat(ctx.getAttribute(pre + "ll5[1]"), is("abc"));
 
 625         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont5.leaf13"),
 
 627         assertThat(ctx.getAttribute(pre + "cont4.test-augment:list7[0].leaf14"),
 
 629         assertThat(ctx.getAttribute(pre + "cont4.test-augment:list7[1].leaf14"),
 
 631         assertThat(ctx.getAttribute(pre + "cont4.test-augment:leaf15"),
 
 633         assertThat(ctx.getAttribute(pre + "cont4.test-augment:ll6[0]"),
 
 635         assertThat(ctx.getAttribute(pre + "cont4.test-augment:ll6[1]"),
 
 637         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13" +
 
 638                                             ".cont12.leaf26"), is("abc"));
 
 639         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.list9[0]" +
 
 640                                             ".leaf27"), is("abc"));
 
 641         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.list9[1]" +
 
 642                                             ".leaf27"), is("abc"));
 
 643         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.leaf28"),
 
 645         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.ll9[0]"),
 
 647         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.ll9[1]"),
 
 652      * Verifies the attribute list for decoding from JSON or XML with
 
 655      * @param ctx service logic context
 
 658     private void verifyAttListRpc(SvcLogicContext ctx, String pre) {
 
 659         assertThat(ctx.getAttribute(pre + "cont16.leaf32"), is("abc"));
 
 660         assertThat(ctx.getAttribute(pre + "list11[0].leaf33"), is("abc"));
 
 661         assertThat(ctx.getAttribute(pre + "list11[1].leaf33"), is("abc"));
 
 662         assertThat(ctx.getAttribute(pre + "leaf34"), is("abc"));
 
 663         assertThat(ctx.getAttribute(pre + "ll11[0]"), is("abc"));
 
 664         assertThat(ctx.getAttribute(pre + "ll11[1]"), is("abc"));
 
 665         assertThat(ctx.getAttribute(pre + "cont17.leaf35"), is("abc"));
 
 666         assertThat(ctx.getAttribute(pre + "cont13.cont12.leaf26"), is("abc"));
 
 667         assertThat(ctx.getAttribute(pre + "cont13.list9[0].leaf27"), is("abc"));
 
 668         assertThat(ctx.getAttribute(pre + "cont13.list9[1].leaf27"), is("abc"));
 
 669         assertThat(ctx.getAttribute(pre + "cont13.ll9[0]"), is("abc"));
 
 670         assertThat(ctx.getAttribute(pre + "cont13.ll9[1]"), is("abc"));
 
 671         assertThat(ctx.getAttribute(pre + "cont13.leaf28"), is("abc"));
 
 675      * Captures the data format messages by mocking it, which can be used in
 
 678      * @param <String> capturing data format
 
 680     public class DfCaptor<String> implements Answer {
 
 682         private String result;
 
 685          * Returns the captured data format message.
 
 687          * @return data format message.
 
 689         public String getResult() {
 
 694         public String answer(InvocationOnMock invocationOnMock)
 
 696             result = (String) invocationOnMock.callRealMethod();