Bug 7433 - Remove use of YangSchemaSourceImpl from restconf tests
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / restconf / utils / parser / ParserIdentifierTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.restconf.utils.parser;
10
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;
16
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.controller.md.sal.rest.common.TestRestconfUtils;
31 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
32 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
33 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
34 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
35 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
36 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
37 import org.opendaylight.restconf.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;
44
45 /**
46  * Unit tests for {@link ParserIdentifier}
47  */
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;
52
53     // invalid mount point identifier
54     private static final String INVALID_MOUNT_POINT_IDENT =
55             "mount-point:point-number" + "/" + RestconfConstants.MOUNT;
56
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";
60
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";
64
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";
68
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";
75
76     // invalid test identifier
77     private static final String INVALID_TEST_IDENT =
78             "parser-identifier:cont2/listTest/list-in-grouping=name/leaf-A.B";
79
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;
84
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";
88
89     // mount point and mount point service
90     private DOMMountPoint mountPoint;
91     private DOMMountPointService mountPointService;
92
93     // mock mount point and mount point service
94     @Mock
95     private DOMMountPoint mockMountPoint;
96     @Mock
97     private DOMMountPointService mockMountPointService;
98
99     @Rule
100     public final ExpectedException thrown = ExpectedException.none();
101
102     @Before
103     public void setup() throws Exception {
104         MockitoAnnotations.initMocks(this);
105         this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier"));
106         this.schemaContextOnMountPoint =
107                 YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier"));
108
109         // create and register mount point
110         this.mountPoint = SimpleDOMMountPoint.create(
111                 YangInstanceIdentifier.builder()
112                         .node(QName.create("mount:point", "2016-06-02", "mount-container"))
113                         .node(QName.create("mount:point", "2016-06-02", "point-number"))
114                         .build(),
115                 ImmutableClassToInstanceMap.copyOf(Maps.newHashMap()),
116                 this.schemaContextOnMountPoint
117         );
118
119         this.mountPointService = new DOMMountPointServiceImpl();
120         ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
121
122         // register mount point with null schema context
123         when(this.mockMountPoint.getSchemaContext()).thenReturn(null);
124         when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY)).thenReturn(Optional.of(this.mockMountPoint));
125     }
126
127     /**
128      * {@link ParserIdentifier#toInstanceIdentifier(String, SchemaContext)} tests
129      */
130
131     /**
132      * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when all nodes are defined
133      * in one module.
134      */
135     @Test
136     public void toInstanceIdentifierTest() {
137         final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
138                 TEST_IDENT, this.schemaContext, Optional.absent());
139
140         assertEquals("Returned not expected identifier",
141                 TEST_IDENT_RESULT, context .getInstanceIdentifier().toString());
142     }
143
144     /**
145      * Positive test of creating <code>InstanceIdentifierContext</code> from identifier when nodes are defined in
146      * multiple modules.
147      */
148     @Test
149     public void toInstanceIdentifierOtherModulesTest() {
150         final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
151                 TEST_IDENT_OTHERS, this.schemaContext, Optional.absent());
152
153         assertEquals("Returned not expected identifier",
154                 TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString());
155     }
156
157     /**
158      * Positive test of creating <code>InstanceIdentifierContext</code> from identifier containing
159      * {@link RestconfConstants#MOUNT}.
160      */
161     @Test
162     public void toInstanceIdentifierMountPointTest() {
163         final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
164                 MOUNT_POINT_IDENT + "/" + TEST_IDENT, this.schemaContext, Optional.of(this.mountPointService));
165
166         assertEquals("Returned not expected identifier",
167                 TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString());
168
169         assertEquals("Mount point not found",
170                 this.mountPoint, context.getMountPoint());
171
172         assertEquals("Schema context from mount point expected",
173                 this.schemaContextOnMountPoint, context.getSchemaContext());
174     }
175
176     /**
177      * Test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>.
178      * <code>{@link YangInstanceIdentifier#EMPTY}</code> should be returned.
179      */
180     @Test
181     public void toInstanceIdentifierNullIdentifierTest() {
182         final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
183                 null, this.schemaContext, Optional.absent());
184         assertEquals("Returned not expected identifier",
185                 YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
186     }
187
188     /**
189      * Negative test of creating <code>InstanceIdentifierContext</code> when <code>SchemaContext</code> is
190      * <code>null</code>. Test fails expecting <code>NullPointerException</code>.
191      */
192     @Test
193     public void toInstanceIdentifierNullSchemaContextNegativeTest() {
194         this.thrown.expect(NullPointerException.class);
195         ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.absent());
196     }
197
198     /**
199      * Api path can be empty. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
200      */
201     @Test
202     public void toInstanceIdentifierEmptyIdentifierTest() {
203         final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
204                 "", this.schemaContext, Optional.absent());
205         assertEquals("Returned not expected identifier",
206                 YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
207     }
208
209     /**
210      * Negative test with invalid test identifier. Test should fail with <code>IllegalArgumentException</code>.
211      */
212     @Test
213     public void toInstanceIdentifierInvalidIdentifierNegativeTest() {
214         this.thrown.expect(IllegalArgumentException.class);
215         ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.absent());
216     }
217
218     /**
219      * Negative test when identifier contains {@link RestconfConstants#MOUNT} but identifier part is not valid. Test
220      * should fail with <code>IllegalArgumentException</code>.
221      */
222     @Test
223     public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {
224         this.thrown.expect(IllegalArgumentException.class);
225         ParserIdentifier.toInstanceIdentifier(INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService));
226     }
227
228     /**
229      * Negative test when <code>DOMMountPoint</code> cannot be found. Test is expected to fail with
230      * <code>RestconfDocumentedException</code> error type, error tag and error status code are
231      * compared to expected values.
232      */
233     @Test
234     public void toInstanceIdentifierMissingMountPointNegativeTest() {
235         try {
236             ParserIdentifier.toInstanceIdentifier(
237                     "" + "/" + RestconfConstants.MOUNT, this.schemaContext, Optional.of(this.mountPointService));
238             fail("Test should fail due to missing mount point");
239         } catch (final RestconfDocumentedException e) {
240             assertEquals("Not expected error type",
241                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
242             assertEquals("Not expected error tag",
243                     ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
244             assertEquals("Not expected error status code",
245                     404, e.getErrors().get(0).getErrorTag().getStatusCode());
246         }
247     }
248
249     /**
250      * Negative test when <code>{@link DOMMountPointService}</code> is absent. Test is expected to fail with
251      * <code>RestconfDocumentedException</code> error type, error tag and error status code are
252      * compared to expected values.
253      */
254     @Test
255     public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
256         try {
257             ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.absent());
258             fail("Test should fail due to absent mount point service");
259         } catch (final RestconfDocumentedException e) {
260             assertEquals("Not expected error type",
261                     ErrorType.APPLICATION, e.getErrors().get(0).getErrorType());
262             assertEquals("Not expected error tag",
263                     ErrorTag.OPERATION_FAILED, e.getErrors().get(0).getErrorTag());
264             assertEquals("Not expected error status code",
265                     500, e.getErrors().get(0).getErrorTag().getStatusCode());
266         }
267     }
268
269     /**
270      * {@link ParserIdentifier#makeQNameFromIdentifier(String)} tests
271      */
272
273     /**
274      * Positive test of making <code>QName</code> from identifier and compare values from returned <code>QName</code>
275      * to expected values.
276      */
277     @Test
278     public void makeQNameFromIdentifierTest() {
279         final QName qName = ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION);
280
281         assertNotNull("QName should be created", qName);
282         assertEquals("Returned not expected module name",
283                 TEST_MODULE_NAME, qName.getLocalName());
284         assertEquals("Returned not expected module revision",
285                 TEST_MODULE_REVISION, qName.getFormattedRevision());
286     }
287
288     /**
289      * Negative test when supplied identifier is in invalid format and then revision is not parsable.
290      * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
291      * compared to expected values.
292      */
293     @Test
294     public void makeQNameFromIdentifierInvalidIdentifierNegativeTest() {
295         try {
296             ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME);
297             fail("Test should fail due to invalid identifier format");
298         } catch (final RestconfDocumentedException e) {
299             assertEquals("Not expected error type",
300                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
301             assertEquals("Not expected error tag",
302                     RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
303             assertEquals("Not expected error status code",
304                     400, e.getErrors().get(0).getErrorTag().getStatusCode());
305         }
306     }
307
308     /**
309      * Negative test when supplied identifier is too short (contains only module name).
310      * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
311      * compared to expected values.
312      */
313     @Test
314     public void makeQNameFromIdentifierTooShortIdentifierNegativeTest() {
315         try {
316             ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME);
317             fail("Test should fail due to too short identifier format");
318         } catch (final RestconfDocumentedException e) {
319             assertEquals("Not expected error type",
320                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
321             assertEquals("Not expected error tag",
322                     RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
323             assertEquals("Not expected error status code",
324                     400, e.getErrors().get(0).getErrorTag().getStatusCode());
325         }
326     }
327
328     /**
329      * Positive test of making <code>QName</code> from identifier for module behind mount point. Value from returned
330      * <code>QName</code> are compared to expected values.
331      */
332     @Test
333     public void makeQNameFromIdentifierMountTest() {
334         final QName qName = ParserIdentifier.makeQNameFromIdentifier(
335                 MOUNT_POINT_IDENT
336                 + "/"
337                 + TEST_MODULE_NAME
338                 + "/"
339                 + TEST_MODULE_REVISION);
340
341         assertNotNull("QName should be created", qName);
342         assertEquals("Returned not expected module name",
343                 TEST_MODULE_NAME, qName.getLocalName());
344         assertEquals("Returned not expected module revision",
345                 TEST_MODULE_REVISION, qName.getFormattedRevision());
346     }
347
348     /**
349      * Negative test when supplied identifier for module behind mount point is in invalid format and then revision is
350      * not parsable. <code>RestconfDocumentedException</code> is expected and error type, error tag and error status
351      * code are compared to expected values.
352      */
353     @Test
354     public void makeQNameFromIdentifierMountPointInvalidIdentifierNegativeTest() {
355         try {
356             ParserIdentifier.makeQNameFromIdentifier(
357                     MOUNT_POINT_IDENT
358                     + "/"
359                     + TEST_MODULE_REVISION
360                     + "/"
361                     + TEST_MODULE_NAME);
362
363             fail("Test should fail due to invalid identifier format");
364         } catch (final RestconfDocumentedException e) {
365             assertEquals("Not expected error type",
366                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
367             assertEquals("Not expected error tag",
368                     RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
369             assertEquals("Not expected error status code",
370                     400, e.getErrors().get(0).getErrorTag().getStatusCode());
371         }
372     }
373
374     /**
375      * Negative test when supplied identifier for module behind mount point is too short (contains only module name).
376      * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code
377      * are compared to expected values.
378      */
379     @Test
380     public void makeQNameFromIdentifierMountPointTooShortIdentifierNegativeTest() {
381         try {
382             ParserIdentifier.makeQNameFromIdentifier(
383                     MOUNT_POINT_IDENT
384                     + "/"
385                     + TEST_MODULE_NAME);
386
387             fail("Test should fail due to too short identifier format");
388         } catch (final RestconfDocumentedException e) {
389             assertEquals("Not expected error type",
390                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
391             assertEquals("Not expected error tag",
392                     RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
393             assertEquals("Not expected error status code",
394                     400, e.getErrors().get(0).getErrorTag().getStatusCode());
395         }
396     }
397
398     /**
399      * Negative test trying to make <code>QName</code> from <code>null</code> identifier. Test is expected to fail with
400      * <code>NullPointerException</code>.
401      */
402     @Test
403     public void makeQNameFromIdentifierNullIdentifierNegativeTest() {
404         this.thrown.expect(NullPointerException.class);
405         ParserIdentifier.makeQNameFromIdentifier(null);
406     }
407
408     /**
409      * Negative test trying to make <code>QName</code> from empty identifier. Test is expected to fail with
410      * <code>RestconfDocumentedException</code>. Error type, error tag and error status code is compared to expected
411      * values.
412      */
413     @Test
414     public void makeQNameFromIdentifierEmptyIdentifierNegativeTest() {
415         try {
416             ParserIdentifier.makeQNameFromIdentifier("");
417             fail("Test should fail due to empty identifier");
418         } catch (final RestconfDocumentedException e) {
419             assertEquals("Not expected error type",
420                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
421             assertEquals("Not expected error tag",
422                     RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
423             assertEquals("Not expected error status code",
424                     400, e.getErrors().get(0).getErrorTag().getStatusCode());
425         }
426     }
427
428     /**
429      * Negative test with identifier containing double slash. Between // there is one empty string which will be
430      * incorrectly considered to be module revision. Test is expected to fail with
431      * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
432      * expected values.
433      */
434     @Test
435     public void makeQNameFromIdentifierDoubleSlashNegativeTest() {
436         try {
437             ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION);
438             fail("Test should fail due to identifier containing double slash");
439         } catch (final RestconfDocumentedException e) {
440             assertEquals("Not expected error type",
441                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
442             assertEquals("Not expected error tag",
443                     RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
444             assertEquals("Not expected error status code",
445                     400, e.getErrors().get(0).getErrorTag().getStatusCode());
446         }
447     }
448
449     /**
450      * {@link ParserIdentifier#toSchemaExportContextFromIdentifier(SchemaContext, String, DOMMountPointService)} tests
451      */
452
453     /**
454      * Positive test of getting <code>SchemaExportContext</code>. Expected module name, revision and namespace are
455      * verified.
456      */
457     @Test
458     public void toSchemaExportContextFromIdentifierTest() {
459         final SchemaExportContext exportContext = ParserIdentifier.
460                 toSchemaExportContextFromIdentifier(this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
461
462         assertNotNull("Export context should be parsed", exportContext);
463
464         final Module module = exportContext.getModule();
465         assertNotNull("Export context should contains test module", module);
466
467         assertEquals("Returned not expected module name",
468                 TEST_MODULE_NAME, module.getName());
469         assertEquals("Returned not expected module revision",
470                 TEST_MODULE_REVISION, SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()));
471         assertEquals("Returned not expected module namespace",
472                 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
473     }
474
475     /**
476      * Test of getting <code>SchemaExportContext</code> when desired module is not found.
477      * <code>SchemaExportContext</code> should be created but module should be set to <code>null</code>.
478      */
479     @Test
480     public void toSchemaExportContextFromIdentifierNotFoundTest() {
481         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
482                 this.schemaContext,
483                 "not-existing-module" + "/" + "2016-01-01",
484                 null);
485
486         assertNotNull("Export context should be parsed", exportContext);
487         assertNull("Not-existing module should be null", exportContext.getModule());
488     }
489
490     /**
491      * Negative test trying to get <code>SchemaExportContext</code> with invalid identifier. Test is expected to fail
492      * with <code>RestconfDocumentedException</code> error type, error tag and error status code are compared to
493      * expected values.
494      */
495     @Test
496     public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
497         try {
498             ParserIdentifier.toSchemaExportContextFromIdentifier(
499                     this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null);
500             fail("Test should fail due to invalid identifier supplied");
501         } catch (final RestconfDocumentedException e) {
502             assertEquals("Not expected error type",
503                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
504             assertEquals("Not expected error tag",
505                     RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
506             assertEquals("Not expected error status code",
507                     400, e.getErrors().get(0).getErrorTag().getStatusCode());
508         }
509     }
510
511     /**
512      * Positive test of getting <code>SchemaExportContext</code> for module behind mount point.
513      * Expected module name, revision and namespace are verified.
514      */
515     @Test
516     public void toSchemaExportContextFromIdentifierMountPointTest() {
517         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
518                 this.schemaContext,
519                 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
520                 this.mountPointService);
521
522         final Module module = exportContext.getModule();
523         assertNotNull("Export context should contains test module", module);
524
525         assertEquals("Returned not expected module name",
526                 TEST_MODULE_NAME, module.getName());
527         assertEquals("Returned not expected module revision",
528                 TEST_MODULE_REVISION, SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()));
529         assertEquals("Returned not expected module namespace",
530                 TEST_MODULE_NAMESPACE, module.getNamespace().toString());
531     }
532
533     /**
534      * Negative test of getting <code>SchemaExportContext</code> when desired module is not found behind mount point.
535      * <code>SchemaExportContext</code> should be still created but module should be set to <code>null</code>.
536      */
537     @Test
538     public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
539         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
540                 this.schemaContext,
541                 MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
542                 this.mountPointService);
543
544         assertNotNull("Export context should be parsed", exportContext);
545         assertNull("Not-existing module should be null", exportContext.getModule());
546     }
547
548     /**
549      * Negative test trying to get <code>SchemaExportContext</code> behind mount point with invalid identifier. Test is
550      * expected to fail with <code>RestconfDocumentedException</code> error type, error tag and error status code are
551      * compared to expected values.
552      */
553     @Test
554     public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() {
555         try {
556             ParserIdentifier.toSchemaExportContextFromIdentifier(
557                     this.schemaContext,
558                     MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
559                     this.mountPointService);
560
561             fail("Test should fail due to invalid identifier supplied");
562         } catch (final RestconfDocumentedException e) {
563             assertEquals("Not expected error type",
564                     RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
565             assertEquals("Not expected error tag",
566                     RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
567             assertEquals("Not expected error status code",
568                     400, e.getErrors().get(0).getErrorTag().getStatusCode());
569         }
570     }
571
572     /**
573      * Negative test of getting <code>SchemaExportContext</code> when supplied identifier is null.
574      * <code>NullPointerException</code> is expected. <code>DOMMountPointService</code> is not used.
575      */
576     @Test
577     public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
578         this.thrown.expect(NullPointerException.class);
579         ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null);
580     }
581
582     /**
583      * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
584      * <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
585      */
586     @Test
587     public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
588         this.thrown.expect(NullPointerException.class);
589         ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
590     }
591
592     /**
593      * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>SchemaContext</code> is
594      * <code>null</code> and identifier specifies module behind mount point. Test is expected to fail with
595      * <code>NullPointerException</code>.
596      */
597     @Test
598     public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
599         this.thrown.expect(NullPointerException.class);
600         ParserIdentifier.toSchemaExportContextFromIdentifier(
601                 null,
602                 MOUNT_POINT_IDENT
603                 + "/"
604                 + TEST_MODULE_NAME
605                 + "/"
606                 + TEST_MODULE_REVISION,
607                 this.mountPointService);
608     }
609
610     /**
611      * Negative test of of getting <code>SchemaExportContext</code> when supplied <code>DOMMountPointService</code>
612      * is <code>null</code> and identifier defines module behind mount point. Test is expected to fail with
613      * <code>NullPointerException</code>.
614      */
615     @Test
616     public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
617         this.thrown.expect(NullPointerException.class);
618         ParserIdentifier.toSchemaExportContextFromIdentifier(
619                 this.schemaContext,
620                 MOUNT_POINT_IDENT
621                 + "/"
622                 + TEST_MODULE_NAME
623                 + "/"
624                 + TEST_MODULE_REVISION,
625                 null);
626     }
627
628     /**
629      * Negative test of of getting <code>SchemaExportContext</code> when <code>SchemaContext</code> behind mount
630      * point is <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
631      */
632     @Test
633     public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
634         this.thrown.expect(NullPointerException.class);
635         ParserIdentifier.toSchemaExportContextFromIdentifier(
636                 this.schemaContext,
637                 "/"
638                 + RestconfConstants.MOUNT
639                 + "/"
640                 + TEST_MODULE_NAME
641                 + "/"
642                 + TEST_MODULE_REVISION,
643                 this.mockMountPointService);
644     }
645 }