Remove DocumentedException.ErrorSeverity
[netconf.git] / netconf / mdsal-netconf-connector / src / test / java / org / opendaylight / netconf / mdsal / connector / ops / NetconfMDSalMappingTest.java
index d44bc8482eea020d7e41e88253957f349754aaa7..1af28ba83058d5197d8096e12443e754d6dde9bb 100644 (file)
@@ -5,82 +5,32 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.connector.ops;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doAnswer;
-
-import com.google.common.io.ByteSource;
-import com.google.common.util.concurrent.Futures;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.custommonkey.xmlunit.DetailedDiff;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Assert;
-import org.junit.Before;
+
+import java.net.URI;
 import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker;
-import org.opendaylight.controller.config.util.xml.DocumentedException;
-import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity;
-import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorTag;
-import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorType;
-import org.opendaylight.controller.config.util.xml.XmlElement;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreFactory;
-import org.opendaylight.controller.sal.core.api.model.SchemaService;
-import org.opendaylight.controller.sal.core.spi.data.DOMStore;
-import org.opendaylight.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
+import org.opendaylight.netconf.api.DocumentedException.ErrorType;
+import org.opendaylight.netconf.api.xml.XmlElement;
+import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
-import org.opendaylight.netconf.mdsal.connector.ops.get.Get;
 import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig;
-import org.opendaylight.netconf.util.test.NetconfXmlUnitRecursiveQualifier;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-public class NetconfMDSalMappingTest {
-    private static final Logger LOG = LoggerFactory.getLogger(NetconfMDSalMappingTest.class);
-
+public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest {
     private static final String TARGET_KEY = "target";
-    private static final String RPC_REPLY_ELEMENT = "rpc-reply";
-    private static final String DATA_ELEMENT = "data";
     private static final String FILTER_NODE = "filter";
     private static final String GET_CONFIG = "get-config";
     private static final QName TOP = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "top");
@@ -104,62 +54,6 @@ public class NetconfMDSalMappingTest {
 
     private static final YangInstanceIdentifier AUGMENTED_CONTAINER_IN_MODULES =
             YangInstanceIdentifier.builder().node(TOP).node(MODULES).build();
-    private static final String SESSION_ID_FOR_REPORTING = "netconf-test-session1";
-    private static final Document RPC_REPLY_OK = NetconfMDSalMappingTest.getReplyOk();
-
-    private CurrentSchemaContext currentSchemaContext = null;
-    private SchemaContext schemaContext = null;
-    private TransactionProvider transactionProvider = null;
-
-    @Mock
-    private SchemaSourceProvider<YangTextSchemaSource> sourceProvider;
-
-    @SuppressWarnings("illegalCatch")
-    private static Document getReplyOk() {
-        Document doc;
-        try {
-            doc = XmlFileLoader.xmlFileToDocument("messages/mapping/rpc-reply_ok.xml");
-        } catch (final Exception e) {
-            LOG.debug("unable to load rpc reply ok.", e);
-            doc = XmlUtil.newDocument();
-        }
-        return doc;
-    }
-
-    @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
-        XMLUnit.setIgnoreWhitespace(true);
-        XMLUnit.setIgnoreAttributeOrder(true);
-
-        this.schemaContext = YangParserTestUtils.parseYangStreams(getYangSchemas());
-        schemaContext.getModules();
-        final SchemaService schemaService = createSchemaService();
-
-        final DOMStore operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", schemaService);
-        final DOMStore configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", schemaService);
-
-        final EnumMap<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
-        datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
-        datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
-
-        final ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(
-                16, 16, "CommitFutures");
-
-        final ConcurrentDOMDataBroker cdb = new ConcurrentDOMDataBroker(datastores, listenableFutureExecutor);
-        this.transactionProvider = new TransactionProvider(cdb, SESSION_ID_FOR_REPORTING);
-
-        doAnswer(invocationOnMock -> {
-            final SourceIdentifier sId = (SourceIdentifier) invocationOnMock.getArguments()[0];
-            final YangTextSchemaSource yangTextSchemaSource =
-                    YangTextSchemaSource.delegateForByteSource(sId, ByteSource.wrap("module test".getBytes()));
-            return Futures.immediateCheckedFuture(yangTextSchemaSource);
-
-        }).when(sourceProvider).getSource(any(SourceIdentifier.class));
-
-        this.currentSchemaContext = new CurrentSchemaContext(schemaService, sourceProvider);
-    }
 
     @Test
     public void testEmptyDatastore() throws Exception {
@@ -170,37 +64,37 @@ public class NetconfMDSalMappingTest {
 
     @Test
     public void testIncorrectGet() throws Exception {
-        try {
-            executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider),
-                    "messages/mapping/bad_getConfig.xml");
-            fail("Should have failed, this is an incorrect request");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.OPERATION_FAILED);
-            assertTrue(e.getErrorType() == ErrorType.APPLICATION);
-        }
+        DocumentedException ex = assertThrows(DocumentedException.class,
+            () -> executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
+                    getTransactionProvider()), "messages/mapping/bad_getConfig.xml"));
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.OPERATION_FAILED, ex.getErrorTag());
+        assertEquals(ErrorType.APPLICATION, ex.getErrorType());
 
