Skip to content

Commit ffc5efd

Browse files
committed
[#1641] first draft of @array annotation tests
1 parent 577adb2 commit ffc5efd

File tree

9 files changed

+152
-2
lines changed

9 files changed

+152
-2
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/DB2Database.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class DB2Database implements TestableDatabase {
7373
expectedDBTypeForClass.put( Character.class, "CHARACTER" );
7474
expectedDBTypeForClass.put( char.class, "CHARACTER" );
7575
expectedDBTypeForClass.put( String.class, "VARCHAR" );
76+
expectedDBTypeForClass.put( String[].class, "VARBINARY" );
77+
expectedDBTypeForClass.put( Long[].class, "VARBINARY" );
78+
expectedDBTypeForClass.put( BigDecimal[].class, "VARBINARY" );
79+
expectedDBTypeForClass.put( BigInteger[].class, "VARBINARY" );
80+
expectedDBTypeForClass.put( Boolean[].class, "VARBINARY" );
7681
}}
7782

7883
/**

hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MSSQLServerDatabase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class MSSQLServerDatabase implements TestableDatabase {
8282
expectedDBTypeForClass.put( Character.class, "char" );
8383
expectedDBTypeForClass.put( char.class, "char" );
8484
expectedDBTypeForClass.put( String.class, "varchar" );
85+
expectedDBTypeForClass.put( String[].class, "varbinary" );
86+
expectedDBTypeForClass.put( Long[].class, "varbinary" );
87+
expectedDBTypeForClass.put( BigDecimal[].class, "varbinary" );
88+
expectedDBTypeForClass.put( BigInteger[].class, "varbinary" );
89+
expectedDBTypeForClass.put( Boolean[].class, "varbinary" );
8590
}}
8691

8792
/**

hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MySQLDatabase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class MySQLDatabase implements TestableDatabase {
7373
expectedDBTypeForClass.put( Character.class, "char" );
7474
expectedDBTypeForClass.put( char.class, "char" );
7575
expectedDBTypeForClass.put( String.class, "varchar" );
76+
expectedDBTypeForClass.put( String[].class, "varbinary" );
77+
expectedDBTypeForClass.put( Long[].class, "varbinary" );
78+
expectedDBTypeForClass.put( BigDecimal[].class, "varbinary" );
79+
expectedDBTypeForClass.put( BigInteger[].class, "varbinary" );
80+
expectedDBTypeForClass.put( Boolean[].class, "varbinary" );
7681
}};
7782

7883
/**

hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/OracleDatabase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ class OracleDatabase implements TestableDatabase {
8181
expectedDBTypeForClass.put( Character.class, "CHAR" );
8282
expectedDBTypeForClass.put( char.class, "CHAR" );
8383
expectedDBTypeForClass.put( String.class, "VARCHAR2" );
84+
expectedDBTypeForClass.put( String[].class, "STRINGARRAY" );
85+
expectedDBTypeForClass.put( Long[].class, "LONGARRAY" );
86+
expectedDBTypeForClass.put( BigDecimal[].class, "BIGDECIMALARRAY" );
87+
expectedDBTypeForClass.put( BigInteger[].class, "BIGINTEGERARRAY" );
88+
expectedDBTypeForClass.put( Boolean[].class, "BOOLEANARRAY" );
89+
8490
}
8591
}
8692

hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/PostgreSQLDatabase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class PostgreSQLDatabase implements TestableDatabase {
7373
expectedDBTypeForClass.put( Character.class, "character" );
7474
expectedDBTypeForClass.put( char.class, "character" );
7575
expectedDBTypeForClass.put( String.class, "character varying" );
76+
expectedDBTypeForClass.put( String[].class, "ARRAY" );
77+
expectedDBTypeForClass.put( Long[].class, "ARRAY" );
78+
expectedDBTypeForClass.put( BigDecimal[].class, "ARRAY" );
79+
expectedDBTypeForClass.put( BigInteger[].class, "ARRAY" );
80+
expectedDBTypeForClass.put( Boolean[].class, "ARRAY" );
7681
}}
7782

7883
/**

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import java.util.Date;
1919
import java.util.TimeZone;
2020
import java.util.UUID;
21+
22+
import org.hibernate.annotations.Array;
23+
2124
import jakarta.persistence.Column;
2225
import jakarta.persistence.Convert;
2326
import jakarta.persistence.Entity;
@@ -102,6 +105,31 @@ public class BasicTypesTestEntity {
102105

103106
Duration duration;
104107

108+
String[] stringArray;
109+
110+
@Array( length = 5 )
111+
String[] stringArrayAnnotated;
112+
113+
Long[] longArray;
114+
115+
@Array( length = 5 )
116+
Long[] longArrayAnnotated;
117+
118+
BigDecimal[] bigDecimalArray;
119+
120+
@Array( length = 5 )
121+
BigDecimal[] bigDecimalArrayAnnotated;
122+
123+
BigInteger[] bigIntegerArray;
124+
125+
@Array( length = 5 )
126+
BigInteger[] bigIntegerArrayAnnotated;
127+
128+
Boolean[] fieldBooleanArray;
129+
130+
@Array( length = 5 )
131+
Boolean[] fieldBooleanArrayAnnotated;
132+
105133
Serializable serializable;
106134

107135
public BasicTypesTestEntity() {

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,54 @@ public void testLocalDateTimeType(VertxTestContext context) {
215215
public void testSerializableType(VertxTestContext context) {
216216
testDatatype( context, "serializable", Serializable.class );
217217
}
218+
219+
@Test
220+
public void testStringArrayType(VertxTestContext context) {
221+
testDatatype( context, "stringArray", String[].class );
222+
}
223+
224+
@Test
225+
public void testStringArrayAnnotatedType(VertxTestContext context) {
226+
testDatatype( context, "stringArrayAnnotated", String[].class );
227+
}
228+
229+
@Test
230+
public void testLongArrayType(VertxTestContext context) {
231+
testDatatype( context, "longArray", Long[].class );
232+
}
233+
234+
@Test
235+
public void testLongArrayAnnotatedType(VertxTestContext context) {
236+
testDatatype( context, "longArrayAnnotated", Long[].class );
237+
}
238+
239+
@Test
240+
public void testBigDecimalArrayType(VertxTestContext context) {
241+
testDatatype( context, "bigDecimalArray", BigDecimal[].class );
242+
}
243+
244+
@Test
245+
public void testBigDecimalArrayAnnotatedType(VertxTestContext context) {
246+
testDatatype( context, "bigDecimalArrayAnnotated", BigDecimal[].class );
247+
}
248+
249+
@Test
250+
public void testBigIntegerArrayType(VertxTestContext context) {
251+
testDatatype( context, "bigIntegerArray", BigInteger[].class );
252+
}
253+
254+
@Test
255+
public void testBigIntegerArrayAnnotatedType(VertxTestContext context) {
256+
testDatatype( context, "bigIntegerArrayAnnotated", BigInteger[].class );
257+
}
258+
259+
@Test
260+
public void testFieldBooleanArrayType(VertxTestContext context) {
261+
testDatatype( context, "fieldBooleanArray", Boolean[].class );
262+
}
263+
264+
@Test
265+
public void testFieldBooleanArrayAnnotatedType(VertxTestContext context) {
266+
testDatatype( context, "fieldBooleanArrayAnnotated", Boolean[].class );
267+
}
218268
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1010
import org.hibernate.cfg.Configuration;
1111
import org.hibernate.reactive.BaseReactiveTest;
12+
import org.hibernate.reactive.annotations.DisabledForDbTypes;
1213
import org.hibernate.reactive.provider.Settings;
1314
import org.hibernate.reactive.annotations.DisabledFor;
1415
import org.hibernate.tool.schema.spi.SchemaManagementException;
@@ -25,7 +26,9 @@
2526
import jakarta.persistence.Table;
2627

2728
import static java.util.concurrent.TimeUnit.MINUTES;
29+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.COCKROACHDB;
2830
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
31+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL;
2932
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
3033
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY;
3134
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -38,7 +41,17 @@
3841
* - TODO: Missing column
3942
* - TODO: Wrong column type
4043
*/
41-
@DisabledFor(value = DB2, reason = "No InformationExtractor for Dialect [org.hibernate.dialect.DB2Dialect..]")
44+
@DisabledForDbTypes({
45+
@DisabledFor(value = DB2, reason = "No InformationExtractor for Dialect [org.hibernate.dialect.DB2Dialect..]"),
46+
@DisabledFor(value = COCKROACHDB,
47+
reason = "<Schema-validation: wrong column type encountered in column [bigDecimalArray] in table [BASIC_TYPES_TABLE]; " +
48+
"found [_numeric (Types#NULL)], but expecting [numeric(38,2) array (Types#ARRAY)]> " +
49+
"but was: <Schema-validation: missing table [EXTRA_TABLE]>"),
50+
@DisabledFor(value = POSTGRESQL,
51+
reason = "<Schema-validation: wrong column type encountered in column [bigDecimalArray] in table [BASIC_TYPES_TABLE]; " +
52+
"found [_numeric (Types#NULL)], but expecting [numeric(38,2) array (Types#ARRAY)]> " +
53+
"but was: <Schema-validation: missing table [EXTRA_TABLE]>")
54+
})
4255
public abstract class SchemaValidationTestBase extends BaseReactiveTest {
4356

4457
public static class IndividuallyStrategyTest extends SchemaValidationTestBase {

hibernate-reactive-core/src/test/java/org/hibernate/reactive/types/JavaTypesArrayTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.UUID;
1818
import java.util.function.Consumer;
1919

20+
import org.hibernate.annotations.Array;
2021
import org.hibernate.reactive.BaseReactiveTest;
2122
import org.hibernate.reactive.annotations.DisabledFor;
2223

@@ -277,36 +278,68 @@ public void testBigDecimalArrayType(VertxTestContext context) {
277278
} );
278279
}
279280

