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 .tool .schema .JdbcMetadaAccessStrategy .GROUPED ;
3843import static org .hibernate .tool .schema .JdbcMetadaAccessStrategy .INDIVIDUALLY ;
3944import static org .junit .jupiter .params .provider .Arguments .arguments ;
4651 * - TODO: Test that validation fails when a column is the wrong type
4752 */
4853@ DisabledFor (value = DB2 , reason = "We don't have an information extractor. See https://github.com/hibernate/hibernate-reactive/issues/911" )
49- @ DisabledFor (value = {MARIA , MYSQL }, reason = "HHH-18869: Schema creation creates an invalid schema" )
54+ @ DisabledFor (value = { MARIA , MYSQL }, reason = "HHH-18869: Schema creation creates an invalid schema" )
5055public class SchemaValidationTest extends BaseReactiveTest {
5156
5257 static Stream <Arguments > settings () {
@@ -76,9 +81,18 @@ public void before(VertxTestContext context) {
7681 }
7782
7883 public CompletionStage <Void > setupFactory (String strategy , String type ) {
84+ return setupFactory ( strategy , type , null );
85+ }
86+
87+ public CompletionStage <Void > setupFactory (String strategy , String type , String importFile ) {
7988 Configuration createConf = constructConfiguration ( "create" , strategy , type );
8089 createConf .addAnnotatedClass ( BasicTypesTestEntity .class );
81-
90+ if ( importFile != null ) {
91+ final URL importFileURL = Thread .currentThread ()
92+ .getContextClassLoader ()
93+ .getResource ( importFile );
94+ createConf .setProperty ( AvailableSettings .JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE , importFileURL .getFile () );
95+ }
8296 // Make sure that the extra table is not in the db
8397 Configuration dropConf = constructConfiguration ( "drop" , strategy , type );
8498 dropConf .addAnnotatedClass ( Extra .class );
@@ -96,6 +110,21 @@ public void after(VertxTestContext context) {
96110 closeFactory ( context );
97111 }
98112
113+ @ ParameterizedTest
114+ @ MethodSource ("settings" )
115+ @ EnabledFor ( ORACLE )
116+ public void testOracleColumnTypeValidation (final String strategy , final String type , VertxTestContext context ) {
117+ test (
118+ context , setupFactory ( strategy , type , "oracle-SchemaValidationTest.sql" )
119+ .thenCompose ( v -> {
120+ Configuration validateConf = constructConfiguration ( "validate" , strategy , type );
121+ validateConf .addAnnotatedClass ( Fruit .class );
122+ new StandardServiceRegistryBuilder ().applySettings ( validateConf .getProperties () );
123+ return setupSessionFactory ( validateConf );
124+ } )
125+ );
126+ }
127+
99128 // When we have created the table, the validation should pass
100129 @ ParameterizedTest
101130 @ MethodSource ("settings" )
@@ -112,7 +141,6 @@ context, setupFactory( strategy, type )
112141 );
113142 }
114143
115-
116144 // Validation should fail if a table is missing
117145 @ ParameterizedTest
118146 @ MethodSource ("settings" )
@@ -151,4 +179,43 @@ public static class Extra {
151179
152180 private String description ;
153181 }
182+
183+ @ Entity (name = "Fruit" )
184+ public static class Fruit {
185+
186+ @ Id
187+ @ GeneratedValue
188+ private Integer id ;
189+
190+ @ Column (name = "something_name" , nullable = false , updatable = false )
191+ private String name ;
192+
193+ public Fruit () {
194+ }
195+
196+ public Fruit (String name ) {
197+ this .name = name ;
198+ }
199+
200+ public Integer getId () {
201+ return id ;
202+ }
203+
204+ public void setId (Integer id ) {
205+ this .id = id ;
206+ }
207+
208+ public String getName () {
209+ return name ;
210+ }
211+
212+ public void setName (String name ) {
213+ this .name = name ;
214+ }
215+
216+ @ Override
217+ public String toString () {
218+ return "Fruit{" + id + "," + name + '}' ;
219+ }
220+ }
154221}
0 commit comments