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.Module;
42 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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 SchemaContext schemaContext;
82 // contains the same modules but it is different object (it can be compared with equals)
83 private SchemaContext 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.getSchemaContext()).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());
253 assertEquals("Not expected error status code",
254 404, e.getErrors().get(0).getErrorTag().getStatusCode());
259 * Negative test when <code>{@link DOMMountPointService}</code> is absent. Test is expected to fail with
260 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
261 * compared to expected values.
264 public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
266 ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.empty());
267 fail("Test should fail due to absent mount point service");
268 } catch (final RestconfDocumentedException e) {
269 assertEquals("Not expected error type",
270 ErrorType.APPLICATION, e.getErrors().get(0).getErrorType());
271 assertEquals("Not expected error tag",
272 ErrorTag.OPERATION_FAILED, e.getErrors().get(0).getErrorTag());
273 assertEquals("Not expected error status code",
274 500, e.getErrors().get(0).getErrorTag().getStatusCode());
279 * {@link ParserIdentifier#makeQNameFromIdentifier(String)} tests.
283 * Positive test of making <code>QName</code> from identifier and compare values from returned <code>QName</code>
284 * to expected values.
287 public void makeQNameFromIdentifierTest() {
288 final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
289 TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION);
291 assertNotNull("QName should be created", qName);
292 assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
293 assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
297 * Negative test when supplied identifier is in invalid format and then revision is not parsable.
298 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
299 * compared to expected values.
302 public void makeQNameFromIdentifierInvalidIdentifierNegativeTest() {
304 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME);
305 fail("Test should fail due to invalid identifier format");
306 } catch (final RestconfDocumentedException e) {
307 assertEquals("Not expected error type",
308 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
309 assertEquals("Not expected error tag",
310 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
311 assertEquals("Not expected error status code",
312 400, e.getErrors().get(0).getErrorTag().getStatusCode());
317 * Negative test when supplied identifier is too short (contains only module name).
318 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
319 * compared to expected values.
322 public void makeQNameFromIdentifierTooShortIdentifierNegativeTest() {
324 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME);
325 fail("Test should fail due to too short identifier format");
326 } catch (final RestconfDocumentedException e) {
327 assertEquals("Not expected error type",
328 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
329 assertEquals("Not expected error tag",
330 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
331 assertEquals("Not expected error status code",
332 400, e.getErrors().get(0).getErrorTag().getStatusCode());
337 * Positive test of making <code>QName</code> from identifier for module behind mount point. Value from returned
338 * <code>QName</code> are compared to expected values.
341 public void makeQNameFromIdentifierMountTest() {
342 final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
347 + TEST_MODULE_REVISION);
349 assertNotNull("QName should be created", qName);
350 assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
351 assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
355 * Negative test when supplied identifier for module behind mount point is in invalid format and then revision is
356 * not parsable. <code>RestconfDocumentedException</code> is expected and error type, error tag and error status
357 * code are compared to expected values.
360 public void makeQNameFromIdentifierMountPointInvalidIdentifierNegativeTest() {
362 ParserIdentifier.makeQNameFromIdentifier(
365 + TEST_MODULE_REVISION
369 fail("Test should fail due to invalid identifier format");
370 } catch (final RestconfDocumentedException e) {
371 assertEquals("Not expected error type",
372 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
373 assertEquals("Not expected error tag",
374 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
375 assertEquals("Not expected error status code",
376 400, e.getErrors().get(0).getErrorTag().getStatusCode());
381 * Negative test when supplied identifier for module behind mount point is too short (contains only module name).
382 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code
383 * are compared to expected values.
386 public void makeQNameFromIdentifierMountPointTooShortIdentifierNegativeTest() {
388 ParserIdentifier.makeQNameFromIdentifier(
393 fail("Test should fail due to too short identifier format");
394 } catch (final RestconfDocumentedException e) {
395 assertEquals("Not expected error type",
396 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
397 assertEquals("Not expected error tag",
398 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
399 assertEquals("Not expected error status code",
400 400, e.getErrors().get(0).getErrorTag().getStatusCode());
405 * Negative test trying to make <code>QName</code> from <code>null</code> identifier. Test is expected to fail with
406 * <code>NullPointerException</code>.
409 public void makeQNameFromIdentifierNullIdentifierNegativeTest() {
410 this.thrown.expect(NullPointerException.class);
411 ParserIdentifier.makeQNameFromIdentifier(null);
415 * Negative test trying to make <code>QName</code> from empty identifier. Test is expected to fail with
416 * <code>RestconfDocumentedException</code>. Error type, error tag and error status code is compared to expected
420 public void makeQNameFromIdentifierEmptyIdentifierNegativeTest() {
422 ParserIdentifier.makeQNameFromIdentifier("");
423 fail("Test should fail due to empty identifier");
424 } catch (final RestconfDocumentedException e) {
425 assertEquals("Not expected error type",
426 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
427 assertEquals("Not expected error tag",
428 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
429 assertEquals("Not expected error status code",
430 400, e.getErrors().get(0).getErrorTag().getStatusCode());
435 * Negative test with identifier containing double slash. Between // there is one empty string which will be
436 * incorrectly considered to be module revision. Test is expected to fail with
437 * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
441 public void makeQNameFromIdentifierDoubleSlashNegativeTest() {
443 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION);
444 fail("Test should fail due to identifier containing double slash");
445 } catch (final RestconfDocumentedException e) {
446 assertEquals("Not expected error type",
447 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
448 assertEquals("Not expected error tag",
449 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
450 assertEquals("Not expected error status code",
451 400, e.getErrors().get(0).getErrorTag().getStatusCode());
456 * {@link ParserIdentifier#toSchemaExportContextFromIdentifier(SchemaContext, String, DOMMountPointService)} tests.
460 * Positive test of getting <code>SchemaExportContext</code>. Expected module name, revision and namespace are
464 public void toSchemaExportContextFromIdentifierTest() {
465 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
466 this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
468 assertNotNull("Export context should be parsed", exportContext);
470 final Module module = exportContext.getModule();
471 assertNotNull("Export context should contains test module", module);
473 assertEquals("Returned not expected module name",
474 TEST_MODULE_NAME, module.getName());
475 assertEquals("Returned not expected module revision",
476 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
477 assertEquals("Returned not expected module namespace",
478 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
482 * Test of getting <code>SchemaExportContext</code> when desired module is not found.
483 * <code>SchemaExportContext</code> should be created but module should be set to <code>null</code>.
486 public void toSchemaExportContextFromIdentifierNotFoundTest() {
487 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
489 "not-existing-module" + "/" + "2016-01-01",
490 null, sourceProvider);
492 assertNotNull("Export context should be parsed", exportContext);
493 assertNull("Not-existing module should be null", exportContext.getModule());
497 * Negative test trying to get <code>SchemaExportContext</code> with invalid identifier. Test is expected to fail
498 * with <code>RestconfDocumentedException</code> error type, error tag and error status code are compared to
502 public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
504 ParserIdentifier.toSchemaExportContextFromIdentifier(
505 this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider);
506 fail("Test should fail due to invalid identifier supplied");
507 } catch (final RestconfDocumentedException e) {
508 assertEquals("Not expected error type",
509 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
510 assertEquals("Not expected error tag",
511 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
512 assertEquals("Not expected error status code",
513 400, e.getErrors().get(0).getErrorTag().getStatusCode());
518 * Positive test of getting <code>SchemaExportContext</code> for module behind mount point.
519 * Expected module name, revision and namespace are verified.
522 public void toSchemaExportContextFromIdentifierMountPointTest() {
523 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
525 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
526 this.mountPointService, sourceProvider);
528 final Module module = exportContext.getModule();
529 assertNotNull("Export context should contains test module", module);
531 assertEquals("Returned not expected module name",
532 TEST_MODULE_NAME, module.getName());
533 assertEquals("Returned not expected module revision",
534 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
535 assertEquals("Returned not expected module namespace",
536 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
540 * Negative test of getting <code>SchemaExportContext</code> when desired module is not found behind mount point.
541 * <code>SchemaExportContext</code> should be still created but module should be set to <code>null</code>.
544 public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
545 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
547 MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
548 this.mountPointService, sourceProvider);
550 assertNotNull("Export context should be parsed", exportContext);
551 assertNull("Not-existing module should be null", exportContext.getModule());
555 * Negative test trying to get <code>SchemaExportContext</code> behind mount point with invalid identifier. Test is
556 * expected to fail with <code>RestconfDocumentedException</code> error type, error tag and error status code are
557 * compared to expected values.
560 public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() {
562 ParserIdentifier.toSchemaExportContextFromIdentifier(
564 MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
565 this.mountPointService, sourceProvider);
567 fail("Test should fail due to invalid identifier supplied");
568 } catch (final RestconfDocumentedException e) {
569 assertEquals("Not expected error type",
570 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
571 assertEquals("Not expected error tag",
572 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
573 assertEquals("Not expected error status code",
574 400, e.getErrors().get(0).getErrorTag().getStatusCode());
579 * Negative test of getting <code>SchemaExportContext</code> when supplied identifier is null.
580 * <code>NullPointerException</code> is expected. <code>DOMMountPointService</code> is not used.
583 public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
584 this.thrown.expect(NullPointerException.class);
585 ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null, sourceProvider);
589 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
590 * <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
593 public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
594 this.thrown.expect(NullPointerException.class);
595 ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
600 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
601 * <code>null</code> and identifier specifies module behind mount point. Test is expected to fail with
602 * <code>NullPointerException</code>.
605 public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
606 this.thrown.expect(NullPointerException.class);
607 ParserIdentifier.toSchemaExportContextFromIdentifier(
613 + TEST_MODULE_REVISION,
614 this.mountPointService,
619 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>DOMMountPointService</code>
620 * is <code>null</code> and identifier defines module behind mount point. Test is expected to fail with
621 * <code>NullPointerException</code>.
624 public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
625 this.thrown.expect(NullPointerException.class);
626 ParserIdentifier.toSchemaExportContextFromIdentifier(
632 + TEST_MODULE_REVISION,
638 * Negative test of of getting <code>SchemaExportContext</code> when <code>SchemaContext</code> behind mount
639 * point is <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
642 public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
643 this.thrown.expect(NullPointerException.class);
644 ParserIdentifier.toSchemaExportContextFromIdentifier(
647 + RestconfConstants.MOUNT
651 + TEST_MODULE_REVISION,
652 this.mockMountPointService,
660 * Verify if RPC schema node was found.
663 public void invokeRpcTest() {
664 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
665 INVOKE_RPC, this.schemaContext, Optional.empty());
668 final QName rpcQName = result.getSchemaNode().getQName();
669 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
670 assertEquals("rpc-test", rpcQName.getLocalName());
673 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
674 assertEquals(null, result.getMountPoint());
675 assertEquals(this.schemaContext, result.getSchemaContext());
679 * Test invoke RPC on mount point.
682 * Verify if RPC schema node was found.
685 public void invokeRpcOnMountPointTest() {
686 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
687 MOUNT_POINT_IDENT + "/" + INVOKE_RPC, this.schemaContext, Optional.of(this.mountPointService));
690 final QName rpcQName = result.getSchemaNode().getQName();
691 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
692 assertEquals("rpc-test", rpcQName.getLocalName());
695 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
696 assertEquals(this.mountPoint, result.getMountPoint());
697 assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());
702 * Verify if Action schema node was found.
705 public void invokeActionTest() {
706 final InstanceIdentifierContext<?> result = ParserIdentifier
707 .toInstanceIdentifier(INVOKE_ACTION, this.schemaContext, Optional.empty());
709 // Action schema node
710 final QName actionQName = result.getSchemaNode().getQName();
711 assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
712 assertEquals("reset", actionQName.getLocalName());
715 assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, schemaContext), result.getInstanceIdentifier());
716 assertNull(result.getMountPoint());
717 assertSame(this.schemaContext, result.getSchemaContext());
721 * Test invoke Action on mount point.
722 * Verify if Action schema node was found.
725 public void invokeActionOnMountPointTest() {
726 final InstanceIdentifierContext<?> result = ParserIdentifier
727 .toInstanceIdentifier(MOUNT_POINT_IDENT + "/" + INVOKE_ACTION, this.schemaContext,
728 Optional.of(this.mountPointService));
730 // Action schema node
731 final QName actionQName = result.getSchemaNode().getQName();
732 assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
733 assertEquals("reset", actionQName.getLocalName());
736 assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, schemaContext), result.getInstanceIdentifier());
737 assertEquals(this.mountPoint, result.getMountPoint());
738 assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());