55 */
66package org .hibernate .reactive ;
77
8+ import java .net .URL ;
89import java .util .Collection ;
910import java .util .List ;
10- import java .util .Objects ;
1111
12- import org .hibernate .Session ;
1312import org .hibernate .SessionFactory ;
1413import org .hibernate .boot .registry .StandardServiceRegistry ;
1514import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
15+ import org .hibernate .cfg .AvailableSettings ;
1616import org .hibernate .cfg .Configuration ;
1717import org .hibernate .reactive .annotations .DisabledFor ;
18+ import org .hibernate .reactive .provider .Settings ;
19+ import org .hibernate .reactive .schema .BasicTypesTestEntity ;
1820
1921import org .junit .jupiter .api .AfterEach ;
2022import org .junit .jupiter .api .BeforeEach ;
2123import org .junit .jupiter .api .Test ;
2224
2325import io .vertx .junit5 .Timeout ;
24- import io .vertx .junit5 .VertxTestContext ;
25- import jakarta .persistence .Entity ;
26- import jakarta .persistence .Id ;
27- import jakarta .persistence .Table ;
2826
2927import static java .util .concurrent .TimeUnit .MINUTES ;
3028import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .COCKROACHDB ;
3129import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .DB2 ;
3230import static org .hibernate .reactive .containers .DatabaseConfiguration .dbType ;
3331import static org .hibernate .reactive .provider .Settings .DIALECT ;
3432import static org .hibernate .reactive .provider .Settings .DRIVER ;
35- import static org .junit .jupiter .api .Assertions .assertEquals ;
3633
3734@ Timeout (value = 10 , timeUnit = MINUTES )
3835
@@ -48,14 +45,19 @@ public class ORMReactivePersistenceTest extends BaseReactiveTest {
4845
4946 @ Override
5047 protected Collection <Class <?>> annotatedEntities () {
51- return List .of ( Flour .class );
48+ return List .of ( BasicTypesTestEntity .class );
5249 }
5350
5451 @ BeforeEach
5552 public void prepareOrmFactory () {
5653 Configuration configuration = constructConfiguration ();
54+ configuration .setProperty ( Settings .HBM2DDL_AUTO , "validate" );
5755 configuration .setProperty ( DRIVER , dbType ().getJdbcDriver () );
5856 configuration .setProperty ( DIALECT , dbType ().getDialectClass ().getName () );
57+ final URL importFileURL = Thread .currentThread ()
58+ .getContextClassLoader ()
59+ .getResource ( "oracleSchemaValidationTest.sql" );
60+ configuration .setProperty ( AvailableSettings .JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE , importFileURL .getFile () );
5961
6062 StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder ()
6163 .applySettings ( configuration .getProperties () );
@@ -70,112 +72,7 @@ public void closeOrmFactory() {
7072 }
7173
7274 @ Test
73- public void testORMWithStageSession (VertxTestContext context ) {
74- final Flour almond = new Flour ( 1 , "Almond" , "made from ground almonds." , "Gluten free" );
75+ public void testORMWithStageSession () {
7576
76- try (Session session = ormFactory .openSession ()) {
77- session .beginTransaction ();
78- session .persist ( almond );
79- session .getTransaction ().commit ();
80- }
81-
82- // Check database with Stage session and verify 'almond' flour exists
83- test ( context , openSession ()
84- .thenCompose ( stageSession -> stageSession .find ( Flour .class , almond .id ) )
85- .thenAccept ( entityFound -> assertEquals ( almond , entityFound ) )
86- );
87- }
88-
89- @ Test
90- public void testORMWitMutinySession (VertxTestContext context ) {
91- final Flour rose = new Flour ( 2 , "Rose" , "made from ground rose pedals." , "Full fragrance" );
92-
93- try (Session ormSession = ormFactory .openSession ()) {
94- ormSession .beginTransaction ();
95- ormSession .persist ( rose );
96- ormSession .getTransaction ().commit ();
97- }
98-
99- // Check database with Mutiny session and verify 'rose' flour exists
100- test ( context , openMutinySession ()
101- .chain ( session -> session .find ( Flour .class , rose .id ) )
102- .invoke ( foundRose -> assertEquals ( rose , foundRose ) )
103- );
104- }
105-
106- @ Entity (name = "Flour" )
107- @ Table (name = "Flour" )
108- public static class Flour {
109- @ Id
110- private Integer id ;
111- private String name ;
112- private String description ;
113- private String type ;
114-
115- public Flour () {
116- }
117-
118- public Flour (Integer id , String name , String description , String type ) {
119- this .id = id ;
120- this .name = name ;
121- this .description = description ;
122- this .type = type ;
123- }
124-
125- public Integer getId () {
126- return id ;
127- }
128-
129- public void setId (Integer id ) {
130- this .id = id ;
131- }
132-
133- public String getName () {
134- return name ;
135- }
136-
137- public void setName (String name ) {
138- this .name = name ;
139- }
140-
141- public String getDescription () {
142- return description ;
143- }
144-
145- public void setDescription (String description ) {
146- this .description = description ;
147- }
148-
149- public String getType () {
150- return type ;
151- }
152-
153- public void setType (String type ) {
154- this .type = type ;
155- }
156-
157- @ Override
158- public String toString () {
159- return name ;
160- }
161-
162- @ Override
163- public boolean equals (Object o ) {
164- if ( this == o ) {
165- return true ;
166- }
167- if ( o == null || getClass () != o .getClass () ) {
168- return false ;
169- }
170- Flour flour = (Flour ) o ;
171- return Objects .equals ( name , flour .name ) &&
172- Objects .equals ( description , flour .description ) &&
173- Objects .equals ( type , flour .type );
174- }
175-
176- @ Override
177- public int hashCode () {
178- return Objects .hash ( name , description , type );
179- }
18077 }
18178}
0 commit comments