-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8511 from Sanne/ValidatorORMTestBackup
Introduce a test for #8323 : Hibernate Validator to be able to use the Hibernate ORM helpers to traverse graphs with uninitialized proxies
- Loading branch information
Showing
4 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
integration-tests/main/src/main/java/io/quarkus/it/validator/Hello.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,52 @@ | ||
package io.quarkus.it.validator; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotEmpty; | ||
|
||
@Entity | ||
@Table(name = "Hello") | ||
public class Hello { | ||
|
||
@Id | ||
private int id; | ||
|
||
@NotEmpty | ||
private String greetingText; | ||
|
||
@Valid | ||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false) | ||
@JoinColumn(nullable = false) | ||
private Human greetedHuman; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(final int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getGreetingText() { | ||
return greetingText; | ||
} | ||
|
||
public void setGreetingText(final String greetingText) { | ||
this.greetingText = greetingText; | ||
} | ||
|
||
public Human getGreetedHuman() { | ||
return greetedHuman; | ||
} | ||
|
||
public void setGreetedHuman(final Human greetedHuman) { | ||
this.greetedHuman = greetedHuman; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
integration-tests/main/src/main/java/io/quarkus/it/validator/Human.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,55 @@ | ||
package io.quarkus.it.validator; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotEmpty; | ||
|
||
import com.sun.istack.NotNull; | ||
|
||
@Entity | ||
@Table(name = "Human") | ||
public class Human { | ||
|
||
@Id | ||
private int id; | ||
|
||
@NotEmpty | ||
private String name; | ||
|
||
@NotNull | ||
@Valid | ||
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "greetedHuman") | ||
private Set<Hello> greetings = new HashSet<>(); | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(final int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(final String name) { | ||
this.name = name; | ||
} | ||
|
||
public Set<Hello> getGreetings() { | ||
return greetings; | ||
} | ||
|
||
public void setGreetings(final Set<Hello> greetings) { | ||
this.greetings = greetings; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ests/main/src/main/java/io/quarkus/it/validator/TestValidatorAndHibernateORMEndpoint.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,56 @@ | ||
package io.quarkus.it.validator; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
import javax.transaction.Transactional; | ||
import javax.validation.Validator; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
/** | ||
* Verifies that Hibernate Validator can use Hibernate ORM's PersistenceUtilHelper | ||
* to traverse managed object graphs which contain enhanced proxies. | ||
* | ||
* Test for issue https://github.com/quarkusio/quarkus/issues/8323 | ||
*/ | ||
@Path("/validator-and-orm") | ||
public class TestValidatorAndHibernateORMEndpoint { | ||
|
||
@Inject | ||
EntityManager em; | ||
|
||
@Inject | ||
Validator validator; | ||
|
||
@GET | ||
@Path("/store") | ||
@Transactional | ||
public String storeData() { | ||
//Create hello#1 | ||
Hello hello = new Hello(); | ||
hello.setId(1); | ||
hello.setGreetingText("hello"); | ||
//Create human#3 | ||
Human human = new Human(); | ||
human.setId(3); | ||
human.setName("Batman"); | ||
//create the relation | ||
human.getGreetings().add(hello); | ||
hello.setGreetedHuman(human); | ||
//Store it all | ||
em.persist(human); | ||
return "passed"; | ||
} | ||
|
||
@GET | ||
@Path("/load") | ||
@Transactional | ||
public String loadData() { | ||
//Load hello#1 - this will lead to have an uninitialized enhanced proxy associated to it | ||
Hello hello = em.find(Hello.class, 1); | ||
//Check that we can still validate the managed object graph, even when we don't know the name of the guy in the mask who we just greeted! | ||
validator.validate(hello); | ||
return "passed"; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
integration-tests/main/src/test/java/io/quarkus/it/main/ValidatorAndOrmTestCase.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,21 @@ | ||
package io.quarkus.it.main; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
public class ValidatorAndOrmTestCase { | ||
|
||
@Test | ||
public void triggerValidatorAndHibernateORMTests() { | ||
RestAssured.when().get("/validator-and-orm/store").then() | ||
.body(is("passed")); | ||
RestAssured.when().get("/validator-and-orm/load").then() | ||
.body(is("passed")); | ||
} | ||
|
||
} |