From aca66f6d6b8065b88d73bec17822ac6d226d9199 Mon Sep 17 00:00:00 2001 From: Ivan Hrasko Date: Wed, 15 Mar 2017 08:41:54 +0100 Subject: [PATCH 1/1] Bug 7987: Json HTTP PATCH: Problem parsing simple leaf value Change-Id: I8094797fc2a26bd809631d995a29e111320e664e Signed-off-by: Ivan Hrasko --- .../sal/rest/impl/JsonToPATCHBodyReader.java | 6 ++++++ .../jersey/providers/JsonToPATCHBodyReader.java | 6 ++++++ .../test/providers/TestJsonPATCHBodyReader.java | 16 ++++++++++++++++ .../TestJsonPATCHBodyReaderMountPoint.java | 16 ++++++++++++++++ .../JsonPATCHBodyReaderMountPointTest.java | 16 ++++++++++++++++ .../providers/JsonPATCHBodyReaderTest.java | 16 ++++++++++++++++ .../json/jsonPATCHSimpleLeafValue.json | 17 +++++++++++++++++ 7 files changed, 93 insertions(+) create mode 100644 restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java index 9968a25fc0..5b169885bc 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java @@ -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("{"); diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java index e139e65d91..7f53e24d13 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java @@ -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("{"); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReader.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReader.java index b999c036cc..d324791f97 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReader.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReader.java @@ -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); + } } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReaderMountPoint.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReaderMountPoint.java index 74058ca93b..7395aa6b0c 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReaderMountPoint.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPATCHBodyReaderMountPoint.java @@ -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); + } } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderMountPointTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderMountPointTest.java index 4bce4fda99..f50106e96f 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderMountPointTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderMountPointTest.java @@ -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); + } } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderTest.java index 5ab4432b80..6d8808ec0c 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPATCHBodyReaderTest.java @@ -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 index 0000000000..4a109efb91 --- /dev/null +++ b/restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json @@ -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 -- 2.36.6