Package org.hibernate.search.test.util

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


  private FullTextSession sess;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    builder = new FullTextSessionBuilder();
    sess = builder
      .addAnnotatedClass( AlternateBook.class )
      .addAnnotatedClass( Employee.class )
      .setProperty( "hibernate.default_batch_fetch_size", "10" )
      .build();
View Full Code Here


      fullTextSessionBuilder.close();
    }
  }

  private static FullTextSessionBuilder createSearchFactory(boolean indexMetadataIsComplete) {
    FullTextSessionBuilder builder = new FullTextSessionBuilder()
        .setProperty( "hibernate.search.default.worker.backend", LeakingLuceneBackend.class.getName() )
        .setProperty( "hibernate.search.default.optimizer.implementation", LeakingOptimizer.class.getCanonicalName() )
        .addAnnotatedClass( Document.class );
    if ( !indexMetadataIsComplete ) {
      builder.setProperty( "hibernate.search.default.index_metadata_complete", "false" );
    }
    return builder.build();
  }
View Full Code Here

  private LoadCountingListener loadCountListener;

  @Test
  public void testScenario() {

    FullTextSessionBuilder fullTextSessionBuilder = createSearchFactory();
    try {
      //check no operations are done:
      assertOperationsPerformed( 0 );
      assertLocationsLoaded( 0 );
      //create initial data
      initializeData( fullTextSessionBuilder );
      //this should have triggered 5 indexing operations, no entity loadings:
      assertOperationsPerformed( 5 );
      assertLocationsLoaded( 0 );
      FullTextSession fullTextSession = fullTextSessionBuilder.openFullTextSession();
      //now check index state:
      assertFoundLocations( fullTextSession, "floor", 5 );
      assertFoundLocations( fullTextSession, "airport", 0 );
      fullTextSession.clear();
      try {
        //we add a new Location to the group:
        addLocationToGroupCollection( fullTextSession );
        //NOTHING else should be loaded, there was no need to reindex unrelated Locations!
        assertLocationsLoaded( 0 );
        //of course the new Location should have been indexed:
        assertOperationsPerformed( 1 );
        fullTextSession.clear();
        //so now we have 6 Locations in the index, in LocationGroup "floor":
        assertFoundLocations( fullTextSession, "floor", 6 );
        assertFoundLocations( fullTextSession, "airport", 0 );
        //changing the locationGroup name to Airport:
        updateLocationGroupName( fullTextSession );
        fullTextSession.clear();
        //check index functionality:
        assertFoundLocations( fullTextSession, "floor", 0 );
        assertFoundLocations( fullTextSession, "airport", 6 );
        //six locations have been loaded for re-indexing:
        assertLocationsLoaded( 6 );
        //and six update operations have been sent to the backend:
        assertOperationsPerformed( 6 );
      }
      finally {
        fullTextSession.close();
      }
    }
    finally {
      fullTextSessionBuilder.close();
    }
  }
View Full Code Here

    LeakingLuceneBackend.reset();
  }

  private FullTextSessionBuilder createSearchFactory() {
    loadCountListener = new LoadCountingListener();
    FullTextSessionBuilder builder = new FullTextSessionBuilder()
        .setProperty( "hibernate.search.default.worker.backend",
            LeakingLuceneBackend.class.getName() )
        .addAnnotatedClass( LocationGroup.class )
        .addAnnotatedClass( Location.class )
        .addLoadEventListener( loadCountListener );
    return builder.build();
  }
