Fix get and get-config ordering for netconf-mdsal 46/30146/4
authorMaros Marsalek <mmarsale@cisco.com>
Tue, 24 Nov 2015 15:25:59 +0000 (16:25 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 7 Dec 2015 09:36:57 +0000 (09:36 +0000)
Change-Id: Ic31c3d44d89674240d77809041e29a2c7dd50638
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/AbstractGet.java
opendaylight/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/controller/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java
opendaylight/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_merge_multiple_keys_1.xml [new file with mode: 0644]
opendaylight/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml [new file with mode: 0644]
opendaylight/netconf/mdsal-netconf-connector/src/test/resources/yang/mdsal-netconf-mapping-test.yang

index d028a89e36d6d34c8d2535988739e5807908224f..984e50dc19c130e0ee827cda8874dbd96c149d94 100644 (file)
@@ -85,7 +85,7 @@ public abstract class AbstractGet extends AbstractSingletonNetconfOperation {
         final NormalizedNodeStreamWriter nnStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter,
                 schemaContext.getCurrentContext(), getSchemaPath(dataRoot));
 
-        final NormalizedNodeWriter nnWriter = NormalizedNodeWriter.forStreamWriter(nnStreamWriter);
+        final NormalizedNodeWriter nnWriter = NormalizedNodeWriter.forStreamWriter(nnStreamWriter, true);
 
         writeRootElement(xmlWriter, nnWriter, (ContainerNode) data);
         return result.getNode();
index b4f5a9756bae94ce3d46f12b2c27139834a55148..587375db7a46081f7ea20028b9b140b699f2c86c 100644 (file)
@@ -187,6 +187,24 @@ public class NetconfMDSalMappingTest {
 
     }
 
+    @Test
+    public void testKeyOrder() throws Exception {
+        verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_keys_1.xml"), RPC_REPLY_OK);
+        verifyResponse(commit(), RPC_REPLY_OK);
+        final Document configRunning = getConfigRunning();
+        final String responseAsString = XmlUtil.toString(configRunning);
+        verifyResponse(configRunning, XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml"));
+
+        final int key3 = responseAsString.indexOf("key3");
+        final int key1 = responseAsString.indexOf("key1");
+        final int key2 = responseAsString.indexOf("key2");
+
+        assertTrue(String.format("Key ordering invalid, should be key3(%d) < key1(%d) < key2(%d)", key3, key1, key2),
+            key3 < key1 && key1 < key2);
+
+        deleteDatastore();
+    }
+
     @Test
     public void testMultipleEditsWithMerge() throws Exception {
 
diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_merge_multiple_keys_1.xml b/opendaylight/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_merge_multiple_keys_1.xml
new file mode 100644 (file)
index 0000000..6b9ce73
--- /dev/null
@@ -0,0 +1,30 @@
+<!--
+  ~ Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+  ~
+  ~ This program and the accompanying materials are made available under the
+  ~ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+  ~ and is available at http://www.eclipse.org/legal/epl-v10.html
+  -->
+<rpc message-id="a" a="64" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+    <edit-config>
+        <target>
+            <candidate/>
+        </target>
+        <test-option>
+            set
+        </test-option>
+        <default-operation>merge</default-operation>
+        <config>
+            <mapping-nodes xmlns="urn:opendaylight:mdsal:mapping:test">
+                <multiple-keys>
+                    <!-- We can handle keys out of order -->
+                    <value2>22</value2>
+                    <key2>2</key2>
+                    <key1>1</key1>
+                    <value1>11</value1>
+                    <key3>3</key3>
+                </multiple-keys>
+            </mapping-nodes>
+        </config>
+    </edit-config>
+</rpc>
\ No newline at end of file
diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml b/opendaylight/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml
new file mode 100644 (file)
index 0000000..01a8661
--- /dev/null
@@ -0,0 +1,21 @@
+<!--
+  ~ Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+  ~
+  ~ This program and the accompanying materials are made available under the
+  ~ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+  ~ and is available at http://www.eclipse.org/legal/epl-v10.html
+  -->
+
+<rpc-reply id="a" a="64" xmlnx="a:b:c:d" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
+    <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+        <mapping-nodes xmlns="urn:opendaylight:mdsal:mapping:test">
+            <multiple-keys>
+                <key3>3</key3>
+                <key1>1</key1>
+                <key2>2</key2>
+                <value2>22</value2>
+                <value1>11</value1>
+            </multiple-keys>
+        </mapping-nodes>
+    </data>
+</rpc-reply>
\ No newline at end of file
index 399ae4b3bc423976353856de4eb2a9c8d9c92d2b..831638826c373943c7e6be471bbc63e53f6fb551 100644 (file)
@@ -7,6 +7,30 @@ module config {
 
     container mapping-nodes {
 
+        list multiple-keys {
+            key "key3 key1 key2";
+
+            leaf value1 {
+                type string;
+            }
+
+            leaf key1 {
+                type string;
+            }
+
+            leaf value2 {
+                type string;
+            }
+
+            leaf key2 {
+                type string;
+            }
+
+            leaf key3 {
+                type string;
+            }
+        }
+
         list mapping-node{
             key "id";
             leaf id {