Bug 7231 - Upgrade ietf-restconf draft17 to draft18
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / restconf / rest / services / impl / RestconfModulesServiceTest.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 package org.opendaylight.restconf.rest.services.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.spy;
16 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.ALLOWED_KEYWORDS;
17 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.MOUNT_POINT;
18 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.NOT_EXISTING_MODULE;
19 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.NOT_EXISTING_MODULE_BEHIND_MOUNT_POINT;
20 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.NOT_REGISTERED_MOUNT_POINT;
21 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.TEST_MODULE;
22 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.TEST_MODULE_BEHIND_MOUNT_POINT;
23 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.TEST_MODULE_BEHIND_NOT_REGISTERED_MOUNT_POINT;
24 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.getExpectedModules;
25 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.getExpectedModulesBehindMountPoint;
26 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.setupCustomRestconfModule;
27 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.setupCustomRestconfModuleMountPoint;
28 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.setupMissingRestconfModule;
29 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.setupMissingRestconfModuleMountPoint;
30 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.setupNormal;
31 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.setupNormalMountPoint;
32 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.setupNullMountPointService;
33 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.verifyModule;
34 import static org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.verifyModules;
35
36 import java.util.AbstractMap.SimpleImmutableEntry;
37 import java.util.Collection;
38 import java.util.Collections;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import java.util.Map.Entry;
42 import java.util.Set;
43 import org.junit.Rule;
44 import org.junit.Test;
45 import org.junit.rules.ExpectedException;
46 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
47 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
48 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
49 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
50 import org.opendaylight.restconf.Draft18.RestconfModule;
51 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
52 import org.opendaylight.restconf.handlers.SchemaContextHandler;
53 import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
54 import org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.TestModule;
55 import org.opendaylight.restconf.utils.RestconfConstants;
56 import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeConstants;
57 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
58 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
59 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
60 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
61 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
62 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerAttrNode;
63 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
64 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
65
66 /**
67  * Unit tests of the {@link RestconfModulesServiceImpl}
68  *
69  */
70 public class RestconfModulesServiceTest {
71     @Rule public ExpectedException thrown = ExpectedException.none();
72
73     /**
74      * Test non-null init of {@link RestconfModulesServiceImpl}.
75      */
76     @Test
77     public void restconfModulesServiceImplInitTest() {
78         assertNotNull("Modules service should be initialized and not null",
79                 new RestconfModulesServiceImpl(mock(SchemaContextHandler.class),
80                         mock(DOMMountPointServiceHandler.class)));
81     }
82
83     /**
84      * Test getting all modules supported by the server. Retrieved modules are verified by the name, namespace and
85      * revision.
86      */
87     @Test
88     public void getModulesTest() throws Exception {
89         // load schema context with testing modules and correct Restconf module
90         final RestconfModulesService modulesService = setupNormal();
91
92         // make test
93         final NormalizedNodeContext nodeContext = modulesService.getModules(null);
94
95         // check if expected modules were loaded
96         assertNotNull("Node context cannot be null", nodeContext);
97         final Collection<?> modules = (Collection<?>) ((ContainerNode) nodeContext .getData())
98                 .getValue().iterator().next().getValue();
99         final Set<TestModule> loadedModules = new HashSet<>();
100
101         for (final Object node : modules) {
102             final Iterator mapEntries = ((AbstractImmutableDataContainerAttrNode) node).getChildren().entrySet()
103                     .iterator();
104             final TestModule loadedModule = new TestModule();
105
106             while (mapEntries.hasNext()) {
107                 final Entry e = ((SimpleImmutableEntry) mapEntries.next());
108                 final String key = ((NodeIdentifier) e.getKey()).getNodeType().getLocalName();
109
110                 assertTrue("Not allowed keyword", ALLOWED_KEYWORDS.contains(key));
111
112                 switch (key) {
113                     case RestconfMappingNodeConstants.NAME:
114                         loadedModule.setName((String) ((LeafNode) e.getValue()).getValue());
115                         break;
116                     case RestconfMappingNodeConstants.NAMESPACE:
117                         loadedModule.setNamespace((String) ((LeafNode) e.getValue()).getValue());
118                         break;
119                     case RestconfMappingNodeConstants.REVISION:
120                          loadedModule.setRevision((String) ((LeafNode) e.getValue()).getValue());
121                     break;
122                     case RestconfMappingNodeConstants.FEATURE:
123                         break;
124                 }
125             }
126
127             loadedModules.add(loadedModule);
128         }
129
130         verifyModules(getExpectedModules(), loadedModules);
131     }
132
133     /**
134      * Test getting all modules supported by the mount point. Retrieved modules are verified by the name, namespace and
135      * revision.
136      */
137     @Test
138     public void getModulesMountPointTest() throws Exception {
139         // load testing modules and correct Restconf module behind mount point
140         final RestconfModulesService modulesService = setupNormalMountPoint();
141
142         // make test
143         final NormalizedNodeContext nodeContext = modulesService.getModules(MOUNT_POINT, null);
144
145         // check if expected modules were loaded, use module name as map key
146         assertNotNull("Node context cannot be null", nodeContext);
147         final Collection<?> modules = (Collection<?>) ((ContainerNode) nodeContext .getData())
148                 .getValue().iterator().next().getValue();
149         final Set<TestModule> loadedModules = new HashSet<>();
150
151         for (final Object node : modules) {
152             final Iterator mapEntries = ((AbstractImmutableDataContainerAttrNode) node).getChildren().entrySet()
153                     .iterator();
154             final TestModule loadedModule = new TestModule();
155
156             while (mapEntries.hasNext()) {
157                 final Entry e = ((SimpleImmutableEntry) mapEntries.next());
158                 final String key = ((NodeIdentifier) e.getKey()).getNodeType().getLocalName();
159
160                 assertTrue("Not allowed keyword", ALLOWED_KEYWORDS.contains(key));
161
162                 switch (key) {
163                     case RestconfMappingNodeConstants.NAME:
164                         loadedModule.setName((String) ((LeafNode) e.getValue()).getValue());
165                         break;
166                     case RestconfMappingNodeConstants.NAMESPACE:
167                         loadedModule.setNamespace((String) ((LeafNode) e.getValue()).getValue());
168                         break;
169                     case RestconfMappingNodeConstants.REVISION:
170                          loadedModule.setRevision((String) ((LeafNode) e.getValue()).getValue());
171                     break;
172                     case RestconfMappingNodeConstants.FEATURE:
173                         break;
174                 }
175             }
176
177             loadedModules.add(loadedModule);
178         }
179
180         verifyModules(getExpectedModulesBehindMountPoint(), loadedModules);
181     }
182
183     /**
184      * Test getting the specific module supported by the server. Module name, revision, namespace and features are
185      * compared to have expected values.
186      */
187     @Test
188     public void getModuleTest() throws Exception {
189         // prepare condition
190         final RestconfModulesService modulesService = setupNormal();
191
192         // get test module
193         final NormalizedNodeContext nodeContext = modulesService.getModule(TEST_MODULE, null);
194
195         // verify loaded module
196         assertNotNull("Node context cannot be null", nodeContext);
197         final MapEntryNode node = ((MapNode) nodeContext.getData()).getValue().iterator().next();
198         final Iterator mapEntries = ((AbstractImmutableDataContainerAttrNode) node).getChildren().entrySet().iterator();
199         verifyModule("module1", "module:1", "2014-01-01", Collections.emptySet(), mapEntries);
200     }
201
202     /**
203      * Test getting the specific module supported by the mount point.
204      */
205     @Test
206     public void getModuleMountPointTest() throws Exception {
207         // prepare condition
208         final RestconfModulesService modulesService = setupNormalMountPoint();
209
210         // get test module schemaContextBehindMountPoint mount point
211         final NormalizedNodeContext nodeContext = modulesService.getModule(TEST_MODULE_BEHIND_MOUNT_POINT, null);
212
213         // verify loaded module
214         assertNotNull("Node context cannot be null", nodeContext);
215         final MapEntryNode node = ((MapNode) nodeContext.getData()).getValue().iterator().next();
216         final Iterator mapEntries = ((AbstractImmutableDataContainerAttrNode) node).getChildren().entrySet().iterator();
217         verifyModule("module1-behind-mount-point", "module:1:behind:mount:point", "2014-02-03",
218                 Collections.emptySet(), mapEntries);
219     }
220
221     /**
222      * Test getting all modules supported by the server if Restconf module is <code>null</code>. Test is expected to
223      * fail with <code>NullPointerException</code>.
224      */
225     @Test
226     public void getModulesWithoutRestconfModuleNegativeTest() throws Exception {
227         // prepare condition
228         final RestconfModulesService modulesService = setupMissingRestconfModule();
229
230         // make test
231         this.thrown.expect(NullPointerException.class);
232         modulesService.getModules(null);
233     }
234
235     /**
236      * Test getting all modules supported by the mount point if Restconf module is <code>null</code>. Test is expected
237      * to fail with <code>NullPointerException</code>.
238      */
239     @Test
240     public void getModulesWithoutRestconfModuleMountPointNegativeTest() throws Exception {
241         // prepare condition
242         final RestconfModulesService modulesService = setupMissingRestconfModuleMountPoint();
243
244         // make test
245         this.thrown.expect(NullPointerException.class);
246         modulesService.getModules(MOUNT_POINT, null);
247     }
248
249     /**
250      * Test getting all modules supported by the mount point with <code>null</code> value of
251      * identifier for mount point. Test is expected to fail with <code>NullPointerException</code>.
252      */
253     @Test
254     public void getModulesWithNullIdentifierOfMountPointNegativeTest() throws Exception {
255         // prepare condition
256         final RestconfModulesService modulesService = setupNormalMountPoint();
257
258         // make test
259         this.thrown.expect(NullPointerException.class);
260         modulesService.getModules(null, null);
261     }
262
263     /**
264      * Test getting all modules supported by the mount point if identifier does
265      * not contains {@link RestconfConstants#MOUNT}. Catching
266      * {@link RestconfDocumentedException} and testing error tyupe, error tag and error status code.
267      */
268     @Test
269     public void getModulesWithoutMountConstantInMountPointIdentifierNegativeTest() throws Exception {
270         // prepare condition
271         final RestconfModulesService modulesService = setupNormalMountPoint();
272
273         try {
274             modulesService.getModules(MOUNT_POINT.replace("/" + RestconfConstants.MOUNT + "/", ""), null);
275             fail("Test should fail due to missing " + RestconfConstants.MOUNT + " constant in mount point identifier");
276         } catch (final RestconfDocumentedException e) {
277             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
278             assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
279             assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
280         }
281     }
282
283     /**
284      * Test getting all modules supported by the server when Restconf module does not contain node with name
285      * {@link RestconfModule#MODULES_CONTAINER_SCHEMA_NODE}. Test is expected to fail with
286      * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
287      * expected values.
288      */
289     @Test
290     public void getModulesRestconfModuleWithMissingContainerModulesNegativeTest() throws Exception {
291         // prepare condition
292         final RestconfModulesService modulesService = setupCustomRestconfModule(
293                 "restconf-module-with-missing-container-modules");
294
295         // make test
296         try {
297             modulesService.getModules(null);
298             fail("Test should fail due to missing " + RestconfModule.MODULES_CONTAINER_SCHEMA_NODE
299                     + " node in Restconf module");
300         } catch (final RestconfDocumentedException e) {
301             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
302             assertEquals("Error tag is not correct", ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
303             assertEquals("Error status code is not correct", 404, e.getErrors().get(0).getErrorTag().getStatusCode());
304         }
305     }
306
307     /**
308      * Test getting all modules supported by the server when Restconf module contains node with name
309      * {@link RestconfModule#MODULES_CONTAINER_SCHEMA_NODE} but it is not of type {@link ContainerSchemaNode}. Test is
310      * expected to fail with <code>IllegalStateException</code>.
311      */
312     @Test
313     public void getModulesRestconfModuleWithIllegalContainerModulesNegativeTest() throws Exception {
314         // prepare condition
315         final RestconfModulesService modulesService = setupCustomRestconfModule(
316                 "restconf-module-with-illegal-container-modules");
317
318         // make test
319         this.thrown.expect(IllegalStateException.class);
320         modulesService.getModules(null);
321     }
322
323     /**
324      * Test getting all modules supported by the mount point when Restconf module does not contain node with name
325      * {@link RestconfModule#MODULES_CONTAINER_SCHEMA_NODE}. Test is expected to fail with
326      * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
327      * expected values.
328      */
329     @Test
330     public void getModulesRestconfModuleWithMissingContainerModulesMountPointNegativeTest() throws Exception {
331         // prepare condition
332         final RestconfModulesService modulesService = setupCustomRestconfModuleMountPoint(
333                 "restconf-module-with-missing-container-modules");
334
335         try {
336             modulesService.getModules(MOUNT_POINT, null);
337             fail("Test should fail due to missing " + RestconfModule.MODULES_CONTAINER_SCHEMA_NODE
338                     + " node in Restconf module");
339         } catch (final RestconfDocumentedException e) {
340             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
341             assertEquals("Error tag is not correct", ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
342             assertEquals("Error status code is not correct", 404, e.getErrors().get(0).getErrorTag().getStatusCode());
343         }
344     }
345
346     /**
347      * Test getting all modules supported by the mount point when Restconf module contains node with name
348      * {@link RestconfModule#MODULES_CONTAINER_SCHEMA_NODE} but it is not of type {@link ContainerSchemaNode}. Test
349      * is expected to fail with <code>IllegalStateException</code>.
350      */
351     @Test
352     public void getModulesRestconfModuleWithIllegalContainerModulesMountPointNegativeTest() throws Exception {
353         // prepare condition
354         final RestconfModulesService modulesService = setupCustomRestconfModuleMountPoint(
355                 "restconf-module-with-illegal-container-modules");
356
357         // make test
358         this.thrown.expect(IllegalStateException.class);
359         modulesService.getModules(MOUNT_POINT, null);
360     }
361
362     /**
363      * Test of getting specific module supported by the server/mount point with <code>null</code> identifier. Test is
364      * expected to fail with <code>NullPointerException</code>.
365      */
366     @Test
367     public void getModuleWithNullIdentifierNegativeTest() throws Exception {
368         // prepare condition
369         final RestconfModulesService modulesService = spy(new RestconfModulesServiceImpl(
370                 mock(SchemaContextHandler.class),
371                 mock(DOMMountPointServiceHandler.class)));
372
373         // make test
374         this.thrown.expect(NullPointerException.class);
375         modulesService.getModule(null, null);
376     }
377
378     /**
379      * Testing getting specific module supported by the server with module identifier which
380      * does not exist in <code>SchemaContext</code>. Catching {@link RestconfDocumentedException}
381      * and testing error type, error tag and error status code.
382      */
383     @Test
384     public void getModuleNotExistModuleNegativeTest() throws Exception {
385         // prepare condition
386         final RestconfModulesService modulesService = setupNormal();
387
388         // make test
389         try {
390             modulesService.getModule(NOT_EXISTING_MODULE, null);
391             fail("Test should fail due to searching for not-existing module");
392         } catch (final RestconfDocumentedException e) {
393             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
394             assertEquals("Error tag is not correct", ErrorTag.UNKNOWN_ELEMENT, e.getErrors().get(0).getErrorTag());
395             assertEquals("Error code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
396         }
397     }
398
399     /**
400      * Testing getting specific module supported by the mount point with module identifier which
401      * does not exist in <code>SchemaContext</code>. Catching {@link RestconfDocumentedException}
402      * and testing error type, error tag and error status code.
403      */
404     @Test
405     public void getModuleNotExistModuleMountPointNegativeTest() throws Exception {
406         // prepare condition
407         final RestconfModulesService modulesService = setupNormalMountPoint();
408
409         // make test
410         try {
411             modulesService.getModule(NOT_EXISTING_MODULE_BEHIND_MOUNT_POINT, null);
412             fail("Test should fail due to searching for not-existing module");
413         } catch (final RestconfDocumentedException e) {
414             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
415             assertEquals("Error tag is not correct", ErrorTag.UNKNOWN_ELEMENT, e.getErrors().get(0).getErrorTag());
416             assertEquals("Error code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
417         }
418     }
419
420     /**
421      * Test getting specific module supported by the server when Restconf module is null. Test is expected to fail
422      * with <code>NullPointerException</code>.
423      */
424     @Test
425     public void getModuleWithoutRestconfModuleNegativeTest() throws Exception {
426         // prepare conditions
427         final RestconfModulesService modulesService = setupMissingRestconfModule();
428
429         this.thrown.expect(NullPointerException.class);
430         modulesService.getModule(TEST_MODULE, null);
431     }
432
433     /**
434      * Test getting specific module supported by the mount point when Restconf module is null. Test is expected to fail
435      * with <code>NullPointerException</code>.
436      */
437     @Test
438     public void getModuleWithoutRestconfModuleMountPointNegativeTest() throws Exception {
439         // prepare conditions
440         final RestconfModulesService modulesService = setupMissingRestconfModuleMountPoint();
441
442         this.thrown.expect(NullPointerException.class);
443         modulesService.getModule(TEST_MODULE_BEHIND_MOUNT_POINT, null);
444     }
445
446     /**
447      * Test getting specific module supported by the server when Restconf module does not contain node with
448      * name {@link RestconfModule#MODULE_LIST_SCHEMA_NODE}. Test is expected to fail with
449      * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
450      * expected values.
451      */
452     @Test
453     public void getModuleRestconfModuleWithMissingListModuleNegativeTest() throws Exception {
454         // prepare condition
455         final RestconfModulesService modulesService =
456                 setupCustomRestconfModule("restconf-module-with-missing-list-module");
457
458         // make test
459         try {
460             modulesService.getModule(TEST_MODULE, null);
461             fail("Test should fail due to missing " + RestconfModule.MODULE_LIST_SCHEMA_NODE
462                     + " node in Restconf module");
463         } catch (final RestconfDocumentedException e) {
464             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
465             assertEquals("Error tag is not correct", ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
466             assertEquals("Error code is not correct", 404, e.getErrors().get(0).getErrorTag().getStatusCode());
467         }
468     }
469
470     /**
471      * Test getting specific module supported by the server when Restconf module contains node with name
472      * {@link RestconfModule#MODULE_LIST_SCHEMA_NODE} but it is not of type {@link ListSchemaNode}. Test is expected
473      * to fail with <code>IllegalStateException</code>.
474      */
475     @Test
476     public void getModuleRestconfModuleWitIllegalListSchemaNodeNegativeTest() throws Exception {
477         // prepare condition
478         final RestconfModulesService modulesService = setupCustomRestconfModule(
479                 "restconf-module-with-illegal-list-module");
480
481         // make test
482         this.thrown.expect(IllegalStateException.class);
483         modulesService.getModule(TEST_MODULE, null);
484     }
485
486     /**
487      * Test getting specific module supported by the mount point when Restconf module does not contain node with
488      * name {@link RestconfModule#MODULE_LIST_SCHEMA_NODE}. Test is expected to fail with
489      * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
490      * expected values.
491      */
492     @Test
493     public void getModuleRestconfModuleWithMissingListModuleMountPointNegativeTest() throws Exception {
494         // prepare condition
495         final RestconfModulesService modulesService =
496                 setupCustomRestconfModuleMountPoint("restconf-module-with-missing-list-module");
497
498         // make test
499         try {
500             modulesService.getModule(TEST_MODULE_BEHIND_MOUNT_POINT, null);
501             fail("Test should fail due to missing " + RestconfModule.MODULE_LIST_SCHEMA_NODE
502                     + " node in Restconf module");
503         } catch (final RestconfDocumentedException e) {
504             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
505             assertEquals("Error tag is not correct", ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
506             assertEquals("Error code is not correct", 404, e.getErrors().get(0).getErrorTag().getStatusCode());
507         }
508     }
509
510     /**
511      * Test getting specific module supported by the mount point when Restconf module contains node with name
512      * {@link RestconfModule#MODULE_LIST_SCHEMA_NODE} but it is not of type {@link ListSchemaNode}. Test is expected
513      * to fail with <code>IllegalStateException</code>.
514      */
515     @Test
516     public void getModuleRestconfModuleWitIllegalListModuleMountPointNegativeTest() throws Exception {
517         // prepare condition
518         final RestconfModulesService modulesService = setupCustomRestconfModuleMountPoint(
519                 "restconf-module-with-illegal-list-module");
520
521         // make test
522         this.thrown.expect(IllegalStateException.class);
523         modulesService.getModule(TEST_MODULE_BEHIND_MOUNT_POINT, null);
524     }
525
526     /**
527      * Negative test of specific module supported by the mount point when <code>DOMMountPointServiceHandler</code>
528      * contains <code>null</code> reference to  <code>DOMMountPointService</code>. Test is expected to fail with
529      * <code>NullPointerException</code>.
530      */
531     @Test
532     public void getModuleMissingMountPointServiceNegativeTest() throws Exception {
533         // prepare conditions
534         final RestconfModulesService modulesService = setupNullMountPointService();
535
536         // make test
537         this.thrown.expect(NullPointerException.class);
538         modulesService.getModule(TEST_MODULE_BEHIND_MOUNT_POINT, null);
539     }
540
541     /**
542      * Negative test of getting all modules supported by the mount point when <code>DOMMountPointServiceHandler</code>
543      * contains <code>null</code> reference to  <code>DOMMountPointService</code>. Test is expected to fail with
544      * <code>NullPointerException</code>.
545      */
546     @Test
547     public void getModulesMissingMountPointServiceNegativeTest() throws Exception {
548         // prepare conditions
549         final RestconfModulesService modulesService = setupNullMountPointService();
550
551         // make test
552         this.thrown.expect(NullPointerException.class);
553         modulesService.getModules(MOUNT_POINT, null);
554     }
555
556     /**
557      * Negative test of getting specific module supported by the mount point when specified mount point is not found
558      * (it is not registered in <code>DOMMountPointService</code>). Test is expected to fail with
559      * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
560      * expected values.
561      */
562     @Test
563     public void getModuleMountPointNotFoundNegativeTest() throws Exception {
564         // prepare conditions
565         final RestconfModulesService modulesService = setupNormalMountPoint();
566
567         // make test
568         try {
569             modulesService.getModule(TEST_MODULE_BEHIND_NOT_REGISTERED_MOUNT_POINT, null);
570             fail("Test should fail due to missing mount point");
571         } catch (final RestconfDocumentedException e) {
572             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
573             assertEquals("Error tag is not correct", ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
574             assertEquals("Error code is not correct", 404, e.getErrors().get(0).getErrorTag().getStatusCode());
575         }
576     }
577
578     /**
579      * Negative test of getting all modules supported by the mount point when specified mount point is not found (it
580      * is not registered in <code>DOMMountPointService</code>). Test is expected to fail with
581      * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
582      * expected values.
583      */
584     @Test
585     public void getModulesMountPointNotFoundNegativeTest() throws Exception {
586         // prepare conditions
587         final RestconfModulesService modulesService = setupNormalMountPoint();
588
589         // make test
590         try {
591             modulesService.getModules(NOT_REGISTERED_MOUNT_POINT, null);
592             fail("Test should fail due to missing mount point");
593         } catch (final RestconfDocumentedException e) {
594             assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
595             assertEquals("Error tag is not correct", ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
596             assertEquals("Error code is not correct", 404, e.getErrors().get(0).getErrorTag().getStatusCode());
597         }
598     }
599 }