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 java.util.Map.Entry;
21 import org.junit.Before;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
28 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
29 import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
30 import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
31 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
32 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
33 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
34 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
35 import org.opendaylight.restconf.common.errors.RestconfError;
36 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
37 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
38 import org.opendaylight.restconf.common.schema.SchemaExportContext;
39 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
40 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
41 import org.opendaylight.yangtools.yang.common.QName;
42 import org.opendaylight.yangtools.yang.common.Revision;
43 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
44 import org.opendaylight.yangtools.yang.model.api.Module;
45 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
46 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
49 * Unit tests for {@link ParserIdentifier}.
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 // schema context with test modules
84 private SchemaContext schemaContext;
85 // contains the same modules but it is different object (it can be compared with equals)
86 private SchemaContext schemaContextOnMountPoint;
88 private static final String TEST_MODULE_NAME = "test-module";
89 private static final String TEST_MODULE_REVISION = "2016-06-02";
90 private static final String TEST_MODULE_NAMESPACE = "test:module";
92 private static final String INVOKE_RPC = "invoke-rpc-module:rpc-test";
94 // mount point and mount point service
95 private DOMMountPoint mountPoint;
96 private DOMMountPointService mountPointService;
98 // mock mount point and mount point service
100 private DOMMountPoint mockMountPoint;
102 private DOMMountPointService mockMountPointService;
104 private DOMSchemaService domSchemaService;
106 private DOMYangTextSourceProvider sourceProvider;
109 public final ExpectedException thrown = ExpectedException.none();
112 public void setup() throws Exception {
113 MockitoAnnotations.initMocks(this);
114 this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
115 this.schemaContextOnMountPoint =
116 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
118 // create and register mount point
119 this.mountPoint = SimpleDOMMountPoint.create(
120 YangInstanceIdentifier.builder()
121 .node(QName.create("mount:point", "2016-06-02", "mount-container"))
122 .node(QName.create("mount:point", "2016-06-02", "point-number"))
124 ImmutableClassToInstanceMap.copyOf(Maps.newHashMap()),
125 this.schemaContextOnMountPoint
128 this.mountPointService = new DOMMountPointServiceImpl();
129 ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
131 // register mount point with null schema context
132 when(this.mockMountPoint.getSchemaContext()).thenReturn(null);
133 when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY))
134 .thenReturn(Optional.of(this.mockMountPoint));
138 * {@link ParserIdentifier#toInstanceIdentifier(String, SchemaContext)} tests.
142 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when all nodes are defined
146 public void toInstanceIdentifierTest() {
147 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
148 TEST_IDENT, this.schemaContext, Optional.absent());
150 assertEquals("Returned not expected identifier",
151 TEST_IDENT_RESULT, context .getInstanceIdentifier().toString());
155 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when nodes are defined in
159 public void toInstanceIdentifierOtherModulesTest() {
160 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
161 TEST_IDENT_OTHERS, this.schemaContext, Optional.absent());
163 assertEquals("Returned not expected identifier",
164 TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString());
168 * Positive test of creating <code>InstanceIdentifierContext</code> from identifier containing
169 * {@link RestconfConstants#MOUNT}.
172 public void toInstanceIdentifierMountPointTest() {
173 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
174 MOUNT_POINT_IDENT + "/" + TEST_IDENT, this.schemaContext, Optional.of(this.mountPointService));
176 assertEquals("Returned not expected identifier",
177 TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString());
179 assertEquals("Mount point not found",
180 this.mountPoint, context.getMountPoint());
182 assertEquals("Schema context from mount point expected",
183 this.schemaContextOnMountPoint, context.getSchemaContext());
187 * Test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>.
188 * <code>{@link YangInstanceIdentifier#EMPTY}</code> should be returned.
191 public void toInstanceIdentifierNullIdentifierTest() {
192 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
193 null, this.schemaContext, Optional.absent());
194 assertEquals("Returned not expected identifier",
195 YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
199 * Negative test of creating <code>InstanceIdentifierContext</code> when <code>SchemaContext</code> is
200 * <code>null</code>. Test fails expecting <code>NullPointerException</code>.
203 public void toInstanceIdentifierNullSchemaContextNegativeTest() {
204 this.thrown.expect(NullPointerException.class);
205 ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.absent());
209 * Api path can be empty. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
212 public void toInstanceIdentifierEmptyIdentifierTest() {
213 final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
214 "", this.schemaContext, Optional.absent());
215 assertEquals("Returned not expected identifier",
216 YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
220 * Negative test with invalid test identifier. Test should fail with <code>IllegalArgumentException</code>.
223 public void toInstanceIdentifierInvalidIdentifierNegativeTest() {
224 this.thrown.expect(IllegalArgumentException.class);
225 ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.absent());
229 * Negative test when identifier contains {@link RestconfConstants#MOUNT} but identifier part is not valid. Test
230 * should fail with <code>IllegalArgumentException</code>.
233 public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {
234 this.thrown.expect(IllegalArgumentException.class);
235 ParserIdentifier.toInstanceIdentifier(
236 INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService));
240 * Negative test when <code>DOMMountPoint</code> cannot be found. Test is expected to fail with
241 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
242 * compared to expected values.
245 public void toInstanceIdentifierMissingMountPointNegativeTest() {
247 ParserIdentifier.toInstanceIdentifier(
248 "" + "/" + RestconfConstants.MOUNT, this.schemaContext, Optional.of(this.mountPointService));
249 fail("Test should fail due to missing mount point");
250 } catch (final RestconfDocumentedException e) {
251 assertEquals("Not expected error type",
252 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
253 assertEquals("Not expected error tag",
254 ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
255 assertEquals("Not expected error status code",
256 404, e.getErrors().get(0).getErrorTag().getStatusCode());
261 * Negative test when <code>{@link DOMMountPointService}</code> is absent. Test is expected to fail with
262 * <code>RestconfDocumentedException</code> error type, error tag and error status code are
263 * compared to expected values.
266 public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
268 ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.absent());
269 fail("Test should fail due to absent mount point service");
270 } catch (final RestconfDocumentedException e) {
271 assertEquals("Not expected error type",
272 ErrorType.APPLICATION, e.getErrors().get(0).getErrorType());
273 assertEquals("Not expected error tag",
274 ErrorTag.OPERATION_FAILED, e.getErrors().get(0).getErrorTag());
275 assertEquals("Not expected error status code",
276 500, e.getErrors().get(0).getErrorTag().getStatusCode());
281 * {@link ParserIdentifier#makeQNameFromIdentifier(String)} tests.
285 * Positive test of making <code>QName</code> from identifier and compare values from returned <code>QName</code>
286 * to expected values.
289 public void makeQNameFromIdentifierTest() {
290 final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
291 TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION);
293 assertNotNull("QName should be created", qName);
294 assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
295 assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
299 * Negative test when supplied identifier is in invalid format and then revision is not parsable.
300 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
301 * compared to expected values.
304 public void makeQNameFromIdentifierInvalidIdentifierNegativeTest() {
306 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME);
307 fail("Test should fail due to invalid identifier format");
308 } catch (final RestconfDocumentedException e) {
309 assertEquals("Not expected error type",
310 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
311 assertEquals("Not expected error tag",
312 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
313 assertEquals("Not expected error status code",
314 400, e.getErrors().get(0).getErrorTag().getStatusCode());
319 * Negative test when supplied identifier is too short (contains only module name).
320 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
321 * compared to expected values.
324 public void makeQNameFromIdentifierTooShortIdentifierNegativeTest() {
326 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME);
327 fail("Test should fail due to too short identifier format");
328 } catch (final RestconfDocumentedException e) {
329 assertEquals("Not expected error type",
330 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
331 assertEquals("Not expected error tag",
332 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
333 assertEquals("Not expected error status code",
334 400, e.getErrors().get(0).getErrorTag().getStatusCode());
339 * Positive test of making <code>QName</code> from identifier for module behind mount point. Value from returned
340 * <code>QName</code> are compared to expected values.
343 public void makeQNameFromIdentifierMountTest() {
344 final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
349 + TEST_MODULE_REVISION);
351 assertNotNull("QName should be created", qName);
352 assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
353 assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
357 * Negative test when supplied identifier for module behind mount point is in invalid format and then revision is
358 * not parsable. <code>RestconfDocumentedException</code> is expected and error type, error tag and error status
359 * code are compared to expected values.
362 public void makeQNameFromIdentifierMountPointInvalidIdentifierNegativeTest() {
364 ParserIdentifier.makeQNameFromIdentifier(
367 + TEST_MODULE_REVISION
371 fail("Test should fail due to invalid identifier format");
372 } catch (final RestconfDocumentedException e) {
373 assertEquals("Not expected error type",
374 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
375 assertEquals("Not expected error tag",
376 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
377 assertEquals("Not expected error status code",
378 400, e.getErrors().get(0).getErrorTag().getStatusCode());
383 * Negative test when supplied identifier for module behind mount point is too short (contains only module name).
384 * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code
385 * are compared to expected values.
388 public void makeQNameFromIdentifierMountPointTooShortIdentifierNegativeTest() {
390 ParserIdentifier.makeQNameFromIdentifier(
395 fail("Test should fail due to too short identifier format");
396 } catch (final RestconfDocumentedException e) {
397 assertEquals("Not expected error type",
398 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
399 assertEquals("Not expected error tag",
400 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
401 assertEquals("Not expected error status code",
402 400, e.getErrors().get(0).getErrorTag().getStatusCode());
407 * Negative test trying to make <code>QName</code> from <code>null</code> identifier. Test is expected to fail with
408 * <code>NullPointerException</code>.
411 public void makeQNameFromIdentifierNullIdentifierNegativeTest() {
412 this.thrown.expect(NullPointerException.class);
413 ParserIdentifier.makeQNameFromIdentifier(null);
417 * Negative test trying to make <code>QName</code> from empty identifier. Test is expected to fail with
418 * <code>RestconfDocumentedException</code>. Error type, error tag and error status code is compared to expected
422 public void makeQNameFromIdentifierEmptyIdentifierNegativeTest() {
424 ParserIdentifier.makeQNameFromIdentifier("");
425 fail("Test should fail due to empty identifier");
426 } catch (final RestconfDocumentedException e) {
427 assertEquals("Not expected error type",
428 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
429 assertEquals("Not expected error tag",
430 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
431 assertEquals("Not expected error status code",
432 400, e.getErrors().get(0).getErrorTag().getStatusCode());
437 * Negative test with identifier containing double slash. Between // there is one empty string which will be
438 * incorrectly considered to be module revision. Test is expected to fail with
439 * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
443 public void makeQNameFromIdentifierDoubleSlashNegativeTest() {
445 ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION);
446 fail("Test should fail due to identifier containing double slash");
447 } catch (final RestconfDocumentedException e) {
448 assertEquals("Not expected error type",
449 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
450 assertEquals("Not expected error tag",
451 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
452 assertEquals("Not expected error status code",
453 400, e.getErrors().get(0).getErrorTag().getStatusCode());
458 * {@link ParserIdentifier#toSchemaExportContextFromIdentifier(SchemaContext, String, DOMMountPointService)} tests.
462 * Positive test of getting <code>SchemaExportContext</code>. Expected module name, revision and namespace are
466 public void toSchemaExportContextFromIdentifierTest() {
467 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
468 this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
470 assertNotNull("Export context should be parsed", exportContext);
472 final Module module = exportContext.getModule();
473 assertNotNull("Export context should contains test module", module);
475 assertEquals("Returned not expected module name",
476 TEST_MODULE_NAME, module.getName());
477 assertEquals("Returned not expected module revision",
478 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
479 assertEquals("Returned not expected module namespace",
480 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
484 * Test of getting <code>SchemaExportContext</code> when desired module is not found.
485 * <code>SchemaExportContext</code> should be created but module should be set to <code>null</code>.
488 public void toSchemaExportContextFromIdentifierNotFoundTest() {
489 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
491 "not-existing-module" + "/" + "2016-01-01",
492 null, sourceProvider);
494 assertNotNull("Export context should be parsed", exportContext);
495 assertNull("Not-existing module should be null", exportContext.getModule());
499 * Negative test trying to get <code>SchemaExportContext</code> with invalid identifier. Test is expected to fail
500 * with <code>RestconfDocumentedException</code> error type, error tag and error status code are compared to
504 public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
506 ParserIdentifier.toSchemaExportContextFromIdentifier(
507 this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider);
508 fail("Test should fail due to invalid identifier supplied");
509 } catch (final RestconfDocumentedException e) {
510 assertEquals("Not expected error type",
511 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
512 assertEquals("Not expected error tag",
513 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
514 assertEquals("Not expected error status code",
515 400, e.getErrors().get(0).getErrorTag().getStatusCode());
520 * Positive test of getting <code>SchemaExportContext</code> for module behind mount point.
521 * Expected module name, revision and namespace are verified.
524 public void toSchemaExportContextFromIdentifierMountPointTest() {
525 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
527 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
528 this.mountPointService, sourceProvider);
530 final Module module = exportContext.getModule();
531 assertNotNull("Export context should contains test module", module);
533 assertEquals("Returned not expected module name",
534 TEST_MODULE_NAME, module.getName());
535 assertEquals("Returned not expected module revision",
536 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
537 assertEquals("Returned not expected module namespace",
538 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
542 * Negative test of getting <code>SchemaExportContext</code> when desired module is not found behind mount point.
543 * <code>SchemaExportContext</code> should be still created but module should be set to <code>null</code>.
546 public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
547 final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
549 MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
550 this.mountPointService, sourceProvider);
552 assertNotNull("Export context should be parsed", exportContext);
553 assertNull("Not-existing module should be null", exportContext.getModule());
557 * Negative test trying to get <code>SchemaExportContext</code> behind mount point with invalid identifier. Test is
558 * expected to fail with <code>RestconfDocumentedException</code> error type, error tag and error status code are
559 * compared to expected values.
562 public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() {
564 ParserIdentifier.toSchemaExportContextFromIdentifier(
566 MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
567 this.mountPointService, sourceProvider);
569 fail("Test should fail due to invalid identifier supplied");
570 } catch (final RestconfDocumentedException e) {
571 assertEquals("Not expected error type",
572 RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
573 assertEquals("Not expected error tag",
574 RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
575 assertEquals("Not expected error status code",
576 400, e.getErrors().get(0).getErrorTag().getStatusCode());
581 * Negative test of getting <code>SchemaExportContext</code> when supplied identifier is null.
582 * <code>NullPointerException</code> is expected. <code>DOMMountPointService</code> is not used.
585 public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
586 this.thrown.expect(NullPointerException.class);
587 ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null, sourceProvider);
591 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
592 * <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
595 public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
596 this.thrown.expect(NullPointerException.class);
597 ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
602 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
603 * <code>null</code> and identifier specifies module behind mount point. Test is expected to fail with
604 * <code>NullPointerException</code>.
607 public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
608 this.thrown.expect(NullPointerException.class);
609 ParserIdentifier.toSchemaExportContextFromIdentifier(
615 + TEST_MODULE_REVISION,
616 this.mountPointService,
621 * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>DOMMountPointService</code>
622 * is <code>null</code> and identifier defines module behind mount point. Test is expected to fail with
623 * <code>NullPointerException</code>.
626 public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
627 this.thrown.expect(NullPointerException.class);
628 ParserIdentifier.toSchemaExportContextFromIdentifier(
634 + TEST_MODULE_REVISION,
640 * Negative test of of getting <code>SchemaExportContext</code> when <code>SchemaContext</code> behind mount
641 * point is <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
644 public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
645 this.thrown.expect(NullPointerException.class);
646 ParserIdentifier.toSchemaExportContextFromIdentifier(
649 + RestconfConstants.MOUNT
653 + TEST_MODULE_REVISION,
654 this.mockMountPointService,
662 * Verify if RPC schema node was found.
665 public void invokeRpcTest() {
666 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
667 INVOKE_RPC, this.schemaContext, Optional.absent());
670 final QName rpcQName = result.getSchemaNode().getQName();
671 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
672 assertEquals("rpc-test", rpcQName.getLocalName());
675 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
676 assertEquals(null, result.getMountPoint());
677 assertEquals(this.schemaContext, result.getSchemaContext());
681 * Test invoke RPC on mount point.
684 * Verify if RPC schema node was found.
687 public void invokeRpcOnMountPointTest() {
688 final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
689 MOUNT_POINT_IDENT + "/" + INVOKE_RPC, this.schemaContext, Optional.of(this.mountPointService));
692 final QName rpcQName = result.getSchemaNode().getQName();
693 assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
694 assertEquals("rpc-test", rpcQName.getLocalName());
697 assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
698 assertEquals(this.mountPoint, result.getMountPoint());
699 assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());