-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
I have a case, where I need to check if a service is sending a 302 code.
I have generated my client with the java generator, using the rest-assured library.
I was expecting to be able to write something like this:
api.myService().param1Query(“value”).execute(r -> r.thenReturn())
.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_MOVED_TEMPORARILY)
.header("Location", "https://example.com/");
This does not work, because by default rest-assured follow the redirect.
I get 200 and the content of https://example.com/.
With Rest-Assured, the solution (1) is to add .redirects().follow(false) after RestAssured.given().
But with the client generated by OpenAPI Generator, it is not possible to access the RequestSpecification created by RestAssured.given() (or I did not find how).
In StoreApiTest.java you will use the generated StoreApi.java (the execute(..) method). This execute(..) creates the RestAssured.given(). But in my test I do not have access to it.
Should the generator be extended to generate two execute methods in order to expose requestSpecification for special cases like mine. Something like this:
public <T> T execute(Function<Response, T> handler) {
return execute(RestAssured.given(), handler);
}
public <T> T execute(RequestSpecification requestSpecification, Function<Response, T> handler) {
return handler.apply(requestSpecification.spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(DELETE, REQ_URI));
}
(and the same for executeAs...)
Is there a better solution?
(1) https://groups.google.com/forum/#!msg/rest-assured/Sq_83Hc98Oo/2HUszbc6AgAJ