-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3273 Test creation of field templates in Elasticsearch schema…
… management
- Loading branch information
Showing
3 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
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
169 changes: 169 additions & 0 deletions
169
...rch/schema/management/ElasticsearchIndexSchemaManagerCreationMappingFieldTemplatesIT.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,169 @@ | ||
/* | ||
* 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.integrationtest.backend.elasticsearch.schema.management; | ||
|
||
import static org.hibernate.search.integrationtest.backend.elasticsearch.schema.management.ElasticsearchIndexSchemaManagerTestUtils.defaultMetadataMappingAndCommaForExpectations; | ||
import static org.hibernate.search.integrationtest.backend.elasticsearch.schema.management.ElasticsearchIndexSchemaManagerTestUtils.defaultMetadataMappingForExpectations; | ||
import static org.hibernate.search.util.impl.test.JsonHelper.assertJsonEquals; | ||
|
||
import java.util.EnumSet; | ||
import java.util.function.Consumer; | ||
|
||
import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurationContext; | ||
import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer; | ||
import org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchBackendSettings; | ||
import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement; | ||
import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField; | ||
import org.hibernate.search.engine.backend.document.model.dsl.ObjectFieldStorage; | ||
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper; | ||
import org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.rule.TestElasticsearchClient; | ||
import org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappedIndex; | ||
import org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingSchemaManagementStrategy; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
/** | ||
* Tests related to the mapping's field templates when creating indexes, | ||
* for all index-creating schema management operations. | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class ElasticsearchIndexSchemaManagerCreationMappingFieldTemplatesIT { | ||
|
||
private static final String INDEX_NAME = "IndexName"; | ||
|
||
@Parameters(name = "With operation {0}") | ||
public static EnumSet<ElasticsearchIndexSchemaManagerOperation> operations() { | ||
return ElasticsearchIndexSchemaManagerOperation.creating(); | ||
} | ||
|
||
@Rule | ||
public SearchSetupHelper setupHelper = new SearchSetupHelper(); | ||
|
||
@Rule | ||
public TestElasticsearchClient elasticSearchClient = new TestElasticsearchClient(); | ||
|
||
private final ElasticsearchIndexSchemaManagerOperation operation; | ||
|
||
public ElasticsearchIndexSchemaManagerCreationMappingFieldTemplatesIT(ElasticsearchIndexSchemaManagerOperation operation) { | ||
this.operation = operation; | ||
} | ||
|
||
@Test | ||
public void rootFieldTemplates() { | ||
elasticSearchClient.index( INDEX_NAME ) | ||
.ensureDoesNotExist().registerForCleanup(); | ||
|
||
setupAndCreateIndex( root -> { | ||
root.objectFieldTemplate( "myTemplate1", ObjectFieldStorage.NESTED ) | ||
.matchingPathGlob( "*_obj" ); | ||
root.fieldTemplate( "myTemplate2", f -> f.asString() ) | ||
.matchingPathGlob( "*_kw" ); | ||
} ); | ||
|
||
assertJsonEquals( | ||
"{" | ||
+ "'dynamic': 'true'," | ||
+ "'dynamic_templates': [" | ||
+ "{'myTemplate1': {" | ||
+ "'match_mapping_type': 'object'," | ||
+ "'path_match': '*_obj'," | ||
+ "'mapping': {" | ||
+ "'type': 'nested'," | ||
+ "'dynamic': 'true'" | ||
+ "}" | ||
+ "} }," | ||
+ "{'myTemplate2': {" | ||
+ "'path_match': '*_kw'," | ||
+ "'mapping': {" | ||
+ "'type': 'keyword'," | ||
+ "'doc_values': false," | ||
+ "'index': true," | ||
+ "'norms': false," | ||
+ "'store': false" | ||
+ "}" | ||
+ "} }" | ||
+ "]," | ||
+ "'properties': {" | ||
+ defaultMetadataMappingForExpectations() | ||
+ "}" | ||
+ "}", | ||
elasticSearchClient.index( INDEX_NAME ).type().getMapping() | ||
); | ||
} | ||
|
||
@Test | ||
public void nonRootFieldTemplates() { | ||
elasticSearchClient.index( INDEX_NAME ) | ||
.ensureDoesNotExist().registerForCleanup(); | ||
|
||
setupAndCreateIndex( root -> { | ||
IndexSchemaObjectField objectField = root.objectField( "staticObject" ); | ||
objectField.toReference(); | ||
objectField.objectFieldTemplate( "myTemplate1", ObjectFieldStorage.NESTED ) | ||
.matchingPathGlob( "*_obj" ); | ||
objectField.fieldTemplate( "myTemplate2", f -> f.asString() ) | ||
.matchingPathGlob( "*_kw" ); | ||
} ); | ||
|
||
assertJsonEquals( | ||
"{" | ||
+ "'dynamic': 'strict'," | ||
+ "'dynamic_templates': [" | ||
+ "{'staticObject.myTemplate1': {" | ||
+ "'match_mapping_type': 'object'," | ||
+ "'path_match': 'staticObject.*_obj'," | ||
+ "'mapping': {" | ||
+ "'type': 'nested'," | ||
+ "'dynamic': 'true'" | ||
+ "}" | ||
+ "} }," | ||
+ "{'staticObject.myTemplate2': {" | ||
+ "'path_match': 'staticObject.*_kw'," | ||
+ "'mapping': {" | ||
+ "'type': 'keyword'," | ||
+ "'doc_values': false," | ||
+ "'index': true," | ||
+ "'norms': false," | ||
+ "'store': false" | ||
+ "}" | ||
+ "} }" | ||
+ "]," | ||
+ "'properties': {" | ||
+ defaultMetadataMappingAndCommaForExpectations() | ||
+ "'staticObject': {" | ||
+ "'type': 'object'," | ||
+ "'dynamic': 'true'" | ||
+ "}" | ||
+ "}" | ||
+ "}", | ||
elasticSearchClient.index( INDEX_NAME ).type().getMapping() | ||
); | ||
} | ||
|
||
private void setupAndCreateIndex(Consumer<IndexSchemaElement> binder) { | ||
StubMappedIndex index = StubMappedIndex.withoutRetrievableBinding( INDEX_NAME, binder ); | ||
|
||
setupHelper.start() | ||
.withIndex( index ) | ||
.withSchemaManagement( StubMappingSchemaManagementStrategy.DROP_ON_SHUTDOWN_ONLY ) | ||
.withBackendProperty( | ||
// Don't contribute any analysis definitions, migration of those is tested in another test class | ||
ElasticsearchBackendSettings.ANALYSIS_CONFIGURER, | ||
(ElasticsearchAnalysisConfigurer) (ElasticsearchAnalysisConfigurationContext context) -> { | ||
// No-op | ||
} | ||
) | ||
.setup(); | ||
|
||
operation.apply( index.getSchemaManager() ).join(); | ||
} | ||
|
||
} |
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