From 644a9aebbcee3a8b2cfd6afa907227f067e49ac4 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Thu, 23 May 2024 11:18:47 +0800 Subject: [PATCH] HHH-17909 Improve test to cover schema generated by named ordinal enum --- .../orm/test/type/OracleEnumTest.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleEnumTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleEnumTest.java index e805261a93..e1b3f7e14d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleEnumTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleEnumTest.java @@ -43,7 +43,7 @@ public class OracleEnumTest { assertEquals( ts.activity.activityType, ActivityType.Play ); } - @Test public void testOrdinalEnum(SessionFactoryScope scope) { + @Test public void testNamedOrdinalEnum(SessionFactoryScope scope) { Weather weather = new Weather(); Sky sky = new Sky(); sky.skyType = SkyType.Sunny; @@ -57,31 +57,62 @@ public class OracleEnumTest { scope.inSession( s -> { s.doWork( c -> { + boolean namedEnumFound = false; + boolean namedOrdinalEnumFound = false; + try(Statement stmt = c.createStatement()) { try(ResultSet typeInfo = stmt.executeQuery("select name, decode(instr(data_display,'WHEN '''),0,'NUMBER','VARCHAR2') from user_domains where type='ENUMERATED'")) { while (typeInfo.next()) { String name = typeInfo.getString(1); String baseType = typeInfo.getString(2); if (name.equalsIgnoreCase("ActivityType") && baseType.equals("VARCHAR2")) { - return; + namedEnumFound = true; + continue; + } + if (name.equalsIgnoreCase("SkyType") && baseType.equals("NUMBER")) { + namedOrdinalEnumFound = true; + continue; } } } } - fail("named enum type not exported"); + + if (!namedEnumFound) { + fail("named enum type not exported"); + } + if (!namedOrdinalEnumFound) { + fail("named ordinal enum type not exported"); + } } ); }); scope.inSession( s -> { s.doWork( c -> { + boolean namedEnumFound = false; + boolean namedOrdinalEnumFound = false; + ResultSet tableInfo = c.getMetaData().getColumns(null, null, "ACTIVITY", "ACTIVITYTYPE" ); while ( tableInfo.next() ) { String type = tableInfo.getString(6); assertEquals( "VARCHAR2", type ); - return; + namedEnumFound = true; + break; + } + tableInfo = c.getMetaData().getColumns(null, null, "SKY", "SKYTYPE" ); + while ( tableInfo.next() ) { + String type = tableInfo.getString(6); + assertEquals( "NUMBER", type ); + namedOrdinalEnumFound = true; + break; + } + + if (!namedEnumFound) { + fail("named enum type not exported"); + } + if (!namedOrdinalEnumFound) { + fail("named ordinal enum type not exported"); } - fail("named enum column not exported"); } ); });