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 java.util.HashMap;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.invocation.InvocationOnMock;
29 import org.mockito.stubbing.Answer;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.plugins.restapicall.HttpResponse;
33 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
34 import org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiCallNode;
35 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
36 import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
37 import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
39 import static org.hamcrest.MatcherAssert.assertThat;
40 import static org.hamcrest.core.Is.is;
41 import static org.mockito.Matchers.any;
42 import static org.mockito.Mockito.doAnswer;
43 import static org.mockito.Mockito.doCallRealMethod;
44 import static org.mockito.Mockito.doReturn;
45 import static org.mockito.Mockito.mock;
46 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.GET;
47 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PATCH;
48 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.POST;
49 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT;
50 import static org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiUtils.parseUrl;
51 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_ANYXML_RESPONSE;
52 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_JSON_RPC;
53 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_XML_RPC;
54 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_ANYXML;
55 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID;
56 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID_PUT;
57 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_RPC;
58 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG;
59 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_AUG_POST;
60 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_PUT;
61 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID;
62 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID_PUT;
63 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_RPC;
64 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG;
65 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG_AUG_POST;
66 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG_PUT;
70 * Unit test cases for data format serialization and restconf api call node.
72 public class DataFormatSerializerTest {
74 private Map<String, String> p;
76 private RestconfApiCallNode restconf;
78 private RestapiCallNode restApi;
80 private YangParserFactory parserFactory;
82 private DfCaptor dfCaptor;
85 * Sets up the pre-requisite for each test case.
87 * @throws SvcLogicException when test case fails
90 public void setUp() throws SvcLogicException {
92 p.put("restapiUser", "user1");
93 p.put("restapiPassword", "abc123");
94 p.put("responsePrefix", "response");
95 p.put("skipSending", "true");
96 restApi = new RestapiCallNode();
97 parserFactory = new YangParserFactoryImpl();
98 restconf = mock(RestconfApiCallNode.class);
99 dfCaptor = new DfCaptor();
104 * Creates method mocks using mockito for RestconfApiCallNode class.
106 * @throws SvcLogicException when test case fails
108 private void createMethodMocks() throws SvcLogicException {
109 doReturn(restApi).when(restconf).getRestapiCallNode();
110 doReturn(parserFactory).when(restconf).getParserFactory();
111 doCallRealMethod().when(restconf).sendRequest(
112 any(Map.class), any(SvcLogicContext.class));
113 doCallRealMethod().when(restconf).sendRequest(
114 any(Map.class), any(SvcLogicContext.class), any(Integer.class));
115 doAnswer(dfCaptor).when(restconf).serializeRequest(
116 any(Map.class), any(YangParameters.class), any(String.class),
117 any(InstanceIdentifierContext.class));
118 doAnswer(dfCaptor).when(restconf).updateReq(
119 any(String.class), any(YangParameters.class),
120 any(InstanceIdentifierContext.class));
124 * Creates mock using mockito with input data for decoding.
126 * @param decodeData input data
127 * @throws SvcLogicException when test case fails
129 private void createMockForDecode(String decodeData)
130 throws SvcLogicException {
131 doReturn(decodeData).when(restconf).getResponse(
132 any(SvcLogicContext.class), any(YangParameters.class),
133 any(String.class), any(HttpResponse.class));
134 doCallRealMethod().when(restconf).serializeResponse(
135 any(YangParameters.class), any(String.class), any(String.class),
136 any(InstanceIdentifierContext.class));
140 * Verifies encoding of parameters to JSON data format with identity-ref
141 * and inter-file linking.
143 * @throws SvcLogicException when test case fails
146 public void encodeToJsonId() throws SvcLogicException {
147 String pre = "identity-test_test.";
148 SvcLogicContext ctx = createAttList(pre);
149 ctx.setAttribute(pre + "l", "abc");
150 p.put("dirPath", "src/test/resources");
151 p.put("format", "json");
152 p.put("httpMethod", "post");
153 p.put("restapiUrl", "http://echo.getpostman" +
154 ".com/restconf/operations/identity-test:test");
155 restconf.sendRequest(p, ctx);
156 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID));
160 * Verifies encoding of parameters to JSON data format any xml in it.
162 * @throws SvcLogicException when test case fails
165 public void encodeForAnyXml() throws SvcLogicException {
166 String pre = "execution-service_process.";
167 SvcLogicContext ctx = createAnyXmlAttList(pre);
168 p.put("dirPath", "src/test/resources");
169 p.put("format", "json");
170 p.put("httpMethod", "post");
171 p.put("restapiUrl", "http://echo.getpostman" +
172 ".com/api/v1/execution-service/process");
173 restconf.sendRequest(p, ctx);
174 assertThat(dfCaptor.getResult(), is(ENCODE_TO_ANYXML));
178 * Verifies encoding of parameters to JSON data format with identity-ref
179 * and inter-file linking for put operation-type.
181 * @throws SvcLogicException when test case fails
184 public void encodeToJsonIdWithPut() throws SvcLogicException {
185 String pre = "identity-test_test.";
186 SvcLogicContext ctx = createAttList(pre);
187 ctx.setAttribute(pre + "l", "abc");
188 p.put("dirPath", "src/test/resources");
189 p.put("format", "json");
190 p.put("httpMethod", "put");
191 p.put("restapiUrl", "http://echo.getpostman" +
192 ".com/restconf/operations/identity-test:test");
193 restconf.sendRequest(p, ctx);
194 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID_PUT));
198 * Verifies encoding of parameters to JSON data format with identity-ref
199 * and inter-file linking for patch operation-type.
201 * @throws SvcLogicException when test case fails
204 public void encodeToJsonIdWithPatch() throws SvcLogicException {
205 String pre = "identity-test_test.";
206 SvcLogicContext ctx = createAttList(pre);
207 ctx.setAttribute(pre + "l", "abc");
208 p.put("dirPath", "src/test/resources");
209 p.put("format", "json");
210 p.put("httpMethod", "patch");
211 p.put("restapiUrl", "http://echo.getpostman" +
212 ".com/restconf/operations/identity-test:test");
213 restconf.sendRequest(p, ctx);
214 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID_PUT));
218 * Verifies encoding of parameters to XML data format with identity-ref
219 * and inter-file linking.
221 * @throws SvcLogicException when test case fails
224 public void encodeToXmlId() throws SvcLogicException {
225 String pre = "identity-test_test.";
226 SvcLogicContext ctx = createAttList(pre);
227 p.put("dirPath", "src/test/resources");
228 p.put("format", "xml");
229 p.put("httpMethod", "post");
230 p.put("restapiUrl", "http://echo.getpostman" +
231 ".com/restconf/operations/identity-test:test");
232 restconf.sendRequest(p, ctx);
233 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID));
237 * Verifies encoding of parameters to XML data format with identity-ref
238 * and inter-file linking for put operation-type.
240 * @throws SvcLogicException when test case fails
243 public void encodeToXmlIdWithPut() throws SvcLogicException {
244 String pre = "identity-test_test.";
245 SvcLogicContext ctx = createAttList(pre);
246 p.put("dirPath", "src/test/resources");
247 p.put("format", "xml");
248 p.put("httpMethod", "put");
249 p.put("restapiUrl", "http://echo.getpostman" +
250 ".com/restconf/operations/identity-test:test");
251 restconf.sendRequest(p, ctx);
252 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID_PUT));
256 * Verifies encoding of parameters to XML data format with identity-ref
257 * and inter-file linking for patch operation-type.
259 * @throws SvcLogicException when test case fails
262 public void encodeToXmlIdWithPatch() throws SvcLogicException {
263 String pre = "identity-test_test.";
264 SvcLogicContext ctx = createAttList(pre);
265 p.put("dirPath", "src/test/resources");
266 p.put("format", "xml");
267 p.put("httpMethod", "patch");
268 p.put("restapiUrl", "http://echo.getpostman" +
269 ".com/restconf/operations/identity-test:test");
270 restconf.sendRequest(p, ctx);
271 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID_PUT));
275 * Verifies decoding of parameters from JSON data format with identity-ref
276 * and inter-file linking.
278 * @throws SvcLogicException when test case fails
281 public void decodeToJsonId() throws SvcLogicException {
282 createMockForDecode(ENCODE_TO_JSON_ID);
283 SvcLogicContext ctx = new SvcLogicContext();
284 String pre = "identity-test_test.";
285 p.put("dirPath", "src/test/resources");
286 p.put("format", "json");
287 p.put("httpMethod", "get");
288 p.put("restapiUrl", "http://echo.getpostman" +
289 ".com/restconf/operations/identity-test:test");
290 restconf.sendRequest(p, ctx);
291 assertThat(ctx.getAttribute(pre + "l"), is("abc"));
292 verifyAttList(ctx, pre);
296 * Verifies decoding of parameters from XML data format with identity-ref
297 * and inter-file linking.
299 * @throws SvcLogicException when test case fails
302 public void decodeToXmlId() throws SvcLogicException {
303 createMockForDecode(ENCODE_TO_XML_ID);
304 SvcLogicContext ctx = new SvcLogicContext();
305 String pre = "identity-test_test.";
306 p.put("dirPath", "src/test/resources");
307 p.put("format", "xml");
308 p.put("httpMethod", "get");
309 p.put("restapiUrl", "http://echo.getpostman" +
310 ".com/restconf/operations/identity-test:test");
311 restconf.sendRequest(p, ctx);
312 verifyAttList(ctx, pre);
316 * Verifies encoding of parameters to JSON data format with containers,
317 * grouping and augment.
319 * @throws SvcLogicException when test case fails
322 public void encodeToJsonYang() throws SvcLogicException {
323 String pre = "test-yang_cont1.cont2.";
324 SvcLogicContext ctx = createAttListYang(pre);
325 p.put("dirPath", "src/test/resources");
326 p.put("format", "json");
327 p.put("httpMethod", "post");
328 p.put("restapiUrl", "http://echo.getpostman" +
329 ".com/restconf/operations/test-yang:cont1");
330 restconf.sendRequest(p, ctx);
331 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG));
335 * Verifies encoding of parameters to JSON data format with containers,
336 * grouping and augment for put operation-type.
338 * @throws SvcLogicException when test case fails
341 public void encodeToJsonYangWithPut() throws SvcLogicException {
342 String pre = "test-yang_cont1.cont2.";
343 SvcLogicContext ctx = createAttListYang(pre);
344 p.put("dirPath", "src/test/resources");
345 p.put("format", "json");
346 p.put("httpMethod", "put");
347 p.put("restapiUrl", "http://echo.getpostman" +
348 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
349 restconf.sendRequest(p, ctx);
350 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT));
354 * Verifies encoding of parameters to JSON data format with containers,
355 * grouping and augment for patch operation-type.
357 * @throws SvcLogicException when test case fails
360 public void encodeToJsonYangWithPatch() throws SvcLogicException {
361 String pre = "test-yang_cont1.cont2.";
362 SvcLogicContext ctx = createAttListYang(pre);
363 p.put("dirPath", "src/test/resources");
364 p.put("format", "json");
365 p.put("httpMethod", "patch");
366 p.put("restapiUrl", "http://echo.getpostman" +
367 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
368 restconf.sendRequest(p, ctx);
369 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT));
373 * Verifies encoding of parameters to JSON data format with augment as
376 * @throws SvcLogicException when test case fails
379 public void encodeToJsonWithAugAsRootChild() throws SvcLogicException {
380 String pre = "test-yang_cont1.cont2.";
381 SvcLogicContext ctx = createAttListYang(pre);
382 p.put("dirPath", "src/test/resources");
383 p.put("format", "json");
384 p.put("httpMethod", "post");
385 p.put("restapiUrl", "http://echo.getpostman" +
386 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
387 restconf.sendRequest(p, ctx);
388 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_AUG_POST));
392 * Verifies decoding of parameters from JSON data format with containers,
393 * grouping and augment.
395 * @throws SvcLogicException when test case fails
398 public void decodeToJsonYang() throws SvcLogicException {
399 createMockForDecode(ENCODE_TO_JSON_YANG);
400 SvcLogicContext ctx = new SvcLogicContext();
401 String pre = "test-yang_cont1.cont2.";
402 p.put("dirPath", "src/test/resources");
403 p.put("format", "json");
404 p.put("httpMethod", "get");
405 p.put("restapiUrl", "http://echo.getpostman" +
406 ".com/restconf/operations/test-yang:cont1");
407 restconf.sendRequest(p, ctx);
408 verifyAttListYang(ctx, pre);
412 * Verifies encoding of parameters to XML data format with containers,
413 * grouping and augment.
415 * @throws SvcLogicException when test case fails
418 public void encodeToXmlYang() throws SvcLogicException {
419 String pre = "test-yang_cont1.cont2.";
420 SvcLogicContext ctx = createAttListYang(pre);
421 p.put("dirPath", "src/test/resources");
422 p.put("format", "xml");
423 p.put("httpMethod", "post");
424 p.put("restapiUrl", "http://echo.getpostman" +
425 ".com/restconf/operations/test-yang:cont1");
426 restconf.sendRequest(p, ctx);
427 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG));
431 * Verifies encoding of parameters to XML data format with containers,
432 * grouping and augment for put operation-type
434 * @throws SvcLogicException when test case fails
437 public void encodeToXmlYangWithPut() throws SvcLogicException {
438 String pre = "test-yang_cont1.cont2.";
439 SvcLogicContext ctx = createAttListYang(pre);
440 p.put("dirPath", "src/test/resources");
441 p.put("format", "xml");
442 p.put("httpMethod", "put");
443 p.put("restapiUrl", "http://echo.getpostman" +
444 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
445 restconf.sendRequest(p, ctx);
446 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT));
450 * Verifies encoding of parameters to XML data format with containers,
451 * grouping and augment for patch operation-type
453 * @throws SvcLogicException when test case fails
456 public void encodeToXmlYangWithPatch() throws SvcLogicException {
457 String pre = "test-yang_cont1.cont2.";
458 SvcLogicContext ctx = createAttListYang(pre);
459 p.put("dirPath", "src/test/resources");
460 p.put("format", "xml");
461 p.put("httpMethod", "put");
462 p.put("restapiUrl", "http://echo.getpostman" +
463 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
464 restconf.sendRequest(p, ctx);
465 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT));
469 * Verifies encoding of parameters to XML data format with augment as
472 * @throws SvcLogicException when test case fails
475 public void encodeToXmlWithAugAsRootChild() throws SvcLogicException {
476 String pre = "test-yang_cont1.cont2.";
477 SvcLogicContext ctx = createAttListYang(pre);
478 p.put("dirPath", "src/test/resources");
479 p.put("format", "xml");
480 p.put("httpMethod", "post");
481 p.put("restapiUrl", "http://echo.getpostman" +
482 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
483 restconf.sendRequest(p, ctx);
484 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_AUG_POST));
488 * Verifies decoding of parameters from XML data format with containers,
489 * grouping and augment.
491 * @throws SvcLogicException when test case fails
494 public void decodeToXmlYang() throws SvcLogicException {
495 createMockForDecode(ENCODE_TO_XML_YANG);
496 SvcLogicContext ctx = new SvcLogicContext();
497 String pre = "test-yang_cont1.cont2.";
498 p.put("dirPath", "src/test/resources");
499 p.put("format", "xml");
500 p.put("httpMethod", "get");
501 p.put("restapiUrl", "http://echo.getpostman" +
502 ".com/restconf/operations/test-yang:cont1");
503 restconf.sendRequest(p, ctx);
504 verifyAttListYang(ctx, pre);
508 * Verifies encoding of and decoding from, JSON respectively for data
509 * format with containers, grouping and augment.
511 * @throws SvcLogicException when test case fails
514 public void codecToJsonRpc() throws SvcLogicException {
515 createMockForDecode(DECODE_FROM_JSON_RPC);
516 String inPre = "test-yang_create-sfc.input.";
517 String outPre = "test-yang_create-sfc.output.";
518 SvcLogicContext ctx = createAttListRpc(inPre);
519 p.put("dirPath", "src/test/resources");
520 p.put("format", "json");
521 p.put("httpMethod", "post");
522 p.put("restapiUrl", "http://echo.getpostman" +
523 ".com/restconf/operations/test-yang:create-sfc");
524 restconf.sendRequest(p, ctx);
525 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_RPC));
526 verifyAttListRpc(ctx, outPre);
530 * Verifies encoding of and decoding from, JSON for ANYXML.
532 * @throws SvcLogicException when test case fails
535 public void codecForNormalAnyXml() throws SvcLogicException {
536 createMockForDecode(DECODE_ANYXML_RESPONSE);
537 String inPre = "execution-service_process.";
538 SvcLogicContext ctx = createAnyXmlAttList(inPre);
539 p.put("dirPath", "src/test/resources");
540 p.put("format", "json");
541 p.put("httpMethod", "post");
542 p.put("responsePrefix", "pp");
543 p.put("restapiUrl", "http://echo.getpostman" +
544 ".com/api/v1/execution-service/process");
545 restconf.sendRequest(p, ctx);
546 assertThat(dfCaptor.getResult(), is(ENCODE_TO_ANYXML));
547 verifyOutputOfAnyXml(ctx);
551 * Verifies encoding of and decoding from, XML respectively for data
552 * format with containers, grouping and augment.
554 * @throws SvcLogicException when test case fails
557 public void codecToXmlRpc() throws SvcLogicException {
558 createMockForDecode(DECODE_FROM_XML_RPC);
559 String inPre = "test-yang_create-sfc.input.";
560 String outPre = "test-yang_create-sfc.output.";
561 SvcLogicContext ctx = createAttListRpc(inPre);
562 p.put("dirPath", "src/test/resources");
563 p.put("format", "xml");
564 p.put("httpMethod", "post");
565 p.put("restapiUrl", "http://echo.getpostman" +
566 ".com/restconf/operations/test-yang:create-sfc");
567 restconf.sendRequest(p, ctx);
568 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_RPC));
569 verifyAttListRpc(ctx, outPre);
573 * Verifies URL parser returning path with only schema information for all
576 * @throws SvcLogicException when test case fails
579 public void validateUrlParser() throws SvcLogicException {
580 String actVal = "identity-test:test";
581 String putId = "/for-put";
582 String url1 = "http://echo.getpostman.com/restconf/operations/" +
584 String url2 = "http://echo.getpostman.com/restconf/data/" + actVal;
585 String url3 = "https://echo.getpostman.com/restconf/operations/" +
587 String url4 = "https://echo.getpostman.com/restconf/data/" + actVal +
589 String url5 = "http://localhost:8282/restconf/operations/" + actVal;
590 String url6 = "https://localhost:8282/restconf/operations/" + actVal;
591 String url7 = "http://localhost:8282/restconf/data/" + actVal +
593 String url8 = "https://localhost:8282/restconf/data/" + actVal;
594 String url9 = "http://182.2.61.24:2250/restconf/data/" + actVal;
595 String url10 = "https://182.2.61.24:2250/restconf/operations/" + actVal;
596 String url11 = "https://182.2.61.24:2250/api/v1/execution-service" +
598 String url12 = "https://182.2.61.24:2250/api/v1/execution-service" +
600 String url13 = "https://182.2.61.24:2250/api/v1/execution-service" +
602 String val1 = parseUrl(url1, POST);
603 String val2 = parseUrl(url2, GET);
604 String val3 = parseUrl(url3, PATCH);
605 String val4 = parseUrl(url4, PUT);
606 String val5 = parseUrl(url5, GET);
607 String val6 = parseUrl(url6, POST);
608 String val7 = parseUrl(url7, PUT);
609 String val8 = parseUrl(url8, POST);
610 String val9 = parseUrl(url9, GET);
611 String val10 = parseUrl(url10, POST);
612 String val11 = parseUrl(url11, POST);
613 String val12 = parseUrl(url12, POST);
614 String val13 = parseUrl(url13, POST);
615 assertThat(val1, is(actVal));
616 assertThat(val2, is(actVal));
617 assertThat(val3, is(actVal));
618 assertThat(val4, is(actVal + putId));
619 assertThat(val5, is(actVal));
620 assertThat(val6, is(actVal));
621 assertThat(val7, is(actVal + putId));
622 assertThat(val8, is(actVal));
623 assertThat(val9, is(actVal));
624 assertThat(val10, is(actVal));
625 assertThat(val11, is("execution-service:process"));
626 assertThat(val12, is("execution-service:process/payload"));
627 assertThat(val13, is("execution-service:process/payload/"));
631 * Creates attribute list for encoding JSON or XML with ANYXML YANG
635 * @return service logic context
637 private SvcLogicContext createAnyXmlAttList(String pre) {
638 SvcLogicContext ctx = new SvcLogicContext();
639 String pre1 = pre + "commonHeader.";
640 String pre2 = pre + "actionIdentifiers.";
641 ctx.setAttribute(pre + "isNonAppend", "true");
642 ctx.setAttribute(pre1 + "originatorId", "SDNC_DG");
643 ctx.setAttribute(pre1 + "requestId", "123456-1000");
644 ctx.setAttribute(pre1 + "subRequestId", "sub-123456-1000");
645 ctx.setAttribute(pre2 + "blueprintName",
646 "baseconfiguration");
647 ctx.setAttribute(pre2 + "blueprintVersion", "1.0.0");
648 ctx.setAttribute(pre2 + "actionName", "assign-activate");
649 ctx.setAttribute(pre2 + "mode", "sync");
650 ctx.setAttribute(pre + "payload." +
651 "template-prefix", "vDNS-test");
652 ctx.setAttribute(pre + "payload.resource-assignment-request" +
653 ".resource-assignment-properties",
655 " \"service-instance-id\": " +
657 " \"vnf-id\": \"3526\",\n" +
658 " \"customer-name\": \"htipl\",\n" +
659 " \"subscriber-name\": \"huawei\"\n" +
665 * Creates attribute list for encoding JSON or XML with identity-ref YANG
669 * @return service logic context
671 private SvcLogicContext createAttList(String pre) {
672 SvcLogicContext ctx = new SvcLogicContext();
673 String pre1 = pre + "con1.interfaces.";
674 ctx.setAttribute(pre + "con1.interface", "identity-types:physical");
675 ctx.setAttribute(pre1 + "int-list[0].iden", "optical");
676 ctx.setAttribute(pre1 + "int-list[0].available.ll[0]", "Giga");
677 ctx.setAttribute(pre1 + "int-list[0].available.ll[1]",
678 "identity-types:Loopback");
679 ctx.setAttribute(pre1 + "int-list[0].available.ll[2]",
680 "identity-types-second:Ethernet");
681 ctx.setAttribute(pre1 + "int-list[0].available.leaf1", "58");
682 ctx.setAttribute(pre1 + "int-list[0].available.leaf2",
683 "identity-types-second:iden2");
685 ctx.setAttribute(pre1 + "int-list[1].iden", "214748364");
686 ctx.setAttribute(pre1 + "int-list[1].available.ll[0]", "Giga");
687 ctx.setAttribute(pre1 + "int-list[1].available.ll[1]",
688 "identity-types:Loopback");
689 ctx.setAttribute(pre1 + "int-list[1].available.ll[2]",
690 "identity-types-second:Ethernet");
691 ctx.setAttribute(pre1 + "int-list[1].available.leaf1",
693 ctx.setAttribute(pre1 + "int-list[1].available.leaf2",
694 "identity-types-second:iden2");
699 * Creates attribute list for encoding JSON or XML with container,
700 * grouping and augmented YANG file.
703 * @return service logic context
705 private SvcLogicContext createAttListYang(String pre) {
706 SvcLogicContext ctx = new SvcLogicContext();
707 ctx.setAttribute(pre + "cont3.leaf10", "abc");
708 ctx.setAttribute(pre + "list1[0].leaf1", "true");
709 ctx.setAttribute(pre + "list1[0].leaf2", "abc");
710 ctx.setAttribute(pre + "list1[0].leaf3", "abc");
711 ctx.setAttribute(pre + "list1[0].ll1[0]", "abc");
712 ctx.setAttribute(pre + "list1[0].ll1[1]", "abc");
713 ctx.setAttribute(pre + "list1[0].ll2[0]", "abc");
714 ctx.setAttribute(pre + "list1[0].ll2[1]", "abc");
715 ctx.setAttribute(pre + "list1[0].cont4.leaf11", "abc");
716 ctx.setAttribute(pre + "list1[0].list4[0].leaf8", "abc");
717 ctx.setAttribute(pre + "list1[0].list4[1].leaf8", "abc");
718 ctx.setAttribute(pre + "list1[0].list5[0].leaf9", "abc");
719 ctx.setAttribute(pre + "list1[0].list5[1].leaf9", "abc");
720 ctx.setAttribute(pre + "list1[1].leaf1", "true");
721 ctx.setAttribute(pre + "list1[1].leaf2", "abc");
722 ctx.setAttribute(pre + "list1[1].leaf3", "abc");
723 ctx.setAttribute(pre + "list1[1].ll1[0]", "abc");
724 ctx.setAttribute(pre + "list1[1].ll1[1]", "abc");
725 ctx.setAttribute(pre + "list1[1].ll2[0]", "abc");
726 ctx.setAttribute(pre + "list1[1].ll2[1]", "abc");
727 ctx.setAttribute(pre + "list1[1].cont4.leaf11", "abc");
728 ctx.setAttribute(pre + "list1[1].list4[0].leaf8", "abc");
729 ctx.setAttribute(pre + "list1[1].list4[1].leaf8", "abc");
730 ctx.setAttribute(pre + "list1[1].list5[0].leaf9", "abc");
731 ctx.setAttribute(pre + "list1[1].list5[1].leaf9", "abc");
732 ctx.setAttribute(pre + "list2[0].leaf4", "abc");
733 ctx.setAttribute(pre + "list2[1].leaf4", "abc");
734 ctx.setAttribute(pre + "leaf5", "abc");
735 ctx.setAttribute(pre + "leaf6", "abc");
736 ctx.setAttribute(pre + "ll3[0]", "abc");
737 ctx.setAttribute(pre + "ll3[1]", "abc");
738 ctx.setAttribute(pre + "ll4[0]", "abc");
739 ctx.setAttribute(pre + "ll4[1]", "abc");
740 ctx.setAttribute(pre + "cont4.leaf10", "abc");
741 ctx.setAttribute(pre + "list6[0].leaf11", "abc");
742 ctx.setAttribute(pre + "list6[1].leaf11", "abc");
743 ctx.setAttribute(pre + "leaf12", "abc");
744 ctx.setAttribute(pre + "ll5[0]", "abc");
745 ctx.setAttribute(pre + "ll5[1]", "abc");
746 ctx.setAttribute(pre + "cont4.test-augment_cont5.leaf13", "true");
747 ctx.setAttribute(pre + "cont4.test-augment_list7[0].leaf14", "test");
748 ctx.setAttribute(pre + "cont4.test-augment_list7[1].leaf14", "create");
749 ctx.setAttribute(pre + "cont4.test-augment_leaf15", "abc");
750 ctx.setAttribute(pre + "cont4.test-augment_ll6[0]", "unbounded");
751 ctx.setAttribute(pre + "cont4.test-augment_ll6[1]", "8");
752 ctx.setAttribute(pre + "cont4.test-augment_cont13.cont12.leaf26",
754 ctx.setAttribute(pre + "cont4.test-augment_cont13.list9[0].leaf27",
756 ctx.setAttribute(pre + "cont4.test-augment_cont13.list9[1].leaf27",
758 ctx.setAttribute(pre + "cont4.test-augment_cont13.leaf28", "abc");
759 ctx.setAttribute(pre + "cont4.test-augment_cont13.ll9[0]", "abc");
760 ctx.setAttribute(pre + "cont4.test-augment_cont13.ll9[1]", "abc");
765 * Creates attribute list for encoding JSON or XML with RPC YANG file.
768 * @return service logic context
770 private SvcLogicContext createAttListRpc(String pre) {
771 SvcLogicContext ctx = new SvcLogicContext();
772 ctx.setAttribute(pre + "cont14.leaf28", "abc");
773 ctx.setAttribute(pre + "list10[0].leaf29", "abc");
774 ctx.setAttribute(pre + "list10[1].leaf29", "abc");
775 ctx.setAttribute(pre + "leaf30", "abc");
776 ctx.setAttribute(pre + "ll10[0]", "abc");
777 ctx.setAttribute(pre + "ll10[1]", "abc");
778 ctx.setAttribute(pre + "cont15.leaf31", "abc");
779 ctx.setAttribute(pre + "cont13.list9[0].leaf27", "abc");
780 ctx.setAttribute(pre + "cont13.list9[1].leaf27", "abc");
781 ctx.setAttribute(pre + "cont13.leaf28", "abc");
782 ctx.setAttribute(pre + "cont13.ll9[0]", "abc");
783 ctx.setAttribute(pre + "cont13.ll9[1]", "abc");
788 * Verifies the attribute list for decoding from JSON or XML with
789 * identity-ref YANG file.
791 * @param ctx service logic context
794 private void verifyAttList(SvcLogicContext ctx, String pre) {
795 String pre1 = pre + "con1.interfaces.";
796 assertThat(ctx.getAttribute(pre + "con1.interface"), is(
797 "identity-types:physical"));
798 assertThat(ctx.getAttribute(pre + "con1.interface"), is(
799 "identity-types:physical"));
800 assertThat(ctx.getAttribute(pre1 + "int-list[0].iden"), is("optical"));
801 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[0]"), is(
803 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[1]"), is(
804 "identity-types:Loopback"));
805 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[2]"), is(
806 "identity-types-second:Ethernet"));
807 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf1"), is(
809 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf2"), is(
810 "identity-types-second:iden2"));
812 assertThat(ctx.getAttribute(pre1 + "int-list[1].iden"), is(
814 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[0]"), is(
816 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[1]"), is(
817 "identity-types:Loopback"));
818 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[2]"), is(
819 "identity-types-second:Ethernet"));
820 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf1"), is(
822 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf2"), is(
823 "identity-types-second:iden2"));
827 * Verifies the attribute list for decoding from JSON or XML with
828 * container, grouping and augmented file.
830 * @param ctx service logic context
833 private void verifyAttListYang(SvcLogicContext ctx, String pre) {
834 assertThat(ctx.getAttribute(pre + "cont3.leaf10"), is("abc"));
835 assertThat(ctx.getAttribute(pre + "list1[0].leaf1"), is("true"));
836 assertThat(ctx.getAttribute(pre + "list1[0].leaf2"), is("abc"));
837 assertThat(ctx.getAttribute(pre + "list1[0].leaf3"), is("abc"));
838 assertThat(ctx.getAttribute(pre + "list1[0].ll1[0]"), is("abc"));
839 assertThat(ctx.getAttribute(pre + "list1[0].ll1[1]"), is("abc"));
840 assertThat(ctx.getAttribute(pre + "list1[0].ll2[0]"), is("abc"));
841 assertThat(ctx.getAttribute(pre + "list1[0].ll2[1]"), is("abc"));
842 assertThat(ctx.getAttribute(pre + "list1[0].cont4.leaf11"), is("abc"));
843 assertThat(ctx.getAttribute(pre + "list1[0].list4[0].leaf8"),
845 assertThat(ctx.getAttribute(pre + "list1[0].list4[1].leaf8"),
847 assertThat(ctx.getAttribute(pre + "list1[0].list5[0].leaf9"),
849 assertThat(ctx.getAttribute(pre + "list1[0].list5[1].leaf9"),
851 assertThat(ctx.getAttribute(pre + "list1[1].leaf1"), is("true"));
852 assertThat(ctx.getAttribute(pre + "list1[1].leaf2"), is("abc"));
853 assertThat(ctx.getAttribute(pre + "list1[1].leaf3"), is("abc"));
854 assertThat(ctx.getAttribute(pre + "list1[1].ll1[0]"), is("abc"));
855 assertThat(ctx.getAttribute(pre + "list1[1].ll1[1]"), is("abc"));
856 assertThat(ctx.getAttribute(pre + "list1[1].ll2[0]"), is("abc"));
857 assertThat(ctx.getAttribute(pre + "list1[1].ll2[1]"), is("abc"));
858 assertThat(ctx.getAttribute(pre + "list1[1].cont4.leaf11"), is("abc"));
859 assertThat(ctx.getAttribute(pre + "list1[1].list4[0].leaf8"),
861 assertThat(ctx.getAttribute(pre + "list1[1].list4[1].leaf8"),
863 assertThat(ctx.getAttribute(pre + "list1[1].list5[0].leaf9"),
865 assertThat(ctx.getAttribute(pre + "list1[1].list5[1].leaf9"),
867 assertThat(ctx.getAttribute(pre + "list2[0].leaf4"), is("abc"));
868 assertThat(ctx.getAttribute(pre + "list2[1].leaf4"), is("abc"));
869 assertThat(ctx.getAttribute(pre + "leaf5"), is("abc"));
870 assertThat(ctx.getAttribute(pre + "leaf6"), is("abc"));
871 assertThat(ctx.getAttribute(pre + "ll3[0]"), is("abc"));
872 assertThat(ctx.getAttribute(pre + "ll3[1]"), is("abc"));
873 assertThat(ctx.getAttribute(pre + "ll4[0]"), is("abc"));
874 assertThat(ctx.getAttribute(pre + "ll4[1]"), is("abc"));
875 assertThat(ctx.getAttribute(pre + "cont4.leaf10"), is( "abc"));
876 assertThat(ctx.getAttribute(pre + "list6[0].leaf11"), is("abc"));
877 assertThat(ctx.getAttribute(pre + "list6[1].leaf11"), is("abc"));
878 assertThat(ctx.getAttribute(pre + "leaf12"), is("abc"));
879 assertThat(ctx.getAttribute(pre + "ll5[0]"), is("abc"));
880 assertThat(ctx.getAttribute(pre + "ll5[1]"), is("abc"));
881 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont5.leaf13"),
883 assertThat(ctx.getAttribute(pre + "cont4.test-augment_list7[0].leaf14"),
885 assertThat(ctx.getAttribute(pre + "cont4.test-augment_list7[1].leaf14"),
887 assertThat(ctx.getAttribute(pre + "cont4.test-augment_leaf15"),
889 assertThat(ctx.getAttribute(pre + "cont4.test-augment_ll6[0]"),
891 assertThat(ctx.getAttribute(pre + "cont4.test-augment_ll6[1]"),
893 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13" +
894 ".cont12.leaf26"), is("abc"));
895 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.list9[0]" +
896 ".leaf27"), is("abc"));
897 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.list9[1]" +
898 ".leaf27"), is("abc"));
899 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.leaf28"),
901 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.ll9[0]"),
903 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.ll9[1]"),
908 * Verifies the attribute list for decoding from JSON or XML with
911 * @param ctx service logic context
914 private void verifyAttListRpc(SvcLogicContext ctx, String pre) {
915 assertThat(ctx.getAttribute(pre + "cont16.leaf32"), is("abc"));
916 assertThat(ctx.getAttribute(pre + "list11[0].leaf33"), is("abc"));
917 assertThat(ctx.getAttribute(pre + "list11[1].leaf33"), is("abc"));
918 assertThat(ctx.getAttribute(pre + "leaf34"), is("abc"));
919 assertThat(ctx.getAttribute(pre + "ll11[0]"), is("abc"));
920 assertThat(ctx.getAttribute(pre + "ll11[1]"), is("abc"));
921 assertThat(ctx.getAttribute(pre + "cont17.leaf35"), is("abc"));
922 assertThat(ctx.getAttribute(pre + "cont13.cont12.leaf26"), is("abc"));
923 assertThat(ctx.getAttribute(pre + "cont13.list9[0].leaf27"), is("abc"));
924 assertThat(ctx.getAttribute(pre + "cont13.list9[1].leaf27"), is("abc"));
925 assertThat(ctx.getAttribute(pre + "cont13.ll9[0]"), is("abc"));
926 assertThat(ctx.getAttribute(pre + "cont13.ll9[1]"), is("abc"));
927 assertThat(ctx.getAttribute(pre + "cont13.leaf28"), is("abc"));
931 * Verifies the attribute list for decoding from JSON or XML with
934 * @param ctx service logic context
936 private void verifyOutputOfAnyXml(SvcLogicContext ctx) {
937 System.out.println(ctx.getAttribute("pp.status.eventType"));
938 assertThat(ctx.getAttribute("pp.status.eventType"), is(
939 "EVENT_COMPONENT_EXECUTED"));
940 assertThat(ctx.getAttribute("pp.actionIdentifiers.blueprintName"),
942 assertThat(ctx.getAttribute("pp.actionIdentifiers.mode"),
944 assertThat(ctx.getAttribute("pp.stepData.name"),
945 is("resource-assignment"));
946 assertThat(ctx.getAttribute("pp.status.message"),
948 assertThat(ctx.getAttribute("pp.commonHeader.originatorId"),
950 assertThat(ctx.getAttribute("pp.status.code"),
952 assertThat(ctx.getAttribute("pp.commonHeader.requestId"),
954 assertThat(ctx.getAttribute("pp.commonHeader.subRequestId"),
956 assertThat(ctx.getAttribute("pp.commonHeader.timestamp"),
957 is("2019-05-18T23:42:41.658Z"));
958 assertThat(ctx.getAttribute("pp.status.timestamp"),
959 is("2019-05-18T23:42:41.950Z"));
960 assertThat(ctx.getAttribute("pp.actionIdentifiers.blueprintV" +
961 "ersion"), is("1.0.0"));
962 assertThat(ctx.getAttribute("pp.actionIdentifiers.actionName"),
963 is("resource-assignment"));
964 assertThat(ctx.getAttribute("pp.payload.resource-assignment-resp" +
965 "onse.meshed-template.vf-module-1"),
966 is("<interface>\n <description>This i" +
967 "s the Virtual Firewall entity</description>\n" +
968 " <vfw>10.0.101.20/24</vfw>\n" +
970 assertThat(ctx.getAttribute("pp.actionIdentifiers.actionName"),
971 is("resource-assignment"));
976 * Captures the data format messages by mocking it, which can be used in
979 * @param <String> capturing data format
981 public class DfCaptor<String> implements Answer {
983 private String result;
986 * Returns the captured data format message.
988 * @return data format message.
990 public String getResult() {
995 public String answer(InvocationOnMock invocationOnMock)
997 result = (String) invocationOnMock.callRealMethod();