|
5 | 5 | import static io.github.mfaisalkhatri.api.restfulecommerce.testdata.OrderDataBuilder.getPartialUpdatedOrder;
|
6 | 6 | import static io.github.mfaisalkhatri.api.restfulecommerce.testdata.OrderDataBuilder.getUpdatedOrder;
|
7 | 7 | import static io.github.mfaisalkhatri.api.restfulecommerce.testdata.TokenBuilder.getCredentials;
|
| 8 | +import static io.github.mfaisalkhatri.api.restfulecommerce.testdata.TokenBuilder.getInvalidCredentials; |
8 | 9 | import static org.testng.Assert.assertEquals;
|
9 | 10 |
|
10 | 11 | import java.util.ArrayList;
|
@@ -294,6 +295,7 @@ public void testShouldNotDeleteOrder_WhenTokenIsMissing () {
|
294 | 295 |
|
295 | 296 | @Test
|
296 | 297 | public void testShouldNotDeleteOrder_WhenOrderIdIsNotFound () {
|
| 298 | + |
297 | 299 | final APIResponse authResponse = this.request.post ("/auth", RequestOptions.create ()
|
298 | 300 | .setData (getCredentials ()));
|
299 | 301 |
|
@@ -330,4 +332,32 @@ public void testShouldNotDeleteOrderWithInvalidToken () {
|
330 | 332 | assertEquals (response.status (), 400);
|
331 | 333 | assertEquals (responseObject.get ("message"), "Failed to authenticate token!");
|
332 | 334 | }
|
| 335 | + |
| 336 | + @Test |
| 337 | + public void testShouldNotGenerateToken_ForInvalidCredentials () { |
| 338 | + |
| 339 | + final APIResponse response = this.request.post ("/auth", RequestOptions.create () |
| 340 | + .setData (getInvalidCredentials ())); |
| 341 | + |
| 342 | + logResponse (response); |
| 343 | + |
| 344 | + final JSONObject responseObject = new JSONObject (response.text ()); |
| 345 | + |
| 346 | + assertEquals (response.status (), 401); |
| 347 | + assertEquals (responseObject.get ("message"), "Authentication Failed! Invalid username or password!"); |
| 348 | + } |
| 349 | + |
| 350 | + @Test |
| 351 | + public void testShouldNotGenerateToken_WhenCredentialsAreMissing () { |
| 352 | + |
| 353 | + final APIResponse response = this.request.post ("/auth", RequestOptions.create ()); |
| 354 | + |
| 355 | + logResponse (response); |
| 356 | + |
| 357 | + final JSONObject responseObject = new JSONObject (response.text ()); |
| 358 | + |
| 359 | + assertEquals (response.status (), 400); |
| 360 | + assertEquals (responseObject.get ("message"), "Username and Password is required for authentication!"); |
| 361 | + } |
| 362 | + |
333 | 363 | }
|
0 commit comments