Author: sannegrinovero
Date: 2009-07-01 18:38:30 -0400 (Wed, 01 Jul 2009)
New Revision: 16989
Added:
search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
Modified:
search/trunk/src/main/java/org/hibernate/search/backend/WorkerFactory.java
search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
search/trunk/src/main/java/org/hibernate/search/impl/InitContext.java
search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
search/trunk/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
Log:
HSEARCH-384 improve error messages for loading plugins and add consistency to the
performed checks
Modified: search/trunk/src/main/java/org/hibernate/search/backend/WorkerFactory.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/WorkerFactory.java 2009-07-01
13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/backend/WorkerFactory.java 2009-07-01
22:38:30 UTC (rev 16989)
@@ -5,11 +5,10 @@
import java.util.Properties;
import org.hibernate.search.Environment;
-import org.hibernate.search.SearchException;
import org.hibernate.search.backend.impl.TransactionalWorker;
import org.hibernate.search.cfg.SearchConfiguration;
import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.util.ReflectHelper;
+import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.StringHelper;
/**
@@ -41,21 +40,11 @@
worker = new TransactionalWorker();
}
else {
- try {
- Class workerClass = ReflectHelper.classForName( impl, WorkerFactory.class );
- worker = (Worker) workerClass.newInstance();
- }
- catch (ClassNotFoundException e) {
- throw new SearchException( "Unable to find worker class: " + impl, e );
- }
- catch (IllegalAccessException e) {
- throw new SearchException( "Unable to instanciate worker class: " + impl, e
);
- }
- catch (InstantiationException e) {
- throw new SearchException( "Unable to instanciate worker class: " + impl, e
);
- }
+ worker = PluginLoader.instanceFromName( Worker.class,
+ impl, WorkerFactory.class, "worker" );
}
worker.initialize( props, searchFactoryImplementor );
return worker;
}
+
}
Modified:
search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
---
search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-07-01
13:30:20 UTC (rev 16988)
+++
search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2009-07-01
22:38:30 UTC (rev 16989)
@@ -12,10 +12,8 @@
import org.slf4j.Logger;
import org.hibernate.Hibernate;
-import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
import org.hibernate.search.Environment;
-import org.hibernate.search.SearchException;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.QueueingProcessor;
@@ -30,6 +28,7 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.engine.DocumentBuilderContainedEntity;
import org.hibernate.search.util.LoggerFactory;
+import org.hibernate.search.util.PluginLoader;
/**
* Batch work until {@link #performWorks} is called.
@@ -88,19 +87,8 @@
backendQueueProcessorFactory = new BlackHoleBackendQueueProcessorFactory();
}
else {
- try {
- Class<?> processorFactoryClass = ReflectHelper.classForName( backend,
BatchedQueueingProcessor.class );
- backendQueueProcessorFactory = ( BackendQueueProcessorFactory )
processorFactoryClass.newInstance();
- }
- catch ( ClassNotFoundException e ) {
- throw new SearchException( "Unable to find processor class: " + backend, e
);
- }
- catch ( IllegalAccessException e ) {
- throw new SearchException( "Unable to instanciate processor class: " +
backend, e );
- }
- catch ( InstantiationException e ) {
- throw new SearchException( "Unable to instanciate processor class: " +
backend, e );
- }
+ backendQueueProcessorFactory = PluginLoader.instanceFromName(
BackendQueueProcessorFactory.class,
+ backend, BatchedQueueingProcessor.class, "processor" );
}
backendQueueProcessorFactory.initialize( properties, searchFactoryImplementor );
searchFactoryImplementor.setBackendQueueProcessorFactory( backendQueueProcessorFactory
);
Modified: search/trunk/src/main/java/org/hibernate/search/impl/InitContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/InitContext.java 2009-07-01
13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/impl/InitContext.java 2009-07-01
22:38:30 UTC (rev 16989)
@@ -16,7 +16,11 @@
import org.hibernate.search.annotations.AnalyzerDef;
import org.hibernate.search.cfg.SearchConfiguration;
import org.hibernate.search.util.DelegateNamedAnalyzer;
+import org.hibernate.search.util.LoggerFactory;
+import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.ReflectHelper;
+import org.hibernate.util.StringHelper;
+import org.slf4j.Logger;
/**
* Provides access to some default configuration settings (eg default
<code>Analyzer</code> or default
@@ -27,6 +31,9 @@
* @author Hardy Ferentschik
*/
public class InitContext {
+
+ private static final Logger log = LoggerFactory.make();
+
private final Map<String, AnalyzerDef> analyzerDefs = new HashMap<String,
AnalyzerDef>();
private final List<DelegateNamedAnalyzer> lazyAnalyzers = new
ArrayList<DelegateNamedAnalyzer>();
private final Analyzer defaultAnalyzer;
@@ -69,26 +76,18 @@
*/
private Analyzer initAnalyzer(SearchConfiguration cfg) {
Class analyzerClass;
- String analyzerClassName = cfg.getProperty( Environment.ANALYZER_CLASS);
- if (analyzerClassName != null) {
+ String analyzerClassName = cfg.getProperty( Environment.ANALYZER_CLASS );
+ if ( analyzerClassName != null ) {
try {
- analyzerClass = ReflectHelper.classForName(analyzerClassName);
+ analyzerClass = ReflectHelper.classForName( analyzerClassName );
} catch (Exception e) {
return buildLazyAnalyzer( analyzerClassName );
}
} else {
analyzerClass = StandardAnalyzer.class;
}
- // Initialize analyzer
- Analyzer defaultAnalyzer;
- try {
- defaultAnalyzer = (Analyzer) analyzerClass.newInstance();
- } catch (ClassCastException e) {
- throw new SearchException("Lucene analyzer does not implement " +
Analyzer.class.getName() + ": "
- + analyzerClassName, e);
- } catch (Exception e) {
- throw new SearchException("Failed to instantiate lucene analyzer with type "
+ analyzerClassName, e);
- }
+ Analyzer defaultAnalyzer = PluginLoader.instanceFromClass( Analyzer.class,
+ analyzerClass, "Lucene analyzer" );
return defaultAnalyzer;
}
@@ -99,36 +98,17 @@
* @return returns the default similarity class.
*/
private Similarity initSimilarity(SearchConfiguration cfg) {
- Class similarityClass;
String similarityClassName = cfg.getProperty(Environment.SIMILARITY_CLASS);
- if (similarityClassName != null) {
- try {
- similarityClass = ReflectHelper.classForName(similarityClassName);
- } catch (Exception e) {
- throw new SearchException("Lucene Similarity class '" +
similarityClassName + "' defined in property '"
- + Environment.SIMILARITY_CLASS + "' could not be found.", e);
- }
+ Similarity defaultSimilarity;
+ if ( StringHelper.isEmpty( similarityClassName ) ) {
+ defaultSimilarity = Similarity.getDefault();
}
else {
- similarityClass = null;
+ defaultSimilarity = PluginLoader.instanceFromName(
+ Similarity.class, similarityClassName, InitContext.class, "default
similarity" );
}
-
- // Initialize similarity
- if ( similarityClass == null ) {
- return Similarity.getDefault();
- }
- else {
- Similarity defaultSimilarity;
- try {
- defaultSimilarity = (Similarity) similarityClass.newInstance();
- } catch (ClassCastException e) {
- throw new SearchException("Lucene similarity does not extend " +
Similarity.class.getName() + ": "
- + similarityClassName, e);
- } catch (Exception e) {
- throw new SearchException("Failed to instantiate lucene similarity with type
" + similarityClassName, e);
- }
- return defaultSimilarity;
- }
+ log.debug( "Using default similarity implementation: {}",
defaultSimilarity.getClass().getName() );
+ return defaultSimilarity;
}
public Analyzer getDefaultAnalyzer() {
@@ -176,7 +156,7 @@
// SolrAnalyzerBuilder references Solr classes.
// InitContext should not (directly or indirectly) load a Solr class to avoid hard
dependency
// unless necessary
- // the curent mecanism (check sor class presence and call SolrAnalyzerBuilder if
needed
+ // the current mechanism (check Solr class presence and call SolrAnalyzerBuilder if
needed
// seems to be sufficient on Apple VM (derived from Sun's
// TODO check on other VMs and be ready for a more reflexive approach
return SolrAnalyzerBuilder.buildAnalyzer( analyzerDef );
Modified: search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-07-01
13:30:20 UTC (rev 16988)
+++ search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-07-01
22:38:30 UTC (rev 16989)
@@ -24,7 +24,6 @@
import org.hibernate.annotations.common.reflection.MetadataProvider;
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
-import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
import org.hibernate.search.Environment;
import org.hibernate.search.SearchException;
@@ -64,6 +63,7 @@
import org.hibernate.search.store.DirectoryProviderFactory;
import org.hibernate.search.store.optimization.OptimizerStrategy;
import org.hibernate.search.util.LoggerFactory;
+import org.hibernate.search.util.PluginLoader;
/**
* @author Emmanuel Bernard
@@ -489,20 +489,8 @@
filterCachingStrategy = new MRUFilterCachingStrategy();
}
else {
- try {
- Class filterCachingStrategyClass = ReflectHelper
- .classForName( impl, SearchFactoryImpl.class );
- filterCachingStrategy = ( FilterCachingStrategy )
filterCachingStrategyClass.newInstance();
- }
- catch ( ClassNotFoundException e ) {
- throw new SearchException( "Unable to find filterCachingStrategy class: " +
impl, e );
- }
- catch ( IllegalAccessException e ) {
- throw new SearchException( "Unable to instantiate filterCachingStrategy class:
" + impl, e );
- }
- catch ( InstantiationException e ) {
- throw new SearchException( "Unable to instantiate filterCachingStrategy class:
" + impl, e );
- }
+ filterCachingStrategy = PluginLoader.instanceFromName( FilterCachingStrategy.class,
+ impl, SearchFactoryImpl.class, "filterCachingStrategy" );
}
filterCachingStrategy.initialize( properties );
return filterCachingStrategy;
@@ -556,20 +544,8 @@
batchBackend = new LuceneBatchBackend();
}
else {
- try {
- Class batchBackendClass = ReflectHelper
- .classForName( impl, SearchFactoryImpl.class );
- batchBackend = ( BatchBackend ) batchBackendClass.newInstance();
- }
- catch ( ClassNotFoundException e ) {
- throw new SearchException( "Unable to find batchbackend implementation class:
" + impl, e );
- }
- catch ( IllegalAccessException e ) {
- throw new SearchException( "Unable to instantiate batchbackend class: " +
impl, e );
- }
- catch ( InstantiationException e ) {
- throw new SearchException( "Unable to instantiate batchbackend class: " +
impl, e );
- }
+ batchBackend = PluginLoader.instanceFromName( BatchBackend.class, impl,
SearchFactoryImpl.class,
+ "batchbackend" );
}
Properties batchBackendConfiguration = new MaskedProperty(
this.configurationProperties, Environment.BATCH_BACKEND );
Modified:
search/trunk/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java
===================================================================
---
search/trunk/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java 2009-07-01
13:30:20 UTC (rev 16988)
+++
search/trunk/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java 2009-07-01
22:38:30 UTC (rev 16989)
@@ -5,10 +5,9 @@
import java.util.Properties;
import org.hibernate.search.Environment;
-import org.hibernate.search.SearchException;
import org.hibernate.search.cfg.SearchConfiguration;
import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.util.ReflectHelper;
+import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.StringHelper;
/**
@@ -47,19 +46,8 @@
readerProvider = new SharingBufferReaderProvider();
}
else {
- try {
- Class readerProviderClass = ReflectHelper.classForName( impl,
ReaderProviderFactory.class );
- readerProvider = (ReaderProvider) readerProviderClass.newInstance();
- }
- catch (ClassNotFoundException e) {
- throw new SearchException( "Unable to find readerProvider class: " + impl,
e );
- }
- catch (IllegalAccessException e) {
- throw new SearchException( "Unable to instanciate readerProvider class: " +
impl, e );
- }
- catch (InstantiationException e) {
- throw new SearchException( "Unable to instanciate readerProvider class: " +
impl, e );
- }
+ readerProvider = PluginLoader.instanceFromName( ReaderProvider.class, impl,
+ ReaderProviderFactory.class, "readerProvider" );
}
readerProvider.initialize( props, searchFactoryImplementor );
return readerProvider;
Modified:
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
===================================================================
---
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java 2009-07-01
13:30:20 UTC (rev 16988)
+++
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java 2009-07-01
22:38:30 UTC (rev 16989)
@@ -18,7 +18,7 @@
import org.hibernate.search.store.optimization.IncrementalOptimizerStrategy;
import org.hibernate.search.store.optimization.NoOpOptimizerStrategy;
import org.hibernate.search.store.optimization.OptimizerStrategy;
-import org.hibernate.util.ReflectHelper;
+import org.hibernate.search.util.PluginLoader;
import org.hibernate.util.StringHelper;
/**
@@ -41,7 +41,6 @@
public class DirectoryProviderFactory {
private final List<DirectoryProvider<?>> providers = new
ArrayList<DirectoryProvider<?>>();
- private static final String DEFAULT_DIRECTORY_PROVIDER =
FSDirectoryProvider.class.getName();
private static final String SHARDING_STRATEGY = "sharding_strategy";
private static final String NBR_OF_SHARDS = SHARDING_STRATEGY +
".nbr_of_shards";
@@ -77,25 +76,8 @@
}
}
else {
- try {
- Class shardigStrategyClass = ReflectHelper.classForName( shardingStrategyName,
this.getClass() );
- shardingStrategy = (IndexShardingStrategy) shardigStrategyClass.newInstance();
- }
- catch (ClassNotFoundException e) {
- throw new SearchException( "Unable to find IndexShardingStrategy class " +
shardingStrategyName + " for " + directoryProviderName, e );
- }
- catch (IllegalAccessException e) {
- throw new SearchException( "Unable to create instance of IndexShardingStrategy
class " + shardingStrategyName
- + " Be sure to have a no-arg constructor", e );
- }
- catch (InstantiationException e) {
- throw new SearchException( "Unable to create instance of IndexShardingStrategy
class " + shardingStrategyName
- + " Be sure to have a no-arg constructor", e );
- }
- catch (ClassCastException e) {
- throw new SearchException( "ShardingStrategy class does not implement
IndexShardingStrategy: "
- + shardingStrategyName, e );
- }
+ shardingStrategy = PluginLoader.instanceFromName( IndexShardingStrategy.class,
+ shardingStrategyName, DirectoryProviderFactory.class,
"IndexShardingStrategy" );
}
shardingStrategy.initialize(
new MaskedProperty( indexProps[0], SHARDING_STRATEGY ), providers );
@@ -111,20 +93,14 @@
private DirectoryProvider<?> createDirectoryProvider(String directoryProviderName,
Properties indexProps,
Class entity, SearchFactoryImplementor searchFactoryImplementor) {
String className = indexProps.getProperty( "directory_provider" );
+ DirectoryProvider<?> provider;
if ( StringHelper.isEmpty( className ) ) {
- className = DEFAULT_DIRECTORY_PROVIDER;
+ provider = new FSDirectoryProvider();
}
- DirectoryProvider<?> provider;
- try {
- @SuppressWarnings( "unchecked" )
- Class<DirectoryProvider> directoryClass = ReflectHelper.classForName(
- className, DirectoryProviderFactory.class
- );
- provider = directoryClass.newInstance();
+ else {
+ provider = PluginLoader.instanceFromName( DirectoryProvider.class, className,
+ DirectoryProviderFactory.class, "directory provider" );
}
- catch (Exception e) {
- throw new SearchException( "Unable to instantiate directory provider: " +
className, e );
- }
try {
provider.initialize( directoryProviderName, indexProps, searchFactoryImplementor );
}
Added: search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
(rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java 2009-07-01
22:38:30 UTC (rev 16989)
@@ -0,0 +1,81 @@
+package org.hibernate.search.util;
+
+import org.hibernate.search.SearchException;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ *
+ * @author Sanne Grinovero
+ *
+ * @param <T>
+ */
+public class PluginLoader {
+
+ public static <T> T instanceFromName(Class<T> targetSuperType, String
classNameToLoad,
+ Class<?> caller, String componentDescription) {
+ final Class<?> clazzDef;
+ try {
+ clazzDef = ReflectHelper.classForName( classNameToLoad, caller );
+ } catch (ClassNotFoundException e) {
+ throw new SearchException( "Unable to find " + componentDescription +
+ " implementation class: " + classNameToLoad, e );
+ }
+ return instanceFromClass( targetSuperType, clazzDef, componentDescription );
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T instanceFromClass(Class<T> targetSuperType,
Class<?> classToLoad, String componentDescription) {
+ checkClassType( classToLoad, componentDescription );
+ checkHasValidconstructor( classToLoad, componentDescription );
+ Object instance;
+ try {
+ instance = classToLoad.newInstance();
+ }
+ catch ( IllegalAccessException e ) {
+ throw new SearchException(
+ "Unable to instantiate " + componentDescription + " class: " +
classToLoad.getName() +
+ ". Class or constructor is not accessible.", e );
+ }
+ catch ( InstantiationException e ) {
+ throw new SearchException(
+ "Unable to instantiate " + componentDescription + " class: " +
classToLoad.getName() +
+ ". Verify it has a no-args public constructor and is not abstract.", e );
+ }
+ if ( ! targetSuperType.isInstance( instance ) ) {
+ // have a proper error message according to interface implementation or subclassing
+ if ( targetSuperType.isInterface() ) {
+ throw new SearchException(
+ "Wrong configuration of " + componentDescription + ": class " +
classToLoad.getName()
+ + " does not implement interface " + targetSuperType.getName() );
+ }
+ else {
+ throw new SearchException(
+ "Wrong configuration of " + componentDescription + ": class " +
classToLoad.getName()
+ + " is not a subtype of " + targetSuperType.getName() );
+ }
+ }
+ else {
+ return (T) instance;
+ }
+ }
+
+ private static void checkClassType(Class<?> classToLoad, String
componentDescription) {
+ if ( classToLoad.isInterface() ) {
+ throw new SearchException( classToLoad.getName() + " defined for component "
+ componentDescription
+ + " is an interface: implementation required." );
+ }
+ }
+
+ public static void checkHasValidconstructor(Class<?> classToLoad, String
componentDescription) {
+ try {
+ classToLoad.getConstructor();
+ } catch (SecurityException e) {
+ throw new SearchException( classToLoad.getName() + " defined for component "
+ componentDescription
+ + " could not be instantiated because of a security manager error", e );
+ } catch (NoSuchMethodException e) {
+ throw new SearchException( classToLoad.getName() + " defined for component "
+ componentDescription
+ + " is missing a no-arguments constructor" );
+ }
+ }
+
+}
Property changes on:
search/trunk/src/main/java/org/hibernate/search/util/PluginLoader.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
(rev 0)
+++
search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java 2009-07-01
22:38:30 UTC (rev 16989)
@@ -0,0 +1,91 @@
+// $Id$
+package org.hibernate.search.test.util;
+
+import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.Similarity;
+import org.hibernate.Session;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.impl.batchlucene.BatchBackend;
+import org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend;
+import org.hibernate.search.impl.FullTextSessionImpl;
+import org.hibernate.search.util.PluginLoader;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for PluginLoader, also verifying it throws easy to understand exceptions
+ *
+ * @author Sanne Grinovero
+ */
+public class PluginLoaderTest extends TestCase {
+
+ public void testInstanceFromName() {
+ BatchBackend batchBackend = PluginLoader.instanceFromName(BatchBackend.class,
LuceneBatchBackend.class.getName(), getClass(), "Lucene batch backend");
+ assertNotNull( batchBackend );
+ assertTrue( batchBackend.getClass().equals( LuceneBatchBackend.class ) );
+
+ try {
+ PluginLoader.instanceFromName( BackendQueueProcessorFactory.class,
"HeyThisClassIsNotThere", getClass(), "backend" );
+ fail( "was expecting a SearchException" );
+ }
+ catch (Exception e) {
+ assertEquals( e.getClass(), SearchException.class );
+ assertEquals( "Unable to find backend implementation class:
HeyThisClassIsNotThere", e.getMessage() );
+ }
+ }
+
+ public void testInstanceFromClass() {
+ //testing for interface implementation:
+ BatchBackend batchBackend = PluginLoader.instanceFromClass( BatchBackend.class,
LuceneBatchBackend.class, "Lucene batch backend" );
+ assertNotNull( batchBackend );
+ assertTrue( batchBackend.getClass().equals( LuceneBatchBackend.class ) );
+
+ //testing for subclasses:
+ Similarity sim = PluginLoader.instanceFromClass( Similarity.class,
DefaultSimilarity.class, "default similarity" );
+ assertNotNull( sim );
+ assertTrue( sim.getClass().equals( DefaultSimilarity.class ) );
+
+ //testing proper error messages:
+ wrappingTestFromClass(
+ "Wrong configuration of Lucene batch backend: class " +
+ "org.hibernate.search.test.util.PluginLoaderTest does not implement " +
+ "interface org.hibernate.search.backend.impl.batchlucene.BatchBackend",
+ BatchBackend.class, PluginLoaderTest.class, "Lucene batch backend"
+ );
+ wrappingTestFromClass(
+ "org.hibernate.search.impl.FullTextSessionImpl defined for component session
" +
+ "is missing a no-arguments constructor",
+ FullTextSession.class, FullTextSessionImpl.class, "session"
+ );
+ wrappingTestFromClass(
+ "org.hibernate.Session defined for component session is an interface:
implementation required.",
+ FullTextSession.class, Session.class, "session"
+ );
+ wrappingTestFromClass(
+ "Wrong configuration of default similarity: " +
+ "class org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend "
+
+ "is not a subtype of org.apache.lucene.search.Similarity",
+ Similarity.class, LuceneBatchBackend.class, "default similarity"
+ );
+ wrappingTestFromClass(
+ "Unable to instantiate default similarity class:
org.apache.lucene.search.Similarity. " +
+ "Verify it has a no-args public constructor and is not abstract.",
+ Similarity.class, Similarity.class, "default similarity"
+ );
+ }
+
+ private void wrappingTestFromClass(String expectedErrorMessage, Class<?> interf,
Class<?> impl, String componentName) {
+ try {
+ PluginLoader.instanceFromClass( interf, impl, componentName );
+ fail( "was expecting a SearchException" );
+ }
+ catch (Exception e) {
+ assertEquals( e.getClass(), SearchException.class );
+ assertEquals( expectedErrorMessage, e.getMessage() );
+ }
+ }
+
+}
+
Property changes on:
search/trunk/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
___________________________________________________________________
Name: svn:keywords
+ Id