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