-        try {
-            executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider),
-                    "messages/mapping/bad_namespace_getConfig.xml");
-            fail("Should have failed, this is an incorrect request");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.OPERATION_FAILED);
-            assertTrue(e.getErrorType() == ErrorType.APPLICATION);
-        }
+        ex = assertThrows(DocumentedException.class,
+            () -> executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
+                    getTransactionProvider()), "messages/mapping/bad_namespace_getConfig.xml"));
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.OPERATION_FAILED, ex.getErrorTag());
+        assertEquals(ErrorType.APPLICATION, ex.getErrorType());
+    }
+
+    @Test
+    public void testConfigMissing() throws Exception {
+        final DocumentedException ex = assertThrows(DocumentedException.class,
+            () -> edit("messages/mapping/editConfigs/editConfig_no_config.xml"));
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.MISSING_ELEMENT, ex.getErrorTag());
+        assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
     }
 
     @Test
     public void testEditRunning() throws Exception {
-        try {
-            edit("messages/mapping/editConfigs/editConfig_running.xml");
-            fail("Should have failed - edit config on running datastore is not supported");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED);
-            assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
-        }
+        final DocumentedException ex = assertThrows(DocumentedException.class,
+            () -> edit("messages/mapping/editConfigs/editConfig_running.xml"));
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
+        assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
     }
 
     @Test
@@ -252,7 +146,6 @@ public class NetconfMDSalMappingTest {
         deleteDatastore();
     }
 
-
     @Test
     public void testMultipleEditsWithMerge() throws Exception {
         verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
@@ -312,7 +205,6 @@ public class NetconfMDSalMappingTest {
         verifyResponse(commit(), RPC_REPLY_OK);
 
         deleteDatastore();
-
     }
 
     @Test
@@ -327,7 +219,6 @@ public class NetconfMDSalMappingTest {
         verifyResponse(commit(), RPC_REPLY_OK);
 
         deleteDatastore();
-
     }
 
     @Test
@@ -360,46 +251,30 @@ public class NetconfMDSalMappingTest {
     public void testLock() throws Exception {
         verifyResponse(lockCandidate(), RPC_REPLY_OK);
 
-        try {
-            lock();
-            fail("Should have failed - locking of running datastore is not supported");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED);
-            assertTrue(e.getErrorType() == ErrorType.APPLICATION);
-        }
+        DocumentedException ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::lock);
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
+        assertEquals(ErrorType.APPLICATION, ex.getErrorType());
 
-        try {
-            lockWithoutTarget();
-            fail("Should have failed, target is missing");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.INVALID_VALUE);
-            assertTrue(e.getErrorType() == ErrorType.APPLICATION);
-        }
+        ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::lockWithoutTarget);
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrorTag());
+        assertEquals(ErrorType.APPLICATION, ex.getErrorType());
     }
 
     @Test
     public void testUnlock() throws Exception {
         verifyResponse(unlockCandidate(), RPC_REPLY_OK);
 
-        try {
-            unlock();
-            fail("Should have failed - unlocking of running datastore is not supported");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED);
-            assertTrue(e.getErrorType() == ErrorType.APPLICATION);
-        }
+        DocumentedException ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::unlock);
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
+        assertEquals(ErrorType.APPLICATION, ex.getErrorType());
 
-        try {
-            unlockWithoutTarget();
-            fail("Should have failed, target is missing");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.INVALID_VALUE);
-            assertTrue(e.getErrorType() == ErrorType.APPLICATION);
-        }
+        ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::unlockWithoutTarget);
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.INVALID_VALUE, ex.getErrorTag());
+        assertEquals(ErrorType.APPLICATION, ex.getErrorType());
     }
 
     @Test
