mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-07 03:38:16 +00:00
HHH-10425 - Add test for issue
This commit is contained in:
parent
50365b591b
commit
76a59f1641
@ -9,13 +9,22 @@
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.model.relational.Database;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
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.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
|
import org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl;
|
||||||
|
import org.hibernate.tool.schema.extract.spi.DatabaseInformation;
|
||||||
|
import org.hibernate.tool.schema.internal.TargetDatabaseImpl;
|
||||||
|
import org.hibernate.tool.schema.internal.TargetStdoutImpl;
|
||||||
|
import org.hibernate.tool.schema.spi.SchemaManagementTool;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -50,7 +59,7 @@ public void tearsDown() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-10420")
|
@TestForIssue(jiraKey = "HHH-10420")
|
||||||
public void testForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
|
public void testSchemaExportForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
|
||||||
|
|
||||||
final MetadataSources metadataSources = new MetadataSources( ssr );
|
final MetadataSources metadataSources = new MetadataSources( ssr );
|
||||||
|
|
||||||
@ -71,4 +80,48 @@ public void testForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exce
|
|||||||
is( true )
|
is( true )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-10420")
|
||||||
|
public void testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
|
||||||
|
|
||||||
|
final MetadataSources metadataSources = new MetadataSources( ssr );
|
||||||
|
|
||||||
|
metadataSources.addAnnotatedClass( SchemaOneEntity.class );
|
||||||
|
metadataSources.addAnnotatedClass( SchemaTwoEntity.class );
|
||||||
|
metadata = (MetadataImplementor) metadataSources.buildMetadata();
|
||||||
|
metadata.validate();
|
||||||
|
|
||||||
|
final Database database = metadata.getDatabase();
|
||||||
|
|
||||||
|
DatabaseInformation dbInfo = new DatabaseInformationImpl(
|
||||||
|
ssr,
|
||||||
|
database.getJdbcEnvironment(),
|
||||||
|
ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(),
|
||||||
|
database.getDefaultNamespace().getPhysicalName().getCatalog(),
|
||||||
|
database.getDefaultNamespace().getPhysicalName().getSchema()
|
||||||
|
);
|
||||||
|
|
||||||
|
ssr.getService( SchemaManagementTool.class ).getSchemaMigrator( Collections.emptyMap() ).doMigration(
|
||||||
|
metadata,
|
||||||
|
dbInfo,
|
||||||
|
true,
|
||||||
|
Arrays.asList(
|
||||||
|
new TargetStdoutImpl(),
|
||||||
|
new TargetDatabaseImpl( ssr.getService( JdbcServices.class )
|
||||||
|
.getBootstrapJdbcConnectionAccess() )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ssr.getService( SchemaManagementTool.class ).getSchemaDropper( null ).doDrop(
|
||||||
|
metadata,
|
||||||
|
false,
|
||||||
|
Arrays.asList(
|
||||||
|
new TargetStdoutImpl(),
|
||||||
|
new TargetDatabaseImpl( ssr.getService( JdbcServices.class )
|
||||||
|
.getBootstrapJdbcConnectionAccess() )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user