[hibernate-commits] Hibernate SVN: r18594 - in core/trunk/annotations/src/test/java/org/hibernate/test/annotations: idclassgeneratedvalue and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jan 20 15:18:56 EST 2010


Author: hardy.ferentschik
Date: 2010-01-20 15:18:56 -0500 (Wed, 20 Jan 2010)
New Revision: 18594

Added:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/FailureExpected.java
Modified:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/SkipForDialect.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java
Log:
HHH-4822 - Added @FailureExpected to annotations module


Copied: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/FailureExpected.java (from rev 18589, core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java)
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/FailureExpected.java	                        (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/FailureExpected.java	2010-01-20 20:18:56 UTC (rev 18594)
@@ -0,0 +1,42 @@
+// $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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotations used to mark a expected test failure.
+ *
+ * @author Hardy Ferentschik
+ */
+ at Target({ ElementType.METHOD, ElementType.TYPE })
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface FailureExpected {
+	String message() default "";
+	String issueNumber() default "";
+}
\ No newline at end of file

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java	2010-01-20 19:16:38 UTC (rev 18593)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java	2010-01-20 20:18:56 UTC (rev 18594)
@@ -1,4 +1,27 @@
-// $Id:$
+// $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;
 
 import java.lang.annotation.ElementType;

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/SkipForDialect.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/SkipForDialect.java	2010-01-20 19:16:38 UTC (rev 18593)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/SkipForDialect.java	2010-01-20 20:18:56 UTC (rev 18594)
@@ -1,4 +1,27 @@
 // $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;
 
 import java.lang.annotation.ElementType;

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java	2010-01-20 19:16:38 UTC (rev 18593)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java	2010-01-20 20:18:56 UTC (rev 18594)
@@ -1,8 +1,30 @@
 //$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;
 
 import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.sql.Connection;
@@ -24,6 +46,7 @@
 import org.hibernate.dialect.Dialect;
 import org.hibernate.jdbc.Work;
 import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.util.StringHelper;
 
 /**
  * A base class for all tests.
@@ -113,15 +136,10 @@
 	}
 
 	protected void runTest() throws Throwable {
-		try {
-			if ( runTest ) {
-				runTestMethod( runMethod );
-				handleUnclosedSession();
-			}
+		if ( runTest ) {
+			runTestMethod( runMethod );
+			handleUnclosedSession();
 		}
-		catch ( Throwable e ) {
-			closeSession( e );
-		}
 	}
 
 	private void setRunTestFlag(Method runMethod) {
@@ -197,16 +215,38 @@
 	}
 
 	private void runTestMethod(Method runMethod) throws Throwable {
+		boolean failureExpected = runMethod.getAnnotation( FailureExpected.class ) != null;
 		try {
 			runMethod.invoke( this, new Class[0] );
+			if ( failureExpected ) {
+				throw new FailureExpectedTestPassedException();
+			}
 		}
-		catch ( InvocationTargetException e ) {
-			e.fillInStackTrace();
-			throw e.getTargetException();
+		catch ( FailureExpectedTestPassedException t ) {
+			closeSession();
+			throw t;
 		}
-		catch ( IllegalAccessException e ) {
-			e.fillInStackTrace();
-			throw e;
+		catch ( Throwable t ) {
+			closeSession();
+			if ( failureExpected ) {
+				FailureExpected ann = runMethod.getAnnotation( FailureExpected.class );
+				StringBuilder builder = new StringBuilder();
+				if ( StringHelper.isNotEmpty( ann.message() ) ) {
+					builder.append( ann.message() );
+				}
+				else {
+					builder.append( "ignoring test methods annoated with @FailureExpected" );
+				}
+				if ( StringHelper.isNotEmpty( ann.issueNumber() ) ) {
+					builder.append( " (" );
+					builder.append( ann.issueNumber() );
+					builder.append( ")" );
+				}
+				reportSkip( builder.toString(), "Failed with: " + t.toString() );
+			}
+			else {
+				throw t;
+			}
 		}
 	}
 
@@ -215,7 +255,7 @@
 		assertNotNull( fName );
 		Method runMethod = null;
 		try {
-			runMethod = getClass().getMethod( fName, null );
+			runMethod = getClass().getMethod( fName );
 		}
 		catch ( NoSuchMethodException e ) {
 			fail( "Method \"" + fName + "\" not found" );
@@ -240,7 +280,7 @@
 		}
 	}
 
-	private void closeSession(Throwable e) throws Throwable {
+	private void closeSession() {
 		try {
 			if ( session != null && session.isOpen() ) {
 				if ( session.isConnected() ) {
@@ -259,7 +299,6 @@
 		}
 		catch ( Exception ignore ) {
 		}
-		throw e;
 	}
 
 	public Session openSession() throws HibernateException {
@@ -314,10 +353,30 @@
 		export.create( true, true );
 	}
 
+	protected void reportSkip(String reason, String testDescription) {
+		StringBuilder builder = new StringBuilder( );
+		builder.append( "*** skipping test [" );
+		builder.append( runMethod.getDeclaringClass().getName() );
+		builder.append( "." );
+		builder.append(runMethod.getName() );
+		builder.append( "] - " );
+		builder.append( testDescription );
+		builder.append( " : " );
+		builder.append( reason );
+
+		log.warn( builder.toString() );
+	}
+
 	public class RollbackWork implements Work {
 
 		public void execute(Connection connection) throws SQLException {
 			connection.rollback();
 		}
 	}
+
+	private static class FailureExpectedTestPassedException extends Exception {
+		public FailureExpectedTestPassedException() {
+			super( "Test marked as @FailureExpected, but did not fail!" );
+		}
+	}
 }


Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
___________________________________________________________________
Name: svn:keywords
   - Date Revision Author Id
   + Id

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java	2010-01-20 19:16:38 UTC (rev 18593)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java	2010-01-20 20:18:56 UTC (rev 18594)
@@ -1,3 +1,4 @@
+// $Id:$
 /*
  * Hibernate, Relational Persistence for Idiomatic Java
  *
@@ -23,11 +24,10 @@
  */
 package org.hibernate.test.annotations.idclassgeneratedvalue;
 
-import java.math.BigDecimal;
 import java.util.List;
 
 import org.hibernate.Session;
-import org.hibernate.Transaction;
+import org.hibernate.test.annotations.FailureExpected;
 import org.hibernate.test.annotations.TestCase;
 
 /**
@@ -52,7 +52,7 @@
 		s.beginTransaction();
 		List<Simple> simpleList = s.createQuery( "select s from Simple s" ).list();
 		assertEquals( simpleList.size(), 2 );
-		s1 = (Simple) s.load( Simple.class, new SimplePK( 1L, 2L ) );
+		s1 = ( Simple ) s.load( Simple.class, new SimplePK( 1L, 2L ) );
 		assertEquals( s1.getQuantity(), 10 );
 		s.clear();
 		s.createQuery( "delete Simple" ).executeUpdate();
@@ -60,6 +60,7 @@
 		s.close();
 	}
 
+	@FailureExpected(message = "Not yet implemented", issueNumber = "HHH-4552")
 	@SuppressWarnings({ "unchecked" })
 	public void testSingleGeneratedValue() {
 		Session s = openSession();
@@ -76,39 +77,40 @@
 		s.beginTransaction();
 		List<Simple> simpleList = s.createQuery( "select s from Simple2 s" ).list();
 		assertEquals( simpleList.size(), 2 );
-		s1 = (Simple2) s.load( Simple2.class, new SimplePK( s1Id1, 2L ) );
+		s1 = ( Simple2 ) s.load( Simple2.class, new SimplePK( s1Id1, 2L ) );
 		assertEquals( s1.getQuantity(), 10 );
 		s.clear();
 		s.createQuery( "delete Simple2" ).executeUpdate();
 		s.getTransaction().commit();
 		s.close();
 	}
-	
-	   @SuppressWarnings({ "unchecked" })
-	    public void testMultipleGeneratedValue() {
-	        Session s = openSession();
-	        s.beginTransaction();
-	        Multiple m1 = new Multiple( 1000L, 10 );
-	        s.persist( m1 );
-	        Long m1Id1 = m1.getId1();
-	        Long m1Id2 = m1.getId2();
-	        Multiple m2 = new Multiple( 2000L, 20 );
-	        s.persist( m2 );
-	        s.getTransaction().commit();
-	        s.close();
 
-	        s = openSession();
-	        s.beginTransaction();
-	        List<Simple> simpleList = s.createQuery( "select m from Multiple m" ).list();
-	        assertEquals( simpleList.size(), 2 );
-	        m1 = (Multiple) s.load( Multiple.class, new MultiplePK( m1Id1, m1Id2, 2L ) );
-	        assertEquals( m1.getQuantity(), 10 );
-	        s.clear();
-	        s.createQuery( "delete Multiple" ).executeUpdate();
-	        s.getTransaction().commit();
-	        s.close();
-	    }
+	@FailureExpected(message = "Not yet implemented", issueNumber = "HHH-4552")
+	@SuppressWarnings({ "unchecked" })
+	public void testMultipleGeneratedValue() {
+		Session s = openSession();
+		s.beginTransaction();
+		Multiple m1 = new Multiple( 1000L, 10 );
+		s.persist( m1 );
+		Long m1Id1 = m1.getId1();
+		Long m1Id2 = m1.getId2();
+		Multiple m2 = new Multiple( 2000L, 20 );
+		s.persist( m2 );
+		s.getTransaction().commit();
+		s.close();
 
+		s = openSession();
+		s.beginTransaction();
+		List<Simple> simpleList = s.createQuery( "select m from Multiple m" ).list();
+		assertEquals( simpleList.size(), 2 );
+		m1 = ( Multiple ) s.load( Multiple.class, new MultiplePK( m1Id1, m1Id2, 2L ) );
+		assertEquals( m1.getQuantity(), 10 );
+		s.clear();
+		s.createQuery( "delete Multiple" ).executeUpdate();
+		s.getTransaction().commit();
+		s.close();
+	}
+
 //	public void testComplexIdClass() {
 //		Session s = openSession();
 //		Transaction tx = s.beginTransaction();
@@ -155,7 +157,7 @@
 				Simple.class,
 				Simple2.class,
 				Multiple.class
-				
+
 		};
 	}
 }


Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the hibernate-commits mailing list