66package org .hibernate .reactive .schema ;
77
88
9+ import java .net .URL ;
910import java .util .concurrent .CompletionStage ;
1011import java .util .stream .Stream ;
1112
1213import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
14+ import org .hibernate .cfg .AvailableSettings ;
1315import org .hibernate .cfg .Configuration ;
1416import org .hibernate .reactive .BaseReactiveTest ;
1517import org .hibernate .reactive .annotations .DisabledFor ;
18+ import org .hibernate .reactive .annotations .EnabledFor ;
1619import org .hibernate .reactive .provider .Settings ;
1720import org .hibernate .tool .schema .spi .SchemaManagementException ;
1821
2326
2427import io .vertx .junit5 .Timeout ;
2528import io .vertx .junit5 .VertxTestContext ;
29+ import jakarta .persistence .Column ;
2630import jakarta .persistence .Entity ;
2731import jakarta .persistence .GeneratedValue ;
2832import jakarta .persistence .Id ;
3438import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .DB2 ;
3539import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .MARIA ;
3640import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .MYSQL ;
41+ import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .ORACLE ;
3742import static org .hibernate .reactive .testing .ReactiveAssertions .assertThrown ;
3843import static org .hibernate .tool .schema .JdbcMetadaAccessStrategy .GROUPED ;
3944import static org .hibernate .tool .schema .JdbcMetadaAccessStrategy .INDIVIDUALLY ;
4752 * - TODO: Test that validation fails when a column is the wrong type
4853 */
4954@ DisabledFor (value = DB2 , reason = "We don't have an information extractor. See https://github.com/hibernate/hibernate-reactive/issues/911" )
50- @ DisabledFor (value = {MARIA , MYSQL }, reason = "HHH-18869: Schema creation creates an invalid schema" )
55+ @ DisabledFor (value = { MARIA , MYSQL }, reason = "HHH-18869: Schema creation creates an invalid schema" )
5156public class SchemaValidationTest extends BaseReactiveTest {
5257
5358 static Stream <Arguments > settings () {
@@ -77,9 +82,18 @@ public void before(VertxTestContext context) {
7782 }
7883
7984 public CompletionStage <Void > setupFactory (String strategy , String type ) {
85+ return setupFactory ( strategy , type , null );
86+ }
87+
88+ public CompletionStage <Void > setupFactory (String strategy , String type , String importFile ) {
8089 Configuration createConf = constructConfiguration ( "create" , strategy , type );
8190 createConf .addAnnotatedClass ( BasicTypesTestEntity .class );
82-
91+ if ( importFile != null ) {
92+ final URL importFileURL = Thread .currentThread ()
93+ .getContextClassLoader ()
94+ .getResource ( importFile );
95+ createConf .setProperty ( AvailableSettings .JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE , importFileURL .getFile () );
96+ }
8397 // Make sure that the extra table is not in the db
8498 Configuration dropConf = constructConfiguration ( "drop" , strategy , type );
8599 dropConf .addAnnotatedClass ( Extra .class );
@@ -97,6 +111,21 @@ public void after(VertxTestContext context) {
97111 closeFactory ( context );
98112 }
99113
114+ @ ParameterizedTest
115+ @ MethodSource ("settings" )
116+ @ EnabledFor ( ORACLE )
117+ public void testOracleColumnTypeValidation (final String strategy , final String type , VertxTestContext context ) {
118+ test (
119+ context , setupFactory ( strategy , type , "oracle-SchemaValidationTest.sql" )
120+ .thenCompose ( v -> {
121+ Configuration validateConf = constructConfiguration ( "validate" , strategy , type );
122+ validateConf .addAnnotatedClass ( Fruit .class );
123+ new StandardServiceRegistryBuilder ().applySettings ( validateConf .getProperties () );
124+ return setupSessionFactory ( validateConf );
125+ } )
126+ );
127+ }
128+
100129 // When we have created the table, the validation should pass
101130 @ ParameterizedTest
102131 @ MethodSource ("settings" )
@@ -113,7 +142,6 @@ context, setupFactory( strategy, type )
113142 );
114143 }
115144
116-
117145 // Validation should fail if a table is missing
118146 @ ParameterizedTest
119147 @ MethodSource ("settings" )
@@ -147,4 +175,43 @@ public static class Extra {
147175
148176 private String description ;
149177 }
178+
179+ @ Entity (name = "Fruit" )
180+ public static class Fruit {
181+
182+ @ Id
183+ @ GeneratedValue
184+ private Integer id ;
185+
186+ @ Column (name = "something_name" , nullable = false , updatable = false )
187+ private String name ;
188+
189+ public Fruit () {
190+ }
191+
192+ public Fruit (String name ) {
193+ this .name = name ;
194+ }
195+
196+ public Integer getId () {
197+ return id ;
198+ }
199+
200+ public void setId (Integer id ) {
201+ this .id = id ;
202+ }
203+
204+ public String getName () {
205+ return name ;
206+ }
207+
208+ public void setName (String name ) {
209+ this .name = name ;
210+ }
211+
212+ @ Override
213+ public String toString () {
214+ return "Fruit{" + id + "," + name + '}' ;
215+ }
216+ }
150217}
0 commit comments