From f366f722cf5c9a93a0b2b1dd74d84b2508046174 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 26 Aug 2023 10:43:40 +0200 Subject: [PATCH 1/1] Migrate more JSON patch payloads Inline test resources as string literals, making tests a lot cleaner. Change-Id: I575a705167c7981efca977bf6806993fa86ff478 Signed-off-by: Robert Varga --- .../rfc8040/databind/JsonPatchBodyTest.java | 153 ++++++++++++++++-- .../json/jsonPATCHMergeOperationOnList.json | 32 ---- .../json/jsonPATCHSimpleLeafValue.json | 17 -- ...CHTargetTopLevelContainerWithEmptyURI.json | 22 --- .../jsonPATCHdataCompleteTargetInURI.json | 44 ----- .../json/jsonPATCHdataValueNotSupported.json | 20 --- 6 files changed, 139 insertions(+), 149 deletions(-) delete mode 100644 restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHMergeOperationOnList.json delete mode 100644 restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json delete mode 100644 restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHTargetTopLevelContainerWithEmptyURI.json delete mode 100644 restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json delete mode 100644 restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHdataValueNotSupported.json diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/JsonPatchBodyTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/JsonPatchBodyTest.java index 101dd0aa73..d83c0b6c2f 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/JsonPatchBodyTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/JsonPatchBodyTest.java @@ -132,10 +132,29 @@ public class JsonPatchBodyTest extends AbstractPatchBodyTest { */ @Test public final void modulePatchValueNotSupportedNegativeTest() throws Exception { - final var inputStream = JsonPatchBodyTest.class.getResourceAsStream( - "/instanceidentifier/json/jsonPATCHdataValueNotSupported.json"); final var ex = assertThrows(RestconfDocumentedException.class, - () -> parse(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1", inputStream)); + () -> parse(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1", """ + { + "ietf-yang-patch:yang-patch" : { + "patch-id" : "test-patch", + "comment" : "this is test patch", + "edit" : [ + { + "edit-id": "edit2", + "operation": "delete", + "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name=\ +'my-leaf20']", + "value": { + "my-list2": [ + { + "name": "my-leaf20" + } + ] + } + } + ] + } + }""")); assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag()); } @@ -144,9 +163,50 @@ public class JsonPatchBodyTest extends AbstractPatchBodyTest { */ @Test public final void modulePatchCompleteTargetInURITest() throws Exception { - checkPatchContext(parse(mountPrefix() + "instance-identifier-patch-module:patch-cont", - JsonPatchBodyTest.class.getResourceAsStream( - "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json"))); + checkPatchContext(parse(mountPrefix() + "instance-identifier-patch-module:patch-cont", """ + { + "ietf-yang-patch:yang-patch" : { + "patch-id" : "test-patch", + "comment" : "Test to create and replace data in container directly using / sign as a target", + "edit" : [ + { + "edit-id": "edit1", + "operation": "create", + "target": "/", + "value": { + "patch-cont": { + "my-list1": [ + { + "name": "my-list1 - A", + "my-leaf11": "I am leaf11-0", + "my-leaf12": "I am leaf12-1" + }, + { + "name": "my-list1 - B", + "my-leaf11": "I am leaf11-0", + "my-leaf12": "I am leaf12-1" + } + ] + } + } + }, + { + "edit-id": "edit2", + "operation": "replace", + "target": "/", + "value": { + "patch-cont": { + "my-list1": { + "name": "my-list1 - Replacing", + "my-leaf11": "I am leaf11-0", + "my-leaf12": "I am leaf12-1" + } + } + } + } + ] + } + }""")); } /** @@ -154,9 +214,39 @@ public class JsonPatchBodyTest extends AbstractPatchBodyTest { */ @Test public final void modulePatchMergeOperationOnListTest() throws Exception { - checkPatchContext(parse(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1", - JsonPatchBodyTest.class.getResourceAsStream( - "/instanceidentifier/json/jsonPATCHMergeOperationOnList.json"))); + checkPatchContext(parse(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1", """ + { + "ietf-yang-patch:yang-patch" : { + "patch-id" : "Test merge operation", + "comment" : "This is test patch for merge operation on list", + "edit" : [ + { + "edit-id": "edit1", + "operation": "replace", + "target": "/my-list2=my-leaf20", + "value": { + "my-list2": { + "name": "my-leaf20", + "my-leaf21": "I am leaf21-0", + "my-leaf22": "I am leaf22-0" + } + } + }, + { + "edit-id": "edit2", + "operation": "merge", + "target": "/my-list2=my-leaf21", + "value": { + "my-list2": { + "name": "my-leaf21", + "my-leaf21": "I am leaf21-1", + "my-leaf22": "I am leaf22-1" + } + } + } + ] + } + }""")); } /** @@ -215,8 +305,23 @@ public class JsonPatchBodyTest extends AbstractPatchBodyTest { */ @Test public final void modulePatchSimpleLeafValueTest() throws Exception { - final var returnValue = parse(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1", - JsonPatchBodyTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json")); + final var returnValue = parse(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1", """ + { + "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": "/my-list2=my-leaf20/name", + "value": { + "name": "my-leaf20" + } + } + ] + } + }"""); checkPatchContext(returnValue); assertEquals(ImmutableNodes.leafNode(LEAF_NAME_QNAME, "my-leaf20"), returnValue.getData().get(0).getNode()); } @@ -226,9 +331,29 @@ public class JsonPatchBodyTest extends AbstractPatchBodyTest { */ @Test public final void modulePatchTargetTopLevelContainerWithEmptyURITest() throws Exception { - checkPatchContext(parse(mountPrefix(), - JsonPatchBodyTest.class.getResourceAsStream( - "/instanceidentifier/json/jsonPATCHTargetTopLevelContainerWithEmptyURI.json"))); + checkPatchContext(parse(mountPrefix(), """ + { + "ietf-yang-patch:yang-patch" : { + "patch-id" : "test-patch", + "comment" : "Test patch applied to the top-level container with empty URI", + "edit" : [ + { + "edit-id": "edit1", + "operation": "replace", + "target": "/instance-identifier-patch-module:patch-cont", + "value": { + "patch-cont": { + "my-list1": [ + { + "name": "my-leaf10" + } + ] + } + } + } + ] + } + }""")); } /** diff --git a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHMergeOperationOnList.json b/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHMergeOperationOnList.json deleted file mode 100644 index cbb67a9769..0000000000 --- a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHMergeOperationOnList.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "ietf-yang-patch:yang-patch" : { - "patch-id" : "Test merge operation", - "comment" : "This is test patch for merge operation on list", - "edit" : [ - { - "edit-id": "edit1", - "operation": "replace", - "target": "/my-list2=my-leaf20", - "value": { - "my-list2": { - "name": "my-leaf20", - "my-leaf21": "I am leaf21-0", - "my-leaf22": "I am leaf22-0" - } - } - }, - { - "edit-id": "edit2", - "operation": "merge", - "target": "/my-list2=my-leaf21", - "value": { - "my-list2": { - "name": "my-leaf21", - "my-leaf21": "I am leaf21-1", - "my-leaf22": "I am leaf22-1" - } - } - } - ] - } -} diff --git a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json b/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json deleted file mode 100644 index d63d43b8fb..0000000000 --- a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHSimpleLeafValue.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "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": "/my-list2=my-leaf20/name", - "value": { - "name": "my-leaf20" - } - } - ] - } -} diff --git a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHTargetTopLevelContainerWithEmptyURI.json b/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHTargetTopLevelContainerWithEmptyURI.json deleted file mode 100644 index 31bc148c44..0000000000 --- a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHTargetTopLevelContainerWithEmptyURI.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "ietf-yang-patch:yang-patch" : { - "patch-id" : "test-patch", - "comment" : "Test patch applied to the top-level container with empty URI", - "edit" : [ - { - "edit-id": "edit1", - "operation": "replace", - "target": "/instance-identifier-patch-module:patch-cont", - "value": { - "patch-cont": { - "my-list1": [ - { - "name": "my-leaf10" - } - ] - } - } - } - ] - } -} diff --git a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json b/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json deleted file mode 100644 index 1b170c772f..0000000000 --- a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "ietf-yang-patch:yang-patch" : { - - "patch-id" : "test-patch", - "comment" : "Test to create and replace data in container directly using / sign as a target", - "edit" : [ - { - "edit-id": "edit1", - "operation": "create", - "target": "/", - "value": { - "patch-cont": { - "my-list1": [ - { - "name": "my-list1 - A", - "my-leaf11": "I am leaf11-0", - "my-leaf12": "I am leaf12-1" - }, - { - "name": "my-list1 - B", - "my-leaf11": "I am leaf11-0", - "my-leaf12": "I am leaf12-1" - } - ] - } - } - }, - { - "edit-id": "edit2", - "operation": "replace", - "target": "/", - "value": { - "patch-cont": { - "my-list1": { - "name": "my-list1 - Replacing", - "my-leaf11": "I am leaf11-0", - "my-leaf12": "I am leaf12-1" - } - } - } - } - ] - } -} \ No newline at end of file diff --git a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHdataValueNotSupported.json b/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHdataValueNotSupported.json deleted file mode 100644 index 1ad52fb39f..0000000000 --- a/restconf/restconf-nb/src/test/resources/instanceidentifier/json/jsonPATCHdataValueNotSupported.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "ietf-yang-patch:yang-patch" : { - "patch-id" : "test-patch", - "comment" : "this is test patch", - "edit" : [ - { - "edit-id": "edit2", - "operation": "delete", - "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf20']", - "value": { - "my-list2": [ - { - "name": "my-leaf20" - } - ] - } - } - ] - } -} \ No newline at end of file -- 2.36.6