From f4c43cde846cb40e2f904d545ace8e88e126d3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 19 Oct 2016 17:30:05 +0200 Subject: [PATCH] HSEARCH-2393 Fixed IndexingActionInterceptorTest for Elasticsearch --- elasticsearch/pom.xml | 1 - .../search/test/interceptor/Blog.java | 14 +++++ .../IndexingActionInterceptorTest.java | 51 ++++++++++--------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/elasticsearch/pom.xml b/elasticsearch/pom.xml index 2d70b0ecc8b..ce98065c8ad 100644 --- a/elasticsearch/pom.xml +++ b/elasticsearch/pom.xml @@ -234,7 +234,6 @@ **/ProgrammaticMappingTest.java - **/IndexingActionInterceptorTest.java **/ToStringTest.java **/DynamicBoostingTest.java **/IndexAndQueryNullTest.java diff --git a/orm/src/test/java/org/hibernate/search/test/interceptor/Blog.java b/orm/src/test/java/org/hibernate/search/test/interceptor/Blog.java index 9981ce75d9a..cde8903831a 100644 --- a/orm/src/test/java/org/hibernate/search/test/interceptor/Blog.java +++ b/orm/src/test/java/org/hibernate/search/test/interceptor/Blog.java @@ -6,6 +6,8 @@ */ package org.hibernate.search.test.interceptor; +import java.util.Objects; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -29,6 +31,18 @@ public void setId(Integer id) { this.id = id; } + @Override + public boolean equals(Object obj) { + return getClass().equals( obj.getClass() ) + && id != null + && Objects.equals( id, ((Blog) obj).id ); + } + + @Override + public int hashCode() { + return getClass().hashCode(); + } + private Integer id; @Field diff --git a/orm/src/test/java/org/hibernate/search/test/interceptor/IndexingActionInterceptorTest.java b/orm/src/test/java/org/hibernate/search/test/interceptor/IndexingActionInterceptorTest.java index 6519c92fd31..695658bda24 100644 --- a/orm/src/test/java/org/hibernate/search/test/interceptor/IndexingActionInterceptorTest.java +++ b/orm/src/test/java/org/hibernate/search/test/interceptor/IndexingActionInterceptorTest.java @@ -12,14 +12,12 @@ import java.util.List; -import org.apache.lucene.index.Term; import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.Query; import org.hibernate.Transaction; import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.search.FullTextSession; import org.hibernate.search.Search; -import org.hibernate.search.engine.ProjectionConstants; import org.hibernate.search.test.SearchTestBase; import org.junit.After; import org.junit.Before; @@ -64,8 +62,9 @@ public void tearDown() throws Exception { public void testBlogAndArticleAreNotIndexedInDraftStatus() throws Exception { Transaction tx = fullTextSession.beginTransaction(); - assertThat( getBlogEntriesFor( Blog.class ) ).as( "Blog is explicit intercepted" ).hasSize( 0 ); - assertThat( getBlogEntriesFor( Article.class ) ).as( "Article is inherently intercepted" ).hasSize( 0 ); + List blogEntries = getBlogEntries(); + assertThat( blogEntries ).as( "Blog is explicitly intercepted" ).excludes( blog ); + assertThat( blogEntries ).as( "Article is inherently intercepted" ).excludes( article ); tx.commit(); } @@ -73,8 +72,8 @@ public void testBlogAndArticleAreNotIndexedInDraftStatus() throws Exception { @Test public void testTotalArticleIsIndexedInDraftStatus() throws Exception { Transaction tx = fullTextSession.beginTransaction(); - assertThat( getBlogEntriesFor( TotalArticle.class ) ).as( "TotalArticle is explicit not intercepted" ) - .hasSize( 1 ); + List blogEntries = getBlogEntries(); + assertThat( blogEntries ).as( "TotalArticle is explicitly not intercepted" ).contains( totalArticle ); tx.commit(); } @@ -84,10 +83,10 @@ public void testBlogAndArticleAreIndexedInPublishedStatus() throws Exception { setAllBlogEntriesToStatus( BlogStatus.PUBLISHED ); Transaction tx = fullTextSession.beginTransaction(); - assertThat( getBlogEntriesFor( Blog.class ) ).hasSize( 1 ); - assertThat( getBlogEntriesFor( Article.class ) ).as( "Article is inherently intercepted" ).hasSize( 1 ); - assertThat( getBlogEntriesFor( TotalArticle.class ) ).as( "TotalArticle is explicit not intercepted" ) - .hasSize( 1 ); + List blogEntries = getBlogEntries(); + assertThat( blogEntries ).contains( blog ); + assertThat( blogEntries ).as( "Article is inherently intercepted" ).contains( article ); + assertThat( blogEntries ).as( "TotalArticle is explicitly not intercepted" ).contains( totalArticle ); tx.commit(); } @@ -98,8 +97,9 @@ public void testBlogAndArticleAreNotIndexedInRemovedStatus() throws Exception { setAllBlogEntriesToStatus( BlogStatus.REMOVED ); Transaction tx = fullTextSession.beginTransaction(); - assertThat( getBlogEntriesFor( Blog.class ) ).hasSize( 0 ); - assertThat( getBlogEntriesFor( Article.class ) ).as( "Article is inherently intercepted" ).hasSize( 0 ); + List blogEntries = getBlogEntries(); + assertThat( blogEntries ).excludes( blog ); + assertThat( blogEntries ).as( "Article is inherently intercepted" ).excludes( article ); tx.commit(); } @@ -109,8 +109,8 @@ public void testTotalArticleIsIndexedInRemovedStatus() throws Exception { setAllBlogEntriesToStatus( BlogStatus.REMOVED ); Transaction tx = fullTextSession.beginTransaction(); - assertThat( getBlogEntriesFor( TotalArticle.class ) ).as( "TotalArticle is explicit not intercepted" ) - .hasSize( 1 ); + List blogEntries = getBlogEntries(); + assertThat( blogEntries ).as( "TotalArticle is explicitly not intercepted" ).contains( totalArticle ); tx.commit(); } @@ -120,9 +120,9 @@ public void testTotalArticleIsIndexedInRemovedStatus() throws Exception { public void testInterceptorWithMassIndexer() throws Exception { setAllBlogEntriesToStatus( BlogStatus.PUBLISHED ); - List allEntries = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ).list(); - assertEquals( "Wrong total number of entries", 3, allEntries.size() ); - for ( Blog blog : allEntries ) { + List blogEntries = getBlogEntries(); + assertEquals( "Wrong total number of entries", 3, blogEntries.size() ); + for ( Blog blog : blogEntries ) { assertTrue( blog.getStatus().equals( BlogStatus.PUBLISHED ) ); } @@ -134,8 +134,8 @@ public void testInterceptorWithMassIndexer() throws Exception { tx.commit(); - allEntries = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ).list(); - assertEquals( "Wrong total number of entries. Index should be empty after purge.", 0, allEntries.size() ); + blogEntries = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ).list(); + assertEquals( "Wrong total number of entries. Index should be empty after purge.", 0, blogEntries.size() ); tx = fullTextSession.beginTransaction(); fullTextSession.createIndexer() @@ -146,8 +146,8 @@ public void testInterceptorWithMassIndexer() throws Exception { .startAndWait(); tx.commit(); - allEntries = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ).list(); - assertEquals( "Wrong total number of entries.", 3, allEntries.size() ); + blogEntries = getBlogEntries(); + assertEquals( "Wrong total number of entries.", 3, blogEntries.size() ); } private void createPersistAndIndexTestData() { @@ -190,9 +190,10 @@ private void setAllBlogEntriesToStatus(BlogStatus status) { fullTextSession.clear(); } - private List getBlogEntriesFor(Class blogType) { - TermQuery query = new TermQuery( new Term( ProjectionConstants.OBJECT_CLASS, blogType.getName() ) ); - return fullTextSession.createFullTextQuery( query ).list(); + @SuppressWarnings("unchecked") + private List getBlogEntries() { + Query query = new MatchAllDocsQuery(); + return fullTextSession.createFullTextQuery( query, Blog.class ).list(); } @Override