HHH-6702 mysql 51 test failures

This commit is contained in:
Strong Liu 2011-10-01 02:30:09 +08:00
parent 3c07e5d6ba
commit 56ce194a29
1 changed files with 62 additions and 53 deletions

View File

@ -23,8 +23,6 @@
*/ */
package org.hibernate.test.schemaupdate; package org.hibernate.test.schemaupdate;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
@ -38,66 +36,77 @@ import static org.junit.Assert.assertEquals;
* @author Gail Badner * @author Gail Badner
*/ */
public abstract class SchemaExportTest extends BaseUnitTestCase { public abstract class SchemaExportTest extends BaseUnitTestCase {
private final String MAPPING = "org/hibernate/test/schemaupdate/mapping.hbm.xml"; private final String MAPPING = "org/hibernate/test/schemaupdate/mapping.hbm.xml";
protected abstract SchemaExport createSchemaExport(Configuration cfg); protected abstract SchemaExport createSchemaExport(Configuration cfg);
private boolean doesDialectSupportDropTableIfExist(){ private boolean doesDialectSupportDropTableIfExist() {
return Dialect.getDialect().supportsIfExistsAfterTableName() || Dialect.getDialect().supportsIfExistsBeforeTableName(); return Dialect.getDialect().supportsIfExistsAfterTableName() || Dialect.getDialect()
.supportsIfExistsBeforeTableName();
} }
@Test @Test
public void testCreateAndDropOnlyType() { public void testCreateAndDropOnlyType() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
cfg.addResource( MAPPING ); cfg.addResource( MAPPING );
SchemaExport schemaExport = createSchemaExport( cfg ); SchemaExport schemaExport = createSchemaExport( cfg );
// create w/o dropping first; (OK because tables don't exist yet // create w/o dropping first; (OK because tables don't exist yet
schemaExport.execute( false, true, false, true ); schemaExport.execute( false, true, false, true );
assertEquals( 0, schemaExport.getExceptions().size() );
// create w/o dropping again; should be an exception for each table
// (2 total) because the tables exist already
assertEquals( 0, schemaExport.getExceptions().size() );
schemaExport.execute( false, true, false, true );
assertEquals( 2, schemaExport.getExceptions().size() );
// drop tables only
schemaExport.execute( false, true, true, false );
assertEquals( 0, schemaExport.getExceptions().size() );
}
@Test
public void testBothType() {
Configuration cfg = new Configuration();
cfg.addResource( MAPPING );
SchemaExport schemaExport = createSchemaExport( cfg );
// drop before create (nothing to drop yeT)
schemaExport.execute( false, true, false, false );
if ( doesDialectSupportDropTableIfExist() ) { if ( doesDialectSupportDropTableIfExist() ) {
assertEquals( 0, schemaExport.getExceptions().size() ); assertEquals( 0, schemaExport.getExceptions().size() );
} }
else { else {
assertEquals( 2, schemaExport.getExceptions().size() ); assertEquals( 2, schemaExport.getExceptions().size() );
} }
// drop before crete again (this time drops the tables before re-creating) // create w/o dropping again; should be an exception for each table
schemaExport.execute( false, true, false, false ); // (2 total) because the tables exist already
assertEquals( 0, schemaExport.getExceptions().size() ); assertEquals( 0, schemaExport.getExceptions().size() );
// drop tables schemaExport.execute( false, true, false, true );
schemaExport.execute( false, true, true, false ); assertEquals( 2, schemaExport.getExceptions().size() );
assertEquals( 0, schemaExport.getExceptions().size() ); // drop tables only
} schemaExport.execute( false, true, true, false );
assertEquals( 0, schemaExport.getExceptions().size() );
}
@Test @Test
public void testCreateAndDrop() { public void testBothType() {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
cfg.addResource( MAPPING ); cfg.addResource( MAPPING );
SchemaExport schemaExport = createSchemaExport( cfg ); SchemaExport schemaExport = createSchemaExport( cfg );
// should drop before creating, but tables don't exist yet // drop before create (nothing to drop yeT)
schemaExport.create( false, true); schemaExport.execute( false, true, false, false );
assertEquals( 0, schemaExport.getExceptions().size() ); if ( doesDialectSupportDropTableIfExist() ) {
// call create again; it should drop tables before re-creating assertEquals( 0, schemaExport.getExceptions().size() );
schemaExport.create( false, true ); }
assertEquals( 0, schemaExport.getExceptions().size() ); else {
// drop the tables assertEquals( 2, schemaExport.getExceptions().size() );
schemaExport.drop( false, true ); }
assertEquals( 0, schemaExport.getExceptions().size() ); // drop before crete again (this time drops the tables before re-creating)
} schemaExport.execute( false, true, false, false );
assertEquals( 0, schemaExport.getExceptions().size() );
// drop tables
schemaExport.execute( false, true, true, false );
assertEquals( 0, schemaExport.getExceptions().size() );
}
@Test
public void testCreateAndDrop() {
Configuration cfg = new Configuration();
cfg.addResource( MAPPING );
SchemaExport schemaExport = createSchemaExport( cfg );
// should drop before creating, but tables don't exist yet
schemaExport.create( false, true );
if ( doesDialectSupportDropTableIfExist() ) {
assertEquals( 0, schemaExport.getExceptions().size() );
}
else {
assertEquals( 2, schemaExport.getExceptions().size() );
}
// call create again; it should drop tables before re-creating
schemaExport.create( false, true );
assertEquals( 0, schemaExport.getExceptions().size() );
// drop the tables
schemaExport.drop( false, true );
assertEquals( 0, schemaExport.getExceptions().size() );
}
} }