Skip to content

Commit 7acb2d2

Browse files
committed
HHH-17404 Parameterize DDL type for tests
1 parent ae2e4d9 commit 7acb2d2

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/hhh17404/JsonCBLOBToOsonTest.java renamed to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/hhh17404/OracleOsonCompatibilityTest.java

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
import jakarta.persistence.Id;
99
import jakarta.persistence.Table;
1010
import org.hibernate.annotations.JdbcTypeCode;
11+
import org.hibernate.cfg.DialectSpecificSettings;
1112
import org.hibernate.dialect.OracleDialect;
1213
import org.hibernate.orm.test.mapping.basic.JsonMappingTests;
1314
import org.hibernate.testing.orm.junit.DomainModel;
1415
import org.hibernate.testing.orm.junit.RequiresDialect;
16+
import org.hibernate.testing.orm.junit.ServiceRegistry;
1517
import org.hibernate.testing.orm.junit.SessionFactory;
1618
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
import org.hibernate.testing.orm.junit.Setting;
1720
import org.hibernate.type.SqlTypes;
1821
import org.junit.jupiter.api.AfterEach;
1922
import org.junit.jupiter.api.BeforeEach;
2023
import org.junit.jupiter.api.Test;
2124

22-
2325
import static org.hamcrest.MatcherAssert.assertThat;
2426
import static org.hamcrest.Matchers.is;
2527
import static org.hibernate.testing.orm.junit.DialectContext.getDialect;
@@ -32,36 +34,43 @@
3234
*
3335
* @author Emmanuel Jannetti
3436
*/
35-
@DomainModel(annotatedClasses = JsonCBLOBToOsonTest.JsonEntity.class)
36-
@SessionFactory
37+
@DomainModel(annotatedClasses = OracleOsonCompatibilityTest.JsonEntity.class)
38+
@SessionFactory(exportSchema = false)
3739
@RequiresDialect( value = OracleDialect.class, majorVersion = 23 )
38-
public class JsonCBLOBToOsonTest {
39-
40-
@Entity(name = "JsonEntity")
41-
@Table(name = "TEST_OSON_COMPAT")
42-
public static class JsonEntity {
43-
@Id
44-
private Integer id;
45-
@JdbcTypeCode( SqlTypes.JSON )
46-
private JsonMappingTests.StringNode jsonName;
40+
public abstract class OracleOsonCompatibilityTest {
4741

48-
public JsonEntity() {
49-
super();
42+
@ServiceRegistry(settings = @Setting(name = DialectSpecificSettings.ORACLE_OSON_DISABLED, value = "true"))
43+
public static class OracleOsonAsUtf8CompatibilityTest extends OracleOsonCompatibilityTest {
44+
public OracleOsonAsUtf8CompatibilityTest() {
45+
super( "JSON" );
5046
}
51-
public JsonEntity(Integer id, JsonMappingTests.StringNode node) {
52-
this.id = id;
53-
this.jsonName = node;
47+
}
48+
public static class OracleBlobAsOsonCompatibilityTest extends OracleOsonCompatibilityTest {
49+
public OracleBlobAsOsonCompatibilityTest() {
50+
super( "BLOB" );
5451
}
5552
}
53+
public static class OracleClobAsOsonCompatibilityTest extends OracleOsonCompatibilityTest {
54+
public OracleClobAsOsonCompatibilityTest() {
55+
super( "CLOB" );
56+
}
57+
}
58+
59+
60+
private final String jsonType;
61+
62+
public OracleOsonCompatibilityTest(String jsonType) {
63+
this.jsonType = jsonType;
64+
}
5665

5766
@BeforeEach
5867
public void setup(SessionFactoryScope scope) {
5968
scope.inTransaction(
6069
(session) -> {
6170
// force creation of a BLOB column type by creating the table ourselves
62-
session.createNativeQuery( getDialect().getDropTableString( "TEST_OSON_COMPAT" ) )
71+
session.createNativeQuery( session.getDialect().getDropTableString( "TEST_OSON_COMPAT" ) )
6372
.executeUpdate();
64-
session.createNativeQuery( "CREATE TABLE TEST_OSON_COMPAT (id NUMBER, jsonName BLOB CHECK (jsonName is json) ,primary key (id))" )
73+
session.createNativeQuery( "CREATE TABLE TEST_OSON_COMPAT (id NUMBER, jsonName " + jsonType + " CHECK (jsonName is json) ,primary key (id))" )
6574
.executeUpdate();
6675

6776
String insert = "INSERT INTO TEST_OSON_COMPAT (id, jsonName) VALUES(:id,:json)";
@@ -85,11 +94,26 @@ public void tearDown(SessionFactoryScope scope) {
8594
public void verifyReadWorks(SessionFactoryScope scope) {
8695
scope.inTransaction(
8796
(session) -> {
88-
JsonEntity entity = session.find( JsonCBLOBToOsonTest.JsonEntity.class, 1 );
97+
JsonEntity entity = session.find( OracleOsonCompatibilityTest.JsonEntity.class, 1 );
8998
assertThat( entity.jsonName.getString(), is( "john" ) );
90-
9199
}
92100
);
93101
}
94102

103+
@Entity(name = "JsonEntity")
104+
@Table(name = "TEST_OSON_COMPAT")
105+
public static class JsonEntity {
106+
@Id
107+
private Integer id;
108+
@JdbcTypeCode( SqlTypes.JSON )
109+
private JsonMappingTests.StringNode jsonName;
110+
111+
public JsonEntity() {
112+
super();
113+
}
114+
public JsonEntity(Integer id, JsonMappingTests.StringNode node) {
115+
this.id = id;
116+
this.jsonName = node;
117+
}
118+
}
95119
}

0 commit comments

Comments
 (0)