Package org.hibernate.search.test.util

Examples of org.hibernate.search.test.util.FullTextSessionBuilder


public class ResourceNotFoundMessageTest {

  @Test
  public void testIllegalAnalyzerDefinition() {
    try {
      new FullTextSessionBuilder()
          .addAnnotatedClass( User.class )
          .setProperty( Environment.MODEL_MAPPING, ResourceNotFoundMessageTest.class.getName() )
          .build();
      Assert.fail( "should not reach this" );
    }
View Full Code Here


public class CustomLockProviderTest {

  @Test
  public void testUseOfCustomLockingFactory() {
    assertNull( CustomLockFactoryProvider.optionValue );
    FullTextSessionBuilder builder = new FullTextSessionBuilder();
    builder
      .addAnnotatedClass( SnowStorm.class )
      .setProperty( "hibernate.search.default.locking_option", "somethingHere" )
      .setProperty( "hibernate.search.default.locking_strategy",
          "org.hibernate.search.test.directoryProvider.CustomLockFactoryProvider" )
      .build();
    builder.close();
    assertEquals( "somethingHere", CustomLockFactoryProvider.optionValue );
    CustomLockFactoryProvider.optionValue = null;
  }
View Full Code Here

    CustomLockFactoryProvider.optionValue = null;
  }

  @Test
  public void testFailOnNonExistentLockingFactory() {
    FullTextSessionBuilder builder = new FullTextSessionBuilder();
    try {
      builder
        .addAnnotatedClass( SnowStorm.class )
        .setProperty( "hibernate.search.default.locking_option", "somethingHere" )
        .setProperty( "hibernate.search.default.locking_strategy", "org.hibernate.NotExistingFactory")
        .build();
      builder.close();
      fail();
    }
    catch (SearchException e) {
      assertEquals( "Unable to find locking_strategy implementation class: org.hibernate.NotExistingFactory", e.getCause().getMessage() );
    }
View Full Code Here

  public void testUseOfSimpleLockingFactory() {
    testUseOfSelectedLockingFactory( "simple", SimpleFSLockFactory.class, false );
  }

  private void testUseOfSelectedLockingFactory(String optionName, Class expectedType, boolean useRamDirectory) {
    FullTextSessionBuilder builder = new FullTextSessionBuilder();
    FullTextSessionBuilder fullTextSessionBuilder = builder.addAnnotatedClass( SnowStorm.class );
    if ( optionName != null ) {
      fullTextSessionBuilder.setProperty( "hibernate.search.default.locking_strategy", optionName );
    }
    if ( ! useRamDirectory ) {
      fullTextSessionBuilder.useFileSystemDirectoryProvider( CustomLockProviderTest.class );
    }
    FullTextSessionBuilder ftsb = fullTextSessionBuilder.build();
    try {
      SearchFactoryImplementor searchFactory = (SearchFactoryImplementor) ftsb.getSearchFactory();
      EntityIndexBinding indexBindingForEntity = searchFactory.getIndexBinding( SnowStorm.class );
      DirectoryBasedIndexManager indexManager = (DirectoryBasedIndexManager) indexBindingForEntity.getIndexManagers()[0];
      DirectoryProvider directoryProvider = indexManager.getDirectoryProvider();
      Directory directory = directoryProvider.getDirectory();
      LockFactory lockFactory = directory.getLockFactory();
View Full Code Here

    verifyBackendUsage( BlackHoleBackendQueueProcessor.class );
    verifyBackendUsage( LuceneBackendQueueProcessor.class );
  }

  private void verifyBackendUsage(String name, Class<? extends BackendQueueProcessor> backendType) {
    FullTextSessionBuilder builder = new FullTextSessionBuilder();
    FullTextSession ftSession = builder
      .setProperty( "hibernate.search.default.worker.backend", name )
      .addAnnotatedClass( BlogEntry.class )
      .openFullTextSession();
    SearchFactoryImplementor searchFactory = (SearchFactoryImplementor) ftSession.getSearchFactory();
    ftSession.close();
    IndexManagerHolder allIndexesManager = searchFactory.getIndexManagerHolder();
    DirectoryBasedIndexManager indexManager = (DirectoryBasedIndexManager) allIndexesManager.getIndexManager( "org.hibernate.search.test.configuration.BlogEntry" );
    BackendQueueProcessor backendQueueProcessor = indexManager.getBackendQueueProcessor();
    assertEquals( backendType, backendQueueProcessor.getClass() );
    builder.close();
  }
View Full Code Here

*/
public class TestInvalidPaths {

  @Test
  public void testInvalidDeepSimplePath() {
    FullTextSessionBuilder cfg = new FullTextSessionBuilder();
    cfg.addAnnotatedClass( A.class );
    cfg.addAnnotatedClass( B.class );
    cfg.addAnnotatedClass( C.class );
    cfg.addAnnotatedClass( DeepPathSimpleTypeCase.class );
    try {
      cfg.build();
      fail( "Exception should have been thrown for DeepPathSimpleTypeCase having invalid path: b.c.dne" );
    }
    catch (SearchException se) {
      assertTrue( "Expected search exception to contain information about invalid path b.c.dne",
          se.getMessage().contains( "b.c.dne" ) );
View Full Code Here

    }
  }

  @Test
  public void testInvalidDeepSimplePathWithLeadingPrefix() {
    FullTextSessionBuilder cfg = new FullTextSessionBuilder();
    cfg.addAnnotatedClass( A.class );
    cfg.addAnnotatedClass( B.class );
    cfg.addAnnotatedClass( C.class );
    cfg.addAnnotatedClass( DeepPathWithLeadingPrefixCase.class );
    try {
      cfg.build();
      fail( "Exception should have been thrown for DeepPathWithLeadingPrefixCase having invalid path: b.c.dne" );
    }
    catch (SearchException se) {
      assertTrue( "Should contain information about invalid path b.c.dne (message: <" + se.getMessage() + ">)" ,
          se.getMessage().matches( ".*\\[b.c.dne\\].*" ) );
View Full Code Here

    }
  }

  @Test
  public void testInvalidPrefix() {
    FullTextSessionBuilder cfg = new FullTextSessionBuilder();
    cfg.addAnnotatedClass( A.class );
    cfg.addAnnotatedClass( B.class );
    cfg.addAnnotatedClass( C.class );
    cfg.addAnnotatedClass( InvalidPrefixCase.class );
    try {
      cfg.build();
      fail( "Exception should have been thrown for InvalidPrefixCase having invalid path: b.c.dne" );
    }
    catch (SearchException se) {
      assertTrue( "Expected search exception to contain information about invalid path a.b.c.indexed",
          se.getMessage().contains( "a.b.c.indexed" ) );
View Full Code Here

    }
  }

  @Test
  public void testShallowInvalidPath() throws Exception {
    FullTextSessionBuilder cfg = new FullTextSessionBuilder();
    cfg.addAnnotatedClass( A.class );
    cfg.addAnnotatedClass( B.class );
    cfg.addAnnotatedClass( C.class );
    cfg.addAnnotatedClass( InvalidShallowPathCase.class );
    try {
      cfg.build();
      fail( "Exception should have been thrown for ShallowPathCase having invalid path: dne" );
    }
    catch (SearchException se) {
      assertTrue( "Expected search exception to contain information about invalid path dne",
          se.getMessage().contains( "dne" ) );
View Full Code Here

    testOnce();

  }

  private void testOnce() {
    FullTextSessionBuilder builder = new FullTextSessionBuilder()
    .setProperty(
      "hibernate.search.default.directory_provider",
      org.hibernate.search.test.directoryProvider.CloseCheckingDirectoryProvider.class.getName() )
    .addAnnotatedClass( SnowStorm.class )
    .build();
    CloseCheckingDirectoryProvider directoryProvider;
    try {
      SearchFactoryIntegrator searchFactory = (SearchFactoryIntegrator) builder.getSearchFactory();
      EntityIndexBinding snowIndexBinder = searchFactory.getIndexBinding( SnowStorm.class );
      IndexManager[] indexManagers = snowIndexBinder.getIndexManagers();
      assertThat( indexManagers.length ).isEqualTo( 1 );
      assertThat( indexManagers[0] ).isInstanceOf( DirectoryBasedIndexManager.class );
      DirectoryBasedIndexManager dbBasedManager = (DirectoryBasedIndexManager)indexManagers[0];
      assertThat( dbBasedManager.getDirectoryProvider() ).isInstanceOf( CloseCheckingDirectoryProvider.class );
      directoryProvider = (CloseCheckingDirectoryProvider) dbBasedManager.getDirectoryProvider();
      assertThat( directoryProvider.isInitialized() ).isTrue();
      assertThat( directoryProvider.isStarted() ).isTrue();
      assertThat( directoryProvider.isStopped() ).isFalse();
    }
    finally {
      builder.close();
    }
    assertThat( directoryProvider.isStopped() ).isTrue();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.test.util.FullTextSessionBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.