Reuse schemaContext in mdsal-netconf-connector tests
[netconf.git] / netconf / mdsal-netconf-connector / src / test / java / org / opendaylight / netconf / mdsal / connector / ops / NetconfMDSalMappingTest.java
index 3361ec5ea4dd387cfe110b91c27ef4b56ca625df..625acb29994c70a0d2dabdfd1d70a352f9db915e 100644 (file)
@@ -5,7 +5,6 @@
  * 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;
@@ -13,6 +12,7 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.StringWriter;
+import java.net.URI;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
@@ -33,8 +33,6 @@ import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -69,12 +67,6 @@ public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest {
     private static final YangInstanceIdentifier AUGMENTED_CONTAINER_IN_MODULES =
             YangInstanceIdentifier.builder().node(TOP).node(MODULES).build();
 
-    @Override
-    protected SchemaContext getSchemaContext() {
-        return YangParserTestUtils.parseYangResources(NetconfMDSalMappingTest.class,
-            "/META-INF/yang/config@2013-04-05.yang", "/yang/mdsal-netconf-mapping-test.yang");
-    }
-
     @Test
     public void testEmptyDatastore() throws Exception {
         assertEmptyDatastore(get());
@@ -105,6 +97,18 @@ public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest {
         }
     }
 
+    @Test
+    public void testConfigMissing() throws Exception {
+        try {
+            edit("messages/mapping/editConfigs/editConfig_no_config.xml");
+            fail("Should have failed - neither <config> nor <url> element is present");
+        } catch (final DocumentedException e) {
+            assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
+            assertTrue(e.getErrorTag() == ErrorTag.MISSING_ELEMENT);
+            assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
+        }
+    }
+
     @Test
     public void testEditRunning() throws Exception {
         try {
@@ -634,4 +638,17 @@ public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest {
         verifyResponse(commit(), RPC_REPLY_OK);
         assertEmptyDatastore(getConfigRunning());
     }
+
+    @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"));
+    }
 }