Skip to content

Commit 22f307c

Browse files
committed
[#2738] Test column type validation in Oracle
1 parent d219878 commit 22f307c

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

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

Lines changed: 70 additions & 2 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.reactive.testing.ReactiveAssertions.assertThrown;
3843
import static org.hibernate.tool.schema.JdbcMetadataAccessStrategy.GROUPED;
3944
import static org.hibernate.tool.schema.JdbcMetadataAccessStrategy.INDIVIDUALLY;
@@ -47,7 +52,7 @@
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")
5156
public 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
}
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)