December 2019
Intermediate to advanced
314 pages
6h 51m
English
Our test class needs to be adjusted so that it can fit the new secured scenario. In practice, we need to send the header files with the user's credentials, along with the HTTP request, with them to authorize the service's execution. Thanks to the Fluent RestAssured API, it is fairly easy to plug the auth() method into our HTTP request, as shown in the following code:
@Testpublic void testCustomerService() { // Test GET for Customer size given() .auth() .preemptive() .basic("frank", "password123") .when().get("/customers") .then() .statusCode(200) .body("$.size()", is(2)); JsonObject objOrder = Json.createObjectBuilder() .add("item", "bike") .add("price", new Long(100)) .build(); // ...
Read now
Unlock full access