View Full Code Here

  public void testWithDeepClassBridge() {
    testScenario( WITHOUT_CLASS_BRIDGE_ON_ITEM, 1, WITH_CLASS_BRIDGE_ON_CATALOG );
  }

  private void testScenario(boolean withClassBridgeOnItem, int depth, boolean withClassBridgeOnCatalog) {
    FullTextSessionBuilder fulltextSessionBuilder = configure(
        withClassBridgeOnItem,
        depth,
        withClassBridgeOnCatalog
    );
    try {
      initializeData( fulltextSessionBuilder );
      FullTextSession fullTextSession = fulltextSessionBuilder.openFullTextSession();
      try {
        Catalog catalog = (Catalog) fullTextSession.get( Catalog.class, 1L );
        PersistentSet catalogItems = (PersistentSet) catalog.getCatalogItems();
        PersistentBag consumers = (PersistentBag) catalog.getConsumers();

        assertFalse( "consumers should not be initialized", consumers.wasInitialized() );
        assertFalse( "catalogItems should not be initialized", consumers.wasInitialized() );

        updateCatalogsCollection( fullTextSession, catalog );

        if ( ( withClassBridgeOnItem || withClassBridgeOnCatalog ) && depth > 1 ) {
          assertTrue( "catalogItems should have been initialized", catalogItems.wasInitialized() );
        }
        else {
          assertFalse( "catalogItems should not be initialized", catalogItems.wasInitialized() );
        }
      }
      finally {
        fullTextSession.close();
      }
    }
    finally {
      fulltextSessionBuilder.close();
    }
  }
View Full Code Here

      fulltextSessionBuilder.close();
    }
  }

  private FullTextSessionBuilder configure(boolean withClassBridgeOnItem, int depth, boolean withClassBridgeOnCatalog) {
    FullTextSessionBuilder builder = new FullTextSessionBuilder()
        .addAnnotatedClass( Catalog.class )
        .addAnnotatedClass( CatalogItem.class )
        .addAnnotatedClass( Consumer.class )
        .addAnnotatedClass( Item.class );
    SearchMapping fluentMapping = builder.fluentMapping();
    // mapping for Catalog
    EntityMapping catalogMapping = fluentMapping
        .entity( Catalog.class );
    if ( withClassBridgeOnCatalog ) {
      catalogMapping.classBridge( NoopClassBridge.class );
    }
    catalogMapping
        .property( "catalogItems", ElementType.FIELD ).containedIn();

    // mapping for CatalogItem
    fluentMapping.entity( CatalogItem.class )
        .property( "item", ElementType.FIELD ).containedIn()
        .property( "catalog", ElementType.FIELD ).indexEmbedded();

    // mapping for Item
    IndexedMapping itemMapping = fluentMapping
        .entity( Item.class )
        .indexed();
    if ( withClassBridgeOnItem ) {
      itemMapping.classBridge( NoopClassBridge.class );
    }
    itemMapping.property( "catalogItems", ElementType.FIELD ).indexEmbedded().depth( depth );
    return builder.build();
  }
View Full Code Here

  public void testDisablingOptimization() {
    invokeTest( false, 3 );
  }

  private void invokeTest(boolean indexMetadataIsComplete, int expectedBackendOperations) {
    FullTextSessionBuilder fullTextSessionBuilder = createSearchFactory( indexMetadataIsComplete );
    try {
      LeakingOptimizer.reset();
      LeakingLuceneBackend.reset();
      FullTextSession session = fullTextSessionBuilder.openFullTextSession();
      Assert.assertEquals( 0, LeakingOptimizer.getTotalOperations() );

      Transaction tx = session.beginTransaction();
      session.persist( new Document( "The Book", "many paper pages assembled together at one side", "[old language you don't understand]" ) );
      tx.commit();

      Assert.assertEquals( 1, LeakingOptimizer.getTotalOperations() );
      Assert.assertEquals( 1, LeakingLuceneBackend.getLastProcessedQueue().size() );

      tx = session.beginTransaction();
      List list = session.createFullTextQuery( new MatchAllDocsQuery() ).list();
      Document doc = (Document) list.get( 0 );
      doc.setSummary( "Example of what was used in ancient times to read" );
      tx.commit();

      Assert.assertEquals( 1, LeakingLuceneBackend.getLastProcessedQueue().size() );
      Assert.assertEquals( expectedBackendOperations, LeakingOptimizer.getTotalOperations() );
    }
    finally {
      fullTextSessionBuilder.close();
    }
  }
