Move SchemaExportContext
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / utils / parser / ParserIdentifierTest.java
index c2158038b17e04cec931b1b9d850c1c89c280e49..fd4f6a67ffcbaacc02df47a6194203fce80b80cd 100644 (file)
@@ -10,48 +10,52 @@ package org.opendaylight.restconf.nb.rfc8040.utils.parser;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.when;
 
+import java.util.List;
 import java.util.Map.Entry;
 import java.util.Optional;
+import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.Rule;
+import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
+import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
+import org.opendaylight.restconf.common.ErrorTags;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
-import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 /**
  * Unit tests for {@link ParserIdentifier}.
  */
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ParserIdentifierTest {
     // mount point identifier
-    private static final String MOUNT_POINT_IDENT =
-            "mount-point:mount-container/point-number" + "/" + RestconfConstants.MOUNT;
+    private static final String MOUNT_POINT_IDENT = "mount-point:mount-container/point-number/yang-ext:mount";
 
     // invalid mount point identifier
-    private static final String INVALID_MOUNT_POINT_IDENT =
-            "mount-point:point-number" + "/" + RestconfConstants.MOUNT;
+    private static final String INVALID_MOUNT_POINT_IDENT = "mount-point:point-number/yang-ext:mount";
 
     // test identifier + expected result
     private static final String TEST_IDENT =
@@ -76,16 +80,17 @@ public class ParserIdentifierTest {
     private static final String INVALID_TEST_IDENT =
             "parser-identifier:cont2/listTest/list-in-grouping=name/leaf-A.B";
 
-    // schema context with test modules
-    private SchemaContext schemaContext;
-    // contains the same modules but it is different object (it can be compared with equals)
-    private SchemaContext schemaContextOnMountPoint;
-
     private static final String TEST_MODULE_NAME = "test-module";
     private static final String TEST_MODULE_REVISION = "2016-06-02";
     private static final String TEST_MODULE_NAMESPACE = "test:module";
 
     private static final String INVOKE_RPC = "invoke-rpc-module:rpc-test";
+    private static final String INVOKE_ACTION = "example-actions:interfaces/interface=eth0/reset";
+
+    // schema context with test modules
+    private static EffectiveModelContext SCHEMA_CONTEXT;
+    // contains the same modules but it is different object (it can be compared with equals)
+    private static EffectiveModelContext SCHEMA_CONTEXT_ON_MOUNT_POINT;
 
     // mount point and mount point service
     private DOMMountPoint mountPoint;
@@ -101,17 +106,22 @@ public class ParserIdentifierTest {
     @Mock
     private DOMYangTextSourceProvider sourceProvider;
 
-    @Rule
-    public final ExpectedException thrown = ExpectedException.none();
+    @BeforeClass
+    public static void beforeClass() throws Exception {
+        SCHEMA_CONTEXT = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
+        SCHEMA_CONTEXT_ON_MOUNT_POINT =
+                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
+        SCHEMA_CONTEXT_ON_MOUNT_POINT = null;
+    }
 
     @Before
     public void setup() throws Exception {
-        MockitoAnnotations.initMocks(this);
-        this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
-        this.schemaContextOnMountPoint =
-                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
-
-        this.mountPointService = new DOMMountPointServiceImpl();
+        mountPointService = new DOMMountPointServiceImpl();
 
         // create and register mount point
         final YangInstanceIdentifier mountPointId = YangInstanceIdentifier.builder()
@@ -120,14 +130,13 @@ public class ParserIdentifierTest {
                 .build();
 
         mountPoint = mountPointService.createMountPoint(mountPointId)
-                .addInitialSchemaContext(this.schemaContextOnMountPoint)
+                .addService(DOMSchemaService.class, FixedDOMSchemaService.of(SCHEMA_CONTEXT_ON_MOUNT_POINT))
                 .register()
                 .getInstance();
 
         // register mount point with null schema context
-        when(this.mockMountPoint.getSchemaContext()).thenReturn(null);
-        when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY))
-                .thenReturn(Optional.of(this.mockMountPoint));
+        when(mockMountPointService.getMountPoint(YangInstanceIdentifier.empty()))
+                .thenReturn(Optional.of(mockMountPoint));
     }
 
     /**
@@ -140,8 +149,8 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toInstanceIdentifierTest() {
-        final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
-                TEST_IDENT, this.schemaContext, Optional.empty());
+        final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+                TEST_IDENT, SCHEMA_CONTEXT, Optional.empty());
 
         assertEquals("Returned not expected identifier",
                 TEST_IDENT_RESULT, context .getInstanceIdentifier().toString());
@@ -153,8 +162,8 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toInstanceIdentifierOtherModulesTest() {
-        final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
-                TEST_IDENT_OTHERS, this.schemaContext, Optional.empty());
+        final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+                TEST_IDENT_OTHERS, SCHEMA_CONTEXT, Optional.empty());
 
         assertEquals("Returned not expected identifier",
                 TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString());
@@ -166,29 +175,29 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toInstanceIdentifierMountPointTest() {
-        final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
-                MOUNT_POINT_IDENT + "/" + TEST_IDENT, this.schemaContext, Optional.of(this.mountPointService));
+        final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+                MOUNT_POINT_IDENT + "/" + TEST_IDENT, SCHEMA_CONTEXT, Optional.of(mountPointService));
 
         assertEquals("Returned not expected identifier",
                 TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString());
 
         assertEquals("Mount point not found",
-                this.mountPoint, context.getMountPoint());
+                mountPoint, context.getMountPoint());
 
         assertEquals("Schema context from mount point expected",
-                this.schemaContextOnMountPoint, context.getSchemaContext());
+                SCHEMA_CONTEXT_ON_MOUNT_POINT, context.getSchemaContext());
     }
 
     /**
      * Test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>.
-     * <code>{@link YangInstanceIdentifier#EMPTY}</code> should be returned.
+     * <code>{@link YangInstanceIdentifier#empty()}</code> should be returned.
      */
     @Test
     public void toInstanceIdentifierNullIdentifierTest() {
-        final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
-                null, this.schemaContext, Optional.empty());
+        final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+                null, SCHEMA_CONTEXT, Optional.empty());
         assertEquals("Returned not expected identifier",
-                YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
+                YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
     }
 
     /**
@@ -197,8 +206,8 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toInstanceIdentifierNullSchemaContextNegativeTest() {
-        this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.empty());
+        assertThrows(NullPointerException.class,
+            () -> ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.empty()));
     }
 
     /**
@@ -206,30 +215,30 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toInstanceIdentifierEmptyIdentifierTest() {
-        final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
-                "", this.schemaContext, Optional.empty());
+        final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+                "", SCHEMA_CONTEXT, Optional.empty());
         assertEquals("Returned not expected identifier",
-                YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
+                YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
     }
 
     /**
-     * Negative test with invalid test identifier. Test should fail with <code>IllegalArgumentException</code>.
+     * Negative test with invalid test identifier. Test should fail with <code>RestconfDocumentedException</code>.
      */
     @Test
     public void toInstanceIdentifierInvalidIdentifierNegativeTest() {
-        this.thrown.expect(IllegalArgumentException.class);
-        ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.empty());
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, SCHEMA_CONTEXT, Optional.empty()));
     }
 
     /**
      * Negative test when identifier contains {@link RestconfConstants#MOUNT} but identifier part is not valid. Test
-     * should fail with <code>IllegalArgumentException</code>.
+     * should fail with <code>RestconfDocumentedException</code>.
      */
     @Test
     public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {
-        this.thrown.expect(IllegalArgumentException.class);
-        ParserIdentifier.toInstanceIdentifier(
-                INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService));
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.toInstanceIdentifier(INVALID_MOUNT_POINT_IDENT, SCHEMA_CONTEXT,
+                Optional.of(mountPointService)));
     }
 
     /**
@@ -239,18 +248,13 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toInstanceIdentifierMissingMountPointNegativeTest() {
-        try {
-            ParserIdentifier.toInstanceIdentifier(
-                    "" + "/" + RestconfConstants.MOUNT, this.schemaContext, Optional.of(this.mountPointService));
-            fail("Test should fail due to missing mount point");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    404, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.toInstanceIdentifier("/yang-ext:mount", SCHEMA_CONTEXT,
+                Optional.of(mountPointService)));
+        final List<RestconfError> errors = ex.getErrors();
+        assertEquals(1, errors.size());
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, errors.get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
     }
 
     /**
@@ -260,17 +264,10 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
-        try {
-            ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.empty());
-            fail("Test should fail due to absent mount point service");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    ErrorType.APPLICATION, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    ErrorTag.OPERATION_FAILED, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    500, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.toInstanceIdentifier("yang-ext:mount", SCHEMA_CONTEXT, Optional.empty()));
+        assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.OPERATION_FAILED, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -298,17 +295,11 @@ public class ParserIdentifierTest {
      */
     @Test
     public void makeQNameFromIdentifierInvalidIdentifierNegativeTest() {
-        try {
-            ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME);
-            fail("Test should fail due to invalid identifier format");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME));
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+            ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -318,17 +309,11 @@ public class ParserIdentifierTest {
      */
     @Test
     public void makeQNameFromIdentifierTooShortIdentifierNegativeTest() {
-        try {
-            ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME);
-            fail("Test should fail due to too short identifier format");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME));
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+            ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -356,23 +341,12 @@ public class ParserIdentifierTest {
      */
     @Test
     public void makeQNameFromIdentifierMountPointInvalidIdentifierNegativeTest() {
-        try {
-            ParserIdentifier.makeQNameFromIdentifier(
-                    MOUNT_POINT_IDENT
-                    + "/"
-                    + TEST_MODULE_REVISION
-                    + "/"
-                    + TEST_MODULE_NAME);
-
-            fail("Test should fail due to invalid identifier format");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.makeQNameFromIdentifier(
+                    MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME));
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+            ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -382,21 +356,11 @@ public class ParserIdentifierTest {
      */
     @Test
     public void makeQNameFromIdentifierMountPointTooShortIdentifierNegativeTest() {
-        try {
-            ParserIdentifier.makeQNameFromIdentifier(
-                    MOUNT_POINT_IDENT
-                    + "/"
-                    + TEST_MODULE_NAME);
-
-            fail("Test should fail due to too short identifier format");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.makeQNameFromIdentifier(MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME));
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+            ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -405,8 +369,7 @@ public class ParserIdentifierTest {
      */
     @Test
     public void makeQNameFromIdentifierNullIdentifierNegativeTest() {
-        this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.makeQNameFromIdentifier(null);
+        assertThrows(NullPointerException.class, () -> ParserIdentifier.makeQNameFromIdentifier(null));
     }
 
     /**
@@ -416,17 +379,11 @@ public class ParserIdentifierTest {
      */
     @Test
     public void makeQNameFromIdentifierEmptyIdentifierNegativeTest() {
-        try {
-            ParserIdentifier.makeQNameFromIdentifier("");
-            fail("Test should fail due to empty identifier");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.makeQNameFromIdentifier(""));
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+            ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -437,17 +394,11 @@ public class ParserIdentifierTest {
      */
     @Test
     public void makeQNameFromIdentifierDoubleSlashNegativeTest() {
-        try {
-            ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION);
-            fail("Test should fail due to identifier containing double slash");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION));
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+            ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -461,19 +412,17 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierTest() {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
-                this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
+                SCHEMA_CONTEXT, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
 
         assertNotNull("Export context should be parsed", exportContext);
 
         final Module module = exportContext.getModule();
         assertNotNull("Export context should contains test module", module);
 
-        assertEquals("Returned not expected module name",
-                TEST_MODULE_NAME, module.getName());
+        assertEquals("Returned not expected module name", TEST_MODULE_NAME, module.getName());
         assertEquals("Returned not expected module revision",
                 Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
-        assertEquals("Returned not expected module namespace",
-                TEST_MODULE_NAMESPACE, module.getNamespace().toString());
+        assertEquals("Returned not expected module namespace", TEST_MODULE_NAMESPACE, module.getNamespace().toString());
     }
 
     /**
@@ -483,7 +432,7 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierNotFoundTest() {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
-                this.schemaContext,
+                SCHEMA_CONTEXT,
                 "not-existing-module" + "/" + "2016-01-01",
                 null, sourceProvider);
 
@@ -498,18 +447,12 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
-        try {
-            ParserIdentifier.toSchemaExportContextFromIdentifier(
-                    this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider);
-            fail("Test should fail due to invalid identifier supplied");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
+                    SCHEMA_CONTEXT, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider));
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+            ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -519,9 +462,9 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierMountPointTest() {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
-                this.schemaContext,
+                SCHEMA_CONTEXT,
                 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
-                this.mountPointService, sourceProvider);
+                mountPointService, sourceProvider);
 
         final Module module = exportContext.getModule();
         assertNotNull("Export context should contains test module", module);
@@ -541,9 +484,9 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
-                this.schemaContext,
+                SCHEMA_CONTEXT,
                 MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
-                this.mountPointService, sourceProvider);
+                mountPointService, sourceProvider);
 
         assertNotNull("Export context should be parsed", exportContext);
         assertNull("Not-existing module should be null", exportContext.getModule());
@@ -556,21 +499,14 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() {
-        try {
-            ParserIdentifier.toSchemaExportContextFromIdentifier(
-                    this.schemaContext,
-                    MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
-                    this.mountPointService, sourceProvider);
+        RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> ParserIdentifier.toSchemaExportContextFromIdentifier(SCHEMA_CONTEXT,
+                MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, mountPointService,
+                sourceProvider));
 
-            fail("Test should fail due to invalid identifier supplied");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Not expected error type",
-                    RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals("Not expected error tag",
-                    RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
-            assertEquals("Not expected error status code",
-                    400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+        assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+            ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -579,8 +515,8 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
-        this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null, sourceProvider);
+        assertThrows(NullPointerException.class,
+            () -> ParserIdentifier.toSchemaExportContextFromIdentifier(SCHEMA_CONTEXT, null, null, sourceProvider));
     }
 
     /**
@@ -589,9 +525,8 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
-        this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
-                sourceProvider);
+        assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(null,
+            TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider));
     }
 
     /**
@@ -601,16 +536,9 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
-        this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(
-                null,
-                MOUNT_POINT_IDENT
-                + "/"
-                + TEST_MODULE_NAME
-                + "/"
-                + TEST_MODULE_REVISION,
-                this.mountPointService,
-                sourceProvider);
+        assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(null,
+            MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, mountPointService,
+            sourceProvider));
     }
 
     /**
@@ -620,35 +548,16 @@ public class ParserIdentifierTest {
      */
     @Test
     public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
-        this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(
-                this.schemaContext,
-                MOUNT_POINT_IDENT
-                + "/"
-                + TEST_MODULE_NAME
-                + "/"
-                + TEST_MODULE_REVISION,
-                null,
-                sourceProvider);
+        assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
+            SCHEMA_CONTEXT, MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
+            sourceProvider));
     }
 
-    /**
-     * Negative test of of getting <code>SchemaExportContext</code> when <code>SchemaContext</code> behind mount
-     * point is <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
-     */
     @Test
     public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
-        this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(
-                this.schemaContext,
-                "/"
-                + RestconfConstants.MOUNT
-                + "/"
-                + TEST_MODULE_NAME
-                + "/"
-                + TEST_MODULE_REVISION,
-                this.mockMountPointService,
-                sourceProvider);
+        assertThrows(IllegalStateException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
+                SCHEMA_CONTEXT, "/yang-ext:mount/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
+                mockMountPointService, sourceProvider));
     }
 
     /**
@@ -659,8 +568,8 @@ public class ParserIdentifierTest {
      */
     @Test
     public void invokeRpcTest() {
-        final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
-                INVOKE_RPC, this.schemaContext, Optional.empty());
+        final InstanceIdentifierContext result = ParserIdentifier.toInstanceIdentifier(
+                INVOKE_RPC, SCHEMA_CONTEXT, Optional.empty());
 
         // RPC schema node
         final QName rpcQName = result.getSchemaNode().getQName();
@@ -668,9 +577,9 @@ public class ParserIdentifierTest {
         assertEquals("rpc-test", rpcQName.getLocalName());
 
         // other fields
-        assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
+        assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, SCHEMA_CONTEXT), result.getInstanceIdentifier());
         assertEquals(null, result.getMountPoint());
-        assertEquals(this.schemaContext, result.getSchemaContext());
+        assertEquals(SCHEMA_CONTEXT, result.getSchemaContext());
     }
 
     /**
@@ -681,8 +590,8 @@ public class ParserIdentifierTest {
      */
     @Test
     public void invokeRpcOnMountPointTest() {
-        final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
-                MOUNT_POINT_IDENT + "/" + INVOKE_RPC, this.schemaContext, Optional.of(this.mountPointService));
+        final InstanceIdentifierContext result = ParserIdentifier.toInstanceIdentifier(
+                MOUNT_POINT_IDENT + "/" + INVOKE_RPC, SCHEMA_CONTEXT, Optional.of(mountPointService));
 
         // RPC schema node
         final QName rpcQName = result.getSchemaNode().getQName();
