[hibernate-commits] Hibernate SVN: r16478 - search/branches/Branch_3_1/src/test/org/hibernate/search/test.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Apr 29 11:29:35 EDT 2009


Author: hardy.ferentschik
Date: 2009-04-29 11:29:34 -0400 (Wed, 29 Apr 2009)
New Revision: 16478

Removed:
   search/branches/Branch_3_1/src/test/org/hibernate/search/test/HANTestCase.java
Modified:
   search/branches/Branch_3_1/src/test/org/hibernate/search/test/SearchTestCase.java
   search/branches/Branch_3_1/src/test/org/hibernate/search/test/TransactionTest.java
Log:
some cleanup

Deleted: search/branches/Branch_3_1/src/test/org/hibernate/search/test/HANTestCase.java
===================================================================
--- search/branches/Branch_3_1/src/test/org/hibernate/search/test/HANTestCase.java	2009-04-29 15:03:16 UTC (rev 16477)
+++ search/branches/Branch_3_1/src/test/org/hibernate/search/test/HANTestCase.java	2009-04-29 15:29:34 UTC (rev 16478)
@@ -1,67 +0,0 @@
-//$Id$
-package org.hibernate.search.test;
-
-import java.io.InputStream;
-
-import org.hibernate.cfg.AnnotationConfiguration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.dialect.Dialect;
-
-/**
- * Originally a copy from Hibernate Annotations.
- *
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-public abstract class HANTestCase extends TestCase {
-
-	public HANTestCase() {
-		super();
-	}
-
-	public HANTestCase(String x) {
-		super( x );
-	}
-
-	protected void buildSessionFactory(Class[] classes, String[] packages, String[] xmlFiles) throws Exception {
-		if ( getSessions() != null ) {
-			getSessions().close();
-		}
-		try {
-			setCfg( new AnnotationConfiguration() );
-			configure( cfg );
-			if ( recreateSchema() ) {
-				cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
-			}
-			for ( String aPackage : packages ) {
-				( ( AnnotationConfiguration ) getCfg() ).addPackage( aPackage );
-			}
-			for ( Class aClass : classes ) {
-				( ( AnnotationConfiguration ) getCfg() ).addAnnotatedClass( aClass );
-			}
-			for ( String xmlFile : xmlFiles ) {
-				InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
-				getCfg().addInputStream( is );
-			}
-			setDialect( Dialect.getDialect() );
-			setSessions( getCfg().buildSessionFactory( /*new TestInterceptor()*/ ) );
-		}
-		catch ( Exception e ) {
-			e.printStackTrace();
-			throw e;
-		}
-	}
-
-	protected void setUp() throws Exception {
-		if ( getSessions() == null || getSessions().isClosed() || lastTestClass != getClass() ) {
-			buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
-			lastTestClass = getClass();
-		}
-	}
-
-	protected abstract Class[] getMappings();
-
-	protected String[] getAnnotatedPackages() {
-		return new String[] { };
-	}
-}

Modified: search/branches/Branch_3_1/src/test/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/branches/Branch_3_1/src/test/org/hibernate/search/test/SearchTestCase.java	2009-04-29 15:03:16 UTC (rev 16477)
+++ search/branches/Branch_3_1/src/test/org/hibernate/search/test/SearchTestCase.java	2009-04-29 15:29:34 UTC (rev 16478)
@@ -2,33 +2,33 @@
 package org.hibernate.search.test;
 
 import java.io.File;
+import java.io.InputStream;
 
 import org.apache.lucene.analysis.StopAnalyzer;
 import org.apache.lucene.store.Directory;
+import org.slf4j.Logger;
 
 import org.hibernate.HibernateException;
 import org.hibernate.Transaction;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.dialect.Dialect;
 import org.hibernate.event.PostInsertEventListener;
 import org.hibernate.impl.SessionFactoryImpl;
 import org.hibernate.search.Environment;
 import org.hibernate.search.FullTextSession;
 import org.hibernate.search.Search;
 import org.hibernate.search.annotations.Indexed;
-import org.hibernate.search.test.inheritance.Animal;
-import org.hibernate.search.test.inheritance.Mammal;
 import org.hibernate.search.event.FullTextIndexEventListener;
 import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.search.store.FSDirectoryProvider;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * Base class for Hibernate Search unit tests.
  *
  * @author Emmanuel Bernard
  */
-public abstract class SearchTestCase extends HANTestCase {
+public abstract class SearchTestCase extends TestCase {
 
 	private static final Logger log = org.hibernate.search.util.LoggerFactory.make();
 
@@ -49,6 +49,11 @@
 		ensureIndexesAreEmpty();
 	}
 
+	protected void tearDown() throws Exception {
+		SchemaExport export = new SchemaExport( cfg );
+		export.drop( false, true );
+	}
+
 	@SuppressWarnings("unchecked")
 	protected Directory getDirectory(Class clazz) {
 		return getLuceneEventListener().getSearchFactoryImplementor().getDirectoryProviders( clazz )[0].getDirectory();
@@ -88,7 +93,7 @@
 		s.close();
 	}
 
-	protected void configure(org.hibernate.cfg.Configuration cfg) {
+	protected void configure(Configuration cfg) {
 		cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
 		cfg.setProperty( "hibernate.search.default.indexBase", indexDir.getAbsolutePath() );
 		cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
@@ -99,4 +104,39 @@
 	protected File getBaseIndexDir() {
 		return indexDir;
 	}
+
+	protected void buildSessionFactory(Class[] classes, String[] packages, String[] xmlFiles) throws Exception {
+		if ( getSessions() != null ) {
+			getSessions().close();
+		}
+		try {
+			setCfg( new AnnotationConfiguration() );
+			configure( cfg );
+			if ( recreateSchema() ) {
+				cfg.setProperty( org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create-drop" );
+			}
+			for ( String aPackage : packages ) {
+				( ( AnnotationConfiguration ) getCfg() ).addPackage( aPackage );
+			}
+			for ( Class aClass : classes ) {
+				( ( AnnotationConfiguration ) getCfg() ).addAnnotatedClass( aClass );
+			}
+			for ( String xmlFile : xmlFiles ) {
+				InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
+				getCfg().addInputStream( is );
+			}
+			setDialect( Dialect.getDialect() );
+			setSessions( getCfg().buildSessionFactory( /*new TestInterceptor()*/ ) );
+		}
+		catch ( Exception e ) {
+			e.printStackTrace();
+			throw e;
+		}
+	}
+
+	protected abstract Class[] getMappings();
+
+	protected String[] getAnnotatedPackages() {
+		return new String[] { };
+	}
 }

Modified: search/branches/Branch_3_1/src/test/org/hibernate/search/test/TransactionTest.java
===================================================================
--- search/branches/Branch_3_1/src/test/org/hibernate/search/test/TransactionTest.java	2009-04-29 15:03:16 UTC (rev 16477)
+++ search/branches/Branch_3_1/src/test/org/hibernate/search/test/TransactionTest.java	2009-04-29 15:29:34 UTC (rev 16478)
@@ -3,9 +3,11 @@
 
 import java.io.IOException;
 
-import org.hibernate.Session;
 import org.apache.lucene.index.IndexReader;
 
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+
 /**
  * @author Emmanuel Bernard
  */
@@ -31,7 +33,9 @@
 		s = getSessions().openSession();
 		s.getTransaction().begin();
 		s.persist(
-				new Document( "Java Persistence with Hibernate", "Object/relational mapping with Hibernate", "blah blah blah" )
+				new Document(
+						"Java Persistence with Hibernate", "Object/relational mapping with Hibernate", "blah blah blah"
+				)
 		);
 		s.flush();
 		s.getTransaction().rollback();
@@ -40,8 +44,11 @@
 		assertEquals( "rollback() should not index", 3, getDocumentNumber() );
 
 		s = getSessions().openSession();
+		s.connection().setAutoCommit( true );  // www.hibernate.org/403.html
 		s.persist(
-				new Document( "Java Persistence with Hibernate", "Object/relational mapping with Hibernate", "blah blah blah" )
+				new Document(
+						"Java Persistence with Hibernate", "Object/relational mapping with Hibernate", "blah blah blah"
+				)
 		);
 		s.flush();
 		s.close();
@@ -60,8 +67,7 @@
 		}
 	}
 
-
 	protected Class[] getMappings() {
-		return new Class[]{Document.class};
+		return new Class[] { Document.class };
 	}
 }




More information about the hibernate-commits mailing list