forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for a convert group on an interface with a generated imple…
…mentation
- Loading branch information
1 parent
e55c54c
commit c303b6b
Showing
7 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...reactive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ctive/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
31 changes: 31 additions & 0 deletions
31
...ve/src/main/java/io/quarkus/it/hibernate/validator/restclient/RestClientTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ive/src/main/java/io/quarkus/it/hibernate/validator/restclient/server/ServerResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...ion-tests/hibernate-validator-resteasy-reactive/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
quarkus.locales=en,de | ||
quarkus.default-locale=en | ||
quarkus.default-locale=en | ||
quarkus.rest-client."io.quarkus.it.hibernate.validator.restclient.RestClientInterface".url=${test.url} |
18 changes: 18 additions & 0 deletions
18
...tor-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/RestClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |