[hibernate-commits] Hibernate SVN: r15594 - in search/trunk/src/test/org/hibernate/search/test: inheritance and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Nov 19 10:12:58 EST 2008


Author: hardy.ferentschik
Date: 2008-11-19 10:12:58 -0500 (Wed, 19 Nov 2008)
New Revision: 15594

Modified:
   search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
   search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
   search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
Log:
Little change in test setup which allows that all test can be run with file system based Lucene directory. setUp() will now ensure that the indexes are empty for every test.

Modified: search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java	2008-11-19 14:35:40 UTC (rev 15593)
+++ search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java	2008-11-19 15:12:58 UTC (rev 15594)
@@ -5,6 +5,7 @@
 
 import org.apache.lucene.analysis.StopAnalyzer;
 import org.apache.lucene.store.Directory;
+
 import org.hibernate.HibernateException;
 import org.hibernate.Transaction;
 import org.hibernate.event.PostInsertEventListener;
@@ -24,27 +25,28 @@
 
 /**
  * Base class for Hibernate Search unit tests.
- * 
+ *
  * @author Emmanuel Bernard
  */
 public abstract class SearchTestCase extends HANTestCase {
-	
-	private static final Logger log = LoggerFactory
-			.getLogger(SearchTestCase.class);
-	
+
+	private static final Logger log = org.hibernate.search.util.LoggerFactory.make();
+
 	private static File indexDir;
+
 	static {
-		String buildDir = System.getProperty("build.dir");
-		if (buildDir == null) {
+		String buildDir = System.getProperty( "build.dir" );
+		if ( buildDir == null ) {
 			buildDir = ".";
 		}
 		File current = new File( buildDir );
 		indexDir = new File( current, "indextemp" );
-		log.debug("Using {} as index directory.", indexDir.getAbsolutePath());
+		log.debug( "Using {} as index directory.", indexDir.getAbsolutePath() );
 	}
-	
+
 	protected void setUp() throws Exception {
 		buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+		ensureIndexesAreEmpty();
 	}
 
 	@SuppressWarnings("unchecked")
@@ -53,20 +55,27 @@
 	}
 
 	private FullTextIndexEventListener getLuceneEventListener() {
-        PostInsertEventListener[] listeners = ( (SessionFactoryImpl) getSessions() ).getEventListeners().getPostInsertEventListeners();
-        FullTextIndexEventListener listener = null;
-        //FIXME this sucks since we mandante the event listener use
-        for (PostInsertEventListener candidate : listeners) {
-            if (candidate instanceof FullTextIndexEventListener ) {
-                listener = (FullTextIndexEventListener) candidate;
-                break;
-            }
-        }
-        if (listener == null) throw new HibernateException("Lucene event listener not initialized");
-        return listener;
-    }
+		PostInsertEventListener[] listeners = ( ( SessionFactoryImpl ) getSessions() ).getEventListeners()
+				.getPostInsertEventListeners();
+		FullTextIndexEventListener listener = null;
+		//FIXME this sucks since we mandante the event listener use
+		for ( PostInsertEventListener candidate : listeners ) {
+			if ( candidate instanceof FullTextIndexEventListener ) {
+				listener = ( FullTextIndexEventListener ) candidate;
+				break;
+			}
+		}
+		if ( listener == null ) {
+			throw new HibernateException( "Lucene event listener not initialized" );
+		}
+		return listener;
+	}
 
 	protected void ensureIndexesAreEmpty() {
+		if ( "jms".equals( getCfg().getProperty( "hibernate.search.worker.backend" ) ) ) {
+			log.debug( "JMS based test. Skipping index emptying" );
+			return;
+		}
 		FullTextSession s = Search.getFullTextSession( openSession() );
 		Transaction tx;
 		tx = s.beginTransaction();
@@ -76,15 +85,17 @@
 			}
 		}
 		tx.commit();
+		s.close();
 	}
 
 	protected void configure(org.hibernate.cfg.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() );
 		cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
 		cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
 	}
-	
+
 	protected File getBaseIndexDir() {
 		return indexDir;
 	}

