From 62fef15fa2b0b90cae6d34135bbc52fe180f598f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 6 Apr 2024 04:22:11 +0200 Subject: [PATCH] Use pretty printing in RestconfDataPatchTest Demonstrate that the pretty-printing options are honoured by specifying them in RestconfDataPatchTest. This increases verbosity a bit, but makes the payloads much more readable. JIRA: NETCONF-773 Change-Id: Icefc77c7ab1abf1e929acc9e159ecaac697d46e6 Signed-off-by: Robert Varga --- .../nb/jaxrs/RestconfDataPatchTest.java | 58 +++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfDataPatchTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfDataPatchTest.java index b09575c21a..84f4e00a77 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfDataPatchTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfDataPatchTest.java @@ -12,6 +12,7 @@ import static org.mockito.Mockito.doReturn; import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFalseFluentFuture; import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateTrueFluentFuture; +import java.util.Map; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.UriInfo; import org.junit.jupiter.api.BeforeEach; @@ -22,6 +23,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction; +import org.opendaylight.restconf.api.query.PrettyPrintParam; import org.opendaylight.restconf.server.spi.YangPatchStatusBody; @ExtendWith(MockitoExtension.class) @@ -34,7 +36,7 @@ class RestconfDataPatchTest extends AbstractRestconfTest { @BeforeEach void beforeEach() { doReturn(tx).when(dataBroker).newReadWriteTransaction(); - doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters(); + doReturn(new MultivaluedHashMap<>(Map.of(PrettyPrintParam.uriName, "true"))).when(uriInfo).getQueryParameters(); } @Test @@ -84,7 +86,14 @@ class RestconfDataPatchTest extends AbstractRestconfTest { }"""), uriInfo, ar)); assertFormat(""" - {"ietf-yang-patch:yang-patch-status":{"patch-id":"test patch id","ok":[null]}}""", body::formatToJSON); + { + "ietf-yang-patch:yang-patch-status": { + "patch-id": "test patch id", + "ok": [ + null + ] + } + }""", body::formatToJSON); } @Test @@ -127,12 +136,40 @@ class RestconfDataPatchTest extends AbstractRestconfTest { }"""), uriInfo, ar)); assertFormat(""" - {"ietf-yang-patch:yang-patch-status":{"patch-id":"test patch id","edit-status":{"edit":[\ - {"edit-id":"create data","ok":[null]},\ - {"edit-id":"remove data","ok":[null]},\ - {"edit-id":"delete data","errors":{"error":[{"error-type":"protocol","error-tag":"data-missing",\ - "error-path":"/example-jukebox:jukebox/player/gap","error-message":"Data does not exist"}]}}]}}}""", - body::formatToJSON); + { + "ietf-yang-patch:yang-patch-status": { + "patch-id": "test patch id", + "edit-status": { + "edit": [ + { + "edit-id": "create data", + "ok": [ + null + ] + }, + { + "edit-id": "remove data", + "ok": [ + null + ] + }, + { + "edit-id": "delete data", + "errors": { + "error": [ + { + "error-type": "protocol", + "error-tag": "data-missing", + "error-path": "/example-jukebox:jukebox/player/gap", + "error-message": "Data does not exist" + } + ] + } + } + ] + } + } + }""", body::formatToJSON); } @Test @@ -178,8 +215,9 @@ class RestconfDataPatchTest extends AbstractRestconfTest { """), uriInfo, ar)); assertFormat(""" - \ - test patch id\ + + test patch id + """, body::formatToXML); } } -- 2.36.6