Skip to content

Commit

Permalink
Add a test for a convert group on an interface with a generated imple…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
marko-bekhta committed Sep 5, 2024
1 parent e55c54c commit c303b6b
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 1 deletion.
34 changes: 34 additions & 0 deletions integration-tests/hibernate-validator-resteasy-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jaxb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
Expand Down Expand Up @@ -146,6 +154,32 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-jsonb-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
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 {
}
}
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);
}
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;
}
}
}
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");
}
}
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}
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);
}
}

0 comments on commit c303b6b

Please sign in to comment.