Skip to content

Commit 890e1f2

Browse files
committed
[#2738] Test column type validation in Oracle
1 parent d76b7ef commit 890e1f2

File tree

2 files changed

+82
-3
lines changed

2 files changed

+82
-3
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaValidationTest.java

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
package org.hibernate.reactive.schema;
77

88

9+
import java.net.URL;
910
import java.util.concurrent.CompletionStage;
1011
import java.util.stream.Stream;
1112

1213
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
14+
import org.hibernate.cfg.AvailableSettings;
1315
import org.hibernate.cfg.Configuration;
1416
import org.hibernate.reactive.BaseReactiveTest;
1517
import org.hibernate.reactive.annotations.DisabledFor;
18+
import org.hibernate.reactive.annotations.EnabledFor;
1619
import org.hibernate.reactive.provider.Settings;
1720
import org.hibernate.tool.schema.spi.SchemaManagementException;
1821

@@ -23,6 +26,7 @@
2326

2427
import io.vertx.junit5.Timeout;
2528
import io.vertx.junit5.VertxTestContext;
29+
import jakarta.persistence.Column;
2630
import jakarta.persistence.Entity;
2731
import jakarta.persistence.GeneratedValue;
2832
import jakarta.persistence.Id;
@@ -34,6 +38,7 @@
3438
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
3539
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
3640
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
41+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
3742
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
3843
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY;
3944
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -46,7 +51,7 @@
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")
5055
public 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
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Import file for testing schema validation in SchemaValidationTest
2+
drop table if exists Fruit cascade constraints
3+
drop sequence if exists Fruit_SEQ
4+
5+
-- Create the table manually, so that we can check if the validation succeeds
6+
create sequence fruit_seq start with 1 increment by 50;
7+
create table Fruit (id number(10,0) not null, something_name nvarchar2(20) not null, primary key (id))
8+
9+
INSERT INTO fruit(id, something_name) VALUES (1, 'Cherry');
10+
INSERT INTO fruit(id, something_name) VALUES (2, 'Apple');
11+
INSERT INTO fruit(id, something_name) VALUES (3, 'Banana');
12+
ALTER SEQUENCE fruit_seq RESTART start with 4;

0 commit comments

Comments
 (0)