Skip to content

Commit

Permalink
HSEARCH-3102 Move backend-specific tests to separate test classes in …
Browse files Browse the repository at this point in the history
…the documentation

So as to avoid NoClassDefFoundError when we'll only have one backend in
the classpath for each Maven Failsafe Plugin execution.
  • Loading branch information
yrodiere committed Jul 13, 2020
1 parent c107f3e commit 159896a
Show file tree
Hide file tree
Showing 30 changed files with 1,663 additions and 672 deletions.
Expand Up @@ -159,7 +159,7 @@ to apply a configuration to a specific index.
====
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/search/documentation/configuration/MyConfigurationIT.java[tags=build-hibernate-configuration]
include::{sourcedir}/org/hibernate/search/documentation/configuration/ElasticsearchConfigurationIT.java[tags=build-hibernate-configuration]
----
====

Expand Down
Expand Up @@ -345,7 +345,7 @@ include::components/elasticsearch-json-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/aggregation/AggregationDslIT.java[tags=elasticsearch-fromJson-jsonObject]
include::{sourcedir}/org/hibernate/search/documentation/search/aggregation/ElasticsearchAggregationDslIT.java[tags=elasticsearch-fromJson-jsonObject]
----
<1> The aggregation result is a `JsonObject`.
====
Expand All @@ -354,7 +354,7 @@ include::{sourcedir}/org/hibernate/search/documentation/search/aggregation/Aggre
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/aggregation/AggregationDslIT.java[tags=elasticsearch-fromJson-string]
include::{sourcedir}/org/hibernate/search/documentation/search/aggregation/ElasticsearchAggregationDslIT.java[tags=elasticsearch-fromJson-string]
----
<1> The aggregation result is a `JsonObject`.
====
Expand Down
Expand Up @@ -1066,7 +1066,7 @@ include::components/lucene-api-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/predicate/PredicateDslIT.java[tags=lucene-fromLuceneQuery]
include::{sourcedir}/org/hibernate/search/documentation/search/predicate/LucenePredicateDslIT.java[tags=lucene-fromLuceneQuery]
----
<1> Build the query as usual,
but using the Lucene extension so that Lucene-specific options are available.
Expand All @@ -1084,7 +1084,7 @@ include::components/elasticsearch-json-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/predicate/PredicateDslIT.java[tags=elasticsearch-fromJson-jsonObject]
include::{sourcedir}/org/hibernate/search/documentation/search/predicate/ElasticsearchPredicateDslIT.java[tags=elasticsearch-fromJson-jsonObject]
----
<1> Build a JSON object using link:{gsonUrl}[Gson].
<2> Build the query as usual,
Expand All @@ -1096,7 +1096,7 @@ but using the Lucene extension so that Lucene-specific options are available.
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/predicate/PredicateDslIT.java[tags=elasticsearch-fromJson-string]
include::{sourcedir}/org/hibernate/search/documentation/search/predicate/ElasticsearchPredicateDslIT.java[tags=elasticsearch-fromJson-string]
----
<1> Build the query as usual,
but using the Lucene extension so that Lucene-specific options are available.
Expand Down
Expand Up @@ -331,7 +331,7 @@ include::components/lucene-api-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/projection/ProjectionDslIT.java[tags=lucene-document]
include::{sourcedir}/org/hibernate/search/documentation/search/projection/LuceneProjectionDslIT.java[tags=lucene-document]
----
====

Expand Down Expand Up @@ -367,7 +367,7 @@ include::components/lucene-api-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/projection/ProjectionDslIT.java[tags=lucene-explanation]
include::{sourcedir}/org/hibernate/search/documentation/search/projection/LuceneProjectionDslIT.java[tags=lucene-explanation]
----
====

Expand All @@ -383,7 +383,7 @@ include::components/elasticsearch-json-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/projection/ProjectionDslIT.java[tags=elasticsearch-source]
include::{sourcedir}/org/hibernate/search/documentation/search/projection/ElasticsearchProjectionDslIT.java[tags=elasticsearch-source]
----
====