281+
@Test
282+
public void testArrayWithLengthAnnotationNotChecked(VertxTestContext context) {
283+
Basic basic = new Basic();
284+
// String[] array has a length set to 10 via @Array(length = 10) annotation
285+
// Construct an array larger than 10.
286+
// When a length check is provided via ORM or Reactive, this test should fail.
287+
String[] dataArray = {"s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s10", "s11" };
288+
basic.stringArray = dataArray;
289+
290+
testField( context, basic, found -> assertArrayEquals( dataArray, found.stringArray ) );
291+
}
292+
280293
@Entity(name = "Basic")
281294
@Table(name = "Basic")
282295
private static class Basic {
283296
@Id
284297
@GeneratedValue
285298
Integer id;
299+
@Array( length = 10 )
286300
String[] stringArray;
301+
@Array( length = 10 )
287302
Boolean[] booleanArray;
303+
@Array( length = 10 )
288304
boolean[] primitiveBooleanArray;
305+
@Array( length = 10 )
289306
Integer[] integerArray;
307+
@Array( length = 10 )
290308
int[] primitiveIntegerArray;
309+
@Array( length = 10 )
291310
Long[] longArray;
311+
@Array( length = 10 )
292312
long[] primitiveLongArray;
313+
@Array( length = 10 )
293314
Float[] floatArray;
315+
@Array( length = 10 )
294316
float[] primitiveFloatArray;
317+
@Array( length = 10 )
295318
Double[] doubleArray;
319+
@Array( length = 10 )
296320
double[] primitiveDoubleArray;
321+
@Array( length = 10 )
297322
UUID[] uuidArray;
323+
@Array( length = 10 )
298324
AnEnum[] enumArray;
325+
@Array( length = 10 )
299326
Short[] shortArray;
327+
@Array( length = 10 )
300328
short[] primitiveShortArray;
329+
@Array( length = 10 )
301330
Date[] dateArray;
331+
@Array( length = 10 )
302332
LocalDate[] localDateArray;
333+
@Array( length = 10 )
303334
LocalTime[] localTimeArray;
335+
@Array( length = 10 )
304336
LocalDateTime[] localDateTimeArray;
305-
337+
@Array( length = 10 )
306338
// We have to specify the length for BigDecimal and BigInteger because
307339
// the default column type when creating the schema is too small on some databases
308340
@Column(length = 5000)
309341
BigInteger[] bigIntegerArray;
342+
@Array( length = 10 )
310343
@Column(length = 5000)
311344
BigDecimal[] bigDecimalArray;
312345
}

0 commit comments

Comments
 (0)