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.parser.api.YangParserFactory;
37 import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory;
39 import static org.hamcrest.MatcherAssert.assertThat;
40 import static org.hamcrest.core.Is.is;
41 import static org.mockito.ArgumentMatchers.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 DefaultYangParserFactory();
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 * Fails for potassium - commenting out for now
167 public void encodeForAnyXml() throws SvcLogicException {
168 String pre = "execution-service_process.";
169 SvcLogicContext ctx = createAnyXmlAttList(pre);
170 p.put("dirPath", "src/test/resources");
171 p.put("format", "json");
172 p.put("httpMethod", "post");
173 p.put("restapiUrl", "http://echo.getpostman" +
174 ".com/api/v1/execution-service/process");
175 restconf.sendRequest(p, ctx);
176 assertThat(dfCaptor.getResult(), is(ENCODE_TO_ANYXML));
181 * Verifies encoding of parameters to JSON data format with identity-ref
182 * and inter-file linking for put operation-type.
184 * @throws SvcLogicException when test case fails
187 public void encodeToJsonIdWithPut() throws SvcLogicException {
188 String pre = "identity-test_test.";
189 SvcLogicContext ctx = createAttList(pre);
190 ctx.setAttribute(pre + "l", "abc");
191 p.put("dirPath", "src/test/resources");
192 p.put("format", "json");
193 p.put("httpMethod", "put");
194 p.put("restapiUrl", "http://echo.getpostman" +
195 ".com/restconf/operations/identity-test:test");
196 restconf.sendRequest(p, ctx);
197 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID_PUT));
201 * Verifies encoding of parameters to JSON data format with identity-ref
202 * and inter-file linking for patch operation-type.
204 * @throws SvcLogicException when test case fails
207 public void encodeToJsonIdWithPatch() throws SvcLogicException {
208 String pre = "identity-test_test.";
209 SvcLogicContext ctx = createAttList(pre);
210 ctx.setAttribute(pre + "l", "abc");
211 p.put("dirPath", "src/test/resources");
212 p.put("format", "json");
213 p.put("httpMethod", "patch");
214 p.put("restapiUrl", "http://echo.getpostman" +
215 ".com/restconf/operations/identity-test:test");
216 restconf.sendRequest(p, ctx);
217 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID_PUT));
221 * Verifies encoding of parameters to XML data format with identity-ref
222 * and inter-file linking.
224 * @throws SvcLogicException when test case fails
227 public void encodeToXmlId() throws SvcLogicException {
228 String pre = "identity-test_test.";
229 SvcLogicContext ctx = createAttList(pre);
230 p.put("dirPath", "src/test/resources");
231 p.put("format", "xml");
232 p.put("httpMethod", "post");
233 p.put("restapiUrl", "http://echo.getpostman" +
234 ".com/restconf/operations/identity-test:test");
235 restconf.sendRequest(p, ctx);
236 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID));
240 * Verifies encoding of parameters to XML data format with identity-ref
241 * and inter-file linking for put operation-type.
243 * @throws SvcLogicException when test case fails
246 public void encodeToXmlIdWithPut() throws SvcLogicException {
247 String pre = "identity-test_test.";
248 SvcLogicContext ctx = createAttList(pre);
249 p.put("dirPath", "src/test/resources");
250 p.put("format", "xml");
251 p.put("httpMethod", "put");
252 p.put("restapiUrl", "http://echo.getpostman" +
253 ".com/restconf/operations/identity-test:test");
254 restconf.sendRequest(p, ctx);
255 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID_PUT));
259 * Verifies encoding of parameters to XML data format with identity-ref
260 * and inter-file linking for patch operation-type.
262 * @throws SvcLogicException when test case fails
265 public void encodeToXmlIdWithPatch() throws SvcLogicException {
266 String pre = "identity-test_test.";
267 SvcLogicContext ctx = createAttList(pre);
268 p.put("dirPath", "src/test/resources");
269 p.put("format", "xml");
270 p.put("httpMethod", "patch");
271 p.put("restapiUrl", "http://echo.getpostman" +
272 ".com/restconf/operations/identity-test:test");
273 restconf.sendRequest(p, ctx);
274 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID_PUT));
278 * Verifies decoding of parameters from JSON data format with identity-ref
279 * and inter-file linking.
281 * @throws SvcLogicException when test case fails
284 public void decodeToJsonId() throws SvcLogicException {
285 createMockForDecode(ENCODE_TO_JSON_ID);
286 SvcLogicContext ctx = new SvcLogicContext();
287 String pre = "identity-test_test.";
288 p.put("dirPath", "src/test/resources");
289 p.put("format", "json");
290 p.put("httpMethod", "get");
291 p.put("restapiUrl", "http://echo.getpostman" +
292 ".com/restconf/operations/identity-test:test");
293 restconf.sendRequest(p, ctx);
294 assertThat(ctx.getAttribute(pre + "l"), is("abc"));
295 verifyAttList(ctx, pre);
299 * Verifies decoding of parameters from XML data format with identity-ref
300 * and inter-file linking.
302 * @throws SvcLogicException when test case fails
305 public void decodeToXmlId() throws SvcLogicException {
306 createMockForDecode(ENCODE_TO_XML_ID);
307 SvcLogicContext ctx = new SvcLogicContext();
308 String pre = "identity-test_test.";
309 p.put("dirPath", "src/test/resources");
310 p.put("format", "xml");
311 p.put("httpMethod", "get");
312 p.put("restapiUrl", "http://echo.getpostman" +
313 ".com/restconf/operations/identity-test:test");
314 restconf.sendRequest(p, ctx);
315 verifyAttList(ctx, pre);
319 * Verifies encoding of parameters to JSON data format with containers,
320 * grouping and augment.
322 * @throws SvcLogicException when test case fails
325 public void encodeToJsonYang() throws SvcLogicException {
326 String pre = "test-yang_cont1.cont2.";
327 SvcLogicContext ctx = createAttListYang(pre);
328 p.put("dirPath", "src/test/resources");
329 p.put("format", "json");
330 p.put("httpMethod", "post");
331 p.put("restapiUrl", "http://echo.getpostman" +
332 ".com/restconf/operations/test-yang:cont1");
333 restconf.sendRequest(p, ctx);
334 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG));
338 * Verifies encoding of parameters to JSON data format with containers,
339 * grouping and augment for put operation-type.
341 * @throws SvcLogicException when test case fails
344 public void encodeToJsonYangWithPut() throws SvcLogicException {
345 String pre = "test-yang_cont1.cont2.";
346 SvcLogicContext ctx = createAttListYang(pre);
347 p.put("dirPath", "src/test/resources");
348 p.put("format", "json");
349 p.put("httpMethod", "put");
350 p.put("restapiUrl", "http://echo.getpostman" +
351 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
352 restconf.sendRequest(p, ctx);
353 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT));
357 * Verifies encoding of parameters to JSON data format with containers,
358 * grouping and augment for patch operation-type.
360 * @throws SvcLogicException when test case fails
363 public void encodeToJsonYangWithPatch() throws SvcLogicException {
364 String pre = "test-yang_cont1.cont2.";
365 SvcLogicContext ctx = createAttListYang(pre);
366 p.put("dirPath", "src/test/resources");
367 p.put("format", "json");
368 p.put("httpMethod", "patch");
369 p.put("restapiUrl", "http://echo.getpostman" +
370 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
371 restconf.sendRequest(p, ctx);
372 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT));
376 * Verifies encoding of parameters to JSON data format with augment as
379 * @throws SvcLogicException when test case fails
382 public void encodeToJsonWithAugAsRootChild() throws SvcLogicException {
383 String pre = "test-yang_cont1.cont2.";
384 SvcLogicContext ctx = createAttListYang(pre);
385 p.put("dirPath", "src/test/resources");
386 p.put("format", "json");
387 p.put("httpMethod", "post");
388 p.put("restapiUrl", "http://echo.getpostman" +
389 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
390 restconf.sendRequest(p, ctx);
391 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_AUG_POST));
395 * Verifies decoding of parameters from JSON data format with containers,
396 * grouping and augment.
398 * @throws SvcLogicException when test case fails
401 public void decodeToJsonYang() throws SvcLogicException {
402 createMockForDecode(ENCODE_TO_JSON_YANG);
403 SvcLogicContext ctx = new SvcLogicContext();
404 String pre = "test-yang_cont1.cont2.";
405 p.put("dirPath", "src/test/resources");
406 p.put("format", "json");
407 p.put("httpMethod", "get");
408 p.put("restapiUrl", "http://echo.getpostman" +
409 ".com/restconf/operations/test-yang:cont1");
410 restconf.sendRequest(p, ctx);
411 verifyAttListYang(ctx, pre);
415 * Verifies encoding of parameters to XML data format with containers,
416 * grouping and augment.
418 * @throws SvcLogicException when test case fails
421 public void encodeToXmlYang() throws SvcLogicException {
422 String pre = "test-yang_cont1.cont2.";
423 SvcLogicContext ctx = createAttListYang(pre);
424 p.put("dirPath", "src/test/resources");
425 p.put("format", "xml");
426 p.put("httpMethod", "post");
427 p.put("restapiUrl", "http://echo.getpostman" +
428 ".com/restconf/operations/test-yang:cont1");
429 restconf.sendRequest(p, ctx);
430 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG));
434 * Verifies encoding of parameters to XML data format with containers,
435 * grouping and augment for put operation-type
437 * @throws SvcLogicException when test case fails
440 public void encodeToXmlYangWithPut() throws SvcLogicException {
441 String pre = "test-yang_cont1.cont2.";
442 SvcLogicContext ctx = createAttListYang(pre);
443 p.put("dirPath", "src/test/resources");
444 p.put("format", "xml");
445 p.put("httpMethod", "put");
446 p.put("restapiUrl", "http://echo.getpostman" +
447 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
448 restconf.sendRequest(p, ctx);
449 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT));
453 * Verifies encoding of parameters to XML data format with containers,
454 * grouping and augment for patch operation-type
456 * @throws SvcLogicException when test case fails
459 public void encodeToXmlYangWithPatch() throws SvcLogicException {
460 String pre = "test-yang_cont1.cont2.";
461 SvcLogicContext ctx = createAttListYang(pre);
462 p.put("dirPath", "src/test/resources");
463 p.put("format", "xml");
464 p.put("httpMethod", "put");
465 p.put("restapiUrl", "http://echo.getpostman" +
466 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
467 restconf.sendRequest(p, ctx);
468 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT));
472 * Verifies encoding of parameters to XML data format with augment as
475 * @throws SvcLogicException when test case fails
478 public void encodeToXmlWithAugAsRootChild() throws SvcLogicException {
479 String pre = "test-yang_cont1.cont2.";
480 SvcLogicContext ctx = createAttListYang(pre);
481 p.put("dirPath", "src/test/resources");
482 p.put("format", "xml");
483 p.put("httpMethod", "post");
484 p.put("restapiUrl", "http://echo.getpostman" +
485 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
486 restconf.sendRequest(p, ctx);
487 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_AUG_POST));
491 * Verifies decoding of parameters from XML data format with containers,
492 * grouping and augment.
494 * @throws SvcLogicException when test case fails
497 public void decodeToXmlYang() throws SvcLogicException {
498 createMockForDecode(ENCODE_TO_XML_YANG);
499 SvcLogicContext ctx = new SvcLogicContext();
500 String pre = "test-yang_cont1.cont2.";
501 p.put("dirPath", "src/test/resources");
502 p.put("format", "xml");
503 p.put("httpMethod", "get");
504 p.put("restapiUrl", "http://echo.getpostman" +
505 ".com/restconf/operations/test-yang:cont1");
506 restconf.sendRequest(p, ctx);
507 verifyAttListYang(ctx, pre);
511 * Verifies encoding of and decoding from, JSON respectively for data
512 * format with containers, grouping and augment.
514 * @throws SvcLogicException when test case fails
517 public void codecToJsonRpc() throws SvcLogicException {
518 createMockForDecode(DECODE_FROM_JSON_RPC);
519 String inPre = "test-yang_create-sfc.input.";
520 String outPre = "test-yang_create-sfc.output.";
521 SvcLogicContext ctx = createAttListRpc(inPre);
522 p.put("dirPath", "src/test/resources");
523 p.put("format", "json");
524 p.put("httpMethod", "post");
525 p.put("restapiUrl", "http://echo.getpostman" +
526 ".com/restconf/operations/test-yang:create-sfc");
527 restconf.sendRequest(p, ctx);
528 assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_RPC));
529 verifyAttListRpc(ctx, outPre);
533 * Verifies encoding of and decoding from, JSON for ANYXML.
535 * @throws SvcLogicException when test case fails
538 * Fails with ODL Potassium. Commenting out for now
540 public void codecForNormalAnyXml() throws SvcLogicException {
541 createMockForDecode(DECODE_ANYXML_RESPONSE);
542 String inPre = "execution-service_process.";
543 SvcLogicContext ctx = createAnyXmlAttList(inPre);
544 p.put("dirPath", "src/test/resources");
545 p.put("format", "json");
546 p.put("httpMethod", "post");
547 p.put("responsePrefix", "pp");
548 p.put("restapiUrl", "http://echo.getpostman" +
549 ".com/api/v1/execution-service/process");
550 restconf.sendRequest(p, ctx);
551 assertThat(dfCaptor.getResult(), is(ENCODE_TO_ANYXML));
552 verifyOutputOfAnyXml(ctx);
557 * Verifies encoding of and decoding from, XML respectively for data
558 * format with containers, grouping and augment.
560 * @throws SvcLogicException when test case fails
563 public void codecToXmlRpc() throws SvcLogicException {
564 createMockForDecode(DECODE_FROM_XML_RPC);
565 String inPre = "test-yang_create-sfc.input.";
566 String outPre = "test-yang_create-sfc.output.";
567 SvcLogicContext ctx = createAttListRpc(inPre);
568 p.put("dirPath", "src/test/resources");
569 p.put("format", "xml");
570 p.put("httpMethod", "post");
571 p.put("restapiUrl", "http://echo.getpostman" +
572 ".com/restconf/operations/test-yang:create-sfc");
573 restconf.sendRequest(p, ctx);
574 assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_RPC));
575 verifyAttListRpc(ctx, outPre);
579 * Verifies URL parser returning path with only schema information for all
582 * @throws SvcLogicException when test case fails
585 public void validateUrlParser() throws SvcLogicException {
586 String actVal = "identity-test:test";
587 String putId = "/for-put";
588 String url1 = "http://echo.getpostman.com/restconf/operations/" +
590 String url2 = "http://echo.getpostman.com/restconf/data/" + actVal;
591 String url3 = "https://echo.getpostman.com/restconf/operations/" +
593 String url4 = "https://echo.getpostman.com/restconf/data/" + actVal +
595 String url5 = "http://localhost:8282/restconf/operations/" + actVal;
596 String url6 = "https://localhost:8282/restconf/operations/" + actVal;
597 String url7 = "http://localhost:8282/restconf/data/" + actVal +
599 String url8 = "https://localhost:8282/restconf/data/" + actVal;
600 String url9 = "http://182.2.61.24:2250/restconf/data/" + actVal;
601 String url10 = "https://182.2.61.24:2250/restconf/operations/" + actVal;
602 String url11 = "https://182.2.61.24:2250/api/v1/execution-service" +
604 String url12 = "https://182.2.61.24:2250/api/v1/execution-service" +
606 String url13 = "https://182.2.61.24:2250/api/v1/execution-service" +
608 String val1 = parseUrl(url1, POST);
609 String val2 = parseUrl(url2, GET);
610 String val3 = parseUrl(url3, PATCH);
611 String val4 = parseUrl(url4, PUT);
612 String val5 = parseUrl(url5, GET);
613 String val6 = parseUrl(url6, POST);
614 String val7 = parseUrl(url7, PUT);
615 String val8 = parseUrl(url8, POST);
616 String val9 = parseUrl(url9, GET);
617 String val10 = parseUrl(url10, POST);
618 String val11 = parseUrl(url11, POST);
619 String val12 = parseUrl(url12, POST);
620 String val13 = parseUrl(url13, POST);
621 assertThat(val1, is(actVal));
622 assertThat(val2, is(actVal));
623 assertThat(val3, is(actVal));
624 assertThat(val4, is(actVal + putId));
625 assertThat(val5, is(actVal));
626 assertThat(val6, is(actVal));
627 assertThat(val7, is(actVal + putId));
628 assertThat(val8, is(actVal));
629 assertThat(val9, is(actVal));
630 assertThat(val10, is(actVal));
631 assertThat(val11, is("execution-service:process"));
632 assertThat(val12, is("execution-service:process/payload"));
633 assertThat(val13, is("execution-service:process/payload/"));
637 * Creates attribute list for encoding JSON or XML with ANYXML YANG
641 * @return service logic context
643 private SvcLogicContext createAnyXmlAttList(String pre) {
644 SvcLogicContext ctx = new SvcLogicContext();
645 String pre1 = pre + "commonHeader.";
646 String pre2 = pre + "actionIdentifiers.";
647 ctx.setAttribute(pre + "isNonAppend", "true");
648 ctx.setAttribute(pre1 + "originatorId", "SDNC_DG");
649 ctx.setAttribute(pre1 + "requestId", "123456-1000");
650 ctx.setAttribute(pre1 + "subRequestId", "sub-123456-1000");
651 ctx.setAttribute(pre2 + "blueprintName",
652 "baseconfiguration");
653 ctx.setAttribute(pre2 + "blueprintVersion", "1.0.0");
654 ctx.setAttribute(pre2 + "actionName", "assign-activate");
655 ctx.setAttribute(pre2 + "mode", "sync");
656 ctx.setAttribute(pre + "payload." +
657 "template-prefix", "vDNS-test");
658 ctx.setAttribute(pre + "payload.resource-assignment-request" +
659 ".resource-assignment-properties",
661 " \"service-instance-id\": " +
663 " \"vnf-id\": \"3526\",\n" +
664 " \"customer-name\": \"htipl\",\n" +
665 " \"subscriber-name\": \"huawei\"\n" +
671 * Creates attribute list for encoding JSON or XML with identity-ref YANG
675 * @return service logic context
677 private SvcLogicContext createAttList(String pre) {
678 SvcLogicContext ctx = new SvcLogicContext();
679 String pre1 = pre + "con1.interfaces.";
680 ctx.setAttribute(pre + "con1.interface", "identity-types:physical");
681 ctx.setAttribute(pre1 + "int-list[0].iden", "optical");
682 ctx.setAttribute(pre1 + "int-list[0].available.ll[0]", "Giga");
683 ctx.setAttribute(pre1 + "int-list[0].available.ll[1]",
684 "identity-types:Loopback");
685 ctx.setAttribute(pre1 + "int-list[0].available.ll[2]",
686 "identity-types-second:Ethernet");
687 ctx.setAttribute(pre1 + "int-list[0].available.leaf1", "58");
688 ctx.setAttribute(pre1 + "int-list[0].available.leaf2",
689 "identity-types-second:iden2");
691 ctx.setAttribute(pre1 + "int-list[1].iden", "214748364");
692 ctx.setAttribute(pre1 + "int-list[1].available.ll[0]", "Giga");
693 ctx.setAttribute(pre1 + "int-list[1].available.ll[1]",
694 "identity-types:Loopback");
695 ctx.setAttribute(pre1 + "int-list[1].available.ll[2]",
696 "identity-types-second:Ethernet");
697 ctx.setAttribute(pre1 + "int-list[1].available.leaf1",
699 ctx.setAttribute(pre1 + "int-list[1].available.leaf2",
700 "identity-types-second:iden2");
705 * Creates attribute list for encoding JSON or XML with container,
706 * grouping and augmented YANG file.
709 * @return service logic context
711 private SvcLogicContext createAttListYang(String pre) {
712 SvcLogicContext ctx = new SvcLogicContext();
713 ctx.setAttribute(pre + "cont3.leaf10", "abc");
714 ctx.setAttribute(pre + "list1[0].leaf1", "true");
715 ctx.setAttribute(pre + "list1[0].leaf2", "abc");
716 ctx.setAttribute(pre + "list1[0].leaf3", "abc");
717 ctx.setAttribute(pre + "list1[0].ll1[0]", "abc");
718 ctx.setAttribute(pre + "list1[0].ll1[1]", "abc");
719 ctx.setAttribute(pre + "list1[0].ll2[0]", "abc");
720 ctx.setAttribute(pre + "list1[0].ll2[1]", "abc");
721 ctx.setAttribute(pre + "list1[0].cont4.leaf11", "abc");
722 ctx.setAttribute(pre + "list1[0].list4[0].leaf8", "abc");
723 ctx.setAttribute(pre + "list1[0].list4[1].leaf8", "abc");
724 ctx.setAttribute(pre + "list1[0].list5[0].leaf9", "abc");
725 ctx.setAttribute(pre + "list1[0].list5[1].leaf9", "abc");
726 ctx.setAttribute(pre + "list1[1].leaf1", "true");
727 ctx.setAttribute(pre + "list1[1].leaf2", "abc");
728 ctx.setAttribute(pre + "list1[1].leaf3", "abc");
729 ctx.setAttribute(pre + "list1[1].ll1[0]", "abc");
730 ctx.setAttribute(pre + "list1[1].ll1[1]", "abc");
731 ctx.setAttribute(pre + "list1[1].ll2[0]", "abc");
732 ctx.setAttribute(pre + "list1[1].ll2[1]", "abc");
733 ctx.setAttribute(pre + "list1[1].cont4.leaf11", "abc");
734 ctx.setAttribute(pre + "list1[1].list4[0].leaf8", "abc");
735 ctx.setAttribute(pre + "list1[1].list4[1].leaf8", "abc");
736 ctx.setAttribute(pre + "list1[1].list5[0].leaf9", "abc");
737 ctx.setAttribute(pre + "list1[1].list5[1].leaf9", "abc");
738 ctx.setAttribute(pre + "list2[0].leaf4", "abc");
739 ctx.setAttribute(pre + "list2[1].leaf4", "abc");
740 ctx.setAttribute(pre + "leaf5", "abc");
741 ctx.setAttribute(pre + "leaf6", "abc");
742 ctx.setAttribute(pre + "ll3[0]", "abc");
743 ctx.setAttribute(pre + "ll3[1]", "abc");
744 ctx.setAttribute(pre + "ll4[0]", "abc");
745 ctx.setAttribute(pre + "ll4[1]", "abc");
746 ctx.setAttribute(pre + "cont4.leaf10", "abc");
747 ctx.setAttribute(pre + "list6[0].leaf11", "abc");
748 ctx.setAttribute(pre + "list6[1].leaf11", "abc");
749 ctx.setAttribute(pre + "leaf12", "abc");
750 ctx.setAttribute(pre + "ll5[0]", "abc");
751 ctx.setAttribute(pre + "ll5[1]", "abc");
752 ctx.setAttribute(pre + "cont4.test-augment_cont5.leaf13", "true");
753 ctx.setAttribute(pre + "cont4.test-augment_list7[0].leaf14", "test");
754 ctx.setAttribute(pre + "cont4.test-augment_list7[1].leaf14", "create");
755 ctx.setAttribute(pre + "cont4.test-augment_leaf15", "abc");
756 ctx.setAttribute(pre + "cont4.test-augment_ll6[0]", "unbounded");
757 ctx.setAttribute(pre + "cont4.test-augment_ll6[1]", "8");
758 ctx.setAttribute(pre + "cont4.test-augment_cont13.cont12.leaf26",
760 ctx.setAttribute(pre + "cont4.test-augment_cont13.list9[0].leaf27",
762 ctx.setAttribute(pre + "cont4.test-augment_cont13.list9[1].leaf27",
764 ctx.setAttribute(pre + "cont4.test-augment_cont13.leaf28", "abc");
765 ctx.setAttribute(pre + "cont4.test-augment_cont13.ll9[0]", "abc");
766 ctx.setAttribute(pre + "cont4.test-augment_cont13.ll9[1]", "abc");
771 * Creates attribute list for encoding JSON or XML with RPC YANG file.
774 * @return service logic context
776 private SvcLogicContext createAttListRpc(String pre) {
777 SvcLogicContext ctx = new SvcLogicContext();
778 ctx.setAttribute(pre + "cont14.leaf28", "abc");
779 ctx.setAttribute(pre + "list10[0].leaf29", "abc");
780 ctx.setAttribute(pre + "list10[1].leaf29", "abc");
781 ctx.setAttribute(pre + "leaf30", "abc");
782 ctx.setAttribute(pre + "ll10[0]", "abc");
783 ctx.setAttribute(pre + "ll10[1]", "abc");
784 ctx.setAttribute(pre + "cont15.leaf31", "abc");
785 ctx.setAttribute(pre + "cont13.list9[0].leaf27", "abc");
786 ctx.setAttribute(pre + "cont13.list9[1].leaf27", "abc");
787 ctx.setAttribute(pre + "cont13.leaf28", "abc");
788 ctx.setAttribute(pre + "cont13.ll9[0]", "abc");
789 ctx.setAttribute(pre + "cont13.ll9[1]", "abc");
794 * Verifies the attribute list for decoding from JSON or XML with
795 * identity-ref YANG file.
797 * @param ctx service logic context
800 private void verifyAttList(SvcLogicContext ctx, String pre) {
801 String pre1 = pre + "con1.interfaces.";
802 assertThat(ctx.getAttribute(pre + "con1.interface"), is(
803 "identity-types:physical"));
804 assertThat(ctx.getAttribute(pre + "con1.interface"), is(
805 "identity-types:physical"));
806 assertThat(ctx.getAttribute(pre1 + "int-list[0].iden"), is("optical"));
807 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[0]"), is(
809 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[1]"), is(
810 "identity-types:Loopback"));
811 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[2]"), is(
812 "identity-types-second:Ethernet"));
813 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf1"), is(
815 assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf2"), is(
816 "identity-types-second:iden2"));
818 assertThat(ctx.getAttribute(pre1 + "int-list[1].iden"), is(
820 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[0]"), is(
822 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[1]"), is(
823 "identity-types:Loopback"));
824 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[2]"), is(
825 "identity-types-second:Ethernet"));
826 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf1"), is(
828 assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf2"), is(
829 "identity-types-second:iden2"));
833 * Verifies the attribute list for decoding from JSON or XML with
834 * container, grouping and augmented file.
836 * @param ctx service logic context
839 private void verifyAttListYang(SvcLogicContext ctx, String pre) {
840 assertThat(ctx.getAttribute(pre + "cont3.leaf10"), is("abc"));
841 assertThat(ctx.getAttribute(pre + "list1[0].leaf1"), is("true"));
842 assertThat(ctx.getAttribute(pre + "list1[0].leaf2"), is("abc"));
843 assertThat(ctx.getAttribute(pre + "list1[0].leaf3"), is("abc"));
844 assertThat(ctx.getAttribute(pre + "list1[0].ll1[0]"), is("abc"));
845 assertThat(ctx.getAttribute(pre + "list1[0].ll1[1]"), is("abc"));
846 assertThat(ctx.getAttribute(pre + "list1[0].ll2[0]"), is("abc"));
847 assertThat(ctx.getAttribute(pre + "list1[0].ll2[1]"), is("abc"));
848 assertThat(ctx.getAttribute(pre + "list1[0].cont4.leaf11"), is("abc"));
849 assertThat(ctx.getAttribute(pre + "list1[0].list4[0].leaf8"),
851 assertThat(ctx.getAttribute(pre + "list1[0].list4[1].leaf8"),
853 assertThat(ctx.getAttribute(pre + "list1[0].list5[0].leaf9"),
855 assertThat(ctx.getAttribute(pre + "list1[0].list5[1].leaf9"),
857 assertThat(ctx.getAttribute(pre + "list1[1].leaf1"), is("true"));
858 assertThat(ctx.getAttribute(pre + "list1[1].leaf2"), is("abc"));
859 assertThat(ctx.getAttribute(pre + "list1[1].leaf3"), is("abc"));
860 assertThat(ctx.getAttribute(pre + "list1[1].ll1[0]"), is("abc"));
861 assertThat(ctx.getAttribute(pre + "list1[1].ll1[1]"), is("abc"));
862 assertThat(ctx.getAttribute(pre + "list1[1].ll2[0]"), is("abc"));
863 assertThat(ctx.getAttribute(pre + "list1[1].ll2[1]"), is("abc"));
864 assertThat(ctx.getAttribute(pre + "list1[1].cont4.leaf11"), is("abc"));
865 assertThat(ctx.getAttribute(pre + "list1[1].list4[0].leaf8"),
867 assertThat(ctx.getAttribute(pre + "list1[1].list4[1].leaf8"),
869 assertThat(ctx.getAttribute(pre + "list1[1].list5[0].leaf9"),
871 assertThat(ctx.getAttribute(pre + "list1[1].list5[1].leaf9"),
873 assertThat(ctx.getAttribute(pre + "list2[0].leaf4"), is("abc"));
874 assertThat(ctx.getAttribute(pre + "list2[1].leaf4"), is("abc"));
875 assertThat(ctx.getAttribute(pre + "leaf5"), is("abc"));
876 assertThat(ctx.getAttribute(pre + "leaf6"), is("abc"));
877 assertThat(ctx.getAttribute(pre + "ll3[0]"), is("abc"));
878 assertThat(ctx.getAttribute(pre + "ll3[1]"), is("abc"));
879 assertThat(ctx.getAttribute(pre + "ll4[0]"), is("abc"));
880 assertThat(ctx.getAttribute(pre + "ll4[1]"), is("abc"));
881 assertThat(ctx.getAttribute(pre + "cont4.leaf10"), is( "abc"));
882 assertThat(ctx.getAttribute(pre + "list6[0].leaf11"), is("abc"));
883 assertThat(ctx.getAttribute(pre + "list6[1].leaf11"), is("abc"));
884 assertThat(ctx.getAttribute(pre + "leaf12"), is("abc"));
885 assertThat(ctx.getAttribute(pre + "ll5[0]"), is("abc"));
886 assertThat(ctx.getAttribute(pre + "ll5[1]"), is("abc"));
887 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont5.leaf13"),
889 assertThat(ctx.getAttribute(pre + "cont4.test-augment_list7[0].leaf14"),
891 assertThat(ctx.getAttribute(pre + "cont4.test-augment_list7[1].leaf14"),
893 assertThat(ctx.getAttribute(pre + "cont4.test-augment_leaf15"),
895 assertThat(ctx.getAttribute(pre + "cont4.test-augment_ll6[0]"),
897 assertThat(ctx.getAttribute(pre + "cont4.test-augment_ll6[1]"),
899 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13" +
900 ".cont12.leaf26"), is("abc"));
901 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.list9[0]" +
902 ".leaf27"), is("abc"));
903 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.list9[1]" +
904 ".leaf27"), is("abc"));
905 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.leaf28"),
907 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.ll9[0]"),
909 assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.ll9[1]"),
914 * Verifies the attribute list for decoding from JSON or XML with
917 * @param ctx service logic context
920 private void verifyAttListRpc(SvcLogicContext ctx, String pre) {
921 assertThat(ctx.getAttribute(pre + "cont16.leaf32"), is("abc"));
922 assertThat(ctx.getAttribute(pre + "list11[0].leaf33"), is("abc"));
923 assertThat(ctx.getAttribute(pre + "list11[1].leaf33"), is("abc"));
924 assertThat(ctx.getAttribute(pre + "leaf34"), is("abc"));
925 assertThat(ctx.getAttribute(pre + "ll11[0]"), is("abc"));
926 assertThat(ctx.getAttribute(pre + "ll11[1]"), is("abc"));
927 assertThat(ctx.getAttribute(pre + "cont17.leaf35"), is("abc"));
928 assertThat(ctx.getAttribute(pre + "cont13.cont12.leaf26"), is("abc"));
929 assertThat(ctx.getAttribute(pre + "cont13.list9[0].leaf27"), is("abc"));
930 assertThat(ctx.getAttribute(pre + "cont13.list9[1].leaf27"), is("abc"));
931 assertThat(ctx.getAttribute(pre + "cont13.ll9[0]"), is("abc"));
932 assertThat(ctx.getAttribute(pre + "cont13.ll9[1]"), is("abc"));
933 assertThat(ctx.getAttribute(pre + "cont13.leaf28"), is("abc"));
937 * Verifies the attribute list for decoding from JSON or XML with
940 * @param ctx service logic context
942 private void verifyOutputOfAnyXml(SvcLogicContext ctx) {
943 System.out.println(ctx.getAttribute("pp.status.eventType"));
944 assertThat(ctx.getAttribute("pp.status.eventType"), is(
945 "EVENT_COMPONENT_EXECUTED"));
946 assertThat(ctx.getAttribute("pp.actionIdentifiers.blueprintName"),
948 assertThat(ctx.getAttribute("pp.actionIdentifiers.mode"),
950 assertThat(ctx.getAttribute("pp.stepData.name"),
951 is("resource-assignment"));
952 assertThat(ctx.getAttribute("pp.status.message"),
954 assertThat(ctx.getAttribute("pp.commonHeader.originatorId"),
956 assertThat(ctx.getAttribute("pp.status.code"),
958 assertThat(ctx.getAttribute("pp.commonHeader.requestId"),
960 assertThat(ctx.getAttribute("pp.commonHeader.subRequestId"),
962 assertThat(ctx.getAttribute("pp.commonHeader.timestamp"),
963 is("2019-05-18T23:42:41.658Z"));
964 assertThat(ctx.getAttribute("pp.status.timestamp"),
965 is("2019-05-18T23:42:41.950Z"));
966 assertThat(ctx.getAttribute("pp.actionIdentifiers.blueprintV" +
967 "ersion"), is("1.0.0"));
968 assertThat(ctx.getAttribute("pp.actionIdentifiers.actionName"),
969 is("resource-assignment"));
970 assertThat(ctx.getAttribute("pp.payload.resource-assignment-resp" +
971 "onse.meshed-template.vf-module-1"),
972 is("<interface>\n <description>This i" +
973 "s the Virtual Firewall entity</description>\n" +
974 " <vfw>10.0.101.20/24</vfw>\n" +
976 assertThat(ctx.getAttribute("pp.actionIdentifiers.actionName"),
977 is("resource-assignment"));
982 * Captures the data format messages by mocking it, which can be used in
985 * @param <String> capturing data format
987 public class DfCaptor<String> implements Answer {
989 private String result;
992 * Returns the captured data format message.
994 * @return data format message.
996 public String getResult() {
1001 public String answer(InvocationOnMock invocationOnMock)
1003 result = (String) invocationOnMock.callRealMethod();