Expand All @@ -405,7 +405,7 @@ include::components/elasticsearch-json-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/projection/ProjectionDslIT.java[tags=elasticsearch-explanation]
include::{sourcedir}/org/hibernate/search/documentation/search/projection/ElasticsearchProjectionDslIT.java[tags=elasticsearch-explanation]
----
====

Expand All @@ -426,6 +426,6 @@ include::components/elasticsearch-json-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/projection/ProjectionDslIT.java[tags=elasticsearch-jsonHit]
include::{sourcedir}/org/hibernate/search/documentation/search/projection/ElasticsearchProjectionDslIT.java[tags=elasticsearch-jsonHit]
----
====
Expand Up @@ -637,7 +637,7 @@ only use them for debugging purposes.
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/query/QueryDslIT.java[tags=explain-lucene]
include::{sourcedir}/org/hibernate/search/documentation/search/query/LuceneQueryDslIT.java[tags=explain-lucene]
----
<1> Build the query as usual,
but using the Lucene extension so that the retrieved query exposes Lucene-specific operations.
Expand All @@ -654,7 +654,7 @@ you can instead use the Lucene extension on the `SearchQuery` to convert it afte
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/query/QueryDslIT.java[tags=explain-elasticsearch]
include::{sourcedir}/org/hibernate/search/documentation/search/query/ElasticsearchQueryDslIT.java[tags=explain-elasticsearch]
----
<1> Build the query as usual,
but using the Elasticsearch extension so that the retrieved query exposes Elasticsearch-specific operations.
Expand Down Expand Up @@ -702,7 +702,7 @@ Most simple use cases will only need to change the HTTP request slightly, as sho
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/query/QueryDslIT.java[tags=elasticsearch-requestTransformer]
include::{sourcedir}/org/hibernate/search/documentation/search/query/ElasticsearchQueryDslIT.java[tags=elasticsearch-requestTransformer]
----
<1> Build the query as usual,
but using the Elasticsearch extension so that Elasticsearch-specific options are available.
Expand All @@ -720,7 +720,7 @@ For more complicated use cases, it is possible to access the raw JSON of the HTT
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/query/QueryDslIT.java[tags=elasticsearch-responseBody]
include::{sourcedir}/org/hibernate/search/documentation/search/query/ElasticsearchQueryDslIT.java[tags=elasticsearch-responseBody]
----
<1> Build the query as usual,
but using the Elasticsearch extension so that Elasticsearch-specific options are available.
Expand All @@ -743,7 +743,7 @@ so the example above relies on a small, custom helper method to make the code mo
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/query/QueryDslIT.java[tags=elasticsearch-responseBody-helper]
include::{sourcedir}/org/hibernate/search/documentation/search/query/ElasticsearchQueryDslIT.java[tags=elasticsearch-responseBody-helper]
----
====

Expand All @@ -764,7 +764,7 @@ This should only be useful to integrators, but is documented here for the sake o
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/query/QueryDslIT.java[tags=lucene-lowLevel]
include::{sourcedir}/org/hibernate/search/documentation/search/query/LuceneQueryDslIT.java[tags=lucene-lowLevel]
----
<1> Build the query as usual,
but using the Lucene extension so that Lucene-specific options are available.
Expand Down
Expand Up @@ -284,7 +284,7 @@ include::components/lucene-api-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/sort/SortDslIT.java[tags=lucene-fromLuceneSort]
include::{sourcedir}/org/hibernate/search/documentation/search/sort/LuceneSortDslIT.java[tags=lucene-fromLuceneSort]
----
====

Expand All @@ -301,7 +301,7 @@ include::components/lucene-api-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/sort/SortDslIT.java[tags=lucene-fromLuceneSortField]
include::{sourcedir}/org/hibernate/search/documentation/search/sort/LuceneSortDslIT.java[tags=lucene-fromLuceneSortField]
----
====

Expand All @@ -316,15 +316,15 @@ include::components/elasticsearch-json-warning.asciidoc[]
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/sort/SortDslIT.java[tags=elasticsearch-fromJson-jsonObject]
include::{sourcedir}/org/hibernate/search/documentation/search/sort/ElasticsearchSortDslIT.java[tags=elasticsearch-fromJson-jsonObject]
----
====

