Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-2258 Test detection of names collision when two indexes have …
…the same normalized name
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...c/test/java/org/hibernate/search/elasticsearch/test/ElasticsearchIndexNameConflictIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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.elasticsearch.test; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.search.annotations.DocumentId; | ||
import org.hibernate.search.annotations.Field; | ||
import org.hibernate.search.annotations.Indexed; | ||
import org.hibernate.search.elasticsearch.impl.ElasticsearchIndexManager; | ||
import org.hibernate.search.elasticsearch.impl.ElasticsearchIndexNameNormalizer; | ||
import org.hibernate.search.exception.SearchException; | ||
import org.hibernate.search.test.SearchInitializationTestBase; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
/** | ||
* Tests for {@link ElasticsearchIndexManager}'s indexNullAs type checking. | ||
* | ||
* @author Davide D'Alto | ||
*/ | ||
public class ElasticsearchIndexNameConflictIT extends SearchInitializationTestBase { | ||
|
||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@Test | ||
public void testNameCollisionDetection() { | ||
thrown.expect( SearchException.class ); | ||
thrown.expectMessage( "HSEARCH000326" ); | ||
thrown.expectMessage( MyFirstEntity.class.getName() ); | ||
thrown.expectMessage( MyfirstEntity.class.getName() ); | ||
thrown.expectMessage( ElasticsearchIndexNameNormalizer.getElasticsearchIndexName( MyfirstEntity.class.getName() ) ); | ||
|
||
init( MyFirstEntity.class, MyfirstEntity.class ); | ||
} | ||
|
||
@Test | ||
public void testWithoutConflictWhenIndexIsRenamed() { | ||
init( MySecondEntity.class, MysecondEntity.class ); | ||
} | ||
|
||
@Indexed | ||
@Entity | ||
static class MyFirstEntity { | ||
|
||
@DocumentId | ||
@Id | ||
Long id; | ||
|
||
@Field | ||
boolean myField; | ||
} | ||
|
||
@Indexed | ||
@Entity | ||
static class MyfirstEntity { | ||
|
||
@DocumentId | ||
@Id | ||
Long id; | ||
|
||
@Field | ||
boolean myField; | ||
} | ||
|
||
@Indexed(index = "should_not_have_conflict") | ||
@Entity | ||
static class MySecondEntity { | ||
|
||
@DocumentId | ||
@Id | ||
Long id; | ||
|
||
@Field | ||
boolean myField; | ||
} | ||
|
||
@Indexed | ||
@Entity | ||
static class MysecondEntity { | ||
|
||
@DocumentId | ||
@Id | ||
Long id; | ||
|
||
@Field | ||
boolean myField; | ||
} | ||
} |