Author: epbernard
Date: 2010-06-30 09:39:01 -0400 (Wed, 30 Jun 2010)
New Revision: 19862
Added:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ManualConfiguration.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ManualTransactionContext.java
Removed:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
Log:
Share test harness for manual HSearch usage
Share manual configuration and manual transaction context demarcation code
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2010-06-30
13:38:13 UTC (rev 19861)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2010-06-30
13:39:01 UTC (rev 19862)
@@ -60,7 +60,7 @@
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.test.analyzer.inheritance.ISOLatin1Analyzer;
-import org.hibernate.search.test.id.providedId.ManualTransactionContext;
+import org.hibernate.search.test.util.ManualTransactionContext;
import org.hibernate.search.util.LoggerFactory;
import org.slf4j.Logger;
Deleted:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java 2010-06-30
13:38:13 UTC (rev 19861)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java 2010-06-30
13:39:01 UTC (rev 19862)
@@ -1,63 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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.search.test.id.providedId;
-
-import java.util.List;
-import java.util.ArrayList;
-import javax.transaction.Synchronization;
-import javax.transaction.Status;
-
-import org.hibernate.search.backend.TransactionContext;
-
-/**
- * @author Emmanuel Bernard
- */
-public class ManualTransactionContext implements TransactionContext {
- private boolean progress = true;
- private List<Synchronization> syncs = new ArrayList<Synchronization>();
-
- public boolean isTransactionInProgress() {
- return progress;
- }
-
- public Object getTransactionIdentifier() {
- return this;
- }
-
- public void registerSynchronization(Synchronization synchronization) {
- syncs.add(synchronization);
- }
-
- public void end() {
- this.progress = false;
- for (Synchronization sync : syncs) {
- sync.beforeCompletion();
- }
-
- for (Synchronization sync : syncs) {
- sync.afterCompletion( Status.STATUS_COMMITTED );
- }
- }
-}
Modified:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2010-06-30
13:38:13 UTC (rev 19861)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2010-06-30
13:39:01 UTC (rev 19862)
@@ -24,17 +24,22 @@
*/
package org.hibernate.search.test.id.providedId;
+import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TopDocs;
+import org.hibernate.search.Environment;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkType;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.impl.SearchFactoryBuilder;
import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.store.RAMDirectoryProvider;
import org.hibernate.search.test.SearchTestCase;
+import org.hibernate.search.test.util.ManualTransactionContext;
+import org.hibernate.search.test.util.ManualConfiguration;
/**
* @author Navin Surtani
@@ -42,7 +47,14 @@
public class ProvidedIdTest extends junit.framework.TestCase {
public void testProvidedId() throws Exception {
- SearchFactoryImplementor sf = new SearchFactoryBuilder().configuration( new
StandaloneConf() ).buildSearchFactory();
+ final ManualConfiguration configuration = new ManualConfiguration()
+ .addClass( ProvidedIdPerson.class )
+ .addClass( ProvidedIdPersonSub.class )
+ .addProperty( "hibernate.search.default.directory_provider",
RAMDirectoryProvider.class.getName() )
+ .addProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() )
+ .addProperty( "hibernate.search.default.transaction.merge_factor",
"100" )
+ .addProperty( "hibernate.search.default.batch.max_buffered_docs",
"1000" );
+ SearchFactoryImplementor sf = new SearchFactoryBuilder().configuration( configuration
).buildSearchFactory();
ProvidedIdPerson person1 = new ProvidedIdPerson();
person1.setName( "Big Goat" );
@@ -71,7 +83,7 @@
Query luceneQuery = parser.parse( "Goat" );
//we cannot use FTQuery because @ProvidedId does not provide the getter id and
Hibernate Hsearch Query extension
- //needs it. So we use plain Lucene
+ //needs it. So we use plain Lucene
//we know there is only one DP
DirectoryProvider provider = sf
Deleted:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java 2010-06-30
13:38:13 UTC (rev 19861)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java 2010-06-30
13:39:01 UTC (rev 19862)
@@ -1,82 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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.search.test.id.providedId;
-
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Map;
-import java.util.HashMap;
-
-import org.apache.lucene.analysis.StopAnalyzer;
-
-import org.hibernate.search.cfg.SearchConfiguration;
-import org.hibernate.search.cfg.SearchMapping;
-import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.search.Environment;
-import org.hibernate.annotations.common.reflection.ReflectionManager;
-
-/**
- * @author Emmanuel Bernard
- */
-public class StandaloneConf implements SearchConfiguration {
- final Map<String,Class<?>> classes;
- final Properties properties;
-
- public StandaloneConf() {
- classes = new HashMap<String,Class<?>>(2);
- classes.put( ProvidedIdPerson.class.getName(), ProvidedIdPerson.class );
- classes.put( ProvidedIdPersonSub.class.getName(), ProvidedIdPersonSub.class );
-
- properties = new Properties( );
- properties.setProperty( "hibernate.search.default.directory_provider",
RAMDirectoryProvider.class.getName() );
- properties.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- properties.setProperty( "hibernate.search.default.transaction.merge_factor",
"100" );
- properties.setProperty( "hibernate.search.default.batch.max_buffered_docs",
"1000" );
- }
-
- public Iterator<Class<?>> getClassMappings() {
- return classes.values().iterator();
- }
-
- public Class<?> getClassMapping(String name) {
- return classes.get( name );
- }
-
- public String getProperty(String propertyName) {
- return properties.getProperty( propertyName );
- }
-
- public Properties getProperties() {
- return properties;
- }
-
- public ReflectionManager getReflectionManager() {
- return null;
- }
-
- public SearchMapping getProgrammaticMapping() {
- return null;
- }
-}
Copied:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ManualConfiguration.java
(from rev 19861,
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/StandaloneConf.java)
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ManualConfiguration.java
(rev 0)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ManualConfiguration.java 2010-06-30
13:39:01 UTC (rev 19862)
@@ -0,0 +1,84 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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.search.test.util;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.hibernate.search.cfg.SearchConfiguration;
+import org.hibernate.search.cfg.SearchMapping;
+import org.hibernate.annotations.common.reflection.ReflectionManager;
+
+/**
+ * Manually defines the configuration
+ * Classes and properties are the only implemented options at the moment
+ *
+ * @author Emmanuel Bernard
+ */
+public class ManualConfiguration implements SearchConfiguration {
+ final Map<String,Class<?>> classes;
+ final Properties properties;
+
+ public ManualConfiguration() {
+ classes = new HashMap<String,Class<?>>();
+ properties = new Properties( );
+ }
+
+ public ManualConfiguration addProperty(String key , String value) {
+ properties.setProperty( key, value );
+ return this;
+ }
+
+ public ManualConfiguration addClass(Class<?> indexed) {
+ classes.put( indexed.getName(), indexed );
+ return this;
+ }
+
+ public Iterator<Class<?>> getClassMappings() {
+ return classes.values().iterator();
+ }
+
+ public Class<?> getClassMapping(String name) {
+ return classes.get( name );
+ }
+
+ public String getProperty(String propertyName) {
+ return properties.getProperty( propertyName );
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public ReflectionManager getReflectionManager() {
+ return null;
+ }
+
+ public SearchMapping getProgrammaticMapping() {
+ return null;
+ }
+}
Copied:
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ManualTransactionContext.java
(from rev 19861,
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/providedId/ManualTransactionContext.java)
===================================================================
---
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ManualTransactionContext.java
(rev 0)
+++
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ManualTransactionContext.java 2010-06-30
13:39:01 UTC (rev 19862)
@@ -0,0 +1,63 @@
+/* $Id$
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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.search.test.util;
+
+import java.util.List;
+import java.util.ArrayList;
+import javax.transaction.Synchronization;
+import javax.transaction.Status;
+
+import org.hibernate.search.backend.TransactionContext;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ManualTransactionContext implements TransactionContext {
+ private boolean progress = true;
+ private List<Synchronization> syncs = new ArrayList<Synchronization>();
+
+ public boolean isTransactionInProgress() {
+ return progress;
+ }
+
+ public Object getTransactionIdentifier() {
+ return this;
+ }
+
+ public void registerSynchronization(Synchronization synchronization) {
+ syncs.add(synchronization);
+ }
+
+ public void end() {
+ this.progress = false;
+ for (Synchronization sync : syncs) {
+ sync.beforeCompletion();
+ }
+
+ for (Synchronization sync : syncs) {
+ sync.afterCompletion( Status.STATUS_COMMITTED );
+ }
+ }
+}