Skip to content

Commit 43c87f1

Browse files
committed
added sad path scenarios for patch api and updated patch happy path scenario method name, added new testng xml for partial update
1 parent 9257489 commit 43c87f1

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
lines changed

src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/HappyPathTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void testShouldUpdateTheOrderUsingPut() {
208208
}
209209

210210
@Test
211-
public void testShouldUpdateTheOrderUsingPatch() {
211+
public void testShouldPartialUpdateTheOrderUsingPatch() {
212212

213213
final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials()));
214214

src/test/java/io/github/mfaisalkhatri/api/restfulecommerce/SadPathTests.java

+69
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,73 @@ public void testShouldNotUpdateOrderWithInvalidToken() {
173173
assertEquals(responseObject.get("message"), "Failed to authenticate token!");
174174
}
175175

176+
@Test
177+
public void testShouldNotPartialUpdateOrder_WhenTokenIsMissing() {
178+
179+
int orderId = 1;
180+
181+
final OrderData partialUpdatedOrder = getPartialUpdatedOrder();
182+
183+
final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
184+
.setData(partialUpdatedOrder));
185+
186+
final JSONObject responseObject = new JSONObject(response.text());
187+
188+
assertEquals(response.status(), 403);
189+
assertEquals(responseObject.get("message"), "Forbidden! Token is missing!");
190+
}
191+
192+
@Test
193+
public void testShouldNotPartialUpdateOrder_WhenOrderIdIsNotFound() {
194+
final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials()));
195+
196+
final JSONObject authResponseObject = new JSONObject(authResponse.text());
197+
final String token = authResponseObject.get("token").toString();
198+
199+
final OrderData updatedOrder = getPartialUpdatedOrder();
200+
201+
final int orderId = 90;
202+
203+
final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
204+
.setHeader("Authorization", token)
205+
.setData(updatedOrder));
206+
207+
208+
final JSONObject responseObject = new JSONObject(response.text());
209+
210+
assertEquals(response.status(), 404);
211+
assertEquals(responseObject.get("message"), "No Order found with the given Order Id!");
212+
213+
}
214+
215+
@Test
216+
public void testShouldNotPartialUpdateOrder_WhenOrderDetailsAreNotProvided() {
217+
final APIResponse authResponse = this.request.post("/auth", RequestOptions.create().setData(getCredentials()));
218+
219+
final JSONObject authResponseObject = new JSONObject(authResponse.text());
220+
final String token = authResponseObject.get("token").toString();
221+
222+
final int orderId = 2;
223+
224+
final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
225+
.setHeader("Authorization", token));
226+
227+
final JSONObject responseObject = new JSONObject(response.text());
228+
229+
assertEquals(response.status(), 400);
230+
assertEquals(responseObject.get("message"), "Invalid request, no data provided to update!");
231+
}
232+
233+
@Test
234+
public void testShouldNotPartialUpdateOrderWithInvalidToken() {
235+
final int orderId = 2;
236+
237+
final APIResponse response = this.request.patch("/partialUpdateOrder/" + orderId, RequestOptions.create()
238+
.setHeader("Authorization", "token273678"));
239+
240+
final JSONObject responseObject = new JSONObject(response.text());
241+
242+
assertEquals(response.status(), 400);
243+
assertEquals(responseObject.get("message"), "Failed to authenticate token!");
244+
}
176245
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+
<suite name="Restful ECommerce Test Suite">
4+
<test name="Testing Happy Path Scenarios of Creating and Updating Orders">
5+
<classes>
6+
<class name="io.github.mfaisalkhatri.api.restfulecommerce.HappyPathTests">
7+
<methods>
8+
<include name="testShouldCreateNewOrders"/>
9+
<include name="testShouldPartialUpdateTheOrderUsingPatch"/>
10+
</methods>
11+
</class>
12+
</classes>
13+
</test>
14+
<test name="Testing Sad Path Scenarios of Updating Order">
15+
<classes>
16+
<class name="io.github.mfaisalkhatri.api.restfulecommerce.SadPathTests">
17+
<methods>
18+
<include name="testShouldNotPartialUpdateOrder_WhenTokenIsMissing"/>
19+
</methods>
20+
</class>
21+
</classes>
22+
</test>
23+
</suite>

test-suite/testng-restfulecommerce.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<include name="testShouldNotUpdateOrder_WhenTokenIsMissing"/>
1515
<include name="testShouldNotUpdateOrder_WhenOrderIdIsNotFound"/>
1616
<include name="testShouldNotUpdateOrderWithInvalidToken"/>
17+
<include name="testShouldNotPartialUpdateOrder_WhenTokenIsMissing"/>
18+
<include name="testShouldNotPartialUpdateOrder_WhenOrderIdIsNotFound"/>
19+
<include name="testShouldNotPartialUpdateOrder_WhenOrderDetailsAreNotProvided"/>
20+
<include name="testShouldNotPartialUpdateOrderWithInvalidToken"/>
1721
</methods>
1822
</class>
1923
</classes>
@@ -31,7 +35,7 @@
3135
<include name="testShouldGetOrdersUsingOrderIdProductIdAndUserId"/>
3236
<include name="testTokenGeneration"/>
3337
<include name="testShouldUpdateTheOrderUsingPut"/>
34-
<include name="testShouldUpdateTheOrderUsingPatch"/>
38+
<include name="testShouldPartialUpdateTheOrderUsingPatch"/>
3539
<include name="testShouldDeleteTheOrder"/>
3640
<include name="testShouldNotRetrieveDeletedOrder"/>
3741
</methods>

0 commit comments

Comments
 (0)