View Full Code Here

  private FullTextSession sess;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    builder = new FullTextSessionBuilder();
    sess = builder
      .addAnnotatedClass( AlternateBook.class )
      .addAnnotatedClass( Employee.class )
      .setProperty( "hibernate.default_batch_fetch_size", "10" )
      .build();
View Full Code Here

      assertTrue( "Unexpected error message: " + e.getMessage(), e.getMessage().startsWith( "HSEARCH000217" ) );
    }
  }

  private FullTextSessionBuilder buildFullTextSessionBuilder(String objectLookUpMethod, String databaseRetrievalMethod) {
    FullTextSessionBuilder fullTextSessionBuilder = new FullTextSessionBuilder()
        .addAnnotatedClass( Foo.class );
    if ( objectLookUpMethod != null ) {
      fullTextSessionBuilder.setProperty( "hibernate.search.query.object_lookup_method", objectLookUpMethod );
    }
    if ( databaseRetrievalMethod != null ) {
      fullTextSessionBuilder.setProperty( "hibernate.search.query.database_retrieval_method", databaseRetrievalMethod );
    }
    return fullTextSessionBuilder.build();
  }
View Full Code Here

   * test that the MassIndexer is properly identifying the root entities
   * from the selection of classes to be indexed.
   */
  @Test
  public void testEntityHierarchy() {
    FullTextSessionBuilder ftsb = new FullTextSessionBuilder()
        .addAnnotatedClass( ModernBook.class )
        .addAnnotatedClass( AncientBook.class )
        .addAnnotatedClass( Dvd.class )
        .addAnnotatedClass( Book.class )
        .addAnnotatedClass( Nation.class )
        .build();
    FullTextSession fullTextSession = ftsb.openFullTextSession();
    SearchFactoryImplementor searchFactory = (SearchFactoryImplementor) fullTextSession.getSearchFactory();
    {
      TestableMassIndexerImpl tsii = new TestableMassIndexerImpl( searchFactory, Book.class );
      assertTrue( tsii.getRootEntities().contains( Book.class ) );
      assertFalse( tsii.getRootEntities().contains( ModernBook.class ) );
      assertFalse( tsii.getRootEntities().contains( AncientBook.class ) );
    }
    {
      TestableMassIndexerImpl tsii = new TestableMassIndexerImpl(
          searchFactory,
          ModernBook.class,
          AncientBook.class,
          Book.class
      );
      assertTrue( tsii.getRootEntities().contains( Book.class ) );
      assertFalse( tsii.getRootEntities().contains( ModernBook.class ) );
      assertFalse( tsii.getRootEntities().contains( AncientBook.class ) );
    }
    {
      TestableMassIndexerImpl tsii = new TestableMassIndexerImpl(
          searchFactory,
          ModernBook.class,
          AncientBook.class
      );
      assertFalse( tsii.getRootEntities().contains( Book.class ) );
      assertTrue( tsii.getRootEntities().contains( ModernBook.class ) );
      assertTrue( tsii.getRootEntities().contains( AncientBook.class ) );
    }
    //verify that indexing Object will result in one separate indexer working per root indexed entity
    {
      TestableMassIndexerImpl tsii = new TestableMassIndexerImpl( searchFactory, Object.class );
      assertTrue( tsii.getRootEntities().contains( Book.class ) );
      assertTrue( tsii.getRootEntities().contains( Dvd.class ) );
      assertFalse( tsii.getRootEntities().contains( AncientBook.class ) );
      assertFalse( tsii.getRootEntities().contains( Object.class ) );
      assertEquals( 2, tsii.getRootEntities().size() );
    }
    fullTextSession.close();
    ftsb.close();
  }
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.