.Sorting by a native Elasticsearch JSON sort provided as a JSON-formatted string
====
[source, JAVA, indent=0, subs="+callouts"]
----
include::{sourcedir}/org/hibernate/search/documentation/search/sort/SortDslIT.java[tags=elasticsearch-fromJson-string]
include::{sourcedir}/org/hibernate/search/documentation/search/sort/ElasticsearchSortDslIT.java[tags=elasticsearch-fromJson-string]
----
====

Expand Down
Expand Up @@ -13,8 +13,6 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchBackendSettings;
import org.hibernate.search.backend.lucene.cfg.LuceneBackendSettings;
import org.hibernate.search.documentation.testsupport.BackendConfigurations;
import org.hibernate.search.documentation.testsupport.DocumentationSetupHelper;
import org.hibernate.search.mapper.orm.Search;
Expand Down Expand Up @@ -93,123 +91,6 @@ public void simple() {
} );
}

@Test
public void lucene_advanced() {
setupHelper.assumeLucene();

EntityManagerFactory entityManagerFactory = setupHelper.start()
.withBackendProperty(
LuceneBackendSettings.ANALYSIS_CONFIGURER,
new AdvancedLuceneAnalysisConfigurer()
)
.withProperty(
HibernateOrmMapperSettings.MAPPING_CONFIGURER,
(HibernateOrmSearchMappingConfigurer) context -> context.programmaticMapping()
.type( IndexedEntity.class )
.property( "text" )
.fullTextField( "standard" ).analyzer( "standard" )
)
.setup( IndexedEntity.class );

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
IndexedEntity entity = new IndexedEntity();
entity.setText( "the Wording" );
entityManager.persist( entity );
} );

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.session( entityManager );

assertThat(
searchSession.search( IndexedEntity.class )
.where( f -> f.match()
.field( "standard" )
.matching( "wording" )
)
.fetchHits( 20 )
)
.hasSize( 1 );
} );
}

@Test
public void lucene_similarity() {
setupHelper.assumeLucene();

EntityManagerFactory entityManagerFactory = setupHelper.start()
.withBackendProperty(
LuceneBackendSettings.ANALYSIS_CONFIGURER,
new CustomSimilarityLuceneAnalysisConfigurer()
)
.withProperty(
HibernateOrmMapperSettings.MAPPING_CONFIGURER,
(HibernateOrmSearchMappingConfigurer) context -> context.programmaticMapping()
.type( IndexedEntity.class )
.property( "text" )
.fullTextField( "standard" ).analyzer( "english" )
)
.setup( IndexedEntity.class );

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
IndexedEntity entity = new IndexedEntity();
entity.setText( "the Wording" );
entityManager.persist( entity );
} );

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.session( entityManager );

assertThat(
searchSession.search( IndexedEntity.class )
.where( f -> f.match()
.field( "standard" )
.matching( "wording" )
)
.fetchHits( 20 )
)
.hasSize( 1 );
} );
}

@Test
public void elasticsearch_advanced() {
setupHelper.assumeElasticsearch();

EntityManagerFactory entityManagerFactory = setupHelper.start()
.withBackendProperty(
ElasticsearchBackendSettings.ANALYSIS_CONFIGURER,
new AdvancedElasticsearchAnalysisConfigurer()
)
.withProperty(
HibernateOrmMapperSettings.MAPPING_CONFIGURER,
(HibernateOrmSearchMappingConfigurer) context -> context.programmaticMapping()
.type( IndexedEntity.class )
.property( "text" )
.fullTextField( "standard" ).analyzer( "standard" )
)
.setup( IndexedEntity.class );

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
IndexedEntity entity = new IndexedEntity();
entity.setText( "the Wording" );
entityManager.persist( entity );
} );

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.session( entityManager );

assertThat(
searchSession.search( IndexedEntity.class )
.where( f -> f.match()
.field( "standard" )
.matching( "wording" )
)
.fetchHits( 20 )
)
.hasSize( 1 );
} );
}

@Entity(name = IndexedEntity.NAME)
@Indexed
static class IndexedEntity {
Expand Down

0 comments on commit 159896a

Please sign in to comment.