[hibernate-commits] Hibernate SVN: r19741 - in core/branches/Branch_3_5: annotations/src/test/java/org/hibernate/test/annotations/lob and 4 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue Jun 15 11:53:38 EDT 2010
Author: hardy.ferentschik
Date: 2010-06-15 11:53:37 -0400 (Tue, 15 Jun 2010)
New Revision: 19741
Added:
core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/DialectChecks.java
core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java
Modified:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java
core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialect.java
core/branches/Branch_3_5/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
Log:
HHH-5204 backported @RequiresDialectFeature to 3.5 branch
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java 2010-06-15 14:53:17 UTC (rev 19740)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java 2010-06-15 15:53:37 UTC (rev 19741)
@@ -1,10 +1,34 @@
-//$Id$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.annotations.id.sequences;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
+import org.hibernate.junit.DialectChecks;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.mapping.Column;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.annotations.id.sequences.entities.Ball;
@@ -29,27 +53,28 @@
* @author Emmanuel Bernard
*/
@SuppressWarnings("unchecked")
+ at RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class IdTest extends TestCase {
public void testGenericGenerator() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
SoundSystem system = new SoundSystem();
- system.setBrand("Genelec");
- system.setModel("T234");
+ system.setBrand( "Genelec" );
+ system.setModel( "T234" );
Furniture fur = new Furniture();
- s.persist(system);
- s.persist(fur);
+ s.persist( system );
+ s.persist( fur );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
- system = (SoundSystem) s.get(SoundSystem.class, system.getId());
- fur = (Furniture) s.get(Furniture.class, fur.getId());
- assertNotNull(system);
- assertNotNull(fur);
- s.delete(system);
- s.delete(fur);
+ system = ( SoundSystem ) s.get( SoundSystem.class, system.getId() );
+ fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
+ assertNotNull( system );
+ assertNotNull( fur );
+ s.delete( system );
+ s.delete( fur );
tx.commit();
s.close();
@@ -59,13 +84,14 @@
* Ensures that GenericGenerator annotations wrapped inside a
* GenericGenerators holder are bound correctly
*/
+
public void testGenericGenerators() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Monkey monkey = new Monkey();
- s.persist(monkey);
+ s.persist( monkey );
s.flush();
- assertNotNull(monkey.getId());
+ assertNotNull( monkey.getId() );
tx.rollback();
s.close();
}
@@ -77,21 +103,23 @@
Ball b = new Ball();
Dog d = new Dog();
Computer c = new Computer();
- s.persist(b);
- s.persist(d);
- s.persist(c);
+ s.persist( b );
+ s.persist( d );
+ s.persist( c );
tx.commit();
s.close();
- assertEquals("table id not generated", new Integer(1), b.getId());
- assertEquals("generator should not be shared", new Integer(1), d
- .getId());
- assertEquals("default value should work", new Long(1), c.getId());
+ assertEquals( "table id not generated", new Integer( 1 ), b.getId() );
+ assertEquals(
+ "generator should not be shared", new Integer( 1 ), d
+ .getId()
+ );
+ assertEquals( "default value should work", new Long( 1 ), c.getId() );
s = openSession();
tx = s.beginTransaction();
- s.delete(s.get(Ball.class, new Integer(1)));
- s.delete(s.get(Dog.class, new Integer(1)));
- s.delete(s.get(Computer.class, new Long(1)));
+ s.delete( s.get( Ball.class, new Integer( 1 ) ) );
+ s.delete( s.get( Dog.class, new Integer( 1 ) ) );
+ s.delete( s.get( Computer.class, new Long( 1 ) ) );
tx.commit();
s.close();
}
@@ -100,14 +128,14 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
Shoe b = new Shoe();
- s.persist(b);
+ s.persist( b );
tx.commit();
s.close();
- assertNotNull(b.getId());
+ assertNotNull( b.getId() );
s = openSession();
tx = s.beginTransaction();
- s.delete(s.get(Shoe.class, b.getId()));
+ s.delete( s.get( Shoe.class, b.getId() ) );
tx.commit();
s.close();
}
@@ -116,14 +144,14 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
Store b = new Store();
- s.persist(b);
+ s.persist( b );
tx.commit();
s.close();
- assertNotNull(b.getId());
+ assertNotNull( b.getId() );
s = openSession();
tx = s.beginTransaction();
- s.delete(s.get(Store.class, b.getId()));
+ s.delete( s.get( Store.class, b.getId() ) );
tx.commit();
s.close();
}
@@ -132,14 +160,14 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
Department b = new Department();
- s.persist(b);
+ s.persist( b );
tx.commit();
s.close();
- assertNotNull(b.getId());
+ assertNotNull( b.getId() );
s = openSession();
tx = s.beginTransaction();
- s.delete(s.get(Department.class, b.getId()));
+ s.delete( s.get( Department.class, b.getId() ) );
tx.commit();
s.close();
}
@@ -150,16 +178,16 @@
s = openSession();
tx = s.beginTransaction();
Home h = new Home();
- s.persist(h);
+ s.persist( h );
tx.commit();
s.close();
- assertNotNull(h.getId());
+ assertNotNull( h.getId() );
s = openSession();
tx = s.beginTransaction();
- Home reloadedHome = (Home) s.get(Home.class, h.getId());
- assertEquals(h.getId(), reloadedHome.getId());
- s.delete(reloadedHome);
+ Home reloadedHome = ( Home ) s.get( Home.class, h.getId() );
+ assertEquals( h.getId(), reloadedHome.getId() );
+ s.delete( reloadedHome );
tx.commit();
s.close();
}
@@ -170,16 +198,16 @@
s = openSession();
tx = s.beginTransaction();
Home h = new Home();
- s.persist(h);
+ s.persist( h );
tx.commit();
s.close();
- assertNotNull(h.getId());
+ assertNotNull( h.getId() );
s = openSession();
tx = s.beginTransaction();
- Home reloadedHome = (Home) s.get(Home.class, h.getId());
- assertEquals(h.getId(), reloadedHome.getId());
- s.delete(reloadedHome);
+ Home reloadedHome = ( Home ) s.get( Home.class, h.getId() );
+ assertEquals( h.getId(), reloadedHome.getId() );
+ s.delete( reloadedHome );
tx.commit();
s.close();
}
@@ -190,13 +218,13 @@
s = openSession();
tx = s.beginTransaction();
FirTree chrismasTree = new FirTree();
- s.persist(chrismasTree);
+ s.persist( chrismasTree );
tx.commit();
s.clear();
tx = s.beginTransaction();
- chrismasTree = (FirTree) s.get(FirTree.class, chrismasTree.getId());
- assertNotNull(chrismasTree);
- s.delete(chrismasTree);
+ chrismasTree = ( FirTree ) s.get( FirTree.class, chrismasTree.getId() );
+ assertNotNull( chrismasTree );
+ s.delete( chrismasTree );
tx.commit();
s.close();
}
@@ -206,55 +234,58 @@
Transaction tx;
s = openSession();
tx = s.beginTransaction();
- Footballer fb = new Footballer("David", "Beckam", "Arsenal");
- GoalKeeper keeper = new GoalKeeper("Fabien", "Bartez", "OM");
- s.persist(fb);
- s.persist(keeper);
+ Footballer fb = new Footballer( "David", "Beckam", "Arsenal" );
+ GoalKeeper keeper = new GoalKeeper( "Fabien", "Bartez", "OM" );
+ s.persist( fb );
+ s.persist( keeper );
tx.commit();
s.clear();
// lookup by id
tx = s.beginTransaction();
- FootballerPk fpk = new FootballerPk("David", "Beckam");
- fb = (Footballer) s.get(Footballer.class, fpk);
- FootballerPk fpk2 = new FootballerPk("Fabien", "Bartez");
- keeper = (GoalKeeper) s.get(GoalKeeper.class, fpk2);
- assertNotNull(fb);
- assertNotNull(keeper);
- assertEquals("Beckam", fb.getLastname());
- assertEquals("Arsenal", fb.getClub());
- assertEquals(1, s.createQuery(
- "from Footballer f where f.firstname = 'David'").list().size());
+ FootballerPk fpk = new FootballerPk( "David", "Beckam" );
+ fb = ( Footballer ) s.get( Footballer.class, fpk );
+ FootballerPk fpk2 = new FootballerPk( "Fabien", "Bartez" );
+ keeper = ( GoalKeeper ) s.get( GoalKeeper.class, fpk2 );
+ assertNotNull( fb );
+ assertNotNull( keeper );
+ assertEquals( "Beckam", fb.getLastname() );
+ assertEquals( "Arsenal", fb.getClub() );
+ assertEquals(
+ 1, s.createQuery(
+ "from Footballer f where f.firstname = 'David'"
+ ).list().size()
+ );
tx.commit();
// reattach by merge
tx = s.beginTransaction();
- fb.setClub("Bimbo FC");
- s.merge(fb);
+ fb.setClub( "Bimbo FC" );
+ s.merge( fb );
tx.commit();
// reattach by saveOrUpdate
tx = s.beginTransaction();
- fb.setClub("Bimbo FC SA");
- s.saveOrUpdate(fb);
+ fb.setClub( "Bimbo FC SA" );
+ s.saveOrUpdate( fb );
tx.commit();
// clean up
s.clear();
tx = s.beginTransaction();
- fpk = new FootballerPk("David", "Beckam");
- fb = (Footballer) s.get(Footballer.class, fpk);
- assertEquals("Bimbo FC SA", fb.getClub());
- s.delete(fb);
- s.delete(keeper);
+ fpk = new FootballerPk( "David", "Beckam" );
+ fb = ( Footballer ) s.get( Footballer.class, fpk );
+ assertEquals( "Bimbo FC SA", fb.getClub() );
+ s.delete( fb );
+ s.delete( keeper );
tx.commit();
s.close();
}
public void testColumnDefinition() {
- Column idCol = (Column) getCfg().getClassMapping(Ball.class.getName())
+ Column idCol = ( Column ) getCfg().getClassMapping( Ball.class.getName() )
.getIdentifierProperty().getValue().getColumnIterator().next();
- assertEquals("ball_id", idCol.getName());
+ assertEquals( "ball_id", idCol.getName() );
}
public void testLowAllocationSize() throws Exception {
@@ -264,42 +295,39 @@
tx = s.beginTransaction();
int size = 4;
BreakDance[] bds = new BreakDance[size];
- for (int i = 0; i < size; i++) {
+ for ( int i = 0; i < size; i++ ) {
bds[i] = new BreakDance();
- s.persist(bds[i]);
+ s.persist( bds[i] );
}
s.flush();
- for (int i = 0; i < size; i++) {
- assertEquals(i + 1, bds[i].id.intValue());
+ for ( int i = 0; i < size; i++ ) {
+ assertEquals( i + 1, bds[i].id.intValue() );
}
tx.rollback();
s.close();
}
-
-
-
- @Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsSequences();
- }
/**
* @see org.hibernate.test.annotations.TestCase#getAnnotatedClasses()
*/
protected Class[] getAnnotatedClasses() {
- return new Class[] { Ball.class, Shoe.class, Store.class,
+ return new Class[] {
+ Ball.class, Shoe.class, Store.class,
Department.class, Dog.class, Computer.class, Home.class,
Phone.class, Tree.class, FirTree.class, Footballer.class,
SoundSystem.class, Furniture.class, GoalKeeper.class,
- BreakDance.class, Monkey.class};
+ BreakDance.class, Monkey.class
+ };
}
-
+
/**
* @see org.hibernate.test.annotations.TestCase#getAnnotatedPackages()
*/
protected String[] getAnnotatedPackages() {
- return new String[] { "org.hibernate.test.annotations",
- "org.hibernate.test.annotations.id" };
+ return new String[] {
+ "org.hibernate.test.annotations",
+ "org.hibernate.test.annotations.id"
+ };
}
@Override
@@ -311,5 +339,4 @@
protected void configure(Configuration cfg) {
cfg.setProperty( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
}
-
}
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2010-06-15 14:53:17 UTC (rev 19740)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2010-06-15 15:53:37 UTC (rev 19741)
@@ -1,14 +1,38 @@
-//$Id$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.annotations.lob;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.Dialect;
+import org.hibernate.junit.DialectChecks;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase;
/**
* @author Emmanuel Bernard
*/
+ at RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public class LobTest extends TestCase {
public void testSerializableToBlob() throws Exception {
Book book = new Book();
@@ -118,11 +142,6 @@
super( x );
}
- @Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsExpectedLobUsagePattern();
- }
-
protected Class[] getAnnotatedClasses() {
return new Class[] {
Book.class,
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2010-06-15 14:53:17 UTC (rev 19740)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2010-06-15 15:53:37 UTC (rev 19741)
@@ -1,29 +1,54 @@
-//$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.annotations.manytoone.referencedcolumnname;
import java.math.BigDecimal;
+import org.hibernate.Session;
+import org.hibernate.junit.DialectChecks;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase;
-import org.hibernate.Session;
/**
* @author Emmanuel Bernard
*/
public class ManyToOneReferencedColumnNameTest extends TestCase {
+ @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public void testReoverableExceptionInFkOrdering() throws Exception {
//SF should not blow up
Vendor v = new Vendor();
Item i = new Item();
ZItemCost ic = new ZItemCost();
- ic.setCost( new BigDecimal(2) );
+ ic.setCost( new BigDecimal( 2 ) );
ic.setItem( i );
ic.setVendor( v );
WarehouseItem wi = new WarehouseItem();
wi.setDefaultCost( ic );
wi.setItem( i );
wi.setVendor( v );
- wi.setQtyInStock( new BigDecimal(2) );
- Session s = openSession( );
+ wi.setQtyInStock( new BigDecimal( 2 ) );
+ Session s = openSession();
s.getTransaction().begin();
s.save( i );
s.save( v );
@@ -32,16 +57,8 @@
s.flush();
s.getTransaction().rollback();
s.close();
-
}
-
- @Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsIdentityColumns();
- }
-
-
protected Class[] getAnnotatedClasses() {
return new Class[] {
Item.class,
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java 2010-06-15 14:53:17 UTC (rev 19740)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java 2010-06-15 15:53:37 UTC (rev 19741)
@@ -1,7 +1,31 @@
-//$Id:HbmTest.java 9793 2006-04-26 02:20:18 -0400 (mer., 26 avr. 2006) epbernard $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.annotations.xml.hbm;
import org.hibernate.Session;
+import org.hibernate.junit.DialectChecks;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase;
/**
@@ -9,6 +33,7 @@
*/
public class HbmWithIdentityTest extends TestCase {
+ @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public void testManyToOneAndInterface() throws Exception {
Session s = openSession();
s.getTransaction().begin();
@@ -23,11 +48,6 @@
s.close();
}
- @Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsIdentityColumns();
- }
-
protected Class[] getAnnotatedClasses() {
return new Class[] {
Sky.class,
Copied: core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/DialectChecks.java (from rev 19739, core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialect.java)
===================================================================
--- core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/DialectChecks.java (rev 0)
+++ core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/DialectChecks.java 2010-06-15 15:53:37 UTC (rev 19741)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.junit;
+
+import org.hibernate.dialect.Dialect;
+
+/**
+ * Container class for different implementation of the {@code DialectCheck} interface.
+ *
+ * @author Hardy Ferentschik
+ */
+abstract public class DialectChecks {
+
+ abstract public boolean include(Dialect dialect);
+
+ public static class SupportsSequences extends DialectChecks {
+ public boolean include(Dialect dialect) {
+ return dialect.supportsSequences();
+ }
+ }
+
+ public static class SupportsExpectedLobUsagePattern extends DialectChecks {
+ public boolean include(Dialect dialect) {
+ return dialect.supportsExpectedLobUsagePattern();
+ }
+ }
+
+ public static class SupportsIdentityColumns extends DialectChecks {
+ public boolean include(Dialect dialect) {
+ return dialect.supportsIdentityColumns();
+ }
+ }
+
+
+}
+
+
Modified: core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialect.java
===================================================================
--- core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialect.java 2010-06-15 14:53:17 UTC (rev 19740)
+++ core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialect.java 2010-06-15 15:53:37 UTC (rev 19741)
@@ -33,14 +33,15 @@
/**
* Annotation used to indicate that a test should be run only when run against the
* indicated dialects.
- *
+ *
* @author Hardy Ferentschik
*/
- at Target({ElementType.METHOD, ElementType.TYPE})
+ at Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiresDialect {
/**
* The dialects against which to run the test
+ *
* @return The dialects
*/
Class<? extends Dialect>[] value();
@@ -48,7 +49,22 @@
/**
* Used to indicate if the dialects should be matched strictly (classes equal) or
* non-strictly (instanceof).
+ *
* @return Should strict matching be used?
*/
boolean strictMatching() default false;
+
+ /**
+ * Comment describing the reason why the dialect is required.
+ *
+ * @return The comment
+ */
+ String comment() default "";
+
+ /**
+ * The key of a JIRA issue which relates this this restriction
+ *
+ * @return The jira issue key
+ */
+ String jiraKey() default "";
}
Copied: core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java (from rev 19739, core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialect.java)
===================================================================
--- core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java (rev 0)
+++ core/branches/Branch_3_5/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java 2010-06-15 15:53:37 UTC (rev 19741)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.junit;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate that a test should be run only when the current dialect supports the
+ * specified feature.
+ *
+ * @author Hardy Ferentschik
+ */
+ at Target({ ElementType.METHOD, ElementType.TYPE })
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface RequiresDialectFeature {
+ /**
+ * @return The name of the dialect feature.
+ */
+ Class<? extends DialectChecks> value();
+
+ /**
+ * Comment describing the reason why the feature is required.
+ *
+ * @return The comment
+ */
+ String comment() default "";
+
+ /**
+ * The key of a JIRA issue which relates this this feature requirement.
+ *
+ * @return The jira issue key
+ */
+ String jiraKey() default "";
+}
Modified: core/branches/Branch_3_5/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
===================================================================
--- core/branches/Branch_3_5/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-06-15 14:53:17 UTC (rev 19740)
+++ core/branches/Branch_3_5/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-06-15 15:53:37 UTC (rev 19741)
@@ -1,4 +1,3 @@
-// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -30,8 +29,6 @@
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.HashSet;
-import java.util.Set;
import junit.framework.TestCase;
import org.slf4j.Logger;
@@ -40,8 +37,10 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Dialect;
import org.hibernate.jdbc.Work;
+import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.FailureExpected;
import org.hibernate.junit.RequiresDialect;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.junit.SkipForDialect;
import org.hibernate.junit.SkipLog;
import org.hibernate.tool.hbm2ddl.SchemaExport;
@@ -60,23 +59,6 @@
protected static Configuration cfg;
private static Class<?> lastTestClass;
-
- /**
- * Flag indicating whether the test should be run or skipped.
- */
- private boolean runTest = true;
-
- /**
- * List of required dialect for the current {@code runMethod}. If the list is empty any dialect is allowed.
- * Otherwise the current dialect or a superclass of the current dialect must be in the list.
- */
- 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 HibernateTestCase() {
super();
}
@@ -172,7 +154,7 @@
}
}
- protected final Skip determineSkipByDialect(Dialect dialect, Method runMethod) {
+ protected final Skip determineSkipByDialect(Dialect dialect, Method runMethod) throws Exception {
// skips have precedence, so check them first
SkipForDialect skipForDialectAnn = locateAnnotation( SkipForDialect.class, runMethod );
if ( skipForDialectAnn != null ) {
@@ -195,18 +177,28 @@
if ( requiresDialectAnn != null ) {
for ( Class<? extends Dialect> dialectClass : requiresDialectAnn.value() ) {
if ( requiresDialectAnn.strictMatching() ) {
- if ( dialectClass.equals( dialect.getClass() ) ) {
+ if ( !dialectClass.equals( dialect.getClass() ) ) {
return buildSkip( dialect, null, null );
}
}
else {
- if ( dialectClass.isInstance( dialect ) ) {
- return buildSkip( dialect, null, null );
+ if ( !dialectClass.isInstance( dialect ) ) {
+ return buildSkip( dialect, requiresDialectAnn.comment(), requiresDialectAnn.jiraKey() );
}
}
}
}
+ // then check against a dialect feature
+ RequiresDialectFeature requiresDialectFeatureAnn = locateAnnotation( RequiresDialectFeature.class, runMethod );
+ if ( requiresDialectFeatureAnn != null ) {
+ Class<? extends DialectChecks> checkClass = requiresDialectFeatureAnn.value();
+ DialectChecks check = checkClass.newInstance();
+ boolean skip = check.include( dialect );
+ if ( skip ) {
+ return buildSkip( dialect, requiresDialectFeatureAnn.comment(), requiresDialectFeatureAnn.jiraKey() );
+ }
+ }
return null;
}
@@ -244,30 +236,6 @@
return this.getClass().getName() + "#" + this.getName();
}
- protected boolean runForCurrentDialect() {
- 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;
- }
- 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 Method findTestMethod() {
String fName = getName();
assertNotNull( fName );
@@ -289,7 +257,7 @@
protected abstract Class<?>[] getAnnotatedClasses();
protected String[] getMappings() {
- return new String[]{};
+ return new String[] { };
}
protected abstract void handleUnclosedResources();
More information about the hibernate-commits
mailing list