Package org.hibernate.search.test.configuration

Source Code of org.hibernate.search.test.configuration.TypeMetadataTest$Foo

/*
* 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.configuration;

import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.cfg.spi.SearchConfiguration;
import org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider;
import org.hibernate.search.exception.SearchException;
import org.hibernate.search.impl.ConfigContext;
import org.hibernate.search.testsupport.setup.BuildContextForTest;
import org.hibernate.search.testsupport.setup.SearchConfigurationForTest;
import org.junit.Before;
import org.junit.Test;

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

/**
* @author Hardy Ferentschik
*/
public class TypeMetadataTest {

  private AnnotationMetadataProvider metadataProvider;

  @Before
  public void setUp() {
    SearchConfiguration searchConfiguration = new SearchConfigurationForTest();
    ConfigContext configContext = new ConfigContext(
        searchConfiguration,
        new BuildContextForTest( searchConfiguration )
    );
    metadataProvider = new AnnotationMetadataProvider( new JavaReflectionManager(), configContext );
  }

  @Test
  public void testMultipleDocumentIdsCauseException() {
    try {
      metadataProvider.getTypeMetadataFor( Foo.class );
      fail( "An exception should have been thrown" );
    }
    catch (SearchException e) { // getting a HibernateException here, because the listener registration fails
      assertEquals(
          "HSEARCH000167: More than one @DocumentId specified on entity 'org.hibernate.search.test.configuration.TypeMetadataTest$Foo'",
          e.getMessage()
      );
    }
  }

  @Indexed
  public class Foo {
    @DocumentId
    private Integer id;

    @DocumentId
    private String name;

    public Integer getId() {
      return id;
    }

    public void setId(Integer id) {
      this.id = id;
    }

    public String getName() {
      return name;
    }

    public void setName(String name) {
      this.name = name;
    }
  }
}

TOP

Related Classes of org.hibernate.search.test.configuration.TypeMetadataTest$Foo

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.