Merge "Add sal-akka-raft test-jar dependency to sal-distributed-store pom"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / test / java / org / opendaylight / controller / sal / connect / netconf / schema / mapping / NetconfMessageTransformerTest.java
index ee32a596184684bc572efcbf0009fcd12ed06cc8..643c67af287862b92619d295be11ac2f8b8baa0b 100644 (file)
@@ -21,6 +21,7 @@ import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessag
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME;
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME;
+import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_QNAME;
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.createEditConfigStructure;
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
@@ -37,6 +38,7 @@ import java.util.List;
 import java.util.Map;
 import javax.xml.transform.dom.DOMSource;
 import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier;
 import org.custommonkey.xmlunit.XMLUnit;
 import org.hamcrest.CoreMatchers;
 import org.junit.Before;
@@ -79,11 +81,30 @@ public class NetconfMessageTransformerTest {
         XMLUnit.setIgnoreAttributeOrder(true);
         XMLUnit.setIgnoreComments(true);
 
-        schema = getSchema();
+        schema = getSchema(true);
         netconfMessageTransformer = getTransformer(schema);
 
     }
 
+    @Test
+    public void testLockRequestBaseSchemaNotPresent() throws Exception {
+        final SchemaContext partialSchema = getSchema(false);
+        final NetconfMessageTransformer transformer = getTransformer(partialSchema);
+        final NetconfMessage netconfMessage = transformer.toRpcRequest(toPath(NETCONF_LOCK_QNAME),
+                NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME));
+
+        assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<lock"));
+    }
+
+    @Test
+    public void tesLockSchemaRequest() throws Exception {
+        final SchemaContext partialSchema = getSchema(false);
+        final NetconfMessageTransformer transformer = getTransformer(partialSchema);
+        final String result = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>";
+
+        transformer.toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)), toPath(NETCONF_LOCK_QNAME));
+    }
+
     @Test
     public void testDiscardChangesRequest() throws Exception {
         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME),
@@ -97,16 +118,17 @@ public class NetconfMessageTransformerTest {
                 NetconfRemoteSchemaYangSourceProvider.createGetSchemaRequest("module", Optional.of("2012-12-12")));
         assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
                 "<get-schema xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
-                "<format>yang</format>\n" +
+                "<format xmlns:x=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">x:yang</format>\n" +
                 "<identifier>module</identifier>\n" +
                 "<version>2012-12-12</version>\n" +
                 "</get-schema>\n" +
                 "</rpc>");
     }
 
+
     @Test
     public void tesGetSchemaResponse() throws Exception {
-        final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema());
+        final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true));
         final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument(
                 "<rpc-reply message-id=\"101\"\n" +
                         "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
@@ -135,14 +157,14 @@ public class NetconfMessageTransformerTest {
                 "<schema>\n" +
                 "<identifier>module</identifier>\n" +
                 "<version>2012-12-12</version>\n" +
-                "<format>yang</format>\n" +
+                "<format xmlns:x=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">x:yang</format>\n" +
                 "</schema>\n" +
                 "</schemas>\n" +
                 "</netconf-state>\n" +
                 "</data>\n" +
                 "</rpc-reply>"));
 
-        final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema());
+        final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true));
         final DOMRpcResult compositeNodeRpcResult = netconfMessageTransformer.toRpcResult(response, toPath(NETCONF_GET_CONFIG_QNAME));
         assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
         assertNotNull(compositeNodeRpcResult.getResult());
@@ -223,7 +245,7 @@ public class NetconfMessageTransformerTest {
                 "<schema>\n" +
                 "<identifier>module</identifier>\n" +
                 "<version>2012-12-12</version>\n" +
-                "<format>yang</format>\n" +
+                "<format xmlns:x=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">x:yang</format>\n" +
                 "</schema>\n" +
                 "</schemas>\n" +
                 "</netconf-state>\n" +
@@ -234,6 +256,7 @@ public class NetconfMessageTransformerTest {
 
     private void assertSimilarXml(final NetconfMessage netconfMessage, final String xmlContent) throws SAXException, IOException {
         final Diff diff = XMLUnit.compareXML(netconfMessage.getDocument(), XmlUtil.readXmlToDocument(xmlContent));
+        diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
         assertTrue(diff.toString(), diff.similar());
     }
 
@@ -274,9 +297,11 @@ public class NetconfMessageTransformerTest {
         assertNull(compositeNodeRpcResult.getResult());
     }
 
-    public SchemaContext getSchema() {
+    public SchemaContext getSchema(boolean addBase) {
         final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
-        moduleInfoBackedContext.addModuleInfos(Collections.singleton($YangModuleInfoImpl.getInstance()));
+        if(addBase) {
+            moduleInfoBackedContext.addModuleInfos(Collections.singleton($YangModuleInfoImpl.getInstance()));
+        }
         moduleInfoBackedContext.addModuleInfos(Collections.singleton(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.$YangModuleInfoImpl.getInstance()));
         return moduleInfoBackedContext.tryToCreateSchemaContext().get();
     }