2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.utils.parser;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertSame;
14 import static org.junit.Assert.fail;
15 import static org.mockito.Mockito.when;
17 import java.util.Map.Entry;
18 import java.util.Optional;
19 import org.junit.Before;
20 import org.junit.Rule;
21 import org.junit.Test;
22 import org.junit.rules.ExpectedException;
23 import org.mockito.Mock;
24 import org.mockito.MockitoAnnotations;
25 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
26 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
27 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
28 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
29 import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
30 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
31 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
32 import org.opendaylight.restconf.common.errors.RestconfError;
33 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
34 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
35 import org.opendaylight.restconf.common.schema.SchemaExportContext;
36 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
37 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
38 import org.opendaylight.yangtools.yang.common.QName;
39 import org.opendaylight.yangtools.yang.common.Revision;
40 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
41 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
42 import org.opendaylight.yangtools.yang.model.api.Module;
43 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
46 * Unit tests for {@link ParserIdentifier}.
48 public class ParserIdentifierTest {
49 // mount point identifier
50 private static final String MOUNT_POINT_IDENT =
51 "mount-point:mount-container/point-number" + "/" + RestconfConstants.MOUNT;
53 // invalid mount point identifier
54 private static final String INVALID_MOUNT_POINT_IDENT =
55 "mount-point:point-number" + "/" + RestconfConstants.MOUNT;
57 // test identifier + expected result
58 private static final String TEST_IDENT =
59 "parser-identifier:cont1/cont2/listTest/list-in-grouping=name/leaf-A.B";
61 private static final String TEST_IDENT_RESULT =
62 "/(parser:identifier?revision=2016-06-02)cont1/cont2/listTest/listTest/list-in-grouping/"
63 + "list-in-grouping[{(parser:identifier?revision=2016-06-02)name=name}]/leaf-A.B";
65 // test identifier with nodes defined in other modules using augmentation + expected result
66 private static final String TEST_IDENT_OTHERS =
67 "parser-identifier-included:list-1=name,2016-06-02/parser-identifier:augment-leaf";
69 private static final String TEST_IDENT_OTHERS_RESULT =
70 "/(parser:identifier:included?revision=2016-06-02)list-1/list-1"
71 + "[{(parser:identifier:included?revision=2016-06-02)name=name, "
72 + "(parser:identifier:included?revision=2016-06-02)revision=2016-06-02}]"
73 + "/AugmentationIdentifier{childNames=[(parser:identifier?revision=2016-06-02)augment-leaf]}/"
74 + "(parser:identifier?revision=2016-06-02)augment-leaf";
76 // invalid test identifier
77 private static final String INVALID_TEST_IDENT =
78 "parser-identifier:cont2/listTest/list-in-grouping=name/leaf-A.B";
80 // schema context with test modules
81 private EffectiveModelContext schemaContext;
82 // contains the same modules but it is different object (it can be compared with equals)
83 private EffectiveModelContext schemaContextOnMountPoint;
85 private static final String TEST_MODULE_NAME = "test-module";
86 private static final String TEST_MODULE_REVISION = "2016-06-02";
87 private static final String TEST_MODULE_NAMESPACE = "test:module";
89 private static final String INVOKE_RPC = "invoke-rpc-module:rpc-test";
90 private static final String INVOKE_ACTION = "example-actions:interfaces/interface=eth0/reset";
92 // mount point and mount point service
93 private DOMMountPoint mountPoint;
94 private DOMMountPointService mountPointService;
96 // mock mount point and mount point service
98 private DOMMountPoint mockMountPoint;
100 private DOMMountPointService mockMountPointService;
102 private DOMSchemaService domSchemaService;
104 private DOMYangTextSourceProvider sourceProvider;
107 public final ExpectedException thrown = ExpectedException.none();
110 public void setup() throws Exception {
111 MockitoAnnotations.initMocks(this);
112 this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
113 this.schemaContextOnMountPoint =
114 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
116 this.mountPointService = new DOMMountPointServiceImpl();
118 // create and register mount point
119 final YangInstanceIdentifier mountPointId = YangInstanceIdentifier.builder()
120 .node(QName.create("mount:point", "2016-06-02", "mount-container"))
121 .node(QName.create("mount:point", "2016-06-02", "point-number"))
124 mountPoint = mountPointService.createMountPoint(mountPointId)
125 .addInitialSchemaContext(this.schemaContextOnMountPoint)
129 // register mount point with null schema context
130 when(this.mockMountPoint.getEffectiveModelContext()).thenReturn(null);
131 when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.empty()))
132 .thenReturn(Optional.of(this.mockMountPoint));
136 * {@link ParserIdentifier#toInstanceIdentifier(String, SchemaContext)} tests.
140 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when all nodes are defined
144 public void toInstanceIdentifierTest() {
145 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
146 TEST_IDENT, this.schemaContext, Optional.empty());
148 assertEquals("Returned not expected identifier",
149 TEST_IDENT_RESULT, context .getInstanceIdentifier().toString());
153 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when nodes are defined in
157 public void toInstanceIdentifierOtherModulesTest() {
158 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
159 TEST_IDENT_OTHERS, this.schemaContext, Optional.empty());
161 assertEquals("Returned not expected identifier",
162 TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString());
166 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier containing
167 * {@link RestconfConstants#MOUNT}.
170 public void toInstanceIdentifierMountPointTest() {
171 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
172 MOUNT_POINT_IDENT + "/" + TEST_IDENT, this.schemaContext, Optional.of(this.mountPointService));
174 assertEquals("Returned not expected identifier",
175 TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString());
177 assertEquals("Mount point not found",
178 this.mountPoint, context.getMountPoint());
180 assertEquals("Schema context from mount point expected",
181 this.schemaContextOnMountPoint, context.getSchemaContext());
185 * Test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>.
186 * <code>{@link YangInstanceIdentifier#EMPTY}</code> should be returned.
189 public void toInstanceIdentifierNullIdentifierTest() {
190 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
191 null, this.schemaContext, Optional.empty());
192 assertEquals("Returned not expected identifier",
193 YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
197 * Negative test of creating <code>InstanceIdentifierContext</code> when <code>SchemaContext</code> is
198 * <code>null</code>. Test fails expecting <code>NullPointerException</code>.
201 public void toInstanceIdentifierNullSchemaContextNegativeTest() {
202 this.thrown.expect(NullPointerException.class);
203 ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.empty());
207 * Api path can be empty. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
210 public void toInstanceIdentifierEmptyIdentifierTest() {
211 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
212 "", this.schemaContext, Optional.empty());
213 assertEquals("Returned not expected identifier",
214 YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
218 * Negative test with invalid test identifier. Test should fail with <code>RestconfDocumentedException</code>.
221 public void toInstanceIdentifierInvalidIdentifierNegativeTest() {
222 this.thrown.expect(RestconfDocumentedException.class);
223 ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.empty());
227 * Negative test when identifier contains {@link RestconfConstants#MOUNT} but identifier part is not valid. Test
228 * should fail with <code>RestconfDocumentedException</code>.
231 public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {
232 this.thrown.expect(RestconfDocumentedException.class);
233 ParserIdentifier.toInstanceIdentifier(
234 INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService));
238 * Negative test when <code>DOMMountPoint</code> cannot be found. Test is expected to fail with
239 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
240 * compared to expected values.
243 public void toInstanceIdentifierMissingMountPointNegativeTest() {
245 ParserIdentifier.toInstanceIdentifier(
246 "" + "/" + RestconfConstants.MOUNT, this.schemaContext, Optional.of(this.mountPointService));
247 fail("Test should fail due to missing mount point");
248 } catch (final RestconfDocumentedException e) {
249 assertEquals("Not expected error type",
250 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
251 assertEquals("Not expected error tag",
252 ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
257 * Negative test when <code>{@link DOMMountPointService}</code> is absent. Test is expected to fail with
258 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
259 * compared to expected values.
262 public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
264 ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.empty());
265 fail("Test should fail due to absent mount point service");
266 } catch (final RestconfDocumentedException e) {
267 assertEquals("Not expected error type",
268 ErrorType.APPLICATION, e.getErrors().get(0).getErrorType());
269 assertEquals("Not expected error tag",
270 ErrorTag.OPERATION_FAILED, e.getErrors().get(0).getErrorTag());
271 assertEquals("Not expected error status code",
272 500, e.getErrors().get(0).getErrorTag().getStatusCode());
277 * {@link ParserIdentifier#makeQNameFromIdentifier(String)} tests.
281 * Positive test of making <code>QName</code> from identifier and compare values from returned <code>QName</code>
282 * to expected values.
285 public void makeQNameFromIdentifierTest() {
286 final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
287 TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION);
289 assertNotNull("QName should be created", qName);
290 assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
291 assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
295 * Negative test when supplied identifier is in invalid format and then revision is not parsable.
296 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
297 * compared to expected values.
300 public void makeQNameFromIdentifierInvalidIdentifierNegativeTest() {
302 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME);
303 fail("Test should fail due to invalid identifier format");
304 } catch (final RestconfDocumentedException e) {
305 assertEquals("Not expected error type",
306 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
307 assertEquals("Not expected error tag",
308 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
309 assertEquals("Not expected error status code",
310 400, e.getErrors().get(0).getErrorTag().getStatusCode());
315 * Negative test when supplied identifier is too short (contains only module name).
316 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
317 * compared to expected values.
320 public void makeQNameFromIdentifierTooShortIdentifierNegativeTest() {
322 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME);
323 fail("Test should fail due to too short identifier format");
324 } catch (final RestconfDocumentedException e) {
325 assertEquals("Not expected error type",
326 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
327 assertEquals("Not expected error tag",
328 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
329 assertEquals("Not expected error status code",
330 400, e.getErrors().get(0).getErrorTag().getStatusCode());
335 * Positive test of making <code>QName</code> from identifier for module behind mount point. Value from returned
336 * <code>QName</code> are compared to expected values.
339 public void makeQNameFromIdentifierMountTest() {
340 final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
345 + TEST_MODULE_REVISION);
347 assertNotNull("QName should be created", qName);
348 assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
349 assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
353 * Negative test when supplied identifier for module behind mount point is in invalid format and then revision is
354 * not parsable. <code>RestconfDocumentedException</code> is expected and error type, error tag and error status
355 * code are compared to expected values.
358 public void makeQNameFromIdentifierMountPointInvalidIdentifierNegativeTest() {
360 ParserIdentifier.makeQNameFromIdentifier(
363 + TEST_MODULE_REVISION
367 fail("Test should fail due to invalid identifier format");
368 } catch (final RestconfDocumentedException e) {
369 assertEquals("Not expected error type",
370 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
371 assertEquals("Not expected error tag",
372 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
373 assertEquals("Not expected error status code",
374 400, e.getErrors().get(0).getErrorTag().getStatusCode());
379 * Negative test when supplied identifier for module behind mount point is too short (contains only module name).
380 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code
381 * are compared to expected values.
384 public void makeQNameFromIdentifierMountPointTooShortIdentifierNegativeTest() {
386 ParserIdentifier.makeQNameFromIdentifier(
391 fail("Test should fail due to too short identifier format");
392 } catch (final RestconfDocumentedException e) {
393 assertEquals("Not expected error type",
394 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
395 assertEquals("Not expected error tag",
396 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
397 assertEquals("Not expected error status code",
398 400, e.getErrors().get(0).getErrorTag().getStatusCode());
403 * Negative test trying to make <code>QName</code> from <code>null</code> identifier. Test is expected to fail with
404 * <code>NullPointerException</code>.
407 public void makeQNameFromIdentifierNullIdentifierNegativeTest() {
408 this.thrown.expect(NullPointerException.class);
409 ParserIdentifier.makeQNameFromIdentifier(null);
413 * Negative test trying to make <code>QName</code> from empty identifier. Test is expected to fail with
414 * <code>RestconfDocumentedException</code>. Error type, error tag and error status code is compared to expected
418 public void makeQNameFromIdentifierEmptyIdentifierNegativeTest() {
420 ParserIdentifier.makeQNameFromIdentifier("");
421 fail("Test should fail due to empty identifier");
422 } catch (final RestconfDocumentedException e) {
423 assertEquals("Not expected error type",
424 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
425 assertEquals("Not expected error tag",
426 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
427 assertEquals("Not expected error status code",
428 400, e.getErrors().get(0).getErrorTag().getStatusCode());
433 * Negative test with identifier containing double slash. Between // there is one empty string which will be
434 * incorrectly considered to be module revision. Test is expected to fail with
435 * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
439 public void makeQNameFromIdentifierDoubleSlashNegativeTest() {
441 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION);
442 fail("Test should fail due to identifier containing double slash");
443 } catch (final RestconfDocumentedException e) {
444 assertEquals("Not expected error type",
445 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
446 assertEquals("Not expected error tag",
447 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
448 assertEquals("Not expected error status code",
449 400, e.getErrors().get(0).getErrorTag().getStatusCode());
454 * {@link ParserIdentifier#toSchemaExportContextFromIdentifier(SchemaContext, String, DOMMountPointService)} tests.
458 * Positive test of getting <code>SchemaExportContext</code>. Expected module name, revision and namespace are
462 public void toSchemaExportContextFromIdentifierTest() {
463 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
464 this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
466 assertNotNull("Export context should be parsed", exportContext);
468 final Module module = exportContext.getModule();
469 assertNotNull("Export context should contains test module", module);
471 assertEquals("Returned not expected module name",
472 TEST_MODULE_NAME, module.getName());
473 assertEquals("Returned not expected module revision",
474 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
475 assertEquals("Returned not expected module namespace",
476 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
480 * Test of getting <code>SchemaExportContext</code> when desired module is not found.
481 * <code>SchemaExportContext</code> should be created but module should be set to <code>null</code>.
484 public void toSchemaExportContextFromIdentifierNotFoundTest() {
485 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
487 "not-existing-module" + "/" + "2016-01-01",
488 null, sourceProvider);
490 assertNotNull("Export context should be parsed", exportContext);
491 assertNull("Not-existing module should be null", exportContext.getModule());
495 * Negative test trying to get <code>SchemaExportContext</code> with invalid identifier. Test is expected to fail
496 * with <code>RestconfDocumentedException</code> error type, error tag and error status code are compared to
500 public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
502 ParserIdentifier.toSchemaExportContextFromIdentifier(
503 this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider);
504 fail("Test should fail due to invalid identifier supplied");
505 } catch (final RestconfDocumentedException e) {
506 assertEquals("Not expected error type",
507 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
508 assertEquals("Not expected error tag",
509 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
510 assertEquals("Not expected error status code",
511 400, e.getErrors().get(0).getErrorTag().getStatusCode());
516 * Positive test of getting <code>SchemaExportContext</code> for module behind mount point.
517 * Expected module name, revision and namespace are verified.
520 public void toSchemaExportContextFromIdentifierMountPointTest() {
521 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
523 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
524 this.mountPointService, sourceProvider);
526 final Module module = exportContext.getModule();
527 assertNotNull("Export context should contains test module", module);
529 assertEquals("Returned not expected module name",
530 TEST_MODULE_NAME, module.getName());
531 assertEquals("Returned not expected module revision",
532 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
533 assertEquals("Returned not expected module namespace",
534 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
538 * Negative test of getting <code>SchemaExportContext</code> when desired module is not found behind mount point.
539 * <code>SchemaExportContext</code> should be still created but module should be set to <code>null</code>.
542 public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
543 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
545 MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
546 this.mountPointService, sourceProvider);
548 assertNotNull("Export context should be parsed", exportContext);
549 assertNull("Not-existing module should be null", exportContext.getModule());
553 * Negative test trying to get <code>SchemaExportContext</code> behind mount point with invalid identifier. Test is
554 * expected to fail with <code>RestconfDocumentedException</code> error type, error tag and error status code are
555 * compared to expected values.
558 public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() {
560 ParserIdentifier.toSchemaExportContextFromIdentifier(
562 MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
563 this.mountPointService, sourceProvider);
565 fail("Test should fail due to invalid identifier supplied");
566 } catch (final RestconfDocumentedException e) {
567 assertEquals("Not expected error type",
568 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
569 assertEquals("Not expected error tag",
570 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
571 assertEquals("Not expected error status code",
572 400, e.getErrors().get(0).getErrorTag().getStatusCode());
577 * Negative test of getting <code>SchemaExportContext</code> when supplied identifier is null.
578 * <code>NullPointerException</code> is expected. <code>DOMMountPointService</code> is not used.
581 public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
582 this.thrown.expect(NullPointerException.class);
583 ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null, sourceProvider);
587 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
588 * <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
591 public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
592 this.thrown.expect(NullPointerException.class);
593 ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
598 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
599 * <code>null</code> and identifier specifies module behind mount point. Test is expected to fail with
600 * <code>NullPointerException</code>.
603 public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
604 this.thrown.expect(NullPointerException.class);
605 ParserIdentifier.toSchemaExportContextFromIdentifier(
611 + TEST_MODULE_REVISION,
612 this.mountPointService,
617 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>DOMMountPointService</code>
618 * is <code>null</code> and identifier defines module behind mount point. Test is expected to fail with
619 * <code>NullPointerException</code>.
622 public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
623 this.thrown.expect(NullPointerException.class);
624 ParserIdentifier.toSchemaExportContextFromIdentifier(
630 + TEST_MODULE_REVISION,
636 * Negative test of of getting <code>SchemaExportContext</code> when <code>SchemaContext</code> behind mount
637 * point is <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
640 public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
641 this.thrown.expect(NullPointerException.class);
642 ParserIdentifier.toSchemaExportContextFromIdentifier(
645 + RestconfConstants.MOUNT
649 + TEST_MODULE_REVISION,
650 this.mockMountPointService,
658 * Verify if RPC schema node was found.
661 public void invokeRpcTest() {
662 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
663 INVOKE_RPC, this.schemaContext, Optional.empty());
666 final QName rpcQName = result.getSchemaNode().getQName();
667 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
668 assertEquals("rpc-test", rpcQName.getLocalName());
671 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
672 assertEquals(null, result.getMountPoint());
673 assertEquals(this.schemaContext, result.getSchemaContext());
677 * Test invoke RPC on mount point.
680 * Verify if RPC schema node was found.
683 public void invokeRpcOnMountPointTest() {
684 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
685 MOUNT_POINT_IDENT + "/" + INVOKE_RPC, this.schemaContext, Optional.of(this.mountPointService));
688 final QName rpcQName = result.getSchemaNode().getQName();
689 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
690 assertEquals("rpc-test", rpcQName.getLocalName());
693 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
694 assertEquals(this.mountPoint, result.getMountPoint());
695 assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());
700 * Verify if Action schema node was found.
703 public void invokeActionTest() {
704 final InstanceIdentifierContext<?> result = ParserIdentifier
705 .toInstanceIdentifier(INVOKE_ACTION, this.schemaContext, Optional.empty());
707 // Action schema node
708 final QName actionQName = result.getSchemaNode().getQName();
709 assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
710 assertEquals("reset", actionQName.getLocalName());
713 assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, schemaContext), result.getInstanceIdentifier());
714 assertNull(result.getMountPoint());
715 assertSame(this.schemaContext, result.getSchemaContext());
719 * Test invoke Action on mount point.
720 * Verify if Action schema node was found.
723 public void invokeActionOnMountPointTest() {
724 final InstanceIdentifierContext<?> result = ParserIdentifier
725 .toInstanceIdentifier(MOUNT_POINT_IDENT + "/" + INVOKE_ACTION, this.schemaContext,
726 Optional.of(this.mountPointService));
728 // Action schema node
729 final QName actionQName = result.getSchemaNode().getQName();
730 assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
731 assertEquals("reset", actionQName.getLocalName());
734 assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, schemaContext), result.getInstanceIdentifier());
735 assertEquals(this.mountPoint, result.getMountPoint());
736 assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());