From 43c87f10e3af1c164ac4ee0a3361ba8dba790dba Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 5 Oct 2024 14:05:52 +0300 Subject: [PATCH 1/2] added sad path scenarios for patch api and updated patch happy path scenario method name, added new testng xml for partial update --- .../api/restfulecommerce/HappyPathTests.java | 2 +- .../api/restfulecommerce/SadPathTests.java | 69 +++++++++++++++++++ ...ng-restfulecommerce-partialupdateorder.xml | 23 +++++++ test-suite/testng-restfulecommerce.xml | 6 +- 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 test-suite/testng-restfulecommerce-partialupdateorder.xml diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java index ae9abe8..6a1b14f 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java +++ b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java @@ -208,7 +208,7 @@ public void testShouldUpdateTheOrderUsingPut() { } @Test - public void testShouldUpdateTheOrderUsingPatch() { + public void testShouldPartialUpdateTheOrderUsingPatch() { final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials())); diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java index 5d54ce5..6acf8a6 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java +++ b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java @@ -173,4 +173,73 @@ public void testShouldNotUpdateOrderWithInvalidToken() { assertEquals(responseObject.get("message"), "Failed to authenticate token!"); } + @Test + public void testShouldNotPartialUpdateOrder_WhenTokenIsMissing() { + + int orderId = 1; + + final OrderData partialUpdatedOrder = getPartialUpdatedOrder(); + + final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create() + .setData(partialUpdatedOrder)); + + final JSONObject responseObject = new JSONObject(response.text()); + + assertEquals(response.status(), 403); + assertEquals(responseObject.get("message"), "Forbidden! Token is missing!"); + } + + @Test + public void testShouldNotPartialUpdateOrder_WhenOrderIdIsNotFound() { + final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials())); + + final JSONObject authResponseObject = new JSONObject(authResponse.text()); + final String token = authResponseObject.get("token").toString(); + + final OrderData updatedOrder = getPartialUpdatedOrder(); + + final int orderId = 90; + + final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create() + .setHeader("Authorization", token) + .setData(updatedOrder)); + + + final JSONObject responseObject = new JSONObject(response.text()); + + assertEquals(response.status(), 404); + assertEquals(responseObject.get("message"), "No Order found with the given Order Id!"); + + } + + @Test + public void testShouldNotPartialUpdateOrder_WhenOrderDetailsAreNotProvided() { + final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials())); + + final JSONObject authResponseObject = new JSONObject(authResponse.text()); + final String token = authResponseObject.get("token").toString(); + + final int orderId = 2; + + final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create() + .setHeader("Authorization", token)); + + final JSONObject responseObject = new JSONObject(response.text()); + + assertEquals(response.status(), 400); + assertEquals(responseObject.get("message"), "Invalid request, no data provided to update!"); + } + + @Test + public void testShouldNotPartialUpdateOrderWithInvalidToken() { + final int orderId = 2; + + final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create() + .setHeader("Authorization", "token273678")); + + final JSONObject responseObject = new JSONObject(response.text()); + + assertEquals(response.status(), 400); + assertEquals(responseObject.get("message"), "Failed to authenticate token!"); + } } diff --git a/test-suite/testng-restfulecommerce-partialupdateorder.xml b/test-suite/testng-restfulecommerce-partialupdateorder.xml new file mode 100644 index 0000000..d2fd60a --- /dev/null +++ b/test-suite/testng-restfulecommerce-partialupdateorder.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test-suite/testng-restfulecommerce.xml b/test-suite/testng-restfulecommerce.xml index 53be956..0488e9b 100644 --- a/test-suite/testng-restfulecommerce.xml +++ b/test-suite/testng-restfulecommerce.xml @@ -14,6 +14,10 @@ + + + + @@ -31,7 +35,7 @@ - + From ccad251851bed63bae7385c7f563c71e9ca960f0 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 5 Oct 2024 19:51:33 +0300 Subject: [PATCH 2/2] updated testng.xml --- .../api/restfulecommerce/HappyPathTests.java | 5 +---- .../testng-restfulecommerce-partialupdateorder.xml | 9 --------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java index 6a1b14f..3d9bb6a 100644 --- a/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java +++ b/src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java @@ -221,10 +221,7 @@ public void testShouldPartialUpdateTheOrderUsingPatch() { final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create() .setHeader("Authorization", token) .setData(partialUpdatedOrder)); - - final Logger logger = new Logger(response); - logger.logResponseDetails(); - + final JSONObject updateOrderResponseObject = new JSONObject(response.text()); final JSONObject orderObject = updateOrderResponseObject.getJSONObject("order"); diff --git a/test-suite/testng-restfulecommerce-partialupdateorder.xml b/test-suite/testng-restfulecommerce-partialupdateorder.xml index d2fd60a..f18ec38 100644 --- a/test-suite/testng-restfulecommerce-partialupdateorder.xml +++ b/test-suite/testng-restfulecommerce-partialupdateorder.xml @@ -11,13 +11,4 @@ - - - - - - - - -