Bug 7987: Json HTTP PATCH: Problem parsing simple leaf value 13/53313/2
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Wed, 15 Mar 2017 07:41:54 +0000 (08:41 +0100)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Wed, 15 Mar 2017 07:58:40 +0000 (07:58 +0000)
Change-Id: I8094797fc2a26bd809631d995a29e111320e664e
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReader.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReaderMountPoint.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderMountPointTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderTest.java
restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json [new file with mode: 0644]

index 9968a25fc06adcdf0feae4a1b7dacc3b3eb0d771..5b169885bcd1819026bd9aab7eef028b4f3acac9 100644 (file)
@@ -300,6 +300,12 @@ public class JsonToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider
      * @throws IOException
      */
     private void readValueObject(@Nonnull final StringBuffer value, @Nonnull final JsonReader in) throws IOException {
+        // read simple leaf value
+        if (in.peek() == JsonToken.STRING) {
+            value.append("\"" + in.nextString() + "\"");
+            return;
+        }
+
         in.beginObject();
         value.append("{");
 
index e139e65d91e11c9ca282e3d03b9db03424b1f669..7f53e24d13fdeb6b4fd3b03265b84b4a95f7d8c5 100644 (file)
@@ -295,6 +295,12 @@ public class JsonToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider
      * @throws IOException
      */
     private void readValueObject(@Nonnull final StringBuffer value, @Nonnull final JsonReader in) throws IOException {
+        // read simple leaf value
+        if (in.peek() == JsonToken.STRING) {
+            value.append("\"" + in.nextString() + "\"");
+            return;
+        }
+
         in.beginObject();
         value.append("{");
 
index b999c036cc8ad163906f64bfc510212edeedb3e5..d324791f97e8508ef84a8daee31c3249d8b99778 100644 (file)
@@ -158,4 +158,20 @@ public class TestJsonPATCHBodyReader extends AbstractBodyReaderTest {
                 .readFrom(null, null, null, mediaType, null, inputStream);
         checkPATCHContext(returnValue);
     }
+
+    /**
+     * Test reading simple leaf value
+     */
+    @Test
+    public void modulePATCHSimpleLeafValueTest() throws Exception {
+        final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
+        mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+        final InputStream inputStream = TestJsonBodyReader.class
+                .getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
+
+        final PATCHContext returnValue = jsonPATCHBodyReader
+                .readFrom(null, null, null, mediaType, null, inputStream);
+        checkPATCHContext(returnValue);
+    }
 }
index 74058ca93bf02bd25bd0f17fa4c1b4febd17e4c9..7395aa6b0c4b66b47a5f803b78abed4dc30e71b4 100644 (file)
@@ -174,4 +174,20 @@ public class TestJsonPATCHBodyReaderMountPoint extends AbstractBodyReaderTest {
                 .readFrom(null, null, null, mediaType, null, inputStream);
         checkPATCHContextMountPoint(returnValue);
     }
+
+    /**
+     * Test reading simple leaf value
+     */
+    @Test
+    public void modulePATCHSimpleLeafValueTest() throws Exception {
+        final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont/my-list1/leaf1";
+        mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+        final InputStream inputStream = TestJsonBodyReader.class
+                .getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
+
+        final PATCHContext returnValue = jsonPATCHBodyReader
+                .readFrom(null, null, null, mediaType, null, inputStream);
+        checkPATCHContext(returnValue);
+    }
 }
index 4bce4fda996e271b8ace30f16bf1acfe015499f0..f50106e96f67f3a7e8c9621c6f479f25cd0d86a5 100644 (file)
@@ -174,4 +174,20 @@ public class JsonPATCHBodyReaderMountPointTest extends AbstractBodyReaderTest {
                 .readFrom(null, null, null, mediaType, null, inputStream);
         checkPATCHContextMountPoint(returnValue);
     }
+
+    /**
+     * Test reading simple leaf value
+     */
+    @Test
+    public void modulePATCHSimpleLeafValueTest() throws Exception {
+        final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+        mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+        final InputStream inputStream = TestJsonBodyReader.class
+                .getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
+
+        final PATCHContext returnValue = jsonPATCHBodyReader
+                .readFrom(null, null, null, mediaType, null, inputStream);
+        checkPATCHContext(returnValue);
+    }
 }
index 5ab4432b80d4d9035cbda9cc3c09ac6072d799d5..6d8808ec0c2a9b32eeb94d83329089adc9b7741a 100644 (file)
@@ -162,4 +162,20 @@ public class JsonPATCHBodyReaderTest extends AbstractBodyReaderTest {
                 .readFrom(null, null, null, mediaType, null, inputStream);
         checkPATCHContext(returnValue);
     }
+
+    /**
+     * Test reading simple leaf value
+     */
+    @Test
+    public void modulePATCHSimpleLeafValueTest() throws Exception {
+        final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+        mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+        final InputStream inputStream = TestJsonBodyReader.class
+                .getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
+
+        final PATCHContext returnValue = jsonPATCHBodyReader
+                .readFrom(null, null, null, mediaType, null, inputStream);
+        checkPATCHContext(returnValue);
+    }
 }
diff --git a/restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json b/restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json
new file mode 100644 (file)
index 0000000..4a109ef
--- /dev/null
@@ -0,0 +1,17 @@
+{
+  "ietf-yang-patch:yang-patch" : {
+
+    "patch-id" : "test-patch",
+    "comment" : "this is test patch for simple leaf value",
+    "edit" : [
+      {
+        "edit-id": "edit1",
+        "operation": "replace",
+        "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf20']/instance-identifier-patch-module:name",
+        "value": {
+          "name": "my-leaf20"
+        }
+      }
+    ]
+  }
+}
\ No newline at end of file