@@ -690,8 +599,49 @@ public class ParserIdentifierTest {
         assertEquals("rpc-test", rpcQName.getLocalName());
 
         // other fields
-        assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
-        assertEquals(this.mountPoint, result.getMountPoint());
-        assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());
+        assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, SCHEMA_CONTEXT), result.getInstanceIdentifier());
+        assertEquals(mountPoint, result.getMountPoint());
+        assertEquals(SCHEMA_CONTEXT_ON_MOUNT_POINT, result.getSchemaContext());
+    }
+
+    /**
+     * Test Action.
+     * Verify if Action schema node was found.
+     */
+    @Test
+    public void invokeActionTest() {
+        final InstanceIdentifierContext result = ParserIdentifier
+            .toInstanceIdentifier(INVOKE_ACTION, SCHEMA_CONTEXT, Optional.empty());
+
+        // Action schema node
+        final QName actionQName = result.getSchemaNode().getQName();
+        assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
+        assertEquals("reset", actionQName.getLocalName());
+
+        // other fields
+        assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, SCHEMA_CONTEXT), result.getInstanceIdentifier());
+        assertNull(result.getMountPoint());
+        assertSame(SCHEMA_CONTEXT, result.getSchemaContext());
+    }
+
+    /**
+     * Test invoke Action on mount point.
+     * Verify if Action schema node was found.
+     */
+    @Test
+    public void invokeActionOnMountPointTest() {
+        final InstanceIdentifierContext result = ParserIdentifier
+            .toInstanceIdentifier(MOUNT_POINT_IDENT + "/" + INVOKE_ACTION, SCHEMA_CONTEXT,
+                Optional.of(mountPointService));
+
+        // Action schema node
+        final QName actionQName = result.getSchemaNode().getQName();
+        assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
+        assertEquals("reset", actionQName.getLocalName());
+
+        // other fields
+        assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, SCHEMA_CONTEXT), result.getInstanceIdentifier());
+        assertEquals(mountPoint, result.getMountPoint());
+        assertEquals(SCHEMA_CONTEXT_ON_MOUNT_POINT, result.getSchemaContext());
     }
 }