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
9 package org.opendaylight.restconf.nb.rfc8040.utils.parser;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.fail;
15 import static org.mockito.Mockito.when;
17 import com.google.common.base.Optional;
18 import com.google.common.collect.ImmutableClassToInstanceMap;
19 import com.google.common.collect.Maps;
20 import org.junit.Before;
21 import org.junit.Rule;
22 import org.junit.Test;
23 import org.junit.rules.ExpectedException;
24 import org.mockito.Mock;
25 import org.mockito.MockitoAnnotations;
26 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
27 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
28 import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
29 import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
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.SimpleDateFormatUtil;
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";
91 // mount point and mount point service
92 private DOMMountPoint mountPoint;
93 private DOMMountPointService mountPointService;
95 // mock mount point and mount point service
97 private DOMMountPoint mockMountPoint;
99 private DOMMountPointService mockMountPointService;
102 public final ExpectedException thrown = ExpectedException.none();
105 public void setup() throws Exception {
106 MockitoAnnotations.initMocks(this);
107 this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier"));
108 this.schemaContextOnMountPoint =
109 YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier"));
111 // create and register mount point
112 this.mountPoint = SimpleDOMMountPoint.create(
113 YangInstanceIdentifier.builder()
114 .node(QName.create("mount:point", "2016-06-02", "mount-container"))
115 .node(QName.create("mount:point", "2016-06-02", "point-number"))
117 ImmutableClassToInstanceMap.copyOf(Maps.newHashMap()),
118 this.schemaContextOnMountPoint
121 this.mountPointService = new DOMMountPointServiceImpl();
122 ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
124 // register mount point with null schema context
125 when(this.mockMountPoint.getSchemaContext()).thenReturn(null);
126 when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY))
127 .thenReturn(Optional.of(this.mockMountPoint));
131 * {@link ParserIdentifier#toInstanceIdentifier(String, SchemaContext)} tests.
135 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when all nodes are defined
139 public void toInstanceIdentifierTest() {
140 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
141 TEST_IDENT, this.schemaContext, Optional.absent());
143 assertEquals("Returned not expected identifier",
144 TEST_IDENT_RESULT, context .getInstanceIdentifier().toString());
148 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when nodes are defined in
152 public void toInstanceIdentifierOtherModulesTest() {
153 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
154 TEST_IDENT_OTHERS, this.schemaContext, Optional.absent());
156 assertEquals("Returned not expected identifier",
157 TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString());
161 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier containing
162 * {@link RestconfConstants#MOUNT}.
165 public void toInstanceIdentifierMountPointTest() {
166 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
167 MOUNT_POINT_IDENT + "/" + TEST_IDENT, this.schemaContext, Optional.of(this.mountPointService));
169 assertEquals("Returned not expected identifier",
170 TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString());
172 assertEquals("Mount point not found",
173 this.mountPoint, context.getMountPoint());
175 assertEquals("Schema context from mount point expected",
176 this.schemaContextOnMountPoint, context.getSchemaContext());
180 * Test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>.
181 * <code>{@link YangInstanceIdentifier#EMPTY}</code> should be returned.
184 public void toInstanceIdentifierNullIdentifierTest() {
185 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
186 null, this.schemaContext, Optional.absent());
187 assertEquals("Returned not expected identifier",
188 YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
192 * Negative test of creating <code>InstanceIdentifierContext</code> when <code>SchemaContext</code> is
193 * <code>null</code>. Test fails expecting <code>NullPointerException</code>.
196 public void toInstanceIdentifierNullSchemaContextNegativeTest() {
197 this.thrown.expect(NullPointerException.class);
198 ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.absent());
202 * Api path can be empty. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
205 public void toInstanceIdentifierEmptyIdentifierTest() {
206 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
207 "", this.schemaContext, Optional.absent());
208 assertEquals("Returned not expected identifier",
209 YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
213 * Negative test with invalid test identifier. Test should fail with <code>IllegalArgumentException</code>.
216 public void toInstanceIdentifierInvalidIdentifierNegativeTest() {
217 this.thrown.expect(IllegalArgumentException.class);
218 ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.absent());
222 * Negative test when identifier contains {@link RestconfConstants#MOUNT} but identifier part is not valid. Test
223 * should fail with <code>IllegalArgumentException</code>.
226 public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {
227 this.thrown.expect(IllegalArgumentException.class);
228 ParserIdentifier.toInstanceIdentifier(
229 INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService));
233 * Negative test when <code>DOMMountPoint</code> cannot be found. Test is expected to fail with
234 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
235 * compared to expected values.
238 public void toInstanceIdentifierMissingMountPointNegativeTest() {
240 ParserIdentifier.toInstanceIdentifier(
241 "" + "/" + RestconfConstants.MOUNT, this.schemaContext, Optional.of(this.mountPointService));
242 fail("Test should fail due to missing mount point");
243 } catch (final RestconfDocumentedException e) {
244 assertEquals("Not expected error type",
245 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
246 assertEquals("Not expected error tag",
247 ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
248 assertEquals("Not expected error status code",
249 404, e.getErrors().get(0).getErrorTag().getStatusCode());
254 * Negative test when <code>{@link DOMMountPointService}</code> is absent. Test is expected to fail with
255 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
256 * compared to expected values.
259 public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
261 ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.absent());
262 fail("Test should fail due to absent mount point service");
263 } catch (final RestconfDocumentedException e) {
264 assertEquals("Not expected error type",
265 ErrorType.APPLICATION, e.getErrors().get(0).getErrorType());
266 assertEquals("Not expected error tag",
267 ErrorTag.OPERATION_FAILED, e.getErrors().get(0).getErrorTag());
268 assertEquals("Not expected error status code",
269 500, e.getErrors().get(0).getErrorTag().getStatusCode());
274 * {@link ParserIdentifier#makeQNameFromIdentifier(String)} tests.
278 * Positive test of making <code>QName</code> from identifier and compare values from returned <code>QName</code>
279 * to expected values.
282 public void makeQNameFromIdentifierTest() {
283 final QName qName = ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION);
285 assertNotNull("QName should be created", qName);
286 assertEquals("Returned not expected module name",
287 TEST_MODULE_NAME, qName.getLocalName());
288 assertEquals("Returned not expected module revision",
289 TEST_MODULE_REVISION, qName.getFormattedRevision());
293 * Negative test when supplied identifier is in invalid format and then revision is not parsable.
294 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
295 * compared to expected values.
298 public void makeQNameFromIdentifierInvalidIdentifierNegativeTest() {
300 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME);
301 fail("Test should fail due to invalid identifier format");
302 } catch (final RestconfDocumentedException e) {
303 assertEquals("Not expected error type",
304 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
305 assertEquals("Not expected error tag",
306 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
307 assertEquals("Not expected error status code",
308 400, e.getErrors().get(0).getErrorTag().getStatusCode());
313 * Negative test when supplied identifier is too short (contains only module name).
314 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
315 * compared to expected values.
318 public void makeQNameFromIdentifierTooShortIdentifierNegativeTest() {
320 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME);
321 fail("Test should fail due to too short identifier format");
322 } catch (final RestconfDocumentedException e) {
323 assertEquals("Not expected error type",
324 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
325 assertEquals("Not expected error tag",
326 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
327 assertEquals("Not expected error status code",
328 400, e.getErrors().get(0).getErrorTag().getStatusCode());
333 * Positive test of making <code>QName</code> from identifier for module behind mount point. Value from returned
334 * <code>QName</code> are compared to expected values.
337 public void makeQNameFromIdentifierMountTest() {
338 final QName qName = ParserIdentifier.makeQNameFromIdentifier(
343 + TEST_MODULE_REVISION);
345 assertNotNull("QName should be created", qName);
346 assertEquals("Returned not expected module name",
347 TEST_MODULE_NAME, qName.getLocalName());
348 assertEquals("Returned not expected module revision",
349 TEST_MODULE_REVISION, qName.getFormattedRevision());
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);
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 TEST_MODULE_REVISION, SimpleDateFormatUtil.getRevisionFormat().format(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",
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);
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);
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 TEST_MODULE_REVISION, SimpleDateFormatUtil.getRevisionFormat().format(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);
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);
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);
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);
597 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
598 * <code>null</code> and identifier specifies module behind mount point. Test is expected to fail with
599 * <code>NullPointerException</code>.
602 public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
603 this.thrown.expect(NullPointerException.class);
604 ParserIdentifier.toSchemaExportContextFromIdentifier(
610 + TEST_MODULE_REVISION,
611 this.mountPointService);
615 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>DOMMountPointService</code>
616 * is <code>null</code> and identifier defines module behind mount point. Test is expected to fail with
617 * <code>NullPointerException</code>.
620 public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
621 this.thrown.expect(NullPointerException.class);
622 ParserIdentifier.toSchemaExportContextFromIdentifier(
628 + TEST_MODULE_REVISION,
633 * Negative test of of getting <code>SchemaExportContext</code> when <code>SchemaContext</code> behind mount
634 * point is <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
637 public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
638 this.thrown.expect(NullPointerException.class);
639 ParserIdentifier.toSchemaExportContextFromIdentifier(
642 + RestconfConstants.MOUNT
646 + TEST_MODULE_REVISION,
647 this.mockMountPointService);
654 * Verify if RPC schema node was found.
657 public void invokeRpcTest() {
658 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
659 INVOKE_RPC, this.schemaContext, Optional.absent());
662 final QName rpcQName = result.getSchemaNode().getQName();
663 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
664 assertEquals("rpc-test", rpcQName.getLocalName());
667 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
668 assertEquals(null, result.getMountPoint());
669 assertEquals(this.schemaContext, result.getSchemaContext());
673 * Test invoke RPC on mount point.
676 * Verify if RPC schema node was found.
679 public void invokeRpcOnMountPointTest() {
680 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
681 MOUNT_POINT_IDENT + "/" + INVOKE_RPC, this.schemaContext, Optional.of(this.mountPointService));
684 final QName rpcQName = result.getSchemaNode().getQName();
685 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
686 assertEquals("rpc-test", rpcQName.getLocalName());
689 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
690 assertEquals(this.mountPoint, result.getMountPoint());
691 assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());