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.assertThrows;
15 import static org.mockito.Mockito.when;
17 import java.util.Map.Entry;
18 import java.util.Optional;
19 import org.junit.AfterClass;
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.Mock;
25 import org.mockito.junit.MockitoJUnitRunner;
26 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
27 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
28 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
29 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
30 import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
31 import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
32 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
33 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
34 import org.opendaylight.restconf.common.errors.RestconfError;
35 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
36 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
37 import org.opendaylight.restconf.common.schema.SchemaExportContext;
38 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
39 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
40 import org.opendaylight.yangtools.yang.common.QName;
41 import org.opendaylight.yangtools.yang.common.Revision;
42 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
43 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
44 import org.opendaylight.yangtools.yang.model.api.Module;
45 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
48 * Unit tests for {@link ParserIdentifier}.
50 @RunWith(MockitoJUnitRunner.StrictStubs.class)
51 public class ParserIdentifierTest {
52 // mount point identifier
53 private static final String MOUNT_POINT_IDENT =
54 "mount-point:mount-container/point-number" + "/" + RestconfConstants.MOUNT;
56 // invalid mount point identifier
57 private static final String INVALID_MOUNT_POINT_IDENT =
58 "mount-point:point-number" + "/" + RestconfConstants.MOUNT;
60 // test identifier + expected result
61 private static final String TEST_IDENT =
62 "parser-identifier:cont1/cont2/listTest/list-in-grouping=name/leaf-A.B";
64 private static final String TEST_IDENT_RESULT =
65 "/(parser:identifier?revision=2016-06-02)cont1/cont2/listTest/listTest/list-in-grouping/"
66 + "list-in-grouping[{(parser:identifier?revision=2016-06-02)name=name}]/leaf-A.B";
68 // test identifier with nodes defined in other modules using augmentation + expected result
69 private static final String TEST_IDENT_OTHERS =
70 "parser-identifier-included:list-1=name,2016-06-02/parser-identifier:augment-leaf";
72 private static final String TEST_IDENT_OTHERS_RESULT =
73 "/(parser:identifier:included?revision=2016-06-02)list-1/list-1"
74 + "[{(parser:identifier:included?revision=2016-06-02)name=name, "
75 + "(parser:identifier:included?revision=2016-06-02)revision=2016-06-02}]"
76 + "/AugmentationIdentifier{childNames=[(parser:identifier?revision=2016-06-02)augment-leaf]}/"
77 + "(parser:identifier?revision=2016-06-02)augment-leaf";
79 // invalid test identifier
80 private static final String INVALID_TEST_IDENT =
81 "parser-identifier:cont2/listTest/list-in-grouping=name/leaf-A.B";
83 private static final String TEST_MODULE_NAME = "test-module";
84 private static final String TEST_MODULE_REVISION = "2016-06-02";
85 private static final String TEST_MODULE_NAMESPACE = "test:module";
87 private static final String INVOKE_RPC = "invoke-rpc-module:rpc-test";
88 private static final String INVOKE_ACTION = "example-actions:interfaces/interface=eth0/reset";
90 // schema context with test modules
91 private static EffectiveModelContext SCHEMA_CONTEXT;
92 // contains the same modules but it is different object (it can be compared with equals)
93 private static EffectiveModelContext SCHEMA_CONTEXT_ON_MOUNT_POINT;
95 // mount point and mount point service
96 private DOMMountPoint mountPoint;
97 private DOMMountPointService mountPointService;
99 // mock mount point and mount point service
101 private DOMMountPoint mockMountPoint;
103 private DOMMountPointService mockMountPointService;
105 private DOMSchemaService domSchemaService;
107 private DOMYangTextSourceProvider sourceProvider;
110 public static void beforeClass() throws Exception {
111 SCHEMA_CONTEXT = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
112 SCHEMA_CONTEXT_ON_MOUNT_POINT =
113 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
117 public static void afterClass() {
118 SCHEMA_CONTEXT = null;
119 SCHEMA_CONTEXT_ON_MOUNT_POINT = null;
123 public void setup() throws Exception {
124 this.mountPointService = new DOMMountPointServiceImpl();
126 // create and register mount point
127 final YangInstanceIdentifier mountPointId = YangInstanceIdentifier.builder()
128 .node(QName.create("mount:point", "2016-06-02", "mount-container"))
129 .node(QName.create("mount:point", "2016-06-02", "point-number"))
132 mountPoint = mountPointService.createMountPoint(mountPointId)
133 .addService(DOMSchemaService.class, FixedDOMSchemaService.of(SCHEMA_CONTEXT_ON_MOUNT_POINT))
137 // register mount point with null schema context
138 when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.empty()))
139 .thenReturn(Optional.of(this.mockMountPoint));
143 * {@link ParserIdentifier#toInstanceIdentifier(String, SchemaContext)} tests.
147 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when all nodes are defined
151 public void toInstanceIdentifierTest() {
152 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
153 TEST_IDENT, SCHEMA_CONTEXT, Optional.empty());
155 assertEquals("Returned not expected identifier",
156 TEST_IDENT_RESULT, context .getInstanceIdentifier().toString());
160 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when nodes are defined in
164 public void toInstanceIdentifierOtherModulesTest() {
165 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
166 TEST_IDENT_OTHERS, SCHEMA_CONTEXT, Optional.empty());
168 assertEquals("Returned not expected identifier",
169 TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString());
173 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier containing
174 * {@link RestconfConstants#MOUNT}.
177 public void toInstanceIdentifierMountPointTest() {
178 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
179 MOUNT_POINT_IDENT + "/" + TEST_IDENT, SCHEMA_CONTEXT, Optional.of(this.mountPointService));
181 assertEquals("Returned not expected identifier",
182 TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString());
184 assertEquals("Mount point not found",
185 this.mountPoint, context.getMountPoint());
187 assertEquals("Schema context from mount point expected",
188 SCHEMA_CONTEXT_ON_MOUNT_POINT, context.getSchemaContext());
192 * Test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>.
193 * <code>{@link YangInstanceIdentifier#empty()}</code> should be returned.
196 public void toInstanceIdentifierNullIdentifierTest() {
197 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
198 null, SCHEMA_CONTEXT, Optional.empty());
199 assertEquals("Returned not expected identifier",
200 YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
204 * Negative test of creating <code>InstanceIdentifierContext</code> when <code>SchemaContext</code> is
205 * <code>null</code>. Test fails expecting <code>NullPointerException</code>.
208 public void toInstanceIdentifierNullSchemaContextNegativeTest() {
209 assertThrows(NullPointerException.class,
210 () -> ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.empty()));
214 * Api path can be empty. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
217 public void toInstanceIdentifierEmptyIdentifierTest() {
218 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
219 "", SCHEMA_CONTEXT, Optional.empty());
220 assertEquals("Returned not expected identifier",
221 YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
225 * Negative test with invalid test identifier. Test should fail with <code>RestconfDocumentedException</code>.
228 public void toInstanceIdentifierInvalidIdentifierNegativeTest() {
229 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
230 () -> ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, SCHEMA_CONTEXT, Optional.empty()));
234 * Negative test when identifier contains {@link RestconfConstants#MOUNT} but identifier part is not valid. Test
235 * should fail with <code>RestconfDocumentedException</code>.
238 public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {
239 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
240 () -> ParserIdentifier.toInstanceIdentifier(INVALID_MOUNT_POINT_IDENT, SCHEMA_CONTEXT,
241 Optional.of(this.mountPointService)));
245 * Negative test when <code>DOMMountPoint</code> cannot be found. Test is expected to fail with
246 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
247 * compared to expected values.
250 public void toInstanceIdentifierMissingMountPointNegativeTest() {
251 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
252 () -> ParserIdentifier.toInstanceIdentifier("" + "/" + RestconfConstants.MOUNT, SCHEMA_CONTEXT,
253 Optional.of(this.mountPointService)));
254 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
255 assertEquals("Not expected error tag", ErrorTag.DATA_MISSING, ex.getErrors().get(0).getErrorTag());
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() {
265 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
266 () -> ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, SCHEMA_CONTEXT, Optional.empty()));
267 assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
268 assertEquals("Not expected error tag", ErrorTag.OPERATION_FAILED, ex.getErrors().get(0).getErrorTag());
269 assertEquals("Not expected error status code", 500, ex.getErrors().get(0).getErrorTag().getStatusCode());
273 * {@link ParserIdentifier#makeQNameFromIdentifier(String)} tests.
277 * Positive test of making <code>QName</code> from identifier and compare values from returned <code>QName</code>
278 * to expected values.
281 public void makeQNameFromIdentifierTest() {
282 final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
283 TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION);
285 assertNotNull("QName should be created", qName);
286 assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
287 assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
291 * Negative test when supplied identifier is in invalid format and then revision is not parsable.
292 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
293 * compared to expected values.
296 public void makeQNameFromIdentifierInvalidIdentifierNegativeTest() {
297 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
298 () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME));
299 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
300 assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
301 ex.getErrors().get(0).getErrorTag());
302 assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
306 * Negative test when supplied identifier is too short (contains only module name).
307 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
308 * compared to expected values.
311 public void makeQNameFromIdentifierTooShortIdentifierNegativeTest() {
312 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
313 () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME));
314 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
315 assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
316 ex.getErrors().get(0).getErrorTag());
317 assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
321 * Positive test of making <code>QName</code> from identifier for module behind mount point. Value from returned
322 * <code>QName</code> are compared to expected values.
325 public void makeQNameFromIdentifierMountTest() {
326 final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
331 + TEST_MODULE_REVISION);
333 assertNotNull("QName should be created", qName);
334 assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
335 assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
339 * Negative test when supplied identifier for module behind mount point is in invalid format and then revision is
340 * not parsable. <code>RestconfDocumentedException</code> is expected and error type, error tag and error status
341 * code are compared to expected values.
344 public void makeQNameFromIdentifierMountPointInvalidIdentifierNegativeTest() {
345 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
346 () -> ParserIdentifier.makeQNameFromIdentifier(
347 MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME));
348 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
349 assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
350 ex.getErrors().get(0).getErrorTag());
351 assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
355 * Negative test when supplied identifier for module behind mount point is too short (contains only module name).
356 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code
357 * are compared to expected values.
360 public void makeQNameFromIdentifierMountPointTooShortIdentifierNegativeTest() {
361 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
362 () -> ParserIdentifier.makeQNameFromIdentifier(MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME));
363 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
364 assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
365 ex.getErrors().get(0).getErrorTag());
366 assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
370 * Negative test trying to make <code>QName</code> from <code>null</code> identifier. Test is expected to fail with
371 * <code>NullPointerException</code>.
374 public void makeQNameFromIdentifierNullIdentifierNegativeTest() {
375 assertThrows(NullPointerException.class, () -> ParserIdentifier.makeQNameFromIdentifier(null));
379 * Negative test trying to make <code>QName</code> from empty identifier. Test is expected to fail with
380 * <code>RestconfDocumentedException</code>. Error type, error tag and error status code is compared to expected
384 public void makeQNameFromIdentifierEmptyIdentifierNegativeTest() {
385 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
386 () -> ParserIdentifier.makeQNameFromIdentifier(""));
387 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
388 assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
389 ex.getErrors().get(0).getErrorTag());
390 assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
394 * Negative test with identifier containing double slash. Between // there is one empty string which will be
395 * incorrectly considered to be module revision. Test is expected to fail with
396 * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
400 public void makeQNameFromIdentifierDoubleSlashNegativeTest() {
401 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
402 () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION));
403 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
404 assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
405 ex.getErrors().get(0).getErrorTag());
406 assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
410 * {@link ParserIdentifier#toSchemaExportContextFromIdentifier(SchemaContext, String, DOMMountPointService)} tests.
414 * Positive test of getting <code>SchemaExportContext</code>. Expected module name, revision and namespace are
418 public void toSchemaExportContextFromIdentifierTest() {
419 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
420 SCHEMA_CONTEXT, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
422 assertNotNull("Export context should be parsed", exportContext);
424 final Module module = exportContext.getModule();
425 assertNotNull("Export context should contains test module", module);
427 assertEquals("Returned not expected module name",
428 TEST_MODULE_NAME, module.getName());
429 assertEquals("Returned not expected module revision",
430 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
431 assertEquals("Returned not expected module namespace",
432 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
436 * Test of getting <code>SchemaExportContext</code> when desired module is not found.
437 * <code>SchemaExportContext</code> should be created but module should be set to <code>null</code>.
440 public void toSchemaExportContextFromIdentifierNotFoundTest() {
441 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
443 "not-existing-module" + "/" + "2016-01-01",
444 null, sourceProvider);
446 assertNotNull("Export context should be parsed", exportContext);
447 assertNull("Not-existing module should be null", exportContext.getModule());
451 * Negative test trying to get <code>SchemaExportContext</code> with invalid identifier. Test is expected to fail
452 * with <code>RestconfDocumentedException</code> error type, error tag and error status code are compared to
456 public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
457 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
458 () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
459 SCHEMA_CONTEXT, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider));
460 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
461 assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
462 ex.getErrors().get(0).getErrorTag());
463 assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
467 * Positive test of getting <code>SchemaExportContext</code> for module behind mount point.
468 * Expected module name, revision and namespace are verified.
471 public void toSchemaExportContextFromIdentifierMountPointTest() {
472 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
474 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
475 this.mountPointService, sourceProvider);
477 final Module module = exportContext.getModule();
478 assertNotNull("Export context should contains test module", module);
480 assertEquals("Returned not expected module name",
481 TEST_MODULE_NAME, module.getName());
482 assertEquals("Returned not expected module revision",
483 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
484 assertEquals("Returned not expected module namespace",
485 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
489 * Negative test of getting <code>SchemaExportContext</code> when desired module is not found behind mount point.
490 * <code>SchemaExportContext</code> should be still created but module should be set to <code>null</code>.
493 public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
494 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
496 MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
497 this.mountPointService, sourceProvider);
499 assertNotNull("Export context should be parsed", exportContext);
500 assertNull("Not-existing module should be null", exportContext.getModule());
504 * Negative test trying to get <code>SchemaExportContext</code> behind mount point with invalid identifier. Test is
505 * expected to fail with <code>RestconfDocumentedException</code> error type, error tag and error status code are
506 * compared to expected values.
509 public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() {
510 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
511 () -> ParserIdentifier.toSchemaExportContextFromIdentifier(SCHEMA_CONTEXT,
512 MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, this.mountPointService,
515 assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
516 assertEquals("Not expected error tag", RestconfError.ErrorTag.INVALID_VALUE,
517 ex.getErrors().get(0).getErrorTag());
518 assertEquals("Not expected error status code", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
522 * Negative test of getting <code>SchemaExportContext</code> when supplied identifier is null.
523 * <code>NullPointerException</code> is expected. <code>DOMMountPointService</code> is not used.
526 public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
527 assertThrows(NullPointerException.class,
528 () -> ParserIdentifier.toSchemaExportContextFromIdentifier(SCHEMA_CONTEXT, null, null, sourceProvider));
532 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
533 * <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
536 public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
537 assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(null,
538 TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider));
542 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
543 * <code>null</code> and identifier specifies module behind mount point. Test is expected to fail with
544 * <code>NullPointerException</code>.
547 public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
548 assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(null,
549 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, this.mountPointService,
554 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>DOMMountPointService</code>
555 * is <code>null</code> and identifier defines module behind mount point. Test is expected to fail with
556 * <code>NullPointerException</code>.
559 public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
560 assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
561 SCHEMA_CONTEXT, MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
566 public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
567 assertThrows(IllegalStateException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
568 SCHEMA_CONTEXT, "/" + RestconfConstants.MOUNT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
569 this.mockMountPointService, sourceProvider));
576 * Verify if RPC schema node was found.
579 public void invokeRpcTest() {
580 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
581 INVOKE_RPC, SCHEMA_CONTEXT, Optional.empty());
584 final QName rpcQName = result.getSchemaNode().getQName();
585 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
586 assertEquals("rpc-test", rpcQName.getLocalName());
589 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, SCHEMA_CONTEXT), result.getInstanceIdentifier());
590 assertEquals(null, result.getMountPoint());
591 assertEquals(SCHEMA_CONTEXT, result.getSchemaContext());
595 * Test invoke RPC on mount point.
598 * Verify if RPC schema node was found.
601 public void invokeRpcOnMountPointTest() {
602 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
603 MOUNT_POINT_IDENT + "/" + INVOKE_RPC, SCHEMA_CONTEXT, Optional.of(this.mountPointService));
606 final QName rpcQName = result.getSchemaNode().getQName();
607 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
608 assertEquals("rpc-test", rpcQName.getLocalName());
611 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, SCHEMA_CONTEXT), result.getInstanceIdentifier());
612 assertEquals(this.mountPoint, result.getMountPoint());
613 assertEquals(SCHEMA_CONTEXT_ON_MOUNT_POINT, result.getSchemaContext());
618 * Verify if Action schema node was found.
621 public void invokeActionTest() {
622 final InstanceIdentifierContext<?> result = ParserIdentifier
623 .toInstanceIdentifier(INVOKE_ACTION, SCHEMA_CONTEXT, Optional.empty());
625 // Action schema node
626 final QName actionQName = result.getSchemaNode().getQName();
627 assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
628 assertEquals("reset", actionQName.getLocalName());
631 assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, SCHEMA_CONTEXT), result.getInstanceIdentifier());
632 assertNull(result.getMountPoint());
633 assertSame(SCHEMA_CONTEXT, result.getSchemaContext());
637 * Test invoke Action on mount point.
638 * Verify if Action schema node was found.
641 public void invokeActionOnMountPointTest() {
642 final InstanceIdentifierContext<?> result = ParserIdentifier
643 .toInstanceIdentifier(MOUNT_POINT_IDENT + "/" + INVOKE_ACTION, SCHEMA_CONTEXT,
644 Optional.of(this.mountPointService));
646 // Action schema node
647 final QName actionQName = result.getSchemaNode().getQName();
648 assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
649 assertEquals("reset", actionQName.getLocalName());
652 assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, SCHEMA_CONTEXT), result.getInstanceIdentifier());
653 assertEquals(this.mountPoint, result.getMountPoint());
654 assertEquals(SCHEMA_CONTEXT_ON_MOUNT_POINT, result.getSchemaContext());