-
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-2134 Integration test with WildFly
Test integration with Elasticsearch using JBoss Modules and deploying a bean on WildFly
- Loading branch information
Showing
3 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
integrationtest/wildfly/elasticsearchconfiguration/elasticsearch.yml
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,53 @@ | ||
# ======================== Elasticsearch Configuration ========================= | ||
# | ||
# NOTE: Elasticsearch comes with reasonable defaults for most settings. | ||
# This file overrides those reasonable settings for testing purposes | ||
# and is unlikely to be suited for any other goal: do not take this as | ||
# an example to run a production system. | ||
# | ||
# Please see the documentation for further information on configuration options: | ||
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html> | ||
# | ||
# ---------------------------------- Cluster ----------------------------------- | ||
# Use a descriptive name for your cluster: | ||
cluster.name: hsearch-testing | ||
# | ||
# ------------------------------------ Node ------------------------------------ | ||
# Use a descriptive name for the node: | ||
node.name: node-wildfly-1 | ||
|
||
# | ||
# Lock the memory on startup; requires system permissions to be effective, | ||
# but shouldn't be harmful when the permissions are not granted. | ||
bootstrap.mlockall: true | ||
# | ||
# ---------------------------------- Network ----------------------------------- | ||
# Set the bind address to a specific IP (IPv4 or IPv6): | ||
network.host: 127.0.0.1 | ||
http.port: 9200 | ||
|
||
|
||
# --------------------------------- Discovery ---------------------------------- | ||
# Disable discovery to speedup forming a single node cluster: | ||
discovery.zen.ping.multicast.enabled: false | ||
discovery.zen.minimum_master_nodes: 1 | ||
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html> | ||
|
||
# ---------------------------------- Gateway ----------------------------------- | ||
# For more information, see the documentation at: | ||
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html> | ||
|
||
# ---------------------------------- Various ----------------------------------- | ||
# | ||
# Disable starting multiple nodes on a single system: | ||
# | ||
node.max_local_storage_nodes: 1 | ||
|
||
# Additional customizations to run a singleton node: | ||
|
||
node.local: true | ||
index.number_of_shards: 1 | ||
index.number_of_replicas: 0 | ||
|
||
# Enable Groovy scripting support for search: useful for spatial queries | ||
script.engine.groovy.inline.search: on |
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
131 changes: 131 additions & 0 deletions
131
...ernate/search/test/integration/elasticsearch/ElasticsearchModuleMemberRegistrationIT.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,131 @@ | ||
/* | ||
* 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.test.integration.elasticsearch; | ||
|
||
import static org.hibernate.search.test.integration.VersionTestHelper.getWildFlyModuleIdentifier; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import javax.annotation.Resource; | ||
import javax.inject.Inject; | ||
|
||
import org.hibernate.search.test.integration.VersionTestHelper; | ||
import org.hibernate.search.test.integration.wildfly.controller.MemberRegistration; | ||
import org.hibernate.search.test.integration.wildfly.model.Member; | ||
import org.hibernate.search.test.integration.wildfly.util.Resources; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.Asset; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.shrinkwrap.descriptor.api.Descriptors; | ||
import org.jboss.shrinkwrap.descriptor.api.persistence20.PersistenceDescriptor; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Testing Elasticsearch integration using WildFLy | ||
* | ||
* @author Davide D'Alto | ||
* @author Sanne Grinovero | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class ElasticsearchModuleMemberRegistrationIT { | ||
|
||
private static final String EXPECTED_SEARCH_VERSION_RESOURCE = "expectedHibernateSearchVersion"; | ||
|
||
@Deployment | ||
public static Archive<?> createTestArchive() { | ||
return ShrinkWrap | ||
.create( WebArchive.class, ElasticsearchModuleMemberRegistrationIT.class.getSimpleName() + ".war" ) | ||
.addClasses( Member.class, MemberRegistration.class, Resources.class ) | ||
.addAsResource( persistenceXml(), "META-INF/persistence.xml" ) | ||
.addAsWebInfResource( EmptyAsset.INSTANCE, "beans.xml" ) | ||
.addAsWebInfResource( webXml(), "web.xml" ); | ||
} | ||
|
||
private static Asset webXml() { | ||
String webXml = Descriptors.create( org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor.class ) | ||
.createEnvEntry() | ||
.envEntryName( EXPECTED_SEARCH_VERSION_RESOURCE ) | ||
.envEntryValue( VersionTestHelper.getDependencyVersionHibernateSearch() ) | ||
.envEntryType( "java.lang.String" ) | ||
.up() | ||
.exportAsString(); | ||
return new StringAsset( webXml ); | ||
} | ||
|
||
private static Asset persistenceXml() { | ||
String persistenceXml = Descriptors.create( PersistenceDescriptor.class ) | ||
.version( "2.0" ) | ||
.createPersistenceUnit() | ||
.name( "primary" ) | ||
.jtaDataSource( "java:jboss/datasources/ExampleDS" ) | ||
// The deployment Scanner is disabled as the JipiJapa integration is not available because of the custom Hibernate ORM module: | ||
.clazz( Member.class.getName() ) | ||
.getOrCreateProperties() | ||
.createProperty().name( "hibernate.hbm2ddl.auto" ).value( "create-drop" ).up() | ||
.createProperty().name( "hibernate.search.default.lucene_version" ).value( "LUCENE_CURRENT" ).up() | ||
.createProperty().name( "hibernate.search.default.indexmanager" ).value( "elasticsearch" ).up() | ||
.createProperty().name( "wildfly.jpa.hibernate.search.module" ).value( getWildFlyModuleIdentifier() ).up() | ||
.createProperty().name( "hibernate.search.elasticsearch.index_management_strategy" ).value( "CREATE_DELETE" ).up() | ||
.up().up() | ||
.exportAsString(); | ||
return new StringAsset( persistenceXml ); | ||
} | ||
|
||
@Inject | ||
MemberRegistration memberRegistration; | ||
|
||
@Resource(name = EXPECTED_SEARCH_VERSION_RESOURCE) | ||
String expectedSearchVersion; | ||
|
||
@Test | ||
public void HibernateSearchVersion() throws Exception { | ||
assertEquals( expectedSearchVersion, memberRegistration.getHibernateSearchVersionString() ); | ||
} | ||
|
||
@Test | ||
public void testRegister() throws Exception { | ||
Member newMember = memberRegistration.getNewMember(); | ||
newMember.setName( "Davide D'Alto" ); | ||
newMember.setEmail( "davide@mailinator.com" ); | ||
newMember.setPhoneNumber( "2125551234" ); | ||
memberRegistration.register(); | ||
|
||
assertNotNull( newMember.getId() ); | ||
} | ||
|
||
@Test | ||
public void testNewMemberSearch() throws Exception { | ||
Member newMember = memberRegistration.getNewMember(); | ||
newMember.setName( "Peter O'Tall" ); | ||
newMember.setEmail( "peter@mailinator.com" ); | ||
newMember.setPhoneNumber( "4643646643" ); | ||
memberRegistration.register(); | ||
|
||
List<Member> search = memberRegistration.search( "Peter" ); | ||
|
||
assertFalse( "Expected at least one result after the indexing", search.isEmpty() ); | ||
assertEquals( "Search hasn't found a new member", newMember.getName(), search.get( 0 ).getName() ); | ||
} | ||
|
||
@Test | ||
public void testUnexistingMember() throws Exception { | ||
List<Member> search = memberRegistration.search( "TotallyInventedName" ); | ||
|
||
assertNotNull( "Search should never return null", search ); | ||
assertTrue( "Search results should be empty", search.isEmpty() ); | ||
} | ||
} |