Package org.hibernate.search.test.query

Source Code of org.hibernate.search.test.query.QueryUnindexedEntityTest

/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.test.query;

import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.Query;

import org.hibernate.Transaction;

import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.exception.SearchException;
import org.hibernate.search.test.SearchTestBase;
import org.hibernate.search.testsupport.TestConstants;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* HSEARCH-162 - trying to index an entity which is not marked with @Indexed
*
* @author Hardy Ferentschik
*/
public class QueryUnindexedEntityTest extends SearchTestBase {

  @Test
  public void testQueryOnAllEntities() throws Exception {

    FullTextSession s = Search.getFullTextSession( openSession() );

    Transaction tx = s.beginTransaction();
    Person person = new Person();
    person.setName( "Jon Doe" );
    s.save( person );
    tx.commit();

    tx = s.beginTransaction();
    QueryParser parser = new QueryParser( TestConstants.getTargetLuceneVersion(), "name", TestConstants.standardAnalyzer );
    Query query = parser.parse( "name:foo" );
    FullTextQuery hibQuery = s.createFullTextQuery( query );
    try {
      hibQuery.list();
      fail();
    }
    catch (SearchException e) {
      assertTrue( "Wrong message", e.getMessage().startsWith( "There are no mapped entities" ) );
    }

    tx.rollback();
    s.close();
  }

  @Override
  protected Class<?>[] getAnnotatedClasses() {
    return new Class[] {
        Person.class,
    };
  }
}
TOP

Related Classes of org.hibernate.search.test.query.QueryUnindexedEntityTest

TOP
Copyright © 2018 www.massapi.com. 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.