Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-2867 Integration tests for applications using JDK9 modules
- Loading branch information
Showing
8 changed files
with
387 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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>. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>hibernate-search-parent</artifactId> | ||
<groupId>org.hibernate</groupId> | ||
<version>5.8.0-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>hibernate-search-integrationtest-jdk9-modules</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Hibernate Search JDK9 Modules Integration Tests</name> | ||
<description>Hibernate Search integration tests for JDK9 modules</description> | ||
|
||
<properties> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>hibernate-search-orm</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>hibernate-search-engine</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.easytesting</groupId> | ||
<artifactId>fest-assert</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<filtering>true</filtering> | ||
<directory>src/main/resources</directory> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>verify</id> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>9</source> | ||
<target>9</target> | ||
<showWarnings>true</showWarnings> | ||
<showDeprecation>true</showDeprecation> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
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,5 @@ | ||
module hibernate.search.integrationtest.jdk9.modules.client { | ||
exports org.hibernate.search.test.integration.jdk9_modules.client.service; | ||
requires hibernate.search.engine; | ||
requires hibernate.search.orm; | ||
} |
42 changes: 42 additions & 0 deletions
42
...c/main/java/org/hibernate/search/test/integration/jdk9_modules/client/model/MyEntity.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,42 @@ | ||
/* | ||
* 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.jdk9_modules.client.model; | ||
|
||
import javax.persistence.Basic; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.search.annotations.Field; | ||
import org.hibernate.search.annotations.Indexed; | ||
|
||
@Indexed | ||
@Entity | ||
public class MyEntity { | ||
|
||
@Id | ||
private Integer id; | ||
|
||
@Basic | ||
@Field | ||
private String name; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...va/org/hibernate/search/test/integration/jdk9_modules/client/service/MyEntityService.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,112 @@ | ||
/* | ||
* 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.jdk9_modules.client.service; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.EntityTransaction; | ||
|
||
import org.hibernate.boot.Metadata; | ||
import org.hibernate.boot.MetadataSources; | ||
import org.hibernate.boot.SessionFactoryBuilder; | ||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; | ||
import org.hibernate.search.cfg.Environment; | ||
import org.hibernate.search.jpa.FullTextEntityManager; | ||
import org.hibernate.search.jpa.FullTextQuery; | ||
import org.hibernate.search.jpa.Search; | ||
import org.hibernate.search.query.dsl.QueryBuilder; | ||
import org.hibernate.search.test.integration.jdk9_modules.client.model.MyEntity; | ||
import org.hibernate.service.spi.ServiceRegistryImplementor; | ||
|
||
import org.apache.lucene.analysis.en.EnglishAnalyzer; | ||
import org.apache.lucene.search.Query; | ||
|
||
public class MyEntityService implements AutoCloseable { | ||
|
||
private final EntityManagerFactory emf; | ||
|
||
public MyEntityService() { | ||
emf = createSessionFactory(); | ||
} | ||
|
||
private EntityManagerFactory createSessionFactory() { | ||
Map<String, Object> settings = new HashMap<>(); | ||
settings.put( "hibernate.search.default.directory_provider", "local-heap" ); | ||
settings.put( Environment.ANALYZER_CLASS, EnglishAnalyzer.class.getName() ); | ||
settings.put( "hibernate.search.default.indexwriter.merge_factor", "100" ); | ||
settings.put( "hibernate.search.default.indexwriter.max_buffered_docs", "1000" ); | ||
|
||
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder() | ||
.applySettings( settings ); | ||
|
||
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) registryBuilder.build(); | ||
Metadata metadata = new MetadataSources( serviceRegistry ).addAnnotatedClass( MyEntity.class ).buildMetadata(); | ||
SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); | ||
return sfb.build(); | ||
} | ||
|
||
public void add(int id, String name) { | ||
EntityManager em = emf.createEntityManager(); | ||
try { | ||
EntityTransaction tx = em.getTransaction(); | ||
tx.begin(); | ||
try { | ||
MyEntity entity = new MyEntity(); | ||
entity.setId( id ); | ||
entity.setName( name ); | ||
em.persist( entity ); | ||
tx.commit(); | ||
} | ||
catch (Throwable e) { | ||
try { | ||
tx.rollback(); | ||
} | ||
catch (Throwable e2) { | ||
e.addSuppressed( e2 ); | ||
} | ||
throw e; | ||
} | ||
} | ||
finally { | ||
em.close(); | ||
} | ||
} | ||
|
||
public List<Integer> search(String term) { | ||
EntityManager em = emf.createEntityManager(); | ||
try { | ||
EntityTransaction tx = em.getTransaction(); | ||
tx.begin(); | ||
FullTextEntityManager ftEm = Search.getFullTextEntityManager( em ); | ||
QueryBuilder queryBuilder = ftEm.getSearchFactory() | ||
.buildQueryBuilder() | ||
.forEntity( MyEntity.class ) | ||
.get(); | ||
Query luceneQuery = queryBuilder.keyword() | ||
.onField( "name" ) | ||
.matching( term ) | ||
.createQuery(); | ||
FullTextQuery ftQuery = ftEm.createFullTextQuery( luceneQuery ); | ||
List<MyEntity> entities = ftQuery.getResultList(); | ||
List<Integer> ids = entities.stream().map( MyEntity::getId ).collect( Collectors.toList() ); | ||
tx.rollback(); | ||
return ids; | ||
} | ||
finally { | ||
em.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
emf.close(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
integrationtest/jdk9-modules/src/main/resources/hibernate.properties
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,23 @@ | ||
################################################################################################ | ||
# 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>. # | ||
################################################################################################ | ||
hibernate.dialect ${db.dialect} | ||
hibernate.connection.driver_class ${jdbc.driver} | ||
hibernate.connection.url ${jdbc.url} | ||
hibernate.connection.username ${jdbc.user} | ||
hibernate.connection.password ${jdbc.pass} | ||
hibernate.connection.isolation ${jdbc.isolation} | ||
|
||
hibernate.hbm2ddl.auto create-drop | ||
|
||
hibernate.show_sql true | ||
hibernate.format_sql true | ||
|
||
hibernate.max_fetch_depth 5 | ||
|
||
hibernate.cache.region_prefix hibernate.test | ||
hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider | ||
|
35 changes: 35 additions & 0 deletions
35
...s/src/test/java/org/hibernate/search/test/integration/jdk9_modules/MyEntityServiceIT.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,35 @@ | ||
/* | ||
* 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.jdk9_modules; | ||
|
||
import org.hibernate.search.test.integration.jdk9_modules.client.service.MyEntityService; | ||
|
||
import org.junit.Test; | ||
|
||
import org.fest.assertions.Assertions; | ||
|
||
public class MyEntityServiceIT { | ||
|
||
/* | ||
* Test that the service successfully uses Hibernate Search in a JDK9 module. | ||
* We don't really care about the features themselves, | ||
* but that's the easiest way to check that Hibernate Search is being used. | ||
*/ | ||
@Test | ||
public void test() { | ||
MyEntityService service = new MyEntityService(); | ||
service.add( 1, "foo" ); | ||
service.add( 2, "bar" ); | ||
service.add( 3, "foo bar" ); | ||
Assertions.assertThat( service.search( "foo" ) ) | ||
.containsOnly( 1, 3 ); | ||
} | ||
|
||
|
||
} | ||
|
||
|
54 changes: 54 additions & 0 deletions
54
integrationtest/jdk9-modules/src/test/resources/log4j.properties
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,54 @@ | ||
### direct log messages to stdout ### | ||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.Target=System.out | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} (%t) %5p %c{1}:%L - %m%n | ||
|
||
### direct messages to file hibernate.log ### | ||
log4j.appender.file=org.apache.log4j.FileAppender | ||
log4j.appender.file.File=hibernate.log | ||
log4j.appender.file.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} (%t) %5p %c{1}:%L - %m%n | ||
|
||
### direct messages to socket - chainsaw ### | ||
log4j.appender.socket=org.apache.log4j.net.SocketAppender | ||
log4j.appender.socket.remoteHost=localhost | ||
log4j.appender.socket.port=4560 | ||
log4j.appender.socket.locationInfo=true | ||
|
||
### set log levels - for more verbose logging change 'info' to 'debug' ### | ||
|
||
log4j.rootLogger=debug, stdout | ||
log4j.logger.org.jboss=info | ||
#log4j.logger.com.jboss=debug | ||
|
||
log4j.logger.org.hibernate=warn | ||
|
||
log4j.logger.org.hibernate.search=debug | ||
#log4j.logger.org.hibernate.search.backend=debug | ||
|
||
### log just the SQL | ||
log4j.logger.org.hibernate.SQL=debug | ||
|
||
#log4j.logger.org.hibernate.engine.CascadingAction=debug | ||
|
||
### log JDBC bind parameters ### | ||
#log4j.logger.org.hibernate.type=debug | ||
|
||
### log schema export/update ### | ||
log4j.logger.org.hibernate.tool.hbm2ddl=warn | ||
|
||
### log cache activity ### | ||
#log4j.logger.org.hibernate.cache=debug | ||
|
||
### enable the following line if you want to track down connection ### | ||
### leakages when using DriverManagerConnectionProvider ### | ||
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace | ||
|
||
### annotation logs | ||
#log4j.logger.org.hibernate.annotation=info | ||
#log4j.logger.org.hibernate.cfg=info | ||
#log4j.logger.org.hibernate.cfg.SettingsFactory=info | ||
#log4j.logger.org.hibernate.cfg.AnnotationBinder=info | ||
#log4j.logger.org.hibernate.cfg.AnnotationConfiguration=info | ||
#log4j.logger.org.hibernate.cfg.Ejb3Column=info |
Oops, something went wrong.