-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access the response status and headers of the Client Response #130
Comments
I like the idea of giving users more low-level validation access to their HTTP endpoints. Currently users can do this if the REST client returns a One popular REST testing library I know if is REST-assured. Here is a good article about it: https://www.baeldung.com/rest-assured-tutorial @MicroShedTest
public class MyTest {
@Container
public static ApplicationContainer app = // usual config
@Test
public void testCreatePerson() {
// validate that POST request to
// http://<container-ip>:<container-port>/myservice/?name=Hank?age=52
// returns HTTP 200 with content type JSON
given()
.contentType(JSON)
.queryParam("name", "Hank")
.queryParam("age", 52)
.when()
.post("/")
.then()
.statusCode(200)
.contentType(JSON);
}
} |
This looks quite good 👍 |
created a draft PR for the integration here: #134 It can't be merged until the corresponding PR I made on REST-assured gets merged though |
wow, that was fast 👍 I'll try it over the weekend while building REST-Assured with your PR locally |
works great and I really like the Just out of curiosity, if now a user wants to plug a custom |
RestAssured has builtin converters for JSON and XML formats, but if a user wants to implement a converter to handle a custom data format. For JSON-B integration with RestAssured I could have just written the converter in MicroShed code, but then we'd need to have a dependency on RestAssured which I wanted to avoid (i.e. not even an optional dependency) |
PR #134 adds the integration with REST Assured and is now merged, it will be available in the next release (probably 0.6.3) |
Is your feature request related to a problem? Please describe.
Right now we can only write assertions based on the response type of the JAX-RS method class. It would be nice if we can access the actual JAX-RS
Response
to inspect HTTP headers & the response status.Describe the solution you'd like
Maybe reconsider the solution with the injection of the JAX-RS resources class to a static field using
@RESTClient PersonResource personResource
(which is also not that intuitive IMHO). It would be nice to just inject a prepared JAX-RSClient
which is already bound to the application context, has some default provider (e.g. JSON/XML) and can be further configured if required. The Spring framework, for example, provides aWebTestClient
during a test execution with the described setup.I wouldn't go that far as the Spring Framework and also add assertion methods on the client class and just prepare it to be used by the developer like in his production code.
The downside of this idea: The user has to enter the actual path for the JAX-RS resource he/she wants to access, which is currently not required. This might also be a small plus, as with the current solution your integration test would never recognize a URL change in the API e.g.
/resources/persons
to/api/persons
.Describe alternatives you've considered
@RESTClient
Additional context
none
The text was updated successfully, but these errors were encountered: