In a quarkus application, I am trying to write unit test for Controller for the resource method where I need to validate certain header parameters. so How do we validate?
@Path("/abcs")
public class ABCController {
...
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ResponseStatus(CREATED)
public Uni<AbcResponse> createABC(
@Context HttpHeaders httpHeaders,
@Valid @ConvertGroup(to = ValidationGroups.Post.class)
AbcRequest abcRequest) {
String apiKey = httpHeaders.getRequestHeader("X-API-Key").get(0);
if (StringUtils.isBlank(apiKey)) {
throw new RestFulPayoutException("X-API-Key is missing on headers", Response.Status.FORBIDDEN);
}
Write a @QuarkusTest
and with RestAssured
perform a call to your endpoint with various header values and check for response.
All information are available at Quarkus documentation.