-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-4615 Create configuration context and configurer for Standalo…
…ne POJO mapper
- Loading branch information
1 parent
633da08
commit d4b2405
Showing
8 changed files
with
494 additions
and
4 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
24 changes: 24 additions & 0 deletions
24
...ate/search/documentation/mapper/pojo/standalone/entrypoints/StandalonePojoConfigurer.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,24 @@ | ||
/* | ||
* 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.documentation.mapper.pojo.standalone.entrypoints; | ||
|
||
import org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate; | ||
import org.hibernate.search.mapper.pojo.standalone.mapping.StandalonePojoMappingConfigurationContext; | ||
import org.hibernate.search.mapper.pojo.standalone.mapping.StandalonePojoMappingConfigurer; | ||
|
||
// tag::configurer[] | ||
|
||
public class StandalonePojoConfigurer implements StandalonePojoMappingConfigurer { | ||
@Override | ||
public void configure(StandalonePojoMappingConfigurationContext context) { | ||
context.addEntityTypes( Book.class, Associate.class, Manager.class );// <1> | ||
|
||
context.defaultReindexOnUpdate( ReindexOnUpdate.SHALLOW ); // <2> | ||
context.multiTenancyEnabled( true ); | ||
} | ||
} | ||
// end::configurer[] |
67 changes: 67 additions & 0 deletions
67
...e/search/documentation/mapper/pojo/standalone/entrypoints/StandalonePojoConfigurerIT.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,67 @@ | ||
/* | ||
* 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.documentation.mapper.pojo.standalone.entrypoints; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hibernate.search.documentation.testsupport.BackendConfigurations; | ||
import org.hibernate.search.documentation.testsupport.TestConfiguration; | ||
import org.hibernate.search.mapper.pojo.standalone.entity.SearchIndexedEntity; | ||
import org.hibernate.search.mapper.pojo.standalone.mapping.CloseableSearchMapping; | ||
import org.hibernate.search.mapper.pojo.standalone.mapping.SearchMapping; | ||
import org.hibernate.search.util.impl.integrationtest.common.TestConfigurationProvider; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class StandalonePojoConfigurerIT { | ||
|
||
private CloseableSearchMapping theSearchMapping; | ||
|
||
@Rule | ||
public TestConfigurationProvider configurationProvider = new TestConfigurationProvider(); | ||
|
||
@Before | ||
public void setup() { | ||
// tag::setup[] | ||
CloseableSearchMapping searchMapping = SearchMapping.builder() // <1> | ||
.property( | ||
"hibernate.search.mapping.configurer", // <2> | ||
"class:org.hibernate.search.documentation.mapper.pojo.standalone.entrypoints.StandalonePojoConfigurer" | ||
) | ||
.property( | ||
"hibernate.search.backend.hosts", // <3> | ||
"elasticsearch.mycompany.com" | ||
) | ||
// end::setup[] | ||
.properties( TestConfiguration.standalonePojoMapperProperties( | ||
configurationProvider, | ||
BackendConfigurations.simple() | ||
) ) | ||
// tag::setup[] | ||
.build(); // <4> | ||
// end::setup[] | ||
this.theSearchMapping = searchMapping; | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
if ( theSearchMapping != null ) { | ||
theSearchMapping.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void mappingContainsExpectedEntities() { | ||
assertThat( theSearchMapping.allIndexedEntities() ) | ||
.extracting( SearchIndexedEntity::name ) | ||
.contains( "Book", "Associate", "Manager" ) | ||
; | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
...tegrationtest/mapper/pojo/mapping/definition/PojoStandaloneSearchMappingConfigurerIT.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,140 @@ | ||
/* | ||
* 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.mapper.pojo.mapping.definition; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField; | ||
import org.hibernate.search.mapper.pojo.standalone.cfg.StandalonePojoMapperSettings; | ||
import org.hibernate.search.mapper.pojo.standalone.mapping.StandalonePojoMappingConfigurationContext; | ||
import org.hibernate.search.mapper.pojo.standalone.mapping.StandalonePojoMappingConfigurer; | ||
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock; | ||
import org.hibernate.search.util.impl.integrationtest.mapper.pojo.standalone.StandalonePojoMappingSetupHelper; | ||
import org.hibernate.search.util.impl.test.annotation.TestForIssue; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class PojoStandaloneSearchMappingConfigurerIT { | ||
|
||
@Rule | ||
public BackendMock backendMock = new BackendMock(); | ||
|
||
@Rule | ||
public StandalonePojoMappingSetupHelper setupHelper = StandalonePojoMappingSetupHelper.withBackendMock( MethodHandles.lookup(), backendMock ); | ||
|
||
@Test | ||
public void none() { | ||
backendMock.expectSchema( IndexedEntity.INDEX, b -> b | ||
.field( "annotationMapped", String.class ) | ||
); | ||
|
||
setupHelper.start() | ||
.setup( IndexedEntity.class ); | ||
backendMock.verifyExpectationsMet(); | ||
} | ||
|
||
@Test | ||
public void single() { | ||
backendMock.expectSchema( IndexedEntity.INDEX, b -> b | ||
.field( "annotationMapped", String.class ) | ||
.field( "nonAnnotationMapped1", String.class ) | ||
); | ||
|
||
setupHelper.start() | ||
.expectCustomBeans() | ||
.withProperty( StandalonePojoMapperSettings.MAPPING_CONFIGURER, | ||
MappingConfigurer1.class.getName() ) | ||
.setup( IndexedEntity.class ); | ||
backendMock.verifyExpectationsMet(); | ||
} | ||
|
||
public static class MappingConfigurer1 implements StandalonePojoMappingConfigurer { | ||
@Override | ||
public void configure(StandalonePojoMappingConfigurationContext context) { | ||
context.programmaticMapping().type( IndexedEntity.class ) | ||
.property( "nonAnnotationMapped1" ) | ||
.keywordField(); | ||
} | ||
} | ||
|
||
@Test | ||
@TestForIssue(jiraKey = "HSEARCH-4594") | ||
public void multiple() { | ||
backendMock.expectSchema( IndexedEntity.INDEX, b -> b | ||
.field( "annotationMapped", String.class ) | ||
.field( "nonAnnotationMapped1", String.class ) | ||
.field( "nonAnnotationMapped2", String.class ) | ||
); | ||
|
||
setupHelper.start() | ||
.expectCustomBeans() | ||
.withProperty( StandalonePojoMapperSettings.MAPPING_CONFIGURER, | ||
MappingConfigurer1.class.getName() + "," + MappingConfigurer2.class.getName() ) | ||
.setup( IndexedEntity.class ); | ||
backendMock.verifyExpectationsMet(); | ||
} | ||
|
||
public static class MappingConfigurer2 implements StandalonePojoMappingConfigurer { | ||
@Override | ||
public void configure(StandalonePojoMappingConfigurationContext context) { | ||
context.programmaticMapping().type( IndexedEntity.class ) | ||
.property( "nonAnnotationMapped2" ) | ||
.keywordField(); | ||
} | ||
} | ||
|
||
@Indexed(index = IndexedEntity.INDEX) | ||
public static final class IndexedEntity { | ||
public static final String INDEX = "IndexedEntity"; | ||
|
||
@DocumentId | ||
private Integer id; | ||
|
||
@KeywordField | ||
private String annotationMapped; | ||
|
||
private String nonAnnotationMapped1; | ||
|
||
private String nonAnnotationMapped2; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getAnnotationMapped() { | ||
return annotationMapped; | ||
} | ||
|
||
public void setAnnotationMapped(String annotationMapped) { | ||
this.annotationMapped = annotationMapped; | ||
} | ||
|
||
public String getNonAnnotationMapped1() { | ||
return nonAnnotationMapped1; | ||
} | ||
|
||
public void setNonAnnotationMapped1(String nonAnnotationMapped1) { | ||
this.nonAnnotationMapped1 = nonAnnotationMapped1; | ||
} | ||
|
||
public String getNonAnnotationMapped2() { | ||
return nonAnnotationMapped2; | ||
} | ||
|
||
public void setNonAnnotationMapped2(String nonAnnotationMapped2) { | ||
this.nonAnnotationMapped2 = nonAnnotationMapped2; | ||
} | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.