From f91ddee2233cf23e3cb4bb4b43b6874103c3470b Mon Sep 17 00:00:00 2001 From: marko-bekhta Date: Tue, 20 Aug 2024 15:10:43 +0200 Subject: [PATCH] Add a test for a convert group on an interface with a generated implementation --- .../pom.xml | 34 +++++++++++++++++++ .../restclient/RestClientEntity.java | 30 ++++++++++++++++ .../restclient/RestClientInterface.java | 22 ++++++++++++ .../restclient/RestClientTestResource.java | 31 +++++++++++++++++ .../restclient/server/ServerResource.java | 27 +++++++++++++++ .../src/main/resources/application.properties | 3 +- .../hibernate/validator/RestClientTest.java | 18 ++++++++++ 7 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientEntity.java create mode 100644 integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientInterface.java create mode 100644 integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientTestResource.java create mode 100644 integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/server/ServerResource.java create mode 100644 integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/RestClientTest.java diff --git a/integration-tests/hibernate-validator-resteasy-reactive/pom.xml b/integration-tests/hibernate-validator-resteasy-reactive/pom.xml index e97d2598faa5d..7cff86b97d15b 100644 --- a/integration-tests/hibernate-validator-resteasy-reactive/pom.xml +++ b/integration-tests/hibernate-validator-resteasy-reactive/pom.xml @@ -22,6 +22,14 @@ io.quarkus quarkus-rest-jaxb + + io.quarkus + quarkus-rest-client + + + io.quarkus + quarkus-rest-client-jsonb + io.quarkus quarkus-hibernate-validator @@ -146,6 +154,32 @@ + + io.quarkus + quarkus-rest-client-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-rest-client-jsonb-deployment + ${project.version} + pom + test + + + * + * + + + diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientEntity.java b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientEntity.java new file mode 100644 index 0000000000000..2d91a4c46f2ef --- /dev/null +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientEntity.java @@ -0,0 +1,30 @@ +package io.quarkus.it.hibernate.validator.restclient; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.NotNull; + +public class RestClientEntity { + @Max(value = 5, groups = ErrorGroup.class) + public int number; + @NotNull + public String string; + + public RestClientEntity() { + } + + public RestClientEntity(int number, String string) { + this.number = number; + this.string = string; + } + + @Override + public String toString() { + return "RestClientEntity{" + + "number=" + number + + ", string='" + string + '\'' + + '}'; + } + + public interface ErrorGroup { + } +} diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientInterface.java b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientInterface.java new file mode 100644 index 0000000000000..691e03b163760 --- /dev/null +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientInterface.java @@ -0,0 +1,22 @@ +package io.quarkus.it.hibernate.validator.restclient; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.groups.ConvertGroup; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +@RegisterRestClient +@Path("/rest-client") +public interface RestClientInterface { + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + RestClientEntity doSomething( + @Valid @ConvertGroup(to = RestClientEntity.ErrorGroup.class) @NotNull RestClientEntity parameter); +} diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientTestResource.java b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientTestResource.java new file mode 100644 index 0000000000000..a2d547d62cf23 --- /dev/null +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientTestResource.java @@ -0,0 +1,31 @@ +package io.quarkus.it.hibernate.validator.restclient; + +import jakarta.inject.Inject; +import jakarta.validation.ConstraintViolationException; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +import org.eclipse.microprofile.rest.client.inject.RestClient; + +@Path("/hibernate-validator/test-rest-client") +public class RestClientTestResource { + + @Inject + @RestClient + RestClientInterface restClient; + + @GET + @Produces(MediaType.APPLICATION_JSON) + public RestClientEntity doSomething() { + RestClientEntity entity = new RestClientEntity(9, "aaa"); + try { + entity = restClient.doSomething(entity); + throw new IllegalStateException( + "This point should not be reached. Validation should fail on the rest client call."); + } catch (ConstraintViolationException e) { + return entity; + } + } +} diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/server/ServerResource.java b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/server/ServerResource.java new file mode 100644 index 0000000000000..dd96062d4d30b --- /dev/null +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/server/ServerResource.java @@ -0,0 +1,27 @@ +package io.quarkus.it.hibernate.validator.restclient.server; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +import io.quarkus.it.hibernate.validator.restclient.RestClientEntity; + +@Path("/rest-client") +public class ServerResource { + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String doSomething(String parameter) { + return parameter; + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public RestClientEntity doSomething() { + return new RestClientEntity(1, "aa"); + } +} diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/resources/application.properties b/integration-tests/hibernate-validator-resteasy-reactive/src/main/resources/application.properties index e5cfac536ba43..d8d7634c6b535 100644 --- a/integration-tests/hibernate-validator-resteasy-reactive/src/main/resources/application.properties +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/resources/application.properties @@ -1,2 +1,3 @@ quarkus.locales=en,de -quarkus.default-locale=en \ No newline at end of file +quarkus.default-locale=en +quarkus.rest-client."io.quarkus.it.hibernate.validator.restclient.RestClientInterface".url=${test.url} diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/RestClientTest.java b/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/RestClientTest.java new file mode 100644 index 0000000000000..ece06bcaf60b9 --- /dev/null +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/RestClientTest.java @@ -0,0 +1,18 @@ +package io.quarkus.it.hibernate.validator; + +import static io.restassured.RestAssured.given; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class RestClientTest { + + @Test + public void fetchDefault() { + given().get("hibernate-validator/test-rest-client") + .then() + .statusCode(200); + } +}