Bug 5679 - prepare constants for ietf-yang-library model
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / restconf / rest / services / impl / RestconfModulesServiceTest.java
index 998c99c3c53c1b5d32be8a274f8e4bf5f8251b9f..c5e9057848e18add8eced1214683f2ff0ebabdac 100644 (file)
@@ -47,10 +47,11 @@ import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft17.RestconfModule;
+import org.opendaylight.restconf.Draft18.RestconfModule;
+import org.opendaylight.restconf.base.services.api.RestconfModulesService;
+import org.opendaylight.restconf.base.services.impl.RestconfModulesServiceImpl;
 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
 import org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceTestUtils.TestModule;
 import org.opendaylight.restconf.utils.RestconfConstants;
 import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeConstants;
@@ -556,7 +557,8 @@ public class RestconfModulesServiceTest {
     /**
      * Negative test of getting specific module supported by the mount point when specified mount point is not found
      * (it is not registered in <code>DOMMountPointService</code>). Test is expected to fail with
-     * <code>IllegalStateException</code>.
+     * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
+     * expected values.
      */
     @Test
     public void getModuleMountPointNotFoundNegativeTest() throws Exception {
@@ -564,14 +566,21 @@ public class RestconfModulesServiceTest {
         final RestconfModulesService modulesService = setupNormalMountPoint();
 
         // make test
-        this.thrown.expect(IllegalStateException.class);
-        modulesService.getModule(TEST_MODULE_BEHIND_NOT_REGISTERED_MOUNT_POINT, null);
+        try {
+            modulesService.getModule(TEST_MODULE_BEHIND_NOT_REGISTERED_MOUNT_POINT, null);
+            fail("Test should fail due to missing mount point");
+        } catch (final RestconfDocumentedException e) {
+            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
+            assertEquals("Error tag is not correct", ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
+            assertEquals("Error code is not correct", 404, e.getErrors().get(0).getErrorTag().getStatusCode());
+        }
     }
 
     /**
      * Negative test of getting all modules supported by the mount point when specified mount point is not found (it
      * is not registered in <code>DOMMountPointService</code>). Test is expected to fail with
-     * <code>IllegalStateException</code>.
+     * <code>RestconfDocumentedException</code> and error type, error tag and error status code are compared to
+     * expected values.
      */
     @Test
     public void getModulesMountPointNotFoundNegativeTest() throws Exception {
@@ -579,7 +588,13 @@ public class RestconfModulesServiceTest {
         final RestconfModulesService modulesService = setupNormalMountPoint();
 
         // make test
-        this.thrown.expect(IllegalStateException.class);
-        modulesService.getModules(NOT_REGISTERED_MOUNT_POINT, null);
+        try {
+            modulesService.getModules(NOT_REGISTERED_MOUNT_POINT, null);
+            fail("Test should fail due to missing mount point");
+        } catch (final RestconfDocumentedException e) {
+            assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
+            assertEquals("Error tag is not correct", ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
+            assertEquals("Error code is not correct", 404, e.getErrors().get(0).getErrorTag().getStatusCode());
+        }
     }
 }