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 .JdbcMetadataAccessStrategy .GROUPED ;
3944import static org .hibernate .tool .schema .JdbcMetadataAccessStrategy .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" )
@@ -147,4 +176,43 @@ public static class Extra {
147176
148177 private String description ;
149178 }
179+
180+ @ Entity (name = "Fruit" )
181+ public static class Fruit {
182+
183+ @ Id
184+ @ GeneratedValue
185+ private Integer id ;
186+
187+ @ Column (name = "something_name" , nullable = false , updatable = false )
188+ private String name ;
189+
190+ public Fruit () {
191+ }
192+
193+ public Fruit (String name ) {
194+ this .name = name ;
195+ }
196+
197+ public Integer getId () {
198+ return id ;
199+ }
200+
201+ public void setId (Integer id ) {
202+ this .id = id ;
203+ }
204+
205+ public String getName () {
206+ return name ;
207+ }
208+
209+ public void setName (String name ) {
210+ this .name = name ;
211+ }
212+
213+ @ Override
214+ public String toString () {
215+ return "Fruit{" + id + "," + name + '}' ;
216+ }
217+ }
150218}
0 commit comments