@@ -408,14 +283,11 @@ public class NetconfMDSalMappingTest {
         verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
                 "messages/mapping/editConfig_create_n1_control.xml"));
 
-        try {
-            edit("messages/mapping/editConfigs/editConfig_create.xml");
-            fail("Create should have failed - data already exists");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.DATA_EXISTS);
-            assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
-        }
+        final DocumentedException ex = assertThrows(DocumentedException.class,
+            () -> edit("messages/mapping/editConfigs/editConfig_create.xml"));
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.DATA_EXISTS, ex.getErrorTag());
+        assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
 
         verifyResponse(discardChanges(), RPC_REPLY_OK);
     }
@@ -425,14 +297,11 @@ public class NetconfMDSalMappingTest {
         assertEmptyDatastore(getConfigCandidate());
         assertEmptyDatastore(getConfigRunning());
 
-        try {
-            edit("messages/mapping/editConfigs/editConfig_delete-top.xml");
-            fail("Delete should have failed - data is missing");
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.DATA_MISSING);
-            assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
-        }
+        final DocumentedException ex = assertThrows(DocumentedException.class,
+            () -> edit("messages/mapping/editConfigs/editConfig_delete-top.xml"));
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.DATA_MISSING, ex.getErrorTag());
+        assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
     }
 
     @Test
@@ -451,32 +320,15 @@ public class NetconfMDSalMappingTest {
         deleteDatastore();
     }
 
-    private static void printDocument(final Document doc) throws Exception {
-        final TransformerFactory tf = TransformerFactory.newInstance();
-        final Transformer transformer = tf.newTransformer();
-        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
-        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
-        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
-        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
-
-        final StringWriter writer = new StringWriter();
-        transformer.transform(new DOMSource(doc),
-                new StreamResult(writer));
-        LOG.warn(writer.getBuffer().toString());
-    }
-
     @Test
     public void testEditConfigWithMultipleOperations() throws Exception {
         deleteDatastore();
 
         verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_setup.xml"),
                 RPC_REPLY_OK);
-        verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_1.xml"),
-                RPC_REPLY_OK);
+        verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_1.xml"), RPC_REPLY_OK);
 
-        verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2.xml"),
-                RPC_REPLY_OK);
+        verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2.xml"), RPC_REPLY_OK);
         verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
                 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_2_control.xml"));
 
@@ -492,35 +344,26 @@ public class NetconfMDSalMappingTest {
         verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_default-replace.xml"),
                 RPC_REPLY_OK);
 
-        try {
-            edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_create_existing.xml");
-            fail();
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.DATA_EXISTS);
-            assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
-        }
+        DocumentedException ex = assertThrows(DocumentedException.class,
+            () -> edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_create_existing.xml"));
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.DATA_EXISTS, ex.getErrorTag());
+        assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
 
         verifyResponse(edit(
-                "messages/mapping/editConfigs/"
-                        + "editConfig_merge_multiple_operations_4_delete_children_operations.xml"),
+                "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations.xml"),
                 RPC_REPLY_OK);
         verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
                 "messages/mapping/editConfigs/"
                         + "editConfig_merge_multiple_operations_4_delete_children_operations_control.xml"));
         verifyResponse(edit(
-                "messages/mapping/editConfigs/"
-                        + "editConfig_merge_multiple_operations_4_remove-non-existing.xml"),
+                "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_remove-non-existing.xml"),
                 RPC_REPLY_OK);
-        try {
-            edit("messages/mapping/editConfigs/"
-                    + "editConfig_merge_multiple_operations_4_delete-non-existing.xml");
-            fail();
-        } catch (final DocumentedException e) {
-            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
-            assertTrue(e.getErrorTag() == ErrorTag.DATA_MISSING);
-            assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
-        }
+        ex = assertThrows(DocumentedException.class,
+            () -> edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete-non-existing.xml"));
+        assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
+        assertEquals(ErrorTag.DATA_MISSING, ex.getErrorTag());
+        assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
 
         verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup.xml"),
                 RPC_REPLY_OK);
@@ -544,9 +387,6 @@ public class NetconfMDSalMappingTest {
 
     @Test
     public void testEditConfigGetElementByTagName() throws Exception {
-        EditConfig editConfig = new EditConfig("test_edit-config", Mockito.mock(CurrentSchemaContext.class),
-                Mockito.mock(TransactionProvider.class));
-
         String stringWithoutPrefix =
                 "<rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
                         + "  <edit-config>\n"
@@ -556,8 +396,8 @@ public class NetconfMDSalMappingTest {
                         + "  </edit-config>\n"
                         + "</rpc>";
         XmlElement xe = getXmlElement(stringWithoutPrefix);
-        NodeList nodeList = editConfig.getElementsByTagName(xe, TARGET_KEY);
-        Assert.assertEquals(1, nodeList.getLength());
+        NodeList nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
+        assertEquals(1, nodeList.getLength());
 
         String stringWithPrefix =
                 "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
@@ -569,8 +409,8 @@ public class NetconfMDSalMappingTest {
                         + "</nc:rpc>";
 
         xe = getXmlElement(stringWithPrefix);
-        nodeList = editConfig.getElementsByTagName(xe, TARGET_KEY);
-        Assert.assertEquals(1, nodeList.getLength());
+        nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
+        assertEquals(1, nodeList.getLength());
 
         String stringWithoutTarget =
                 "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
@@ -581,17 +421,12 @@ public class NetconfMDSalMappingTest {
                         + "</nc:rpc>";
         xe = getXmlElement(stringWithoutTarget);
 
-        try {
-            nodeList = editConfig.getElementsByTagName(xe, TARGET_KEY);
-            XmlElement.fromDomElement((Element) nodeList.item(0)).getOnlyChildElement();
-            Assert.fail("Not specified target, we should fail");
-        } catch (DocumentedException documentedException) {
-            // Ignore
-        }
-
+        final NodeList targetKey = EditConfig.getElementsByTagName(xe, TARGET_KEY);
+        assertThrows(DocumentedException.class,
+            () -> XmlElement.fromDomElement((Element) targetKey.item(0)).getOnlyChildElement());
     }
 
-    private XmlElement getXmlElement(final String elementAsString) throws Exception {
+    private static XmlElement getXmlElement(final String elementAsString) throws Exception {
         Document document = XmlUtil.readXmlToDocument(elementAsString);
         Element element = document.getDocumentElement();
         return XmlElement.fromDomElement(element);
@@ -693,8 +528,8 @@ public class NetconfMDSalMappingTest {
 
     private void verifyFilterIdentifier(final String resource, final YangInstanceIdentifier identifier)
             throws Exception {
-        final TestingGetConfig getConfig = new TestingGetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext,
-                transactionProvider);
+        final TestingGetConfig getConfig = new TestingGetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
+                getTransactionProvider());
         final Document request = XmlFileLoader.xmlFileToDocument(resource);
         final YangInstanceIdentifier iid = getConfig.getInstanceIdentifierFromDocument(request);
         assertEquals(identifier, iid);
@@ -721,160 +556,16 @@ public class NetconfMDSalMappingTest {
         assertEmptyDatastore(getConfigRunning());
     }
 
-    private static void verifyResponse(final Document response, final Document template) throws Exception {
-        final DetailedDiff dd = new DetailedDiff(new Diff(response, template));
-        dd.overrideElementQualifier(new NetconfXmlUnitRecursiveQualifier());
-
-        printDocument(response);
-        printDocument(template);
-
-        assertTrue(dd.toString(), dd.similar());
-    }
-
-    private static void assertEmptyDatastore(final Document response) {
-        final NodeList nodes = response.getChildNodes();
-        assertTrue(nodes.getLength() == 1);
-
-        assertEquals(nodes.item(0).getLocalName(), RPC_REPLY_ELEMENT);
-
-        final NodeList replyNodes = nodes.item(0).getChildNodes();
-        assertTrue(replyNodes.getLength() == 1);
-
-        final Node dataNode = replyNodes.item(0);
-        assertEquals(dataNode.getLocalName(), DATA_ELEMENT);
-        assertFalse(dataNode.hasChildNodes());
-    }
-
-    private Document commit() throws Exception {
-        final Commit commit = new Commit(SESSION_ID_FOR_REPORTING, transactionProvider);
-        return executeOperation(commit, "messages/mapping/commit.xml");
-    }
-
-    private Document discardChanges() throws Exception {
-        final DiscardChanges discardOp = new DiscardChanges(SESSION_ID_FOR_REPORTING, transactionProvider);
-        return executeOperation(discardOp, "messages/mapping/discardChanges.xml");
-    }
-
-    private Document edit(final String resource) throws Exception {
-        final EditConfig editConfig = new EditConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext,
-                transactionProvider);
-        return executeOperation(editConfig, resource);
-    }
-
-    private Document get() throws Exception {
-        final Get get = new Get(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
-        return executeOperation(get, "messages/mapping/get.xml");
-    }
-
-    private Document getWithFilter(final String resource) throws Exception {
-        final Get get = new Get(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
-        return executeOperation(get, resource);
-    }
-
-    private Document getConfigRunning() throws Exception {
-        final GetConfig getConfig = new GetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
-        return executeOperation(getConfig, "messages/mapping/getConfig.xml");
-    }
-
-    private Document getConfigCandidate() throws Exception {
-        final GetConfig getConfig = new GetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
-        return executeOperation(getConfig, "messages/mapping/getConfig_candidate.xml");
-    }
-
-    private Document getConfigWithFilter(final String resource) throws Exception {
-        final GetConfig getConfig = new GetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
-        return executeOperation(getConfig, resource);
-    }
-
-    private static Document lock() throws Exception {
-        final Lock lock = new Lock(SESSION_ID_FOR_REPORTING);
-        return executeOperation(lock, "messages/mapping/lock.xml");
-    }
-
-    private static Document unlock() throws Exception {
-        final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING);
-        return executeOperation(unlock, "messages/mapping/unlock.xml");
-    }
-
-    private static Document lockWithoutTarget() throws Exception {
-        final Lock lock = new Lock(SESSION_ID_FOR_REPORTING);
-        return executeOperation(lock, "messages/mapping/lock_notarget.xml");
-    }
-
-    private static Document unlockWithoutTarget() throws Exception {
-        final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING);
-        return executeOperation(unlock, "messages/mapping/unlock_notarget.xml");
-    }
-
-    private static Document lockCandidate() throws Exception {
-        final Lock lock = new Lock(SESSION_ID_FOR_REPORTING);
-        return executeOperation(lock, "messages/mapping/lock_candidate.xml");
-    }
-
-    private static Document unlockCandidate() throws Exception {
-        final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING);
-        return executeOperation(unlock, "messages/mapping/unlock_candidate.xml");
-    }
-
-    private static Document executeOperation(final NetconfOperation op, final String filename) throws Exception {
-        final Document request = XmlFileLoader.xmlFileToDocument(filename);
-        final Document response = op.handle(request, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT);
-
-        LOG.debug("Got response {}", response);
-        return response;
-    }
-
-    private List<InputStream> getYangSchemas() {
-        final List<String> schemaPaths = Arrays.asList("/META-INF/yang/config.yang",
-                "/yang/mdsal-netconf-mapping-test.yang");
-        final List<InputStream> schemas = new ArrayList<>();
-
-        for (final String schemaPath : schemaPaths) {
-            final InputStream resourceAsStream = getClass().getResourceAsStream(schemaPath);
-            schemas.add(resourceAsStream);
-        }
-
-        return schemas;
-    }
-
-    private SchemaService createSchemaService() {
-        return new SchemaService() {
-
-            @Override
-            public void addModule(final Module module) {
-            }
-
-            @Override
-            public void removeModule(final Module module) {
-
-            }
-
-            @Override
-            public SchemaContext getSessionContext() {
-                return schemaContext;
-            }
-
-            @Override
-            public SchemaContext getGlobalContext() {
-                return schemaContext;
-            }
-
-            @Override
-            public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
-                    final SchemaContextListener listener) {
-                listener.onGlobalContextUpdated(getGlobalContext());
-                return new ListenerRegistration<SchemaContextListener>() {
-                    @Override
-                    public void close() {
-
-                    }
-
-                    @Override
-                    public SchemaContextListener getInstance() {
-                        return listener;
-                    }
-                };
-            }
-        };
+    @Test
+    public void testEditUsingConfigFromFile() throws Exception {
+        // Ask class loader for URI of config file and use it as <url> in <edit-config> RPC:
+        final String template = XmlFileLoader.fileToString("messages/mapping/editConfigs/editConfig_from_file.xml");
+        final URI uri = getClass().getClassLoader().getResource("messages/mapping/editConfigs/config_file.xml").toURI();
+        final String copyConfig = template.replaceFirst("URL", uri.toString());
+        final Document request = XmlUtil.readXmlToDocument(copyConfig);
+
+        verifyResponse(edit(request), RPC_REPLY_OK);
+        verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
+            "messages/mapping/editConfigs/editConfig_from_file_control.xml"));
     }
-}
\ No newline at end of file
+}