private SearchIntegrator createSearchIntegrator(Class<?> clazz) { SearchConfigurationForTest configuration = new SearchConfigurationForTest() .addClass( clazz ); return integratorResource.create( configuration ); }
private ExtendedSearchIntegrator init(Class<?> providerClass, Class<?> ... entityClasses) { SearchConfigurationForTest cfg = new SearchConfigurationForTest(); for ( Class<?> entityClass : entityClasses ) { cfg.addClass( entityClass ); } cfg.addProperty( PROPERTY_PREFIX + ElasticsearchEnvironment.ANALYSIS_DEFINITION_PROVIDER, providerClass.getName() ); return integratorResource.create( cfg ); }
private ExtendedSearchIntegrator init(Class<?> providerClass, Class<?> ... entityClasses) { SearchConfigurationForTest cfg = new SearchConfigurationForTest(); for ( Class<?> entityClass : entityClasses ) { cfg.addClass( entityClass ); } cfg.addProperty( Environment.ANALYSIS_DEFINITION_PROVIDER, providerClass.getName() ); return integratorResource.create( cfg ); }
@Test(expected = SearchException.class) public void testAgainstInfiniteTypeLoop() throws Exception { final SearchConfiguration configuration = new HibernateManualConfiguration() .addClass( BrokenMammal.class ); try { integratorResource.create( configuration ); } catch (SearchException e) { assertThat( e.getMessage() ).contains( "HSEARCH000221" ); throw e; } }
@Test public void shouldWarnOnSortableFieldWithNonNormalizerAnalyzer() throws Exception { SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addClass( SampleWithTokenizedSortableField.class ); logged.expectMessage( "HSEARCH000345", "'" + SampleWithTokenizedSortableField.class.getName() + "'", "'sortableField'", "Sortable fields should be assigned normalizers" ); integratorResource.create( cfg ); }
@Test public void shouldNotBePossibleToHaveTwoAnalyzerDefsWithTheSameName() throws Exception { thrown.expect( SearchException.class ); SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addClass( SampleWithError.class ); integratorResource.create( cfg ); }
@Test public void shouldNotBePossibleToHaveTwoFilterDefsWithTheSameName() throws Exception { thrown.expect( SearchException.class ); HibernateManualConfiguration cfg = new HibernateManualConfiguration(); cfg.addClass( SampleWithError.class ); integratorResource.create( cfg ); }
private void init(IndexSchemaManagementStrategy strategy, Class<?> ... entityClasses) { SearchConfigurationForTest cfg = new SearchConfigurationForTest() .addClasses( entityClasses ) .addProperty( "hibernate.search.default." + ElasticsearchEnvironment.INDEX_SCHEMA_MANAGEMENT_STRATEGY, strategy.getExternalName() ); this.integrator = integratorResource.create( cfg ); }
@Test public void initializationSucceedsWithNotPackagedAnnotation() throws Exception { SearchConfigurationForTest config = new SearchConfigurationForTest() .addClasses( Entity.class, ClassWithNotPackagedAnnotation.class ); // Just check that initialization succeeds, and that the configuration was taken into account ExtendedSearchIntegrator integrator = integratorResource.create( config ); assertNotNull( integrator.getIndexedTypeDescriptor( TYPE_ID ) ); }
@Test public void shouldNotBePossibleToHaveTwoAnalyzerParametersWithTheSameName() throws Exception { thrown.expect( SearchException.class ); thrown.expectMessage( "Conflicting usage of @Parameter annotation for parameter name: 'maxGramSize'. Can't assign both value '15' and '1'" ); SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addClass( SampleWithAnalyzer.class ); integratorResource.create( cfg ); }
@Test public void shouldNotBePossibleToHaveTwoNormalizerParametersWithTheSameName() throws Exception { thrown.expect( SearchException.class ); thrown.expectMessage( "Conflicting usage of @Parameter annotation for parameter name: 'pattern'. Can't assign both value '[[:digit:]]' and '[[:digit:]]+'" ); SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addClass( SampleWithNormalizer.class ); integratorResource.create( cfg ); }
@Test public void testGetIndexedTypesNoTypeIndexed() { SearchConfigurationForTest cfg = getManualConfiguration(); SearchIntegrator si = integratorResource.create( cfg ); IndexedTypeSet indexedClasses = si.getIndexedTypeIdentifiers(); assertEquals( "Wrong number of indexed entities", 0, indexedClasses.size() ); }
@Test public void testDefaultWorker() { SearchIntegrator searchIntegrator = integratorResource.create( manualConfiguration ); assertNotNull( "Worker should have been created", searchIntegrator.getWorker() ); assertTrue( "Wrong worker class", searchIntegrator.getWorker() instanceof PerTransactionWorker ); }
@Test public void testCustomWorkerWithProperties() { manualConfiguration.addProperty( "hibernate.search.worker.scope", CustomWorkerExpectingFooAndBar.class.getName() ); manualConfiguration.addProperty( "hibernate.search.worker.foo", "foo" ); manualConfiguration.addProperty( "hibernate.search.worker.bar", "bar" ); SearchIntegrator searchIntegrator = integratorResource.create( manualConfiguration ); assertNotNull( "Worker should have been created", searchIntegrator.getWorker() ); assertTrue( "Wrong worker class", searchIntegrator.getWorker() instanceof CustomWorkerExpectingFooAndBar ); }
@Test public void invalid_notAClass() { SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addClass( CustomAnalyzerEntity.class ); cfg.addProperty( PROPERTY_PREFIX + ElasticsearchEnvironment.ANALYSIS_DEFINITION_PROVIDER, "invalidValue" ); thrown.expect( SearchException.class ); thrown.expectMessage( "HSEARCH400075" ); integratorResource.create( cfg ); }
@Test public void invalid() { SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addClass( CustomAnalyzerEntity.class ); cfg.addProperty( Environment.ANALYSIS_DEFINITION_PROVIDER, "invalidValue" ); thrown.expect( SearchException.class ); thrown.expectMessage( "HSEARCH000329" ); integratorResource.create( cfg ); }
@Test public void testExplicitTransactionalWorker() { manualConfiguration.addProperty( "hibernate.search.worker.scope", "transaction" ); SearchIntegrator searchIntegrator = integratorResource.create( manualConfiguration ); assertNotNull( "Worker should have been created", searchIntegrator.getWorker() ); assertTrue( "Wrong worker class", searchIntegrator.getWorker() instanceof PerTransactionWorker ); }
@Test public void testGetTypeDescriptorForUnindexedType() { SearchConfigurationForTest cfg = getManualConfiguration(); SearchIntegrator si = integratorResource.create( cfg ); IndexedTypeDescriptor indexedTypeDescriptor = si.getIndexedTypeDescriptor( new PojoIndexedTypeIdentifier( Foo.class ) ); assertNotNull( indexedTypeDescriptor ); assertFalse( indexedTypeDescriptor.isIndexed() ); }
@Test @Category(SkipOnElasticsearch.class) // This test only works with locally-executed normalizers public void shouldWarnOnTokenizingNormalizerDefinition() throws Exception { SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addClass( SampleWithTokenizingNormalizerDefinition.class ); integrator = integratorResource.create( cfg ); logged.expectMessage( "HSEARCH000344", "'tokenizing_normalizer'", "3 tokens" ); SampleWithTokenizingNormalizerDefinition entity = new SampleWithTokenizingNormalizerDefinition(); entity.id = 1; entity.description = "to be tokenized"; helper.add( entity, entity.id ); }
protected MutableSearchFactory getMutableSearchFactoryWithSingleEntity(SearchConfigurationForTest cfg) { SearchMapping mapping = new SearchMapping(); mapping .entity( Document.class ).indexed().indexName( "index1" ) .property( "id", ElementType.FIELD ).documentId() .property( "title", ElementType.FIELD ).field() ; cfg.setProgrammaticMapping( mapping ); cfg.addClass( Document.class ); return (MutableSearchFactory) integratorResource.create( cfg ); }