use of org.hibernate.tool.schema.spi.ContributableMatcher in project hibernate-orm by hibernate.
the class AbstractSchemaMigratorTest method testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName.
@Test
@TestForIssue(jiraKey = "HHH-13779")
public void testForeignKeyPreExistenceDetectionIgnoresCaseForTableAndColumnName() {
final AbstractSchemaMigrator schemaMigrator = new AbstractSchemaMigrator(null, null) {
@Override
protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, ContributableMatcher contributableInclusionFilter, Dialect dialect, Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace, SqlStringGenerationContext sqlStringGenerationContext, GenerationTarget[] targets) {
return null;
}
};
final TableInformation existingTableInformation = mock(TableInformation.class);
final ArrayList<ForeignKeyInformation.ColumnReferenceMapping> columnReferenceMappings = new ArrayList<>();
final TableInformation destinationTableInformation = mock(TableInformation.class);
doReturn(new QualifiedTableName(toIdentifier("catalog"), toIdentifier("schema"), // Table name is lower case
toIdentifier("referenced_table"))).when(destinationTableInformation).getName();
columnReferenceMappings.add(new ForeignKeyInformationImpl.ColumnReferenceMappingImpl(new // column name is lower case
ColumnInformationImpl(// column name is lower case
null, // column name is lower case
toIdentifier("referencing_column"), 0, "typeName", 255, 0, TruthValue.TRUE), new ColumnInformationImpl(destinationTableInformation, null, 1, "typeName", 0, 0, TruthValue.TRUE)));
doReturn(singletonList(new ForeignKeyInformationImpl(toIdentifier("FKp8mpamfw2inhj88hwhty1eipm"), columnReferenceMappings))).when(existingTableInformation).getForeignKeys();
final boolean existInDatabase = schemaMigrator.equivalentForeignKeyExistsInDatabase(existingTableInformation, "REFERENCING_COLUMN", // Table and column names are UPPER-case here, to prove the test
"REFERENCED_TABLE");
assertThat("Expected ForeignKey pre-existence check to be case-insensitive", existInDatabase, is(true));
}
Aggregations