[HHH-11203] fix some minor test issues

(cherry picked from commit 957ec3fa79)
This commit is contained in:
Martin Simka 2016-10-24 16:55:23 +02:00 committed by Gail Badner
parent 4ab2f4872e
commit e27acf731a
2 changed files with 32 additions and 6 deletions

View File

@ -165,7 +165,7 @@ public class ListAddTest extends BaseNonConfigCoreFunctionalTestCase {
Transaction transaction = session.beginTransaction(); Transaction transaction = session.beginTransaction();
Quizz quizz = session.get( Quizz.class, 1 ); 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(); transaction.commit();
session.close(); session.close();

View File

@ -18,6 +18,8 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Environment; 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.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.TargetType;
@ -62,11 +64,19 @@ public class UniqueConstraintGenerationTest {
.setOutputFile( output.getAbsolutePath() ) .setOutputFile( output.getAbsolutePath() )
.create( EnumSet.of( TargetType.SCRIPT ), metadata ); .create( EnumSet.of( TargetType.SCRIPT ), metadata );
assertThat( if (ssr.getService(JdbcEnvironment.class).getDialect() instanceof DB2Dialect) {
"The test_entity_item table unique constraint has not been generated", assertThat(
isUniqueConstraintGenerated( "test_entity_item", "item" ), "The test_entity_item table unique constraint has not been generated",
is( true ) 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( assertThat(
"The test_entity_children table unique constraint has not been generated", "The test_entity_children table unique constraint has not been generated",
@ -90,4 +100,20 @@ public class UniqueConstraintGenerationTest {
} }
return matches; 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;
}
} }