Skipping  ManyToOneWithFormulaTest.testManyToOneToPkWithOnlyFormula for now. Added a SkipForDialectAnnotation as counterpart for RequiresDialect

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17778 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Hardy Ferentschik 2009-10-16 13:02:53 +00:00
parent 26dce3ac64
commit 6613dce0cb
3 changed files with 91 additions and 36 deletions

View File

@ -0,0 +1,22 @@
// $Id$
package org.hibernate.test.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.hibernate.dialect.Dialect;
/**
* Annotations used to mark a test to be specific to a given dialect.
*
* @author Hardy Ferentschik
*/
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface SkipForDialect {
Class<? extends Dialect>[] value();
String comment();
}

View File

@ -56,6 +56,11 @@ public abstract class TestCase extends junit.framework.TestCase {
*/
private final Set<Class<? extends Dialect>> requiredDialectList = new HashSet<Class<? extends Dialect>>();
/**
* List of dialects for which the current {@code runMethod} should be skipped.
*/
private final Set<Class<? extends Dialect>> skipForDialectList = new HashSet<Class<? extends Dialect>>();
public TestCase() {
super();
}
@ -121,6 +126,7 @@ public abstract class TestCase extends junit.framework.TestCase {
private void setRunTestFlag(Method runMethod) {
updateRequiredDialectList( runMethod );
updateSkipForDialectList( runMethod );
if ( runForCurrentDialect() ) {
runTest = true;
@ -150,19 +156,44 @@ public abstract class TestCase extends junit.framework.TestCase {
}
}
private void updateSkipForDialectList(Method runMethod) {
skipForDialectList.clear();
SkipForDialect skipForDialectMethodAnn = runMethod.getAnnotation( SkipForDialect.class );
if ( skipForDialectMethodAnn != null ) {
Class<? extends Dialect>[] skipDialects = skipForDialectMethodAnn.value();
skipForDialectList.addAll( Arrays.asList( skipDialects ) );
}
SkipForDialect skipForDialectClassAnn = getClass().getAnnotation( SkipForDialect.class );
if ( skipForDialectClassAnn != null ) {
Class<? extends Dialect>[] skipDialects = skipForDialectClassAnn.value();
skipForDialectList.addAll( Arrays.asList( skipDialects ) );
}
}
protected boolean runForCurrentDialect() {
if ( requiredDialectList.isEmpty() ) {
return true;
}
else {
// check whether the current dialect is assignableFrom from any of the specified required dialects.
for ( Class<? extends Dialect> dialect : requiredDialectList ) {
if ( dialect.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
return true;
}
boolean runTestForCurrentDialect = true;
// check whether the current dialect is assignableFrom from any of the specified required dialects.
for ( Class<? extends Dialect> dialect : requiredDialectList ) {
if ( dialect.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
runTestForCurrentDialect = true;
break;
}
return false;
runTestForCurrentDialect = false;
}
// check whether the current dialect is assignableFrom from any of the specified skip for dialects.
for ( Class<? extends Dialect> dialect : skipForDialectList ) {
if ( dialect.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
runTestForCurrentDialect = false;
break;
}
runTestForCurrentDialect = true;
}
return runTestForCurrentDialect;
}
private void runTestMethod(Method runMethod) throws Throwable {

View File

@ -24,11 +24,12 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.manytoonewithformula;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.test.annotations.SkipForDialect;
import org.hibernate.test.annotations.TestCase;
/**
@ -39,13 +40,13 @@ public class ManyToOneWithFormulaTest extends TestCase {
public ManyToOneWithFormulaTest(String x) {
super( x );
}
public void testManyToOneFromNonPk() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Menu menu = new Menu();
menu.setOrderNbr( "123" );
menu.setDefault("F");
menu.setDefault( "F" );
s.persist( menu );
FoodItem foodItem = new FoodItem();
foodItem.setItem( "Mouse" );
@ -53,65 +54,66 @@ public class ManyToOneWithFormulaTest extends TestCase {
s.persist( foodItem );
s.flush();
s.clear();
foodItem = (FoodItem) s.get( FoodItem.class, foodItem.getId() );
foodItem = ( FoodItem ) s.get( FoodItem.class, foodItem.getId() );
assertNotNull( foodItem.getOrder() );
assertEquals( "123", foodItem.getOrder().getOrderNbr() );
tx.rollback();
s.close();
}
public void testManyToOneFromPk() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Company company = new Company();
s.persist( company );
Person person = new Person();
person.setDefaultFlag("T");
person.setCompanyId(company.getId());
s.persist(person);
person.setDefaultFlag( "T" );
person.setCompanyId( company.getId() );
s.persist( person );
s.flush();
s.clear();
company = (Company) s.get( Company.class, company.getId() );
company = ( Company ) s.get( Company.class, company.getId() );
assertNotNull( company.getDefaultContactPerson() );
assertEquals( person.getId(), company.getDefaultContactPerson().getId() );
tx.rollback();
s.close();
}
@SkipForDialect(value = { HSQLDialect.class }, comment = "The used join conditions does not work in HSQLDB. See HHH-4497")
public void testManyToOneToPkWithOnlyFormula() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Language language = new Language();
language.setCode("EN");
language.setName("English");
language.setCode( "EN" );
language.setName( "English" );
s.persist( language );
Message msg = new Message();
msg.setLanguageCode("en");
msg.setLanguageName("English");
s.persist(msg);
msg.setLanguageCode( "en" );
msg.setLanguageName( "English" );
s.persist( msg );
s.flush();
s.clear();
msg = (Message) s.get( Message.class, msg.getId() );
assertNotNull( msg.getLanguage());
msg = ( Message ) s.get( Message.class, msg.getId() );
assertNotNull( msg.getLanguage() );
assertEquals( "EN", msg.getLanguage().getCode() );
tx.rollback();
s.close();
}
/**
* @see org.hibernate.test.annotations.TestCase#getMappings()
*/
protected java.lang.Class<?>[] getMappings() {
return new java.lang.Class[]{
return new java.lang.Class[] {
Menu.class,
FoodItem.class,
Company.class,