Skip to content

Commit 7513799

Browse files
marko-bekhtageoand
authored andcommitted
Add a test for a convert group on an interface with a generated implementation
1 parent 9b0fd8a commit 7513799

File tree

7 files changed

+164
-1
lines changed

7 files changed

+164
-1
lines changed

integration-tests/hibernate-validator-resteasy-reactive/pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
<groupId>io.quarkus</groupId>
2323
<artifactId>quarkus-rest-jaxb</artifactId>
2424
</dependency>
25+
<dependency>
26+
<groupId>io.quarkus</groupId>
27+
<artifactId>quarkus-rest-client</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>io.quarkus</groupId>
31+
<artifactId>quarkus-rest-client-jsonb</artifactId>
32+
</dependency>
2533
<dependency>
2634
<groupId>io.quarkus</groupId>
2735
<artifactId>quarkus-hibernate-validator</artifactId>
@@ -146,6 +154,32 @@
146154
</exclusion>
147155
</exclusions>
148156
</dependency>
157+
<dependency>
158+
<groupId>io.quarkus</groupId>
159+
<artifactId>quarkus-rest-client-deployment</artifactId>
160+
<version>${project.version}</version>
161+
<type>pom</type>
162+
<scope>test</scope>
163+
<exclusions>
164+
<exclusion>
165+
<groupId>*</groupId>
166+
<artifactId>*</artifactId>
167+
</exclusion>
168+
</exclusions>
169+
</dependency>
170+
<dependency>
171+
<groupId>io.quarkus</groupId>
172+
<artifactId>quarkus-rest-client-jsonb-deployment</artifactId>
173+
<version>${project.version}</version>
174+
<type>pom</type>
175+
<scope>test</scope>
176+
<exclusions>
177+
<exclusion>
178+
<groupId>*</groupId>
179+
<artifactId>*</artifactId>
180+
</exclusion>
181+
</exclusions>
182+
</dependency>
149183
</dependencies>
150184

151185
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.quarkus.it.hibernate.validator.restclient;
2+
3+
import jakarta.validation.constraints.Max;
4+
import jakarta.validation.constraints.NotNull;
5+
6+
public class RestClientEntity {
7+
@Max(value = 5, groups = ErrorGroup.class)
8+
public int number;
9+
@NotNull
10+
public String string;
11+
12+
public RestClientEntity() {
13+
}
14+
15+
public RestClientEntity(int number, String string) {
16+
this.number = number;
17+
this.string = string;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "RestClientEntity{" +
23+
"number=" + number +
24+
", string='" + string + '\'' +
25+
'}';
26+
}
27+
28+
public interface ErrorGroup {
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.quarkus.it.hibernate.validator.restclient;
2+
3+
import jakarta.validation.Valid;
4+
import jakarta.validation.constraints.NotNull;
5+
import jakarta.validation.groups.ConvertGroup;
6+
import jakarta.ws.rs.Consumes;
7+
import jakarta.ws.rs.POST;
8+
import jakarta.ws.rs.Path;
9+
import jakarta.ws.rs.Produces;
10+
import jakarta.ws.rs.core.MediaType;
11+
12+
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
13+
14+
@RegisterRestClient
15+
@Path("/rest-client")
16+
public interface RestClientInterface {
17+
@POST
18+
@Consumes(MediaType.APPLICATION_JSON)
19+
@Produces(MediaType.APPLICATION_JSON)
20+
RestClientEntity doSomething(
21+
@Valid @ConvertGroup(to = RestClientEntity.ErrorGroup.class) @NotNull RestClientEntity parameter);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.quarkus.it.hibernate.validator.restclient;
2+
3+
import jakarta.inject.Inject;
4+
import jakarta.validation.ConstraintViolationException;
5+
import jakarta.ws.rs.GET;
6+
import jakarta.ws.rs.Path;
7+
import jakarta.ws.rs.Produces;
8+
import jakarta.ws.rs.core.MediaType;
9+
10+
import org.eclipse.microprofile.rest.client.inject.RestClient;
11+
12+
@Path("/hibernate-validator/test-rest-client")
13+
public class RestClientTestResource {
14+
15+
@Inject
16+
@RestClient
17+
RestClientInterface restClient;
18+
19+
@GET
20+
@Produces(MediaType.APPLICATION_JSON)
21+
public RestClientEntity doSomething() {
22+
RestClientEntity entity = new RestClientEntity(9, "aaa");
23+
try {
24+
entity = restClient.doSomething(entity);
25+
throw new IllegalStateException(
26+
"This point should not be reached. Validation should fail on the rest client call.");
27+
} catch (ConstraintViolationException e) {
28+
return entity;
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.quarkus.it.hibernate.validator.restclient.server;
2+
3+
import jakarta.ws.rs.Consumes;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.POST;
6+
import jakarta.ws.rs.Path;
7+
import jakarta.ws.rs.Produces;
8+
import jakarta.ws.rs.core.MediaType;
9+
10+
import io.quarkus.it.hibernate.validator.restclient.RestClientEntity;
11+
12+
@Path("/rest-client")
13+
public class ServerResource {
14+
15+
@POST
16+
@Consumes(MediaType.APPLICATION_JSON)
17+
@Produces(MediaType.APPLICATION_JSON)
18+
public String doSomething(String parameter) {
19+
return parameter;
20+
}
21+
22+
@GET
23+
@Produces(MediaType.APPLICATION_JSON)
24+
public RestClientEntity doSomething() {
25+
return new RestClientEntity(1, "aa");
26+
}
27+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
quarkus.locales=en,de
2-
quarkus.default-locale=en
2+
quarkus.default-locale=en
3+
quarkus.rest-client."io.quarkus.it.hibernate.validator.restclient.RestClientInterface".url=${test.url}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.quarkus.it.hibernate.validator;
2+
3+
import static io.restassured.RestAssured.given;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import io.quarkus.test.junit.QuarkusTest;
8+
9+
@QuarkusTest
10+
public class RestClientTest {
11+
12+
@Test
13+
public void fetchDefault() {
14+
given().get("hibernate-validator/test-rest-client")
15+
.then()
16+
.statusCode(200);
17+
}
18+
}

0 commit comments

Comments
 (0)