From e27acf731a44703904718460619fb786a6bbffa0 Mon Sep 17 00:00:00 2001 From: Martin Simka Date: Mon, 24 Oct 2016 16:55:23 +0200 Subject: [PATCH] [HHH-11203] fix some minor test issues (cherry picked from commit 957ec3fa79427f3a3304bb5214c331cbc80f510d) --- .../delayedOperation/ListAddTest.java | 2 +- .../UniqueConstraintGenerationTest.java | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/collection/delayedOperation/ListAddTest.java b/hibernate-core/src/test/java/org/hibernate/test/collection/delayedOperation/ListAddTest.java index 7d8c0b822b..3d3b5c509b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/collection/delayedOperation/ListAddTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/collection/delayedOperation/ListAddTest.java @@ -165,7 +165,7 @@ public class ListAddTest extends BaseNonConfigCoreFunctionalTestCase { Transaction transaction = session.beginTransaction(); Quizz quizz = session.get( Quizz.class, 1 ); - assertThat( "expected 4 questions", quizz.getQuestions().size(), is(3) ); + assertThat( "expected 3 questions", quizz.getQuestions().size(), is(3) ); transaction.commit(); session.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/uniqueconstraint/UniqueConstraintGenerationTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/uniqueconstraint/UniqueConstraintGenerationTest.java index 5559334515..367804bc5a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/uniqueconstraint/UniqueConstraintGenerationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/uniqueconstraint/UniqueConstraintGenerationTest.java @@ -18,6 +18,8 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.Environment; +import org.hibernate.dialect.DB2Dialect; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.schema.TargetType; @@ -62,11 +64,19 @@ public class UniqueConstraintGenerationTest { .setOutputFile( output.getAbsolutePath() ) .create( EnumSet.of( TargetType.SCRIPT ), metadata ); - assertThat( - "The test_entity_item table unique constraint has not been generated", - isUniqueConstraintGenerated( "test_entity_item", "item" ), - is( true ) - ); + if (ssr.getService(JdbcEnvironment.class).getDialect() instanceof DB2Dialect) { + assertThat( + "The test_entity_item table unique constraint has not been generated", + isCreateUniqueIndexGenerated("test_entity_item", "item"), + is(true) + ); + } else { + assertThat( + "The test_entity_item table unique constraint has not been generated", + isUniqueConstraintGenerated("test_entity_item", "item"), + is(true) + ); + } assertThat( "The test_entity_children table unique constraint has not been generated", @@ -90,4 +100,20 @@ public class UniqueConstraintGenerationTest { } return matches; } + + private boolean isCreateUniqueIndexGenerated(String tableName, String columnName) throws IOException { + boolean matches = false; + String regex = "create unique index uk_(.)* on " + tableName + " \\(" + columnName + "\\)"; + + final String fileContent = new String( Files.readAllBytes( output.toPath() ) ).toLowerCase(); + final String[] split = fileContent.split( System.lineSeparator() ); + Pattern p = Pattern.compile( regex ); + for ( String line : split ) { + final Matcher matcher = p.matcher( line ); + if ( matcher.matches() ) { + matches = true; + } + } + return matches; + } }