Modified: search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java	2008-11-19 14:35:40 UTC (rev 15593)
+++ search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java	2008-11-19 15:12:58 UTC (rev 15594)
@@ -22,7 +22,6 @@
 
 	protected void setUp() throws Exception {
 		super.setUp();
-		ensureIndexesAreEmpty();
 	}
 
 	public void testInheritance() throws Exception {

Modified: search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java	2008-11-19 14:35:40 UTC (rev 15593)
+++ search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java	2008-11-19 15:12:58 UTC (rev 15594)
@@ -166,7 +166,7 @@
 		assertEquals( "lastname incorrect", "Griffin", projection[1] );
 		assertEquals( "dept incorrect", "ITech", projection[2] );
 		assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
-		assertEquals( "SCORE incorrect", 1.0F, projection[4] );
+		assertTrue( "SCORE incorrect", projection[4] instanceof Float );
 		assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
 		assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
 		assertEquals( "legacy ID incorrect", 1000, projection[6] );
@@ -177,7 +177,7 @@
 		assertEquals( "lastname incorrect", "Whetbrook", projection[1] );
 		assertEquals( "dept incorrect", "ITech", projection[2] );
 		assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
-		assertEquals( "SCORE incorrect", 1.0F, projection[4] );
+		assertTrue( "SCORE incorrect", projection[4] instanceof Float );
 		assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
 		assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
 		assertEquals( "legacy ID incorrect", 1004, projection[6] );
@@ -188,7 +188,7 @@
 		assertEquals( "lastname incorrect", "Stejskal", projection[1] );
 		assertEquals( "dept incorrect", "ITech", projection[2] );
 		assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
-		assertEquals( "SCORE incorrect", 1.0F, projection[4] );
+		assertTrue( "SCORE incorrect", projection[4] instanceof Float );
 		assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
 		assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
 		assertEquals( "legacy ID incorrect", 1003, projection[6] );
@@ -218,7 +218,7 @@
 			counter++;
 			assertEquals( "dept incorrect", "ITech", projection[2] );
 			assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
-			assertEquals( "SCORE incorrect", 1.0F, projection[4] );
+			assertTrue( "SCORE incorrect", projection[4] instanceof Float );
 			assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
 			assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
 		}
@@ -258,7 +258,7 @@
 		assertEquals( "dept incorrect", "Accounting", projection[2] );
 		assertEquals( "THIS incorrect", "Jackson", ( ( Employee ) projection[3] ).getLastname() );
 		assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
-		assertEquals( "SCORE incorrect", 1.9162908F, projection[4] );
+		assertTrue( "SCORE incorrect", projection[4] instanceof Float );
 		assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
 		assertEquals( "DOCUMENT size incorrect", 5, ( ( Document ) projection[5] ).getFields().size() );
 		assertEquals( "ID incorrect", 1001, projection[6] );
@@ -279,7 +279,7 @@
 		assertTrue( "DOCUMENT incorrect", projection[0] instanceof Document );
 		assertEquals( "DOCUMENT size incorrect", 5, ( ( Document ) projection[0] ).getFields().size() );
 		assertEquals( "THIS incorrect", projection[1], s.get( Employee.class, ( Serializable ) projection[4] ) );
-		assertEquals( "SCORE incorrect", 1.9162908F, projection[2] );
+		assertTrue( "SCORE incorrect", projection[2] instanceof Float );
 		assertNull( "BOOST not removed", projection[3] );
 		assertEquals( "ID incorrect", 1001, projection[4] );
 		assertEquals( "id incorrect", 1001, projection[5] );
@@ -331,7 +331,7 @@
 		assertNotNull( projection );
 
 		assertTrue( "THIS incorrect", projection[0] instanceof Employee );
-		assertEquals( "SCORE incorrect", 1.9162908F, projection[1] );
+		assertTrue( "SCORE incorrect", projection[1] instanceof Float );
 		assertEquals( "last name incorrect", "Jackson", projection[3] );
 
 		//cleanup




More information about the hibernate-commits mailing list