├── .github └── dependabot.yml ├── .gitignore ├── Jenkinsfile ├── README.md ├── envers ├── README.md ├── envers-5 │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── envers │ │ │ └── bugs │ │ │ ├── AbstractEnversTestCase.java │ │ │ └── EnversUnitTestCase.java │ │ └── resources │ │ ├── META-INF │ │ └── persistence.xml │ │ ├── hibernate.properties │ │ └── log4j2.properties ├── envers-6 │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── envers │ │ │ └── bugs │ │ │ ├── AbstractEnversTestCase.java │ │ │ └── EnversUnitTestCase.java │ │ └── resources │ │ ├── META-INF │ │ └── persistence.xml │ │ ├── hibernate.properties │ │ └── log4j2.properties └── envers-7 │ ├── pom.xml │ └── src │ └── test │ ├── java │ └── org │ │ └── hibernate │ │ └── envers │ │ └── bugs │ │ ├── AbstractEnversTestCase.java │ │ └── EnversUnitTestCase.java │ └── resources │ ├── META-INF │ └── persistence.xml │ ├── hibernate.properties │ └── log4j2.properties ├── orm ├── README.md ├── hibernate-orm-5 │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── bugs │ │ │ ├── JPAUnitTestCase.java │ │ │ ├── ORMStandaloneTestCase.java │ │ │ └── ORMUnitTestCase.java │ │ └── resources │ │ ├── META-INF │ │ └── persistence.xml │ │ ├── hibernate.properties │ │ └── log4j2.properties ├── hibernate-orm-6 │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── bugs │ │ │ ├── JPAUnitTestCase.java │ │ │ ├── ORMStandaloneTestCase.java │ │ │ ├── ORMUnitTestCase.java │ │ │ ├── QuarkusLikeEnhancementContext.java │ │ │ └── QuarkusLikeORMUnitTestCase.java │ │ └── resources │ │ ├── META-INF │ │ └── persistence.xml │ │ ├── hibernate.properties │ │ └── log4j2.properties └── hibernate-orm-7 │ ├── pom.xml │ └── src │ └── test │ ├── java │ └── org │ │ └── hibernate │ │ └── bugs │ │ ├── JPAUnitTestCase.java │ │ ├── ORMStandaloneTestCase.java │ │ ├── ORMUnitTestCase.java │ │ ├── QuarkusLikeEnhancementContext.java │ │ └── QuarkusLikeORMUnitTestCase.java │ └── resources │ ├── META-INF │ └── persistence.xml │ ├── hibernate.properties │ └── log4j2.properties ├── pom.xml ├── reactive ├── hibernate-reactive-2 │ ├── README.md │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── reactive │ │ │ ├── bugs │ │ │ ├── ReactiveStandaloneTestCase.java │ │ │ └── model │ │ │ │ └── MyEntity.java │ │ │ └── util │ │ │ ├── ConnectionURL.java │ │ │ ├── Database.java │ │ │ └── DockerImage.java │ │ └── resources │ │ └── log4j2.properties ├── hibernate-reactive-3 │ ├── README.md │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── reactive │ │ │ ├── bugs │ │ │ ├── ReactiveStandaloneTestCase.java │ │ │ └── model │ │ │ │ └── MyEntity.java │ │ │ └── util │ │ │ ├── ConnectionURL.java │ │ │ ├── Database.java │ │ │ └── DockerImage.java │ │ └── resources │ │ └── log4j2.properties └── hibernate-reactive-4 │ ├── README.md │ ├── pom.xml │ └── src │ └── test │ ├── java │ └── org │ │ └── hibernate │ │ └── reactive │ │ ├── bugs │ │ ├── ReactiveStandaloneTestCase.java │ │ └── model │ │ │ └── MyEntity.java │ │ └── util │ │ ├── ConnectionURL.java │ │ ├── Database.java │ │ └── DockerImage.java │ └── resources │ └── log4j2.properties ├── search ├── README.md ├── hibernate-search-5 │ ├── README.md │ ├── elasticsearch-2 │ │ └── README.md │ ├── elasticsearch-5 │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── test │ │ │ ├── java │ │ │ └── org │ │ │ │ └── hibernate │ │ │ │ └── search │ │ │ │ └── bugs │ │ │ │ ├── SearchBackendContainer.java │ │ │ │ ├── SearchTestBase.java │ │ │ │ ├── SearchTestJunit4Base.java │ │ │ │ ├── YourAnnotatedEntity.java │ │ │ │ └── YourIT.java │ │ │ └── resources │ │ │ ├── META-INF │ │ │ └── persistence.xml │ │ │ ├── hibernate.properties │ │ │ └── log4j2.properties │ └── lucene │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── search │ │ │ └── bugs │ │ │ ├── SearchTestBase.java │ │ │ ├── YourAnnotatedEntity.java │ │ │ └── YourIT.java │ │ └── resources │ │ ├── META-INF │ │ └── persistence.xml │ │ ├── hibernate.properties │ │ └── log4j2.properties ├── hibernate-search-6 │ ├── README.md │ ├── orm-elasticsearch │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── test │ │ │ ├── java │ │ │ └── org │ │ │ │ └── hibernate │ │ │ │ └── search │ │ │ │ └── bugs │ │ │ │ ├── SearchBackendContainer.java │ │ │ │ ├── SearchTestBase.java │ │ │ │ ├── SearchTestJunit4Base.java │ │ │ │ ├── YourAnalysisConfigurer.java │ │ │ │ ├── YourAnnotatedEntity.java │ │ │ │ └── YourIT.java │ │ │ └── resources │ │ │ ├── META-INF │ │ │ └── persistence.xml │ │ │ ├── hibernate.properties │ │ │ └── log4j2.properties │ └── orm-lucene │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── search │ │ │ └── bugs │ │ │ ├── SearchTestBase.java │ │ │ ├── YourAnalysisConfigurer.java │ │ │ ├── YourAnnotatedEntity.java │ │ │ └── YourIT.java │ │ └── resources │ │ ├── META-INF │ │ └── persistence.xml │ │ ├── hibernate.properties │ │ └── log4j2.properties ├── hibernate-search-7 │ ├── README.md │ ├── orm-elasticsearch │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── test │ │ │ ├── java │ │ │ └── org │ │ │ │ └── hibernate │ │ │ │ └── search │ │ │ │ └── bugs │ │ │ │ ├── SearchBackendContainer.java │ │ │ │ ├── SearchTestBase.java │ │ │ │ ├── SearchTestJunit4Base.java │ │ │ │ ├── YourAnalysisConfigurer.java │ │ │ │ ├── YourAnnotatedEntity.java │ │ │ │ ├── YourBytecodeEnhancedIT.java │ │ │ │ └── YourIT.java │ │ │ └── resources │ │ │ ├── META-INF │ │ │ └── persistence.xml │ │ │ ├── hibernate.properties │ │ │ └── log4j2.properties │ └── orm-lucene │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── hibernate │ │ │ └── search │ │ │ └── bugs │ │ │ ├── SearchTestBase.java │ │ │ ├── YourAnalysisConfigurer.java │ │ │ ├── YourAnnotatedEntity.java │ │ │ ├── YourBytecodeEnhancedIT.java │ │ │ └── YourIT.java │ │ └── resources │ │ ├── META-INF │ │ └── persistence.xml │ │ ├── hibernate.properties │ │ └── log4j2.properties ├── hibernate-search-elasticsearch │ ├── README.md │ ├── hibernate-search-elasticsearch-2 │ │ └── README.md │ └── hibernate-search-elasticsearch-5 │ │ └── README.md └── hibernate-search-lucene │ └── README.md └── validator ├── README.md ├── validator-6 ├── README.md ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── hibernate │ │ └── validator │ │ └── bugs │ │ ├── YourAnnotatedBean.java │ │ └── YourTestCase.java │ └── resources │ └── log4j2.properties ├── validator-8 ├── README.md ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── hibernate │ │ └── validator │ │ └── bugs │ │ ├── YourAnnotatedBean.java │ │ └── YourTestCase.java │ └── resources │ └── log4j2.properties └── validator-9 ├── README.md ├── pom.xml └── src └── test ├── java └── org │ └── hibernate │ └── validator │ └── bugs │ ├── YourAnnotatedBean.java │ └── YourTestCase.java └── resources └── log4j2.properties /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | groups: 8 | quarkus: 9 | patterns: 10 | - "io.quarkus*" 11 | - "io.quarkiverse*" 12 | orm: 13 | patterns: 14 | - "org.hibernate.orm*:*" 15 | search: 16 | patterns: 17 | - "org.hibernate.search:*" 18 | validator: 19 | patterns: 20 | - "org.hibernate.validator:*" 21 | reactive: 22 | patterns: 23 | - "org.hibernate.reactive:*" 24 | reactive-dependencies-jdbc: 25 | patterns: 26 | - "com.mysql:mysql-connector-j" 27 | - "org.mariadb.jdbc:mariadb-java-client" 28 | - "com.ibm.db2:jcc" 29 | - "com.microsoft.sqlserver:mssql-jdbc" 30 | maven-plugins: 31 | patterns: 32 | - "*maven*plugin*" 33 | - "org.apache.maven*:*" 34 | exclude-patterns: 35 | - "io.quarkus*" 36 | - "org.hibernate*" 37 | test: 38 | patterns: 39 | - "org.junit*" 40 | - "org.apache.logging*" 41 | - "com.h2database:*" 42 | - "org.assertj:*" 43 | ignore: 44 | - dependency-name: "org.hibernate.orm.tooling:hibernate-enhance-maven-plugin" 45 | - dependency-name: "org.hibernate:hibernate-core" 46 | update-types: [ "version-update:semver-major", "version-update:semver-minor" ] 47 | - dependency-name: "org.hibernate:*" 48 | update-types: [ "version-update:semver-major" ] 49 | - dependency-name: "org.hibernate.*:*" 50 | update-types: [ "version-update:semver-major" ] 51 | - dependency-name: "com.h2database:h2" 52 | update-types: [ "version-update:semver-major" ] 53 | - dependency-name: "com.github.alexcojocaru:elasticsearch-maven-plugin" 54 | update-types: [ "version-update:semver-major" ] 55 | - dependency-name: "org.elasticsearch:*" 56 | update-types: [ "version-update:semver-major" ] 57 | - dependency-name: "org.elasticsearch.*:*" 58 | update-types: [ "version-update:semver-major" ] 59 | # Major versions of vertx will (most likely) require a new version of Reactive, so will be updated "manually": 60 | - dependency-name: "io.vertx:*" 61 | update-types: [ "version-update:semver-major" ] 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.iml 3 | .idea 4 | 5 | # Eclipse 6 | .settings 7 | .classpath 8 | .project 9 | 10 | .DS_Store 11 | 12 | *.log 13 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { 3 | label 'Worker&&Containers' 4 | } 5 | tools { 6 | jdk 'OpenJDK 17 Latest' 7 | maven 'Apache Maven 3.9' 8 | } 9 | options { 10 | disableConcurrentBuilds(abortPrevious: true) 11 | } 12 | stages { 13 | stage('Build') { 14 | steps { 15 | sh "mvn -B -q clean package -DskipTests=true" 16 | } 17 | } 18 | stage('Test') { 19 | steps { 20 | sh "mvn -B verify" 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates 2 | 3 | When creating a bug report for any project within the Hibernate family, it's extremely helpful (and, frankly, required) 4 | to have an adequate test case available. This is obviously important to make reproducing the issue as easy as 5 | possible. But it's also vital longer-term. Nearly every bug fix should include a regression test, which frequently is based 6 | on the original reproducer (sometimes, it's the reproducer, verbatim). 7 | 8 | To help create useful test cases, we're opening up this repo with various templates. Please see the READMEs in each 9 | project's subdir for more info. 10 | 11 | As always, this is open source for a reason! If these templates can be improved in any way, please let us know (either 12 | through our JIRA instance or through GitHub Issues). Better yet, send us a pull request! -------------------------------------------------------------------------------- /envers/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Envers 2 | 3 | This repo contains test case templates, useful for reporting bugs against Hibernate Envers. 4 | 5 | * EnversUnitTestCase: This provides built-in unit test framework that does much of the heavy lifting for you. All 6 | that is required is your entities, logic, and any necessary settings. Since we nearly always include a regression 7 | test with bug fixes, providing your reproducer using this class simplifies that process. We can then directly add 8 | it, without having to mold it into our existing framework. You're also welcomed to fork hibernate-orm itself, add 9 | your test case directly to the Enver's module test cases (using the template class), then submit it as a pull 10 | request. 11 | -------------------------------------------------------------------------------- /envers/envers-5/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-envers-5 7 | 1.0.0.Final 8 | Hibernate Envers 5 Test Case Template 9 | 10 | 11 | 2.3.232 12 | 4.13.2 13 | 5.6.15.Final 14 | 15 | 16 | 17 | 18 | org.hibernate 19 | hibernate-envers 20 | ${version.org.hibernate} 21 | 22 | 23 | com.h2database 24 | h2 25 | ${version.com.h2database} 26 | 27 | 28 | 29 | org.hibernate 30 | hibernate-testing 31 | ${version.org.hibernate} 32 | test 33 | 34 | 35 | junit 36 | junit 37 | ${version.junit} 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-compiler-plugin 47 | 3.14.0 48 | 49 | 1.8 50 | 1.8 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /envers/envers-5/src/test/java/org/hibernate/envers/bugs/AbstractEnversTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | * See the lgpl.txt file in the root directory or . 6 | */ 7 | package org.hibernate.envers.bugs; 8 | 9 | import org.hibernate.envers.AuditReader; 10 | import org.hibernate.envers.AuditReaderFactory; 11 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 12 | 13 | /** 14 | * @author Chris Cranford 15 | */ 16 | public abstract class AbstractEnversTestCase extends BaseCoreFunctionalTestCase { 17 | private AuditReader auditReader; 18 | 19 | protected AuditReader getAuditReader() { 20 | if ( auditReader == null || session == null || !session.isOpen() ) { 21 | auditReader = AuditReaderFactory.get( openSession() ); 22 | } 23 | return auditReader; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /envers/envers-5/src/test/java/org/hibernate/envers/bugs/EnversUnitTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | * See the lgpl.txt file in the root directory or . 6 | */ 7 | package org.hibernate.envers.bugs; 8 | 9 | import org.hibernate.cfg.AvailableSettings; 10 | import org.hibernate.cfg.Configuration; 11 | import org.hibernate.envers.AuditReader; 12 | import org.junit.Test; 13 | 14 | /** 15 | * This template demonstrates how to develop a test case for Hibernate Envers, using 16 | * its built-in unit test framework. 17 | */ 18 | public class EnversUnitTestCase extends AbstractEnversTestCase { 19 | 20 | // Add your entities here. 21 | @Override 22 | protected Class[] getAnnotatedClasses() { 23 | return new Class[] { 24 | // Foo.class, 25 | // Bar.class 26 | }; 27 | } 28 | 29 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here. 30 | @Override 31 | protected String[] getMappings() { 32 | return new String[] { 33 | // "Foo.hbm.xml", 34 | // "Bar.hbm.xml" 35 | }; 36 | } 37 | // If those mappings reside somewhere other than resources/org/hibernate/test, change this. 38 | @Override 39 | protected String getBaseForMappings() { 40 | return "org/hibernate/test/"; 41 | } 42 | 43 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 44 | @Override 45 | protected void configure(Configuration configuration) { 46 | super.configure( configuration ); 47 | 48 | configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() ); 49 | configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() ); 50 | //configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" ); 51 | } 52 | 53 | // Add your tests, using standard JUnit. 54 | @Test 55 | public void hhh123Test() throws Exception { 56 | AuditReader reader = getAuditReader(); 57 | // Do stuff... 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /envers/envers-5/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Hibernate test case template Persistence Unit 10 | org.hibernate.jpa.HibernatePersistenceProvider 11 | 12 | false 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /envers/envers-5/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | hibernate.dialect org.hibernate.dialect.H2Dialect 9 | hibernate.connection.driver_class org.h2.Driver 10 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE 11 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 12 | hibernate.connection.username sa 13 | 14 | hibernate.connection.pool_size 5 15 | 16 | hibernate.show_sql false 17 | hibernate.format_sql true 18 | 19 | hibernate.max_fetch_depth 5 20 | 21 | hibernate.cache.region_prefix hibernate.test 22 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory 23 | 24 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle 25 | hibernate.jdbc.batch_versioned_data true 26 | 27 | javax.persistence.validation.mode=NONE 28 | hibernate.service.allow_crawling=false 29 | hibernate.session.events.log=true -------------------------------------------------------------------------------- /envers/envers-5/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /envers/envers-6/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-envers-6 7 | 1.0.0.Final 8 | Hibernate Envers 6 Test Case Template 9 | 10 | 11 | 2.3.232 12 | 4.13.2 13 | 6.6.17.Final 14 | 15 | 16 | 17 | 18 | 19 | org.hibernate.orm 20 | hibernate-platform 21 | ${version.org.hibernate.orm} 22 | pom 23 | import 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.hibernate.orm 31 | hibernate-envers 32 | 33 | 34 | com.h2database 35 | h2 36 | ${version.com.h2database} 37 | 38 | 39 | 40 | org.hibernate.orm 41 | hibernate-testing 42 | test 43 | 44 | 45 | junit 46 | junit 47 | ${version.junit} 48 | test 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-compiler-plugin 57 | 3.14.0 58 | 59 | 11 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /envers/envers-6/src/test/java/org/hibernate/envers/bugs/AbstractEnversTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | * See the lgpl.txt file in the root directory or . 6 | */ 7 | package org.hibernate.envers.bugs; 8 | 9 | import org.hibernate.envers.AuditReader; 10 | import org.hibernate.envers.AuditReaderFactory; 11 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 12 | 13 | /** 14 | * @author Chris Cranford 15 | */ 16 | public abstract class AbstractEnversTestCase extends BaseCoreFunctionalTestCase { 17 | private AuditReader auditReader; 18 | 19 | protected AuditReader getAuditReader() { 20 | if ( auditReader == null || session == null || !session.isOpen() ) { 21 | auditReader = AuditReaderFactory.get( openSession() ); 22 | } 23 | return auditReader; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /envers/envers-6/src/test/java/org/hibernate/envers/bugs/EnversUnitTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | * See the lgpl.txt file in the root directory or . 6 | */ 7 | package org.hibernate.envers.bugs; 8 | 9 | import org.hibernate.cfg.AvailableSettings; 10 | import org.hibernate.cfg.Configuration; 11 | import org.hibernate.envers.AuditReader; 12 | import org.junit.Test; 13 | 14 | /** 15 | * This template demonstrates how to develop a test case for Hibernate Envers, using 16 | * its built-in unit test framework. 17 | */ 18 | public class EnversUnitTestCase extends AbstractEnversTestCase { 19 | 20 | // Add your entities here. 21 | @Override 22 | protected Class[] getAnnotatedClasses() { 23 | return new Class[] { 24 | // Foo.class, 25 | // Bar.class 26 | }; 27 | } 28 | 29 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here. 30 | @Override 31 | protected String[] getMappings() { 32 | return new String[] { 33 | // "Foo.hbm.xml", 34 | // "Bar.hbm.xml" 35 | }; 36 | } 37 | // If those mappings reside somewhere other than resources/org/hibernate/test, change this. 38 | @Override 39 | protected String getBaseForMappings() { 40 | return "org/hibernate/test/"; 41 | } 42 | 43 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 44 | @Override 45 | protected void configure(Configuration configuration) { 46 | super.configure( configuration ); 47 | 48 | configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() ); 49 | configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() ); 50 | //configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" ); 51 | } 52 | 53 | // Add your tests, using standard JUnit. 54 | @Test 55 | public void hhh123Test() throws Exception { 56 | AuditReader reader = getAuditReader(); 57 | // Do stuff... 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /envers/envers-6/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | Hibernate test case template Persistence Unit 9 | org.hibernate.jpa.HibernatePersistenceProvider 10 | 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /envers/envers-6/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | hibernate.dialect org.hibernate.dialect.H2Dialect 9 | hibernate.connection.driver_class org.h2.Driver 10 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE 11 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 12 | hibernate.connection.username sa 13 | hibernate.connection.password 14 | 15 | hibernate.connection.pool_size 5 16 | 17 | hibernate.show_sql false 18 | hibernate.format_sql true 19 | 20 | hibernate.max_fetch_depth 5 21 | 22 | hibernate.cache.region_prefix hibernate.test 23 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory 24 | 25 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle 26 | hibernate.jdbc.batch_versioned_data true 27 | 28 | jakarta.persistence.validation.mode=NONE 29 | hibernate.service.allow_crawling=false 30 | hibernate.session.events.log=true -------------------------------------------------------------------------------- /envers/envers-6/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /envers/envers-7/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-envers-7 7 | 1.0.0.Final 8 | Hibernate Envers 7 Test Case Template 9 | 10 | 11 | 2.3.232 12 | 4.13.2 13 | 7.0.0.Final 14 | 15 | 16 | 17 | 18 | 19 | org.hibernate.orm 20 | hibernate-platform 21 | ${version.org.hibernate.orm} 22 | pom 23 | import 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.hibernate.orm 31 | hibernate-envers 32 | 33 | 34 | com.h2database 35 | h2 36 | ${version.com.h2database} 37 | 38 | 39 | 40 | org.hibernate.orm 41 | hibernate-testing 42 | test 43 | 44 | 45 | junit 46 | junit 47 | ${version.junit} 48 | test 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-compiler-plugin 57 | 3.14.0 58 | 59 | 17 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /envers/envers-7/src/test/java/org/hibernate/envers/bugs/AbstractEnversTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.envers.bugs; 2 | 3 | import org.hibernate.envers.AuditReader; 4 | import org.hibernate.envers.AuditReaderFactory; 5 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 6 | 7 | /** 8 | * @author Chris Cranford 9 | */ 10 | public abstract class AbstractEnversTestCase extends BaseCoreFunctionalTestCase { 11 | private AuditReader auditReader; 12 | 13 | protected AuditReader getAuditReader() { 14 | if ( auditReader == null || session == null || !session.isOpen() ) { 15 | auditReader = AuditReaderFactory.get( openSession() ); 16 | } 17 | return auditReader; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /envers/envers-7/src/test/java/org/hibernate/envers/bugs/EnversUnitTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.envers.bugs; 2 | 3 | import org.hibernate.cfg.AvailableSettings; 4 | import org.hibernate.cfg.Configuration; 5 | import org.hibernate.envers.AuditReader; 6 | import org.junit.Test; 7 | 8 | /** 9 | * This template demonstrates how to develop a test case for Hibernate Envers, using 10 | * its built-in unit test framework. 11 | */ 12 | public class EnversUnitTestCase extends AbstractEnversTestCase { 13 | 14 | // Add your entities here. 15 | @Override 16 | protected Class[] getAnnotatedClasses() { 17 | return new Class[] { 18 | // Foo.class, 19 | // Bar.class 20 | }; 21 | } 22 | 23 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here. 24 | @Override 25 | protected String[] getMappings() { 26 | return new String[] { 27 | // "Foo.hbm.xml", 28 | // "Bar.hbm.xml" 29 | }; 30 | } 31 | // If those mappings reside somewhere other than resources/org/hibernate/test, change this. 32 | @Override 33 | protected String getBaseForMappings() { 34 | return "org/hibernate/test/"; 35 | } 36 | 37 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 38 | @Override 39 | protected void configure(Configuration configuration) { 40 | super.configure( configuration ); 41 | 42 | configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() ); 43 | configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() ); 44 | //configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" ); 45 | } 46 | 47 | // Add your tests, using standard JUnit. 48 | @Test 49 | public void hhh123Test() throws Exception { 50 | AuditReader reader = getAuditReader(); 51 | // Do stuff... 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /envers/envers-7/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | Hibernate test case template Persistence Unit 9 | org.hibernate.jpa.HibernatePersistenceProvider 10 | 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /envers/envers-7/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | hibernate.dialect org.hibernate.dialect.H2Dialect 2 | hibernate.connection.driver_class org.h2.Driver 3 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE 4 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 5 | hibernate.connection.username sa 6 | hibernate.connection.password 7 | 8 | hibernate.connection.pool_size 5 9 | 10 | hibernate.show_sql false 11 | hibernate.format_sql true 12 | 13 | hibernate.max_fetch_depth 5 14 | 15 | hibernate.cache.region_prefix hibernate.test 16 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory 17 | 18 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle 19 | hibernate.jdbc.batch_versioned_data true 20 | 21 | jakarta.persistence.validation.mode=NONE 22 | hibernate.service.allow_crawling=false 23 | hibernate.session.events.log=true 24 | -------------------------------------------------------------------------------- /envers/envers-7/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /orm/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: ORM 2 | 3 | This repo contains test case templates, useful for reporting bugs against Hibernate ORM. 4 | 5 | Here's a running list of what's available (there are versions of each test case template, one per Hibernate ORM version 5/6/7): 6 | 7 | * `ORMUnitTestCase`: By far, this one's the most helpful. ORM includes a built-in unit test framework that does much 8 | of the heavy lifting for you. All that's required is your entities, logic, and any necessary settings. Since we nearly 9 | always include a regression test with bug fixes, providing your reproducer using this method simplifies the process. We 10 | can then directly commit it, without having to mold it in first. What's even better? Fork hibernate-orm itself, 11 | add your test case directly to a module's unit tests (using the template class), then submit it as a PR! 12 | * `ORMStandaloneTestCase`: This template is standalone and will look familiar. It simply uses a run-of-the-mill ORM setup. 13 | Although it's perfectly acceptable as a reproducer, lean towards `ORMUnitTestCase` whenever possible. 14 | * `QuarkusLikeORMUnitTestCase`: is the same as the `ORMUnitTestCase` with some properties preconfigured to match the behavior that Quarkus has. 15 | **For a detailed step-by-step tutorial about how you should be using our test case templates check out the [following article](http://in.relation.to/2016/01/14/hibernate-jpa-test-case-template/)**. 16 | -------------------------------------------------------------------------------- /orm/hibernate-orm-5/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-orm-5 7 | 1.0.0.Final 8 | Hibernate ORM 5 Test Case Template 9 | 10 | 11 | 2.3.232 12 | 4.13.2 13 | 5.6.15.Final 14 | 15 | 16 | 17 | 18 | org.hibernate 19 | hibernate-core 20 | ${version.org.hibernate} 21 | 22 | 23 | com.h2database 24 | h2 25 | ${version.com.h2database} 26 | 27 | 28 | 29 | 30 | org.hibernate 31 | hibernate-entitymanager 32 | ${version.org.hibernate} 33 | 34 | 35 | org.hibernate 36 | hibernate-java8 37 | ${version.org.hibernate} 38 | 39 | 40 | 41 | org.hibernate 42 | hibernate-testing 43 | ${version.org.hibernate} 44 | test 45 | 46 | 47 | junit 48 | junit 49 | ${version.junit} 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-compiler-plugin 59 | 3.14.0 60 | 61 | 1.8 62 | 1.8 63 | 64 | 65 | 66 | org.hibernate.orm.tooling 67 | hibernate-enhance-maven-plugin 68 | ${version.org.hibernate} 69 | 70 | 71 | 72 | ${project.build.testOutputDirectory} 73 | ${project.build.testOutputDirectory} 74 | false 75 | false 76 | false 77 | false 78 | 79 | test-compile 80 | 81 | enhance 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import javax.persistence.EntityManager; 4 | import javax.persistence.EntityManagerFactory; 5 | import javax.persistence.Persistence; 6 | 7 | import org.junit.After; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | /** 12 | * This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API. 13 | */ 14 | public class JPAUnitTestCase { 15 | 16 | private EntityManagerFactory entityManagerFactory; 17 | 18 | @Before 19 | public void init() { 20 | entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" ); 21 | } 22 | 23 | @After 24 | public void destroy() { 25 | entityManagerFactory.close(); 26 | } 27 | 28 | // Entities are auto-discovered, so just add them anywhere on class-path 29 | // Add your tests, using standard JUnit. 30 | @Test 31 | public void hhh123Test() throws Exception { 32 | EntityManager entityManager = entityManagerFactory.createEntityManager(); 33 | entityManager.getTransaction().begin(); 34 | // Do stuff... 35 | entityManager.getTransaction().commit(); 36 | entityManager.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/ORMStandaloneTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | /** 11 | * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly 12 | * acceptable as a reproducer, usage of ORMUnitTestCase is preferred! 13 | */ 14 | public class ORMStandaloneTestCase { 15 | 16 | private SessionFactory sf; 17 | 18 | @Before 19 | public void setup() { 20 | StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder() 21 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 22 | .applySetting( "hibernate.show_sql", "true" ) 23 | .applySetting( "hibernate.format_sql", "true" ) 24 | .applySetting( "hibernate.hbm2ddl.auto", "update" ); 25 | 26 | Metadata metadata = new MetadataSources( srb.build() ) 27 | // Add your entities here. 28 | // .addAnnotatedClass( Foo.class ) 29 | .buildMetadata(); 30 | 31 | sf = metadata.buildSessionFactory(); 32 | } 33 | 34 | // Add your tests, using standard JUnit. 35 | 36 | @Test 37 | public void hhh123Test() throws Exception { 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/ORMUnitTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 JBoss Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.hibernate.bugs; 17 | 18 | import org.hibernate.Session; 19 | import org.hibernate.Transaction; 20 | import org.hibernate.cfg.AvailableSettings; 21 | import org.hibernate.cfg.Configuration; 22 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 23 | import org.junit.Test; 24 | 25 | /** 26 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework. 27 | * Although ORMStandaloneTestCase is perfectly acceptable as a reproducer, usage of this class is much preferred. 28 | * Since we nearly always include a regression test with bug fixes, providing your reproducer using this method 29 | * simplifies the process. 30 | * 31 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then 32 | * submit it as a PR! 33 | */ 34 | public class ORMUnitTestCase extends BaseCoreFunctionalTestCase { 35 | 36 | // Add your entities here. 37 | @Override 38 | protected Class[] getAnnotatedClasses() { 39 | return new Class[] { 40 | // Foo.class, 41 | // Bar.class 42 | }; 43 | } 44 | 45 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here. 46 | @Override 47 | protected String[] getMappings() { 48 | return new String[] { 49 | // "Foo.hbm.xml", 50 | // "Bar.hbm.xml" 51 | }; 52 | } 53 | // If those mappings reside somewhere other than resources/org/hibernate/test, change this. 54 | @Override 55 | protected String getBaseForMappings() { 56 | return "org/hibernate/test/"; 57 | } 58 | 59 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 60 | @Override 61 | protected void configure(Configuration configuration) { 62 | super.configure( configuration ); 63 | 64 | configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() ); 65 | configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() ); 66 | //configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" ); 67 | } 68 | 69 | // Add your tests, using standard JUnit. 70 | @Test 71 | public void hhh123Test() throws Exception { 72 | // BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session. 73 | Session s = openSession(); 74 | Transaction tx = s.beginTransaction(); 75 | // Do stuff... 76 | tx.commit(); 77 | s.close(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /orm/hibernate-orm-5/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Hibernate test case template Persistence Unit 10 | org.hibernate.jpa.HibernatePersistenceProvider 11 | 12 | false 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /orm/hibernate-orm-5/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | hibernate.dialect org.hibernate.dialect.H2Dialect 9 | hibernate.connection.driver_class org.h2.Driver 10 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE 11 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 12 | hibernate.connection.username sa 13 | hibernate.connection.password 14 | 15 | hibernate.connection.pool_size 5 16 | 17 | hibernate.show_sql false 18 | hibernate.format_sql true 19 | 20 | hibernate.max_fetch_depth 5 21 | 22 | hibernate.cache.region_prefix hibernate.test 23 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory 24 | 25 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle 26 | hibernate.jdbc.batch_versioned_data true 27 | 28 | javax.persistence.validation.mode=NONE 29 | hibernate.service.allow_crawling=false 30 | hibernate.session.events.log=true -------------------------------------------------------------------------------- /orm/hibernate-orm-5/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /orm/hibernate-orm-6/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-orm-6 7 | 1.0.0.Final 8 | Hibernate ORM 6 Test Case Template 9 | 10 | 11 | 2.3.232 12 | 5.11.4 13 | 6.6.17.Final 14 | 3.27.3 15 | 16 | 17 | 18 | 19 | 20 | org.hibernate.orm 21 | hibernate-platform 22 | ${version.org.hibernate.orm} 23 | pom 24 | import 25 | 26 | 27 | org.junit 28 | junit-bom 29 | ${version.junit-jupiter} 30 | pom 31 | import 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.hibernate.orm 39 | hibernate-core 40 | 41 | 42 | com.h2database 43 | h2 44 | ${version.com.h2database} 45 | 46 | 47 | 48 | org.hibernate.orm 49 | hibernate-testing 50 | test 51 | 52 | 53 | org.junit.jupiter 54 | junit-jupiter 55 | test 56 | 57 | 58 | org.junit.platform 59 | junit-platform-launcher 60 | test 61 | 62 | 63 | org.junit.jupiter 64 | junit-jupiter-engine 65 | test 66 | 67 | 68 | org.assertj 69 | assertj-core 70 | ${version.org.assertj.assertj-core} 71 | test 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-compiler-plugin 80 | 3.14.0 81 | 82 | 11 83 | 84 | 85 | 86 | org.hibernate.orm.tooling 87 | hibernate-enhance-maven-plugin 88 | ${version.org.hibernate.orm} 89 | 90 | 91 | 92 | ${project.build.testOutputDirectory} 93 | ${project.build.testOutputDirectory} 94 | false 95 | false 96 | false 97 | false 98 | 99 | test-compile 100 | 101 | enhance 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.junit.jupiter.api.AfterEach; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import jakarta.persistence.EntityManager; 8 | import jakarta.persistence.EntityManagerFactory; 9 | import jakarta.persistence.Persistence; 10 | 11 | /** 12 | * This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API. 13 | */ 14 | class JPAUnitTestCase { 15 | 16 | private EntityManagerFactory entityManagerFactory; 17 | 18 | @BeforeEach 19 | void init() { 20 | entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" ); 21 | } 22 | 23 | @AfterEach 24 | void destroy() { 25 | entityManagerFactory.close(); 26 | } 27 | 28 | // Entities are auto-discovered, so just add them anywhere on class-path 29 | // Add your tests, using standard JUnit. 30 | @Test 31 | void hhh123Test() throws Exception { 32 | EntityManager entityManager = entityManagerFactory.createEntityManager(); 33 | entityManager.getTransaction().begin(); 34 | // Do stuff... 35 | entityManager.getTransaction().commit(); 36 | entityManager.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/ORMStandaloneTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 7 | 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | 11 | /** 12 | * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly 13 | * acceptable as a reproducer, usage of ORMUnitTestCase is preferred! 14 | */ 15 | class ORMStandaloneTestCase { 16 | 17 | private SessionFactory sf; 18 | 19 | @BeforeEach 20 | void setup() { 21 | StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder() 22 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 23 | .applySetting( "hibernate.show_sql", "true" ) 24 | .applySetting( "hibernate.format_sql", "true" ) 25 | .applySetting( "hibernate.hbm2ddl.auto", "update" ); 26 | 27 | Metadata metadata = new MetadataSources( srb.build() ) 28 | // Add your entities here. 29 | // .addAnnotatedClass( Foo.class ) 30 | .buildMetadata(); 31 | 32 | sf = metadata.buildSessionFactory(); 33 | } 34 | 35 | // Add your tests, using standard JUnit 5: 36 | @Test 37 | void hhh123Test() throws Exception { 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/ORMUnitTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 JBoss Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.hibernate.bugs; 17 | 18 | import org.hibernate.cfg.AvailableSettings; 19 | 20 | import org.hibernate.testing.orm.junit.DomainModel; 21 | import org.hibernate.testing.orm.junit.ServiceRegistry; 22 | import org.hibernate.testing.orm.junit.SessionFactory; 23 | import org.hibernate.testing.orm.junit.SessionFactoryScope; 24 | import org.hibernate.testing.orm.junit.Setting; 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework. 29 | * Although ORMStandaloneTestCase is perfectly acceptable as a reproducer, usage of this class is much preferred. 30 | * Since we nearly always include a regression test with bug fixes, providing your reproducer using this method 31 | * simplifies the process. 32 | *

33 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then 34 | * submit it as a PR! 35 | */ 36 | @DomainModel( 37 | annotatedClasses = { 38 | // Add your entities here. 39 | // Foo.class, 40 | // Bar.class 41 | }, 42 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here. 43 | xmlMappings = { 44 | // "org/hibernate/test/Foo.hbm.xml", 45 | // "org/hibernate/test/Bar.hbm.xml" 46 | } 47 | ) 48 | @ServiceRegistry( 49 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 50 | settings = { 51 | // For your own convenience to see generated queries: 52 | @Setting(name = AvailableSettings.SHOW_SQL, value = "true"), 53 | @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"), 54 | // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ), 55 | 56 | // Add your own settings that are a part of your quarkus configuration: 57 | // @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ), 58 | } 59 | ) 60 | @SessionFactory 61 | class ORMUnitTestCase { 62 | 63 | // Add your tests, using standard JUnit 5. 64 | @Test 65 | void hhh123Test(SessionFactoryScope scope) throws Exception { 66 | scope.inTransaction( session -> { 67 | // Do stuff... 68 | } ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeEnhancementContext.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext; 4 | import org.hibernate.bytecode.enhance.spi.UnloadedField; 5 | import org.hibernate.bytecode.enhance.spi.UnsupportedEnhancementStrategy; 6 | 7 | public class QuarkusLikeEnhancementContext extends DefaultEnhancementContext { 8 | @Override 9 | public boolean doBiDirectionalAssociationManagement(final UnloadedField field) { 10 | //Don't enable automatic association management as it's often too surprising. 11 | //Also, there's several cases in which its semantics are of unspecified, 12 | //such as what should happen when dealing with ordered collections. 13 | return false; 14 | } 15 | 16 | @Override 17 | public UnsupportedEnhancementStrategy getUnsupportedEnhancementStrategy() { 18 | // We expect model classes to be enhanced. 19 | // Lack of enhancement could lead to many problems, 20 | // from bad performance, to Quarkus-specific optimizations causing errors/data loss, 21 | // to incorrect generated bytecode (references to non-existing methods). 22 | // If something prevents enhancement, it's just safer to have Hibernate ORM's enhancer fail 23 | // with a clear error message pointing to the application class that needs to be fixed. 24 | return UnsupportedEnhancementStrategy.FAIL; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 JBoss Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.hibernate.bugs; 17 | 18 | import org.hibernate.cfg.AvailableSettings; 19 | 20 | import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; 21 | import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced; 22 | import org.hibernate.testing.orm.junit.DomainModel; 23 | import org.hibernate.testing.orm.junit.ServiceRegistry; 24 | import org.hibernate.testing.orm.junit.SessionFactory; 25 | import org.hibernate.testing.orm.junit.SessionFactoryScope; 26 | import org.hibernate.testing.orm.junit.Setting; 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework. 31 | *

32 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then 33 | * submit it as a PR! 34 | */ 35 | @DomainModel( 36 | annotatedClasses = { 37 | // Add your entities here, e.g.: 38 | // Foo.class, 39 | // Bar.class 40 | } 41 | ) 42 | @ServiceRegistry( 43 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 44 | settings = { 45 | // For your own convenience to see generated queries: 46 | @Setting(name = AvailableSettings.SHOW_SQL, value = "true"), 47 | @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"), 48 | // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ), 49 | 50 | // Other settings that will make your test case run under similar configuration that Quarkus is using by default: 51 | @Setting(name = AvailableSettings.PREFERRED_POOLED_OPTIMIZER, value = "pooled-lo"), 52 | @Setting(name = AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, value = "16"), 53 | @Setting(name = AvailableSettings.BATCH_FETCH_STYLE, value = "PADDED"), 54 | @Setting(name = AvailableSettings.QUERY_PLAN_CACHE_MAX_SIZE, value = "2048"), 55 | @Setting(name = AvailableSettings.DEFAULT_NULL_ORDERING, value = "none"), 56 | @Setting(name = AvailableSettings.IN_CLAUSE_PARAMETER_PADDING, value = "true"), 57 | @Setting(name = AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, value = "none"), 58 | @Setting(name = AvailableSettings.ORDER_UPDATES, value = "true"), 59 | 60 | // Add your own settings that are a part of your quarkus configuration: 61 | // @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ), 62 | } 63 | ) 64 | @SessionFactory 65 | @BytecodeEnhanced 66 | @CustomEnhancementContext(QuarkusLikeEnhancementContext.class) 67 | class QuarkusLikeORMUnitTestCase { 68 | 69 | // Add your tests, using standard JUnit. 70 | @Test 71 | void hhh123Test(SessionFactoryScope scope) throws Exception { 72 | scope.inTransaction( session -> { 73 | // Do stuff... 74 | } ); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /orm/hibernate-orm-6/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | Hibernate test case template Persistence Unit 9 | org.hibernate.jpa.HibernatePersistenceProvider 10 | 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /orm/hibernate-orm-6/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | hibernate.dialect org.hibernate.dialect.H2Dialect 9 | hibernate.connection.driver_class org.h2.Driver 10 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE 11 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 12 | hibernate.connection.username sa 13 | hibernate.connection.password 14 | 15 | hibernate.connection.pool_size 5 16 | 17 | hibernate.show_sql false 18 | hibernate.format_sql true 19 | 20 | hibernate.max_fetch_depth 5 21 | 22 | hibernate.cache.region_prefix hibernate.test 23 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory 24 | 25 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle 26 | hibernate.jdbc.batch_versioned_data true 27 | 28 | jakarta.persistence.validation.mode=NONE 29 | hibernate.service.allow_crawling=false 30 | hibernate.session.events.log=true -------------------------------------------------------------------------------- /orm/hibernate-orm-6/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /orm/hibernate-orm-7/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-orm-7 7 | 1.0.0.Final 8 | Hibernate ORM 7 Test Case Template 9 | 10 | 11 | 2.3.232 12 | 5.12.2 13 | 7.0.0.Final 14 | 3.27.3 15 | 16 | 17 | 18 | 19 | 20 | org.hibernate.orm 21 | hibernate-platform 22 | ${version.org.hibernate.orm} 23 | pom 24 | import 25 | 26 | 27 | org.junit 28 | junit-bom 29 | ${version.junit-jupiter} 30 | pom 31 | import 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.hibernate.orm 39 | hibernate-core 40 | 41 | 42 | com.h2database 43 | h2 44 | ${version.com.h2database} 45 | 46 | 47 | 48 | org.hibernate.orm 49 | hibernate-testing 50 | test 51 | 52 | 53 | org.junit.jupiter 54 | junit-jupiter 55 | test 56 | 57 | 58 | org.junit.platform 59 | junit-platform-launcher 60 | test 61 | 62 | 63 | org.junit.jupiter 64 | junit-jupiter-engine 65 | test 66 | 67 | 68 | org.assertj 69 | assertj-core 70 | ${version.org.assertj.assertj-core} 71 | test 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-compiler-plugin 80 | 3.14.0 81 | 82 | 17 83 | 84 | 85 | 86 | org.hibernate.orm 87 | hibernate-maven-plugin 88 | ${version.org.hibernate.orm} 89 | 90 | 91 | 92 | ${project.build.testOutputDirectory} 93 |

${project.build.testOutputDirectory} 94 | false 95 | false 96 | false 97 | false 98 | 99 | test-compile 100 | 101 | enhance 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.junit.jupiter.api.AfterEach; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import jakarta.persistence.EntityManager; 8 | import jakarta.persistence.EntityManagerFactory; 9 | import jakarta.persistence.Persistence; 10 | 11 | /** 12 | * This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API. 13 | */ 14 | class JPAUnitTestCase { 15 | 16 | private EntityManagerFactory entityManagerFactory; 17 | 18 | @BeforeEach 19 | void init() { 20 | entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" ); 21 | } 22 | 23 | @AfterEach 24 | void destroy() { 25 | entityManagerFactory.close(); 26 | } 27 | 28 | // Entities are auto-discovered, so just add them anywhere on class-path 29 | // Add your tests, using standard JUnit. 30 | @Test 31 | void hhh123Test() throws Exception { 32 | EntityManager entityManager = entityManagerFactory.createEntityManager(); 33 | entityManager.getTransaction().begin(); 34 | // Do stuff... 35 | entityManager.getTransaction().commit(); 36 | entityManager.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/ORMStandaloneTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 7 | 8 | import org.junit.jupiter.api.BeforeEach; 9 | import org.junit.jupiter.api.Test; 10 | 11 | /** 12 | * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly 13 | * acceptable as a reproducer, usage of ORMUnitTestCase is preferred! 14 | */ 15 | class ORMStandaloneTestCase { 16 | 17 | private SessionFactory sf; 18 | 19 | @BeforeEach 20 | void setup() { 21 | StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder() 22 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 23 | .applySetting( "hibernate.show_sql", "true" ) 24 | .applySetting( "hibernate.format_sql", "true" ) 25 | .applySetting( "hibernate.hbm2ddl.auto", "update" ); 26 | 27 | Metadata metadata = new MetadataSources( srb.build() ) 28 | // Add your entities here. 29 | // .addAnnotatedClass( Foo.class ) 30 | .buildMetadata(); 31 | 32 | sf = metadata.buildSessionFactory(); 33 | } 34 | 35 | // Add your tests, using standard JUnit 5: 36 | @Test 37 | void hhh123Test() throws Exception { 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/ORMUnitTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.hibernate.cfg.AvailableSettings; 4 | 5 | import org.hibernate.testing.orm.junit.DomainModel; 6 | import org.hibernate.testing.orm.junit.ServiceRegistry; 7 | import org.hibernate.testing.orm.junit.SessionFactory; 8 | import org.hibernate.testing.orm.junit.SessionFactoryScope; 9 | import org.hibernate.testing.orm.junit.Setting; 10 | import org.junit.jupiter.api.Test; 11 | 12 | /** 13 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework. 14 | * Although ORMStandaloneTestCase is perfectly acceptable as a reproducer, usage of this class is much preferred. 15 | * Since we nearly always include a regression test with bug fixes, providing your reproducer using this method 16 | * simplifies the process. 17 | *

18 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then 19 | * submit it as a PR! 20 | */ 21 | @DomainModel( 22 | annotatedClasses = { 23 | // Add your entities here. 24 | // Foo.class, 25 | // Bar.class 26 | }, 27 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here. 28 | xmlMappings = { 29 | // "org/hibernate/test/Foo.hbm.xml", 30 | // "org/hibernate/test/Bar.hbm.xml" 31 | } 32 | ) 33 | @ServiceRegistry( 34 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 35 | settings = { 36 | // For your own convenience to see generated queries: 37 | @Setting(name = AvailableSettings.SHOW_SQL, value = "true"), 38 | @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"), 39 | // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ), 40 | 41 | // Add your own settings that are a part of your quarkus configuration: 42 | // @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ), 43 | } 44 | ) 45 | @SessionFactory 46 | class ORMUnitTestCase { 47 | 48 | // Add your tests, using standard JUnit 5. 49 | @Test 50 | void hhh123Test(SessionFactoryScope scope) throws Exception { 51 | scope.inTransaction( session -> { 52 | // Do stuff... 53 | } ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/QuarkusLikeEnhancementContext.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext; 4 | import org.hibernate.bytecode.enhance.spi.UnloadedField; 5 | import org.hibernate.bytecode.enhance.spi.UnsupportedEnhancementStrategy; 6 | 7 | public class QuarkusLikeEnhancementContext extends DefaultEnhancementContext { 8 | @Override 9 | public boolean doBiDirectionalAssociationManagement(final UnloadedField field) { 10 | //Don't enable automatic association management as it's often too surprising. 11 | //Also, there's several cases in which its semantics are of unspecified, 12 | //such as what should happen when dealing with ordered collections. 13 | return false; 14 | } 15 | 16 | @Override 17 | public UnsupportedEnhancementStrategy getUnsupportedEnhancementStrategy() { 18 | // We expect model classes to be enhanced. 19 | // Lack of enhancement could lead to many problems, 20 | // from bad performance, to Quarkus-specific optimizations causing errors/data loss, 21 | // to incorrect generated bytecode (references to non-existing methods). 22 | // If something prevents enhancement, it's just safer to have Hibernate ORM's enhancer fail 23 | // with a clear error message pointing to the application class that needs to be fixed. 24 | return UnsupportedEnhancementStrategy.FAIL; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.bugs; 2 | 3 | import org.hibernate.cfg.AvailableSettings; 4 | 5 | import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; 6 | import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced; 7 | import org.hibernate.testing.orm.junit.DomainModel; 8 | import org.hibernate.testing.orm.junit.ServiceRegistry; 9 | import org.hibernate.testing.orm.junit.SessionFactory; 10 | import org.hibernate.testing.orm.junit.SessionFactoryScope; 11 | import org.hibernate.testing.orm.junit.Setting; 12 | import org.junit.jupiter.api.Test; 13 | 14 | /** 15 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework. 16 | *

17 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then 18 | * submit it as a PR! 19 | */ 20 | @DomainModel( 21 | annotatedClasses = { 22 | // Add your entities here, e.g.: 23 | // Foo.class, 24 | // Bar.class 25 | } 26 | ) 27 | @ServiceRegistry( 28 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. 29 | settings = { 30 | // For your own convenience to see generated queries: 31 | @Setting(name = AvailableSettings.SHOW_SQL, value = "true"), 32 | @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"), 33 | // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ), 34 | 35 | // Other settings that will make your test case run under similar configuration that Quarkus is using by default: 36 | @Setting(name = AvailableSettings.PREFERRED_POOLED_OPTIMIZER, value = "pooled-lo"), 37 | @Setting(name = AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, value = "16"), 38 | @Setting(name = AvailableSettings.QUERY_PLAN_CACHE_MAX_SIZE, value = "2048"), 39 | @Setting(name = AvailableSettings.DEFAULT_NULL_ORDERING, value = "none"), 40 | @Setting(name = AvailableSettings.IN_CLAUSE_PARAMETER_PADDING, value = "true"), 41 | @Setting(name = AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, value = "none"), 42 | @Setting(name = AvailableSettings.ORDER_UPDATES, value = "true"), 43 | 44 | // Add your own settings that are a part of your quarkus configuration: 45 | // @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ), 46 | } 47 | ) 48 | @SessionFactory 49 | @BytecodeEnhanced 50 | @CustomEnhancementContext(QuarkusLikeEnhancementContext.class) 51 | class QuarkusLikeORMUnitTestCase { 52 | 53 | // Add your tests, using standard JUnit. 54 | @Test 55 | void hhh123Test(SessionFactoryScope scope) throws Exception { 56 | scope.inTransaction( session -> { 57 | // Do stuff... 58 | } ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /orm/hibernate-orm-7/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | Hibernate test case template Persistence Unit 9 | org.hibernate.jpa.HibernatePersistenceProvider 10 | 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /orm/hibernate-orm-7/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | hibernate.dialect org.hibernate.dialect.H2Dialect 2 | hibernate.connection.driver_class org.h2.Driver 3 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE 4 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 5 | hibernate.connection.username sa 6 | hibernate.connection.password 7 | 8 | hibernate.connection.pool_size 5 9 | 10 | hibernate.show_sql false 11 | hibernate.format_sql true 12 | 13 | hibernate.max_fetch_depth 5 14 | 15 | hibernate.cache.region_prefix hibernate.test 16 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory 17 | 18 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle 19 | hibernate.jdbc.batch_versioned_data true 20 | 21 | jakarta.persistence.validation.mode=NONE 22 | hibernate.service.allow_crawling=false 23 | hibernate.session.events.log=true 24 | -------------------------------------------------------------------------------- /orm/hibernate-orm-7/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | org.hibernate.testcasetemplate 6 | hibernate-testcasetemplate-aggregator 7 | 1.0-SNAPSHOT 8 | pom 9 | Hibernate Test Case Templates - Aggregator POM 10 | An aggregator POM to build all test case templates in one command, or to simplify configuration of dependabot 11 | 12 | orm/hibernate-orm-5 13 | orm/hibernate-orm-6 14 | orm/hibernate-orm-7 15 | envers/envers-5 16 | envers/envers-6 17 | envers/envers-7 18 | search/hibernate-search-5/elasticsearch-5 19 | search/hibernate-search-5/lucene 20 | search/hibernate-search-6/orm-elasticsearch 21 | search/hibernate-search-6/orm-lucene 22 | search/hibernate-search-7/orm-elasticsearch 23 | search/hibernate-search-7/orm-lucene 24 | validator/validator-6 25 | validator/validator-8 26 | validator/validator-9 27 | reactive/hibernate-reactive-2 28 | reactive/hibernate-reactive-3 29 | reactive/hibernate-reactive-4 30 | 31 | 32 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-2/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Reactive 2 | 3 | This repo contains test case templates, useful for reporting bugs 4 | against [Hibernate Reactive](https://hibernate.org/reactive/). 5 | 6 | The template contains examples of tests written using both the Mutiny and Stage API. 7 | The bug report can be written either with one or the other. 8 | 9 | The database is started via [Testcontainers](https://java.testcontainers.org/). 10 | It's possible to select a different database by changing the value of the constant `SELECT_DB`. 11 | 12 | The package [org.hibernate.reactive.util](src/test/java/org/hibernate/reactive/util) contains: 13 | 14 | * `ConnectionUrl`: The JDBC urls to connect to databases started following the instructions in the 15 | [PODMAN.md](https://github.com/hibernate/hibernate-reactive/blob/main/podman.md) file 16 | in the [Hibernate Reactive GitHub repository](https://github.com/hibernate/hibernate-reactive) 17 | * `Database`: Containers configuration via [Testcontainers](https://java.testcontainers.org/) 18 | * `DockerImage`: Utility class for the creation of a `DockerImageName` to use with Testcontainers 19 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/bugs/ReactiveStandaloneTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 7 | import org.hibernate.reactive.bugs.model.MyEntity; 8 | import org.hibernate.reactive.mutiny.Mutiny; 9 | import org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder; 10 | import org.hibernate.reactive.stage.Stage; 11 | import org.hibernate.reactive.util.Database; 12 | 13 | import org.junit.jupiter.api.AfterAll; 14 | import org.junit.jupiter.api.BeforeAll; 15 | import org.junit.jupiter.api.Test; 16 | import org.junit.jupiter.api.extension.ExtendWith; 17 | 18 | import io.smallrye.mutiny.Uni; 19 | import io.vertx.junit5.VertxExtension; 20 | import io.vertx.junit5.VertxTestContext; 21 | import java.util.concurrent.CompletableFuture; 22 | import org.testcontainers.containers.JdbcDatabaseContainer; 23 | 24 | /** 25 | * Demonstrates how to develop a standalone test case for Hibernate Reactive using 26 | * the {@link org.hibernate.reactive.mutiny.Mutiny.SessionFactory} 27 | * or {@link org.hibernate.reactive.stage.Stage.SessionFactory}. 28 | *

29 | * It uses the {@link VertxExtension} to ease the testing of async code using JUnit. 30 | *

31 | *

32 | * There are two test methods (feel free to pick your favorite): 33 | * 34 | *

  • {@link #testWithMutiny(VertxTestContext)} for using the Mutiny API
  • 35 | *
  • {@link #testWithStage(VertxTestContext)} for using the Stage API
  • 36 | * 37 | *

    38 | *

    39 | * Databases for the tests start via Testcontainers. 40 | * The configuration of the containers is in {@link Database} and the test 41 | * can run on different databases by changing the value of {@link #SELECTED_DB}. 42 | *

    43 | */ 44 | @ExtendWith(VertxExtension.class) 45 | public class ReactiveStandaloneTestCase { 46 | 47 | /** 48 | * The selected database to run the test against. 49 | * If the value is set to null, no container will start. 50 | * 51 | * @see Database 52 | */ 53 | private static final Database SELECTED_DB = Database.POSTGRESQL; 54 | 55 | private static JdbcDatabaseContainer container; 56 | private static SessionFactory sf; 57 | 58 | @BeforeAll 59 | public static void startContainer() { 60 | if ( SELECTED_DB != null ) { 61 | container = SELECTED_DB.startContainer(); 62 | } 63 | } 64 | 65 | @BeforeAll 66 | public static void setup() { 67 | StandardServiceRegistryBuilder srb = new ReactiveServiceRegistryBuilder() 68 | .applySetting( "hibernate.connection.url", container.getJdbcUrl() ) 69 | .applySetting( "hibernate.connection.username", container.getUsername() ) 70 | .applySetting( "hibernate.connection.password", container.getPassword() ) 71 | .applySetting( "hibernate.hbm2ddl.auto", "update" ) 72 | .applySetting( "hibernate.show_sql", "true" ) 73 | .applySetting( "hibernate.highlight_sql", "true" ) 74 | .applySetting( "hibernate.format_sql", "true" ); 75 | 76 | Metadata metadata = new MetadataSources( srb.build() ) 77 | // Add your entities here. 78 | .addAnnotatedClass( MyEntity.class ) 79 | .buildMetadata(); 80 | 81 | sf = metadata.buildSessionFactory(); 82 | } 83 | 84 | @Test 85 | public void testWithMutiny(VertxTestContext context) { 86 | Mutiny.SessionFactory mutinySf = sf.unwrap( Mutiny.SessionFactory.class ); 87 | mutinySf 88 | // Example of transactional block 89 | .withTransaction( session -> { 90 | return Uni.createFrom().voidItem(); 91 | } ) 92 | // Subscribe the uni and wait until it completes 93 | .subscribe().with( res -> context.completeNow(), context::failNow ); 94 | } 95 | 96 | @Test 97 | public void testWithStage(VertxTestContext context) { 98 | Stage.SessionFactory stageSf = sf.unwrap( Stage.SessionFactory.class ); 99 | stageSf 100 | // Example of transactional block 101 | .withTransaction( session -> { 102 | return CompletableFuture.completedFuture( null ); 103 | } ) 104 | // Stop the test when the CompletionStage completes 105 | .whenComplete( (res, err) -> { 106 | if ( err != null ) { 107 | context.failNow( err ); 108 | } 109 | else { 110 | context.completeNow(); 111 | } 112 | } ); 113 | } 114 | 115 | // It's important to always close the factory at the end of the tests. 116 | @AfterAll 117 | public static void closeSessionFactory() { 118 | if ( sf != null ) { 119 | sf.close(); 120 | } 121 | } 122 | 123 | @AfterAll 124 | public static void stopContainer() { 125 | if ( container != null ) { 126 | container.stop(); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/bugs/model/MyEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.bugs.model; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | 6 | /** 7 | * An entity to starts with. 8 | */ 9 | @Entity 10 | public class MyEntity { 11 | 12 | @Id 13 | private Long id; 14 | private String name; 15 | 16 | public Long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Long id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "MyEntity(" + id + ":" + name + ")"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/util/ConnectionURL.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | /** 4 | * JDBC URL connection strings for the property {@link org.hibernate.reactive.provider.Settings#URL} when the database 5 | * is started the instructions from the 6 | * Hibernate Reactive GitHub repository. 7 | */ 8 | public final class ConnectionURL { 9 | public static final String POSTGRES = "jdbc:postgresql://localhost:5432/hreact?user=hreact&password=hreact"; 10 | public static final String COCKROACH = "jdbc:cockroachdb://localhost:26257/postgres?sslmode=disable&user=root"; 11 | public static final String MYSQL = "jdbc:mysql://localhost/hreact?user=hreact&password=hreact"; 12 | public static final String MARIA = "jdbc:mariadb://localhost:3306/hreact?user=hreact&password=hreact"; 13 | public static final String MSSQL = "jdbc:sqlserver://localhost:1433;Encrypt=false;user=sa;password=~!HReact!~"; 14 | public static final String DB2 = "jdbc:db2://localhost:50000/hreact:user=hreact;password=hreact;"; 15 | public static final String ORACLE = "jdbc:oracle:thin:hreact/hreact@localhost:1521/hreact?user=hreact&password=hreact"; 16 | } 17 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/util/Database.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | import java.util.function.Supplier; 4 | import org.testcontainers.containers.CockroachContainer; 5 | import org.testcontainers.containers.Db2Container; 6 | import org.testcontainers.containers.JdbcDatabaseContainer; 7 | import org.testcontainers.containers.MSSQLServerContainer; 8 | import org.testcontainers.containers.MariaDBContainer; 9 | import org.testcontainers.containers.MySQLContainer; 10 | import org.testcontainers.containers.OracleContainer; 11 | import org.testcontainers.containers.PostgreSQLContainer; 12 | 13 | import static org.hibernate.reactive.util.DockerImage.imageName; 14 | 15 | /** 16 | * The only purpose of this class is to make it easier to switch among the available databases 17 | * for the unit tests. 18 | *

    19 | * It's a wrapper around the testcontainers classes. 20 | */ 21 | public enum Database { 22 | POSTGRESQL( () -> new PostgreSQLContainer<>( imageName( "postgres", "16.3" ) ) ), 23 | MYSQL( () -> new MySQLContainer<>( imageName( "mysql", "8.4.0" ) ) ), 24 | MARIADB( () -> new MariaDBContainer<>( imageName( "mariadb", "11.4.2" ) ) ), 25 | DB2( () -> new Db2Container( imageName( "icr.io", "db2_community/db2", "12.1.0.0" ) ).acceptLicense() ), 26 | COCKROACHDB( () -> new CockroachContainer( imageName( "cockroachdb/cockroach", "v24.1.0" ) ) ), 27 | ORACLE( Database::newOracleContainer ), 28 | MSSQL( Database::newMSSqlServer ); 29 | 30 | private final Supplier> containerSupplier; 31 | 32 | Database(Supplier> supplier) { 33 | this.containerSupplier = supplier; 34 | } 35 | 36 | /** 37 | * Start the container using testcontainers and print the log on System.out. 38 | */ 39 | public JdbcDatabaseContainer startContainer() { 40 | return startContainer( true ); 41 | } 42 | 43 | /** 44 | * Start the database using testcontainers. 45 | * 46 | * @param enableLog if true, print the container log 47 | */ 48 | public JdbcDatabaseContainer startContainer(boolean enableLog) { 49 | JdbcDatabaseContainer jdbcDatabaseContainer = containerSupplier.get(); 50 | jdbcDatabaseContainer 51 | .withLogConsumer( of -> logContainerOutput( of.getUtf8String() ) ) 52 | .withReuse( true ) 53 | .start(); 54 | return jdbcDatabaseContainer; 55 | } 56 | 57 | private static MSSQLServerContainer newMSSqlServer() { 58 | return new MSSQLServerContainer<>( imageName( "mcr.microsoft.com", "mssql/server", "2022-latest" ) ) 59 | .acceptLicense(); 60 | } 61 | 62 | private static OracleContainer newOracleContainer() { 63 | return new OracleContainer( imageName( "gvenzl/oracle-free", "23-slim-faststart" ) 64 | .asCompatibleSubstituteFor( "gvenzl/oracle-xe" ) ) 65 | .withStartupAttempts( 1 ) 66 | 67 | // We need to limit the maximum amount of CPUs being used by the container; 68 | // otherwise the hardcoded memory configuration of the DB might not be enough to successfully boot it. 69 | // See https://github.com/gvenzl/oci-oracle-xe/issues/64 70 | // I choose to limit it to "2 cpus": should be more than enough for any local testing needs, 71 | // and keeps things simple. 72 | .withCreateContainerCmdModifier( cmd -> cmd.getHostConfig().withCpuCount( 2L ) ); 73 | } 74 | 75 | private static void logContainerOutput(String line) { 76 | System.out.print( line ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/util/DockerImage.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | import org.testcontainers.utility.DockerImageName; 4 | 5 | /** 6 | * A utility class with methods to generate {@link DockerImageName} for testcontainers. 7 | *

    8 | * Testcontainers might not work if the image required is available in multiple different registries (for example when 9 | * using podman instead of docker). 10 | * These methods make sure to pick a registry as default. 11 | *

    12 | */ 13 | public final class DockerImage { 14 | 15 | public static final String DEFAULT_REGISTRY = "docker.io"; 16 | 17 | public static DockerImageName imageName(String image, String version) { 18 | return imageName( DEFAULT_REGISTRY, image, version ); 19 | } 20 | 21 | public static DockerImageName imageName(String registry, String image, String version) { 22 | return DockerImageName 23 | .parse( registry + "/" + image + ":" + version ) 24 | .asCompatibleSubstituteFor( image ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-2/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Root logger level 2 | rootLogger.level = info 3 | rootLogger.appenderRefs = console 4 | rootLogger.appenderRef.console.ref = console 5 | 6 | # Print the selected dialect information 7 | logger.hibernate-dialect.name = org.hibernate.orm.dialect 8 | logger.hibernate-dialect.level = debug 9 | 10 | # SQL logging disabled by default to speed test suite execution 11 | # It can also be enabled by setting the environment variable: 12 | # JAVA_TOOL_OPTIONS='-Dhibernate.show_sql=true' 13 | logger.hibernate.name = org.hibernate.SQL 14 | logger.hibernate.level = info 15 | 16 | # Setting level TRACE will show when a connection is opened/closed 17 | logger.sql-connection.name = org.hibernate.reactive.pool.impl 18 | logger.sql-connection.level = info 19 | 20 | # Setting level to TRACE will show parameters values for SQL queries 21 | logger.sql-parameters-values.name = org.hibernate.type 22 | logger.sql-parameters-values.level = info 23 | 24 | appender.console.name = console 25 | appender.console.type = Console 26 | appender.console.layout.type = PatternLayout 27 | appender.console.layout.pattern = %highlight{[%p]} %m%n 28 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-3/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Reactive 2 | 3 | This repo contains test case templates, useful for reporting bugs 4 | against [Hibernate Reactive](https://hibernate.org/reactive/). 5 | 6 | The template contains examples of tests written using both the Mutiny and Stage API. 7 | The bug report can be written either with one or the other. 8 | 9 | The database is started via [Testcontainers](https://java.testcontainers.org/). 10 | It's possible to select a different database by changing the value of the constant `SELECT_DB`. 11 | 12 | The package [org.hibernate.reactive.util](src/test/java/org/hibernate/reactive/util) contains: 13 | 14 | * `ConnectionUrl`: The JDBC urls to connect to databases started following the instructions in the 15 | [PODMAN.md](https://github.com/hibernate/hibernate-reactive/blob/main/podman.md) file 16 | in the [Hibernate Reactive GitHub repository](https://github.com/hibernate/hibernate-reactive) 17 | * `Database`: Containers configuration via [Testcontainers](https://java.testcontainers.org/) 18 | * `DockerImage`: Utility class for the creation of a `DockerImageName` to use with Testcontainers 19 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/bugs/ReactiveStandaloneTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 7 | import org.hibernate.reactive.bugs.model.MyEntity; 8 | import org.hibernate.reactive.mutiny.Mutiny; 9 | import org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder; 10 | import org.hibernate.reactive.stage.Stage; 11 | import org.hibernate.reactive.util.Database; 12 | 13 | import org.junit.jupiter.api.AfterAll; 14 | import org.junit.jupiter.api.BeforeAll; 15 | import org.junit.jupiter.api.Test; 16 | import org.junit.jupiter.api.extension.ExtendWith; 17 | 18 | import io.smallrye.mutiny.Uni; 19 | import io.vertx.junit5.VertxExtension; 20 | import io.vertx.junit5.VertxTestContext; 21 | import java.util.concurrent.CompletableFuture; 22 | import org.testcontainers.containers.JdbcDatabaseContainer; 23 | 24 | /** 25 | * Demonstrates how to develop a standalone test case for Hibernate Reactive using 26 | * the {@link org.hibernate.reactive.mutiny.Mutiny.SessionFactory} 27 | * or {@link org.hibernate.reactive.stage.Stage.SessionFactory}. 28 | *

    29 | * It uses the {@link VertxExtension} to ease the testing of async code using JUnit. 30 | *

    31 | *

    32 | * There are two test methods (feel free to pick your favorite): 33 | * 34 | *

  • {@link #testWithMutiny(VertxTestContext)} for using the Mutiny API
  • 35 | *
  • {@link #testWithStage(VertxTestContext)} for using the Stage API
  • 36 | * 37 | *

    38 | *

    39 | * Databases for the tests start via Testcontainers. 40 | * The configuration of the containers is in {@link Database} and the test 41 | * can run on different databases by changing the value of {@link #SELECTED_DB}. 42 | *

    43 | */ 44 | @ExtendWith(VertxExtension.class) 45 | public class ReactiveStandaloneTestCase { 46 | 47 | /** 48 | * The selected database to run the test against. 49 | * If the value is set to null, no container will start. 50 | * 51 | * @see Database 52 | */ 53 | private static final Database SELECTED_DB = Database.POSTGRESQL; 54 | 55 | private static JdbcDatabaseContainer container; 56 | private static SessionFactory sf; 57 | 58 | @BeforeAll 59 | public static void startContainer() { 60 | if ( SELECTED_DB != null ) { 61 | container = SELECTED_DB.startContainer(); 62 | } 63 | } 64 | 65 | @BeforeAll 66 | public static void setup() { 67 | StandardServiceRegistryBuilder srb = new ReactiveServiceRegistryBuilder() 68 | .applySetting( "hibernate.connection.url", container.getJdbcUrl() ) 69 | .applySetting( "hibernate.connection.username", container.getUsername() ) 70 | .applySetting( "hibernate.connection.password", container.getPassword() ) 71 | .applySetting( "hibernate.hbm2ddl.auto", "update" ) 72 | .applySetting( "hibernate.show_sql", "true" ) 73 | .applySetting( "hibernate.highlight_sql", "true" ) 74 | .applySetting( "hibernate.format_sql", "true" ); 75 | 76 | Metadata metadata = new MetadataSources( srb.build() ) 77 | // Add your entities here. 78 | .addAnnotatedClass( MyEntity.class ) 79 | .buildMetadata(); 80 | 81 | sf = metadata.buildSessionFactory(); 82 | } 83 | 84 | @Test 85 | public void testWithMutiny(VertxTestContext context) { 86 | Mutiny.SessionFactory mutinySf = sf.unwrap( Mutiny.SessionFactory.class ); 87 | mutinySf 88 | // Example of transactional block 89 | .withTransaction( session -> { 90 | return Uni.createFrom().voidItem(); 91 | } ) 92 | // Subscribe the uni and wait until it completes 93 | .subscribe().with( res -> context.completeNow(), context::failNow ); 94 | } 95 | 96 | @Test 97 | public void testWithStage(VertxTestContext context) { 98 | Stage.SessionFactory stageSf = sf.unwrap( Stage.SessionFactory.class ); 99 | stageSf 100 | // Example of transactional block 101 | .withTransaction( session -> { 102 | return CompletableFuture.completedFuture( null ); 103 | } ) 104 | // Stop the test when the CompletionStage completes 105 | .whenComplete( (res, err) -> { 106 | if ( err != null ) { 107 | context.failNow( err ); 108 | } 109 | else { 110 | context.completeNow(); 111 | } 112 | } ); 113 | } 114 | 115 | // It's important to always close the factory at the end of the tests. 116 | @AfterAll 117 | public static void closeSessionFactory() { 118 | if ( sf != null ) { 119 | sf.close(); 120 | } 121 | } 122 | 123 | @AfterAll 124 | public static void stopContainer() { 125 | if ( container != null ) { 126 | container.stop(); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/bugs/model/MyEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.bugs.model; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | 6 | /** 7 | * An entity to starts with. 8 | */ 9 | @Entity 10 | public class MyEntity { 11 | 12 | @Id 13 | private Long id; 14 | private String name; 15 | 16 | public Long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Long id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "MyEntity(" + id + ":" + name + ")"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/util/ConnectionURL.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | /** 4 | * JDBC URL connection strings for the property {@link org.hibernate.reactive.provider.Settings#URL} when the database 5 | * is started the instructions from the 6 | * Hibernate Reactive GitHub repository. 7 | */ 8 | public final class ConnectionURL { 9 | public static final String POSTGRES = "jdbc:postgresql://localhost:5432/hreact?user=hreact&password=hreact"; 10 | public static final String COCKROACH = "jdbc:cockroachdb://localhost:26257/postgres?sslmode=disable&user=root"; 11 | public static final String MYSQL = "jdbc:mysql://localhost/hreact?user=hreact&password=hreact"; 12 | public static final String MARIA = "jdbc:mariadb://localhost:3306/hreact?user=hreact&password=hreact"; 13 | public static final String MSSQL = "jdbc:sqlserver://localhost:1433;Encrypt=false;user=sa;password=~!HReact!~"; 14 | public static final String DB2 = "jdbc:db2://localhost:50000/hreact:user=hreact;password=hreact;"; 15 | public static final String ORACLE = "jdbc:oracle:thin:hreact/hreact@localhost:1521/hreact?user=hreact&password=hreact"; 16 | } 17 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/util/Database.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | import java.util.function.Supplier; 4 | import org.testcontainers.containers.CockroachContainer; 5 | import org.testcontainers.containers.Db2Container; 6 | import org.testcontainers.containers.JdbcDatabaseContainer; 7 | import org.testcontainers.containers.MSSQLServerContainer; 8 | import org.testcontainers.containers.MariaDBContainer; 9 | import org.testcontainers.containers.MySQLContainer; 10 | import org.testcontainers.containers.OracleContainer; 11 | import org.testcontainers.containers.PostgreSQLContainer; 12 | 13 | import static org.hibernate.reactive.util.DockerImage.imageName; 14 | 15 | /** 16 | * The only purpose of this class is to make it easier to switch among the available databases 17 | * for the unit tests. 18 | *

    19 | * It's a wrapper around the testcontainers classes. 20 | */ 21 | public enum Database { 22 | POSTGRESQL( () -> new PostgreSQLContainer<>( imageName( "postgres", "16.3" ) ) ), 23 | MYSQL( () -> new MySQLContainer<>( imageName( "mysql", "8.4.0" ) ) ), 24 | MARIADB( () -> new MariaDBContainer<>( imageName( "mariadb", "11.4.2" ) ) ), 25 | DB2( () -> new Db2Container( imageName( "icr.io", "db2_community/db2", "12.1.0.0" ) ).acceptLicense() ), 26 | COCKROACHDB( () -> new CockroachContainer( imageName( "cockroachdb/cockroach", "v24.1.0" ) ) ), 27 | ORACLE( Database::newOracleContainer ), 28 | MSSQL( Database::newMSSqlServer ); 29 | 30 | private final Supplier> containerSupplier; 31 | 32 | Database(Supplier> supplier) { 33 | this.containerSupplier = supplier; 34 | } 35 | 36 | /** 37 | * Start the container using testcontainers and print the log on System.out. 38 | */ 39 | public JdbcDatabaseContainer startContainer() { 40 | return startContainer( true ); 41 | } 42 | 43 | /** 44 | * Start the database using testcontainers. 45 | * 46 | * @param enableLog if true, print the container log 47 | */ 48 | public JdbcDatabaseContainer startContainer(boolean enableLog) { 49 | JdbcDatabaseContainer jdbcDatabaseContainer = containerSupplier.get(); 50 | jdbcDatabaseContainer 51 | .withLogConsumer( of -> logContainerOutput( of.getUtf8String() ) ) 52 | .withReuse( true ) 53 | .start(); 54 | return jdbcDatabaseContainer; 55 | } 56 | 57 | private static MSSQLServerContainer newMSSqlServer() { 58 | return new MSSQLServerContainer<>( imageName( "mcr.microsoft.com", "mssql/server", "2022-latest" ) ) 59 | .acceptLicense(); 60 | } 61 | 62 | private static OracleContainer newOracleContainer() { 63 | return new OracleContainer( imageName( "gvenzl/oracle-free", "23-slim-faststart" ) 64 | .asCompatibleSubstituteFor( "gvenzl/oracle-xe" ) ) 65 | .withStartupAttempts( 1 ) 66 | 67 | // We need to limit the maximum amount of CPUs being used by the container; 68 | // otherwise the hardcoded memory configuration of the DB might not be enough to successfully boot it. 69 | // See https://github.com/gvenzl/oci-oracle-xe/issues/64 70 | // I choose to limit it to "2 cpus": should be more than enough for any local testing needs, 71 | // and keeps things simple. 72 | .withCreateContainerCmdModifier( cmd -> cmd.getHostConfig().withCpuCount( 2L ) ); 73 | } 74 | 75 | private static void logContainerOutput(String line) { 76 | System.out.print( line ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/util/DockerImage.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | import org.testcontainers.utility.DockerImageName; 4 | 5 | /** 6 | * A utility class with methods to generate {@link DockerImageName} for testcontainers. 7 | *

    8 | * Testcontainers might not work if the image required is available in multiple different registries (for example when 9 | * using podman instead of docker). 10 | * These methods make sure to pick a registry as default. 11 | *

    12 | */ 13 | public final class DockerImage { 14 | 15 | public static final String DEFAULT_REGISTRY = "docker.io"; 16 | 17 | public static DockerImageName imageName(String image, String version) { 18 | return imageName( DEFAULT_REGISTRY, image, version ); 19 | } 20 | 21 | public static DockerImageName imageName(String registry, String image, String version) { 22 | return DockerImageName 23 | .parse( registry + "/" + image + ":" + version ) 24 | .asCompatibleSubstituteFor( image ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-3/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Root logger level 2 | rootLogger.level = info 3 | rootLogger.appenderRefs = console 4 | rootLogger.appenderRef.console.ref = console 5 | 6 | # Print the selected dialect information 7 | logger.hibernate-dialect.name = org.hibernate.orm.dialect 8 | logger.hibernate-dialect.level = debug 9 | 10 | # SQL logging disabled by default to speed test suite execution 11 | # It can also be enabled by setting the environment variable: 12 | # JAVA_TOOL_OPTIONS='-Dhibernate.show_sql=true' 13 | logger.hibernate.name = org.hibernate.SQL 14 | logger.hibernate.level = info 15 | 16 | # Setting level TRACE will show when a connection is opened/closed 17 | logger.sql-connection.name = org.hibernate.reactive.pool.impl 18 | logger.sql-connection.level = info 19 | 20 | # Setting level to TRACE will show parameters values for SQL queries 21 | logger.sql-parameters-values.name = org.hibernate.type 22 | logger.sql-parameters-values.level = info 23 | 24 | appender.console.name = console 25 | appender.console.type = Console 26 | appender.console.layout.type = PatternLayout 27 | appender.console.layout.pattern = %highlight{[%p]} %m%n 28 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-4/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Reactive 2 | 3 | This repo contains test case templates, useful for reporting bugs 4 | against [Hibernate Reactive](https://hibernate.org/reactive/). 5 | 6 | The template contains examples of tests written using both the Mutiny and Stage API. 7 | The bug report can be written either with one or the other. 8 | 9 | The database is started via [Testcontainers](https://java.testcontainers.org/). 10 | It's possible to select a different database by changing the value of the constant `SELECT_DB`. 11 | 12 | The package [org.hibernate.reactive.util](src/test/java/org/hibernate/reactive/util) contains: 13 | 14 | * `ConnectionUrl`: The JDBC urls to connect to databases started following the instructions in the 15 | [PODMAN.md](https://github.com/hibernate/hibernate-reactive/blob/main/podman.md) file 16 | in the [Hibernate Reactive GitHub repository](https://github.com/hibernate/hibernate-reactive) 17 | * `Database`: Containers configuration via [Testcontainers](https://java.testcontainers.org/) 18 | * `DockerImage`: Utility class for the creation of a `DockerImageName` to use with Testcontainers 19 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-4/src/test/java/org/hibernate/reactive/bugs/model/MyEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.bugs.model; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | 6 | /** 7 | * An entity to starts with. 8 | */ 9 | @Entity 10 | public class MyEntity { 11 | 12 | @Id 13 | private Long id; 14 | private String name; 15 | 16 | public Long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Long id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "MyEntity(" + id + ":" + name + ")"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-4/src/test/java/org/hibernate/reactive/util/ConnectionURL.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | /** 4 | * JDBC URL connection strings for the property {@link org.hibernate.reactive.provider.Settings#URL} when the database 5 | * is started the instructions from the 6 | * Hibernate Reactive GitHub repository. 7 | */ 8 | public final class ConnectionURL { 9 | public static final String POSTGRES = "jdbc:postgresql://localhost:5432/hreact?user=hreact&password=hreact"; 10 | public static final String COCKROACH = "jdbc:cockroachdb://localhost:26257/postgres?sslmode=disable&user=root"; 11 | public static final String MYSQL = "jdbc:mysql://localhost/hreact?user=hreact&password=hreact"; 12 | public static final String MARIA = "jdbc:mariadb://localhost:3306/hreact?user=hreact&password=hreact"; 13 | public static final String MSSQL = "jdbc:sqlserver://localhost:1433;Encrypt=false;user=sa;password=~!HReact!~"; 14 | public static final String DB2 = "jdbc:db2://localhost:50000/hreact:user=hreact;password=hreact;"; 15 | public static final String ORACLE = "jdbc:oracle:thin:hreact/hreact@localhost:1521/hreact?user=hreact&password=hreact"; 16 | } 17 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-4/src/test/java/org/hibernate/reactive/util/Database.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | import java.util.function.Supplier; 4 | import org.testcontainers.containers.CockroachContainer; 5 | import org.testcontainers.containers.Db2Container; 6 | import org.testcontainers.containers.JdbcDatabaseContainer; 7 | import org.testcontainers.containers.MSSQLServerContainer; 8 | import org.testcontainers.containers.MariaDBContainer; 9 | import org.testcontainers.containers.MySQLContainer; 10 | import org.testcontainers.containers.OracleContainer; 11 | import org.testcontainers.containers.PostgreSQLContainer; 12 | 13 | import static org.hibernate.reactive.util.DockerImage.imageName; 14 | 15 | /** 16 | * The only purpose of this class is to make it easier to switch among the available databases 17 | * for the unit tests. 18 | *

    19 | * It's a wrapper around the testcontainers classes. 20 | */ 21 | public enum Database { 22 | POSTGRESQL( () -> new PostgreSQLContainer<>( imageName( "postgres", "16.3" ) ) ), 23 | MYSQL( () -> new MySQLContainer<>( imageName( "mysql", "8.4.0" ) ) ), 24 | MARIADB( () -> new MariaDBContainer<>( imageName( "mariadb", "11.4.2" ) ) ), 25 | DB2( () -> new Db2Container( imageName( "icr.io", "db2_community/db2", "12.1.0.0" ) ).acceptLicense() ), 26 | COCKROACHDB( () -> new CockroachContainer( imageName( "cockroachdb/cockroach", "v24.1.0" ) ) ), 27 | ORACLE( Database::newOracleContainer ), 28 | MSSQL( Database::newMSSqlServer ); 29 | 30 | private final Supplier> containerSupplier; 31 | 32 | Database(Supplier> supplier) { 33 | this.containerSupplier = supplier; 34 | } 35 | 36 | /** 37 | * Start the container using testcontainers and print the log on System.out. 38 | */ 39 | public JdbcDatabaseContainer startContainer() { 40 | return startContainer( true ); 41 | } 42 | 43 | /** 44 | * Start the database using testcontainers. 45 | * 46 | * @param enableLog if true, print the container log 47 | */ 48 | public JdbcDatabaseContainer startContainer(boolean enableLog) { 49 | JdbcDatabaseContainer jdbcDatabaseContainer = containerSupplier.get(); 50 | jdbcDatabaseContainer 51 | .withLogConsumer( of -> logContainerOutput( of.getUtf8String() ) ) 52 | .withReuse( true ) 53 | .start(); 54 | return jdbcDatabaseContainer; 55 | } 56 | 57 | private static MSSQLServerContainer newMSSqlServer() { 58 | return new MSSQLServerContainer<>( imageName( "mcr.microsoft.com", "mssql/server", "2022-latest" ) ) 59 | .acceptLicense(); 60 | } 61 | 62 | private static OracleContainer newOracleContainer() { 63 | return new OracleContainer( imageName( "gvenzl/oracle-free", "23-slim-faststart" ) 64 | .asCompatibleSubstituteFor( "gvenzl/oracle-xe" ) ) 65 | .withStartupAttempts( 1 ) 66 | 67 | // We need to limit the maximum amount of CPUs being used by the container; 68 | // otherwise the hardcoded memory configuration of the DB might not be enough to successfully boot it. 69 | // See https://github.com/gvenzl/oci-oracle-xe/issues/64 70 | // I choose to limit it to "2 cpus": should be more than enough for any local testing needs, 71 | // and keeps things simple. 72 | .withCreateContainerCmdModifier( cmd -> cmd.getHostConfig().withCpuCount( 2L ) ); 73 | } 74 | 75 | private static void logContainerOutput(String line) { 76 | System.out.print( line ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-4/src/test/java/org/hibernate/reactive/util/DockerImage.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.reactive.util; 2 | 3 | import org.testcontainers.utility.DockerImageName; 4 | 5 | /** 6 | * A utility class with methods to generate {@link DockerImageName} for testcontainers. 7 | *

    8 | * Testcontainers might not work if the image required is available in multiple different registries (for example when 9 | * using podman instead of docker). 10 | * These methods make sure to pick a registry as default. 11 | *

    12 | */ 13 | public final class DockerImage { 14 | 15 | public static final String DEFAULT_REGISTRY = "docker.io"; 16 | 17 | public static DockerImageName imageName(String image, String version) { 18 | return imageName( DEFAULT_REGISTRY, image, version ); 19 | } 20 | 21 | public static DockerImageName imageName(String registry, String image, String version) { 22 | return DockerImageName 23 | .parse( registry + "/" + image + ":" + version ) 24 | .asCompatibleSubstituteFor( image ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /reactive/hibernate-reactive-4/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Root logger level 2 | rootLogger.level = info 3 | rootLogger.appenderRefs = console 4 | rootLogger.appenderRef.console.ref = console 5 | 6 | # Print the selected dialect information 7 | logger.hibernate-dialect.name = org.hibernate.orm.dialect 8 | logger.hibernate-dialect.level = debug 9 | 10 | # SQL logging disabled by default to speed test suite execution 11 | # It can also be enabled by setting the environment variable: 12 | # JAVA_TOOL_OPTIONS='-Dhibernate.show_sql=true' 13 | logger.hibernate.name = org.hibernate.SQL 14 | logger.hibernate.level = info 15 | 16 | # Setting level TRACE will show when a connection is opened/closed 17 | logger.sql-connection.name = org.hibernate.reactive.pool.impl 18 | logger.sql-connection.level = info 19 | 20 | # Setting level to TRACE will show parameters values for SQL queries 21 | logger.sql-parameters-values.name = org.hibernate.type 22 | logger.sql-parameters-values.level = info 23 | 24 | appender.console.name = console 25 | appender.console.type = Console 26 | appender.console.layout.type = PatternLayout 27 | appender.console.layout.pattern = %highlight{[%p]} %m%n 28 | -------------------------------------------------------------------------------- /search/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 2 | 3 | This directory contains test case templates, useful for reporting bugs against Hibernate Search. 4 | 5 | Here's a running list of what's available: 6 | 7 | * `hibernate-search-7`: test case templates for Hibernate Search 7 8 | * `hibernate-search-7/orm-lucene`: a test case template for Hibernate Search 7 in Hibernate ORM backed by an embedded Lucene instance. 9 | * `hibernate-search-7/orm-elasticsearch`: a test case template for Hibernate Search 7 in Hibernate ORM backed by an Elasticsearch cluster. 10 | * `hibernate-search-6`: test case templates for Hibernate Search 6 11 | * `hibernate-search-6/orm-lucene`: a test case template for Hibernate Search 6 in Hibernate ORM backed by an embedded Lucene instance. 12 | * `hibernate-search-6/orm-elasticsearch`: a test case template for Hibernate Search 6 in Hibernate ORM backed by an Elasticsearch cluster. 13 | * `hibernate-search-5`: test case templates for Hibernate Search 5 14 | * `hibernate-search-5/lucene`: a test case template for Hibernate Search 5 in Hibernate ORM backed by an embedded Lucene instance. 15 | * `hibernate-search-5/elasticsearch-2`: a test case template for Hibernate Search 5 in Hibernate ORM backed by an Elasticsearch 2 cluster. 16 | * `hibernate-search-5/elasticsearch-5`: a test case template for Hibernate Search 5 in Hibernate ORM backed by an Elasticsearch 5 cluster. 17 | 18 | Please refer to each subdirectory for instructions on how to run the tests. 19 | 20 | Directories `hibernate-search-elasticsearch` and `hibernate-search-lucene` are remnants of 21 | the former directory structure, only kept to redirect people following old links. 22 | 23 | -------------------------------------------------------------------------------- /search/hibernate-search-5/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 5 2 | 3 | This directory contains test case templates, useful for reporting bugs against Hibernate Search 5. 4 | 5 | Here's a running list of what's available: 6 | 7 | * `lucene`: a test case template for Hibernate Search 5 in Hibernate ORM backed by an embedded Lucene instance. 8 | * `elasticsearch-2`: a test case template for Hibernate Search 5 in Hibernate ORM backed by an Elasticsearch 2 cluster. 9 | * `elasticsearch-5`: a test case template for Hibernate Search 5 in Hibernate ORM backed by an Elasticsearch 5 cluster. 10 | 11 | Please refer to each subdirectory for instructions on how to run the tests. 12 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-2/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 5 with Elasticsearch 2 2 | 3 | This directory used to contain a test case template for Hibernate Search 5 4 | backed with an Elasticsearch 2 cluster. 5 | 6 | As Elasticsearch 2 is very old, we will no longer be accepting test cases like this, 7 | and the test case template has been removed. 8 | 9 | Refer to other templates to submit a reproducer. -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 5 with Elasticsearch 5 2 | 3 | This directory contains a test case template for Hibernate Search 5 4 | backed with an Elasticsearch 5 cluster. 5 | 6 | You can run the integration tests: 7 | * either using the command line with: `mvn verify`: it will automatically launch an instance of Elasticsearch 5; 8 | * or directly from your IDE. In this case, you need to run an instance of Elasticsearch separately using: 9 | `mvn elasticsearch:runforked -Des.setAwait=true`. 10 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/src/test/java/org/hibernate/search/bugs/SearchBackendContainer.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import java.io.Closeable; 4 | import java.time.Duration; 5 | 6 | import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; 7 | import org.testcontainers.elasticsearch.ElasticsearchContainer; 8 | import org.testcontainers.utility.DockerImageName; 9 | 10 | class SearchBackendContainer implements Closeable { 11 | 12 | private static final DockerImageName ELASTICSEARCH_IMAGE_NAME = 13 | DockerImageName.parse( "docker.elastic.co/elasticsearch/elasticsearch" ) 14 | .withTag( "5.6.16" ); 15 | 16 | private ElasticsearchContainer elasticsearchContainer; 17 | 18 | public ElasticsearchContainer setUp() { 19 | elasticsearchContainer = new ElasticsearchContainer( ELASTICSEARCH_IMAGE_NAME ) 20 | .withExposedPorts( 9200, 9300 ) 21 | .waitingFor( new HttpWaitStrategy().forPort( 9200 ).forStatusCode( 200 ) ) 22 | .withStartupTimeout( Duration.ofMinutes( 5 ) ) 23 | .withReuse( true ) 24 | .withEnv( "logger.level", "WARN" ) 25 | .withEnv( "discovery.type", "single-node" ) 26 | .withEnv( "xpack.security.enabled", "false" ) 27 | .withEnv( "ES_JAVA_OPTS", "-Xms1g -Xmx1g" ) 28 | .withEnv( "cluster.routing.allocation.disk.threshold_enabled", "false" ); 29 | elasticsearchContainer.start(); 30 | return elasticsearchContainer; 31 | } 32 | 33 | @Override 34 | public void close() { 35 | try ( ElasticsearchContainer esToClose = this.elasticsearchContainer ) { 36 | // Nothing to do: we just want resources to get closed. 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/src/test/java/org/hibernate/search/bugs/SearchTestBase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.SessionFactoryBuilder; 7 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 | 9 | import org.junit.jupiter.api.AfterEach; 10 | import org.junit.jupiter.api.BeforeEach; 11 | 12 | public abstract class SearchTestBase { 13 | 14 | private SessionFactory sessionFactory; 15 | private SearchBackendContainer elasticsearchContainer; 16 | 17 | @BeforeEach 18 | public void setUp() { 19 | elasticsearchContainer = new SearchBackendContainer(); 20 | 21 | StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(); 22 | registryBuilder.applySetting( 23 | "hibernate.search.default.elasticsearch.host", 24 | elasticsearchContainer.setUp().getHttpHostAddress() 25 | ); 26 | MetadataSources ms = new MetadataSources( registryBuilder.build() ); 27 | Class[] annotatedClasses = getAnnotatedClasses(); 28 | if ( annotatedClasses != null ) { 29 | for ( Class entity : annotatedClasses ) { 30 | ms.addAnnotatedClass( entity ); 31 | } 32 | } 33 | 34 | Metadata metadata = ms.buildMetadata(); 35 | 36 | final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); 37 | this.sessionFactory = sfb.build(); 38 | } 39 | 40 | @AfterEach 41 | public void tearDown() { 42 | try ( SearchBackendContainer esToClose = this.elasticsearchContainer; 43 | SessionFactory sessionFactoryToClose = this.sessionFactory ) { 44 | // Nothing to do: we just want resources to get closed. 45 | } 46 | } 47 | 48 | protected abstract Class[] getAnnotatedClasses(); 49 | 50 | protected SessionFactory getSessionFactory() { 51 | return sessionFactory; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/src/test/java/org/hibernate/search/bugs/SearchTestJunit4Base.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.cfg.Configuration; 4 | 5 | import org.hibernate.testing.AfterClassOnce; 6 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 7 | 8 | public abstract class SearchTestJunit4Base extends BaseCoreFunctionalTestCase { 9 | 10 | private SearchBackendContainer elasticsearchContainer; 11 | 12 | @Override 13 | protected final void configure(Configuration configuration) { 14 | super.configure( configuration ); 15 | 16 | this.elasticsearchContainer = new SearchBackendContainer(); 17 | configuration.setProperty( "hibernate.search.backend.hosts", elasticsearchContainer.setUp().getHttpHostAddress() ); 18 | 19 | configureMore( configuration ); 20 | } 21 | 22 | protected void configureMore(Configuration configuration) { 23 | } 24 | 25 | @Override 26 | protected void releaseSessionFactory() { 27 | try ( SearchBackendContainer esToClose = this.elasticsearchContainer; ) { 28 | super.releaseSessionFactory(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/src/test/java/org/hibernate/search/bugs/YourAnnotatedEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | import org.hibernate.search.annotations.DocumentId; 7 | import org.hibernate.search.annotations.Field; 8 | import org.hibernate.search.annotations.Indexed; 9 | 10 | @Entity 11 | @Indexed 12 | public class YourAnnotatedEntity { 13 | 14 | @Id 15 | @DocumentId 16 | private Long id; 17 | 18 | @Field 19 | private String name; 20 | 21 | protected YourAnnotatedEntity() { 22 | } 23 | 24 | public YourAnnotatedEntity(Long id, String name) { 25 | this.id = id; 26 | this.name = name; 27 | } 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/src/test/java/org/hibernate/search/bugs/YourIT.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.List; 6 | 7 | import org.apache.lucene.search.Query; 8 | import org.hibernate.Session; 9 | import org.hibernate.Transaction; 10 | import org.hibernate.search.FullTextSession; 11 | import org.hibernate.search.Search; 12 | import org.hibernate.search.query.dsl.QueryBuilder; 13 | import org.junit.jupiter.api.Test; 14 | 15 | public class YourIT extends SearchTestBase { 16 | 17 | @Override 18 | public Class[] getAnnotatedClasses() { 19 | return new Class[] { YourAnnotatedEntity.class }; 20 | } 21 | 22 | @Test 23 | @SuppressWarnings("unchecked") 24 | public void testYourBug() { 25 | try ( Session s = getSessionFactory().openSession() ) { 26 | YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" ); 27 | YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" ); 28 | 29 | Transaction tx = s.beginTransaction(); 30 | s.persist( yourEntity1 ); 31 | s.persist( yourEntity2 ); 32 | tx.commit(); 33 | } 34 | 35 | try ( Session s = getSessionFactory().openSession() ) { 36 | FullTextSession session = Search.getFullTextSession( s ); 37 | QueryBuilder qb = session.getSearchFactory().buildQueryBuilder().forEntity( YourAnnotatedEntity.class ).get(); 38 | Query query = qb.keyword().onField( "name" ).matching( "Jane Smith" ).createQuery(); 39 | 40 | List result = (List) session.createFullTextQuery( query ).list(); 41 | assertThat( result.size() ).isEqualTo( 1 ); 42 | assertThat( result.get( 0 ).getId() ).isEqualTo( 1L ); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Hibernate Search with Elasticsearch test case template Persistence Unit 10 | org.hibernate.jpa.HibernatePersistenceProvider 11 | 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | ########################################################### 9 | # Hibernate ORM configuration 10 | ########################################################### 11 | 12 | hibernate.dialect org.hibernate.dialect.H2Dialect 13 | hibernate.connection.driver_class org.h2.Driver 14 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 15 | hibernate.connection.username sa 16 | hibernate.connection.pool_size 5 17 | 18 | # Logs 19 | hibernate.show_sql false 20 | hibernate.format_sql true 21 | 22 | # For tests only 23 | hibernate.hbm2ddl.auto create-drop 24 | 25 | ########################################################### 26 | # Hibernate Search configuration 27 | ########################################################### 28 | hibernate.search.default.indexmanager elasticsearch 29 | hibernate.search.default.elasticsearch.index_management_wait_timeout 10000 30 | 31 | # Logs 32 | hibernate.search.elasticsearch.log.json_pretty_printing true 33 | 34 | # For tests only 35 | hibernate.search.default.elasticsearch.index_schema_management_strategy drop-and-create-and-drop 36 | hibernate.search.default.elasticsearch.required_index_status yellow 37 | hibernate.search.default.elasticsearch.refresh_after_write true 38 | -------------------------------------------------------------------------------- /search/hibernate-search-5/elasticsearch-5/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger 15 | 16 | logger.es_requests.name=org.hibernate.search.elasticsearch.request 17 | logger.es_requests.level=debug 18 | -------------------------------------------------------------------------------- /search/hibernate-search-5/lucene/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search with embedded Lucene 2 | 3 | This directory contains a test case template for Hibernate Search 4 | backed with an embedded Lucene engine. 5 | 6 | You can run the integration tests: 7 | * either using the command line with: `mvn verify`; 8 | * or directly from your IDE. 9 | -------------------------------------------------------------------------------- /search/hibernate-search-5/lucene/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-search-5-lucene 7 | 1.0.0.Final 8 | Hibernate Search 5 with Lucene Test Case Template 9 | 10 | 11 | 5.11.12.Final 12 | 5.4.33 13 | 14 | 2.3.232 15 | 5.11.4 16 | 3.27.3 17 | 18 | UTF-8 19 | UTF-8 20 | 21 | 22 | 23 | 24 | 25 | 26 | org.junit 27 | junit-bom 28 | ${version.junit-jupiter} 29 | pom 30 | import 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.hibernate 38 | hibernate-search-orm 39 | ${version.org.hibernate.search} 40 | 41 | 42 | 43 | org.hibernate 44 | hibernate-core 45 | ${version.org.hibernate} 46 | 47 | 48 | org.hibernate 49 | hibernate-entitymanager 50 | ${version.org.hibernate} 51 | 52 | 53 | 54 | com.h2database 55 | h2 56 | ${version.com.h2database} 57 | 58 | 59 | 60 | org.hibernate 61 | hibernate-testing 62 | ${version.org.hibernate} 63 | test 64 | 65 | 66 | org.hibernate 67 | hibernate-search-testing 68 | ${version.org.hibernate.search} 69 | test 70 | 71 | 72 | org.junit.jupiter 73 | junit-jupiter 74 | test 75 | 76 | 77 | org.junit.platform 78 | junit-platform-launcher 79 | test 80 | 81 | 82 | org.junit.jupiter 83 | junit-jupiter-engine 84 | test 85 | 86 | 87 | org.junit.vintage 88 | junit-vintage-engine 89 | test 90 | 91 | 92 | org.assertj 93 | assertj-core 94 | ${version.org.assertj.assertj-core} 95 | test 96 | 97 | 98 | 99 | 100 | 101 | 102 | org.apache.maven.plugins 103 | maven-compiler-plugin 104 | 3.14.0 105 | 106 | 1.8 107 | 1.8 108 | UTF-8 109 | 110 | 111 | 112 | org.apache.maven.plugins 113 | maven-surefire-plugin 114 | 3.5.3 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-failsafe-plugin 119 | 3.5.3 120 | 121 | 122 | 123 | integration-test 124 | verify 125 | 126 | 127 | 128 | **/*IT.java 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /search/hibernate-search-5/lucene/src/test/java/org/hibernate/search/bugs/SearchTestBase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.SessionFactoryBuilder; 7 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 | 9 | import org.junit.jupiter.api.AfterEach; 10 | import org.junit.jupiter.api.BeforeEach; 11 | 12 | public abstract class SearchTestBase { 13 | 14 | private SessionFactory sessionFactory; 15 | 16 | @BeforeEach 17 | public void setUp() { 18 | StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(); 19 | MetadataSources ms = new MetadataSources( registryBuilder.build() ); 20 | Class[] annotatedClasses = getAnnotatedClasses(); 21 | if ( annotatedClasses != null ) { 22 | for ( Class entity : annotatedClasses ) { 23 | ms.addAnnotatedClass( entity ); 24 | } 25 | } 26 | 27 | Metadata metadata = ms.buildMetadata(); 28 | 29 | final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); 30 | this.sessionFactory = sfb.build(); 31 | } 32 | 33 | @AfterEach 34 | public void tearDown() { 35 | try ( SessionFactory sessionFactoryToClose = this.sessionFactory ) { 36 | // Nothing to do: we just want resources to get closed. 37 | } 38 | } 39 | 40 | protected abstract Class[] getAnnotatedClasses(); 41 | 42 | protected SessionFactory getSessionFactory() { 43 | return sessionFactory; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /search/hibernate-search-5/lucene/src/test/java/org/hibernate/search/bugs/YourAnnotatedEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | import org.hibernate.search.annotations.DocumentId; 7 | import org.hibernate.search.annotations.Field; 8 | import org.hibernate.search.annotations.Indexed; 9 | 10 | @Entity 11 | @Indexed 12 | public class YourAnnotatedEntity { 13 | 14 | @Id 15 | @DocumentId 16 | private Long id; 17 | 18 | @Field 19 | private String name; 20 | 21 | protected YourAnnotatedEntity() { 22 | } 23 | 24 | public YourAnnotatedEntity(Long id, String name) { 25 | this.id = id; 26 | this.name = name; 27 | } 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /search/hibernate-search-5/lucene/src/test/java/org/hibernate/search/bugs/YourIT.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import java.util.List; 7 | 8 | import org.hibernate.Session; 9 | import org.hibernate.Transaction; 10 | import org.hibernate.search.FullTextSession; 11 | import org.hibernate.search.Search; 12 | import org.hibernate.search.query.dsl.QueryBuilder; 13 | import org.hibernate.search.query.engine.spi.QueryDescriptor; 14 | 15 | import org.junit.jupiter.api.Test; 16 | 17 | import org.apache.lucene.search.Query; 18 | 19 | public class YourIT extends SearchTestBase { 20 | 21 | @Override 22 | public Class[] getAnnotatedClasses() { 23 | return new Class[] { YourAnnotatedEntity.class }; 24 | } 25 | 26 | @Test 27 | @SuppressWarnings("unchecked") 28 | public void testYourBug() { 29 | try ( Session s = getSessionFactory().openSession() ) { 30 | YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" ); 31 | YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" ); 32 | 33 | Transaction tx = s.beginTransaction(); 34 | s.persist( yourEntity1 ); 35 | s.persist( yourEntity2 ); 36 | tx.commit(); 37 | } 38 | 39 | try ( Session s = getSessionFactory().openSession() ) { 40 | FullTextSession session = Search.getFullTextSession( s ); 41 | QueryBuilder qb = session.getSearchFactory().buildQueryBuilder().forEntity( YourAnnotatedEntity.class ).get(); 42 | Query query = qb.keyword().onField( "name" ).matching( "Jane Smith" ).createQuery(); 43 | 44 | List result = (List) session.createFullTextQuery( query ).list(); 45 | assertThat( result.size() ).isEqualTo( 1 ); 46 | assertThat( result.get( 0 ).getId() ).isEqualTo( 1L ); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /search/hibernate-search-5/lucene/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Hibernate Search with Lucene test case template Persistence Unit 10 | org.hibernate.jpa.HibernatePersistenceProvider 11 | 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /search/hibernate-search-5/lucene/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | ########################################################### 9 | # Hibernate ORM configuration 10 | ########################################################### 11 | 12 | hibernate.dialect org.hibernate.dialect.H2Dialect 13 | hibernate.connection.driver_class org.h2.Driver 14 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 15 | hibernate.connection.username sa 16 | hibernate.connection.pool_size 5 17 | 18 | # Logs 19 | hibernate.show_sql false 20 | hibernate.format_sql true 21 | 22 | # For tests only 23 | hibernate.hbm2ddl.auto create-drop 24 | 25 | ########################################################### 26 | # Hibernate Search configuration 27 | ########################################################### 28 | hibernate.search.default.directory_provider=ram -------------------------------------------------------------------------------- /search/hibernate-search-5/lucene/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /search/hibernate-search-6/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 6 2 | 3 | This directory contains test case templates, useful for reporting bugs against Hibernate Search 6. 4 | 5 | Here's a running list of what's available: 6 | 7 | * `orm-lucene`: a test case template for Hibernate Search 6 in Hibernate ORM backed by an embedded Lucene instance. 8 | * `orm-elasticsearch`: a test case template for Hibernate Search 6 in Hibernate ORM backed by an Elasticsearch cluster. 9 | 10 | 11 | Please refer to each subdirectory for instructions on how to run the tests. 12 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 6 in Hibernate ORM with Elasticsearch 2 | 3 | This directory contains a test case template for 4 | Hibernate Search 6 in Hibernate ORM backed by an Elasticsearch cluster. 5 | 6 | You can run the integration tests: 7 | * either using the command line with: `mvn verify`: it will automatically launch an instance of Elasticsearch; 8 | * or directly from your IDE. In this case, you need to run an instance of Elasticsearch separately using: 9 | `mvn elasticsearch:runforked -Des.setAwait=true`. 10 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/SearchBackendContainer.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import java.io.Closeable; 4 | import java.time.Duration; 5 | 6 | import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; 7 | import org.testcontainers.elasticsearch.ElasticsearchContainer; 8 | import org.testcontainers.utility.DockerImageName; 9 | 10 | class SearchBackendContainer implements Closeable { 11 | 12 | private static final DockerImageName ELASTICSEARCH_IMAGE_NAME = 13 | DockerImageName.parse( "docker.elastic.co/elasticsearch/elasticsearch" ) 14 | .withTag( "7.16.3" ); 15 | 16 | private ElasticsearchContainer elasticsearchContainer; 17 | 18 | public ElasticsearchContainer setUp() { 19 | elasticsearchContainer = new ElasticsearchContainer( ELASTICSEARCH_IMAGE_NAME ) 20 | .withExposedPorts( 9200, 9300 ) 21 | .waitingFor( new HttpWaitStrategy().forPort( 9200 ).forStatusCode( 200 ) ) 22 | .withStartupTimeout( Duration.ofMinutes( 5 ) ) 23 | .withReuse( true ) 24 | .withEnv( "logger.level", "WARN" ) 25 | .withEnv( "discovery.type", "single-node" ) 26 | .withEnv( "xpack.security.enabled", "false" ) 27 | .withEnv( "ES_JAVA_OPTS", "-Xms1g -Xmx1g" ) 28 | .withEnv( "cluster.routing.allocation.disk.threshold_enabled", "false" ); 29 | elasticsearchContainer.start(); 30 | return elasticsearchContainer; 31 | } 32 | 33 | @Override 34 | public void close() { 35 | try ( ElasticsearchContainer esToClose = this.elasticsearchContainer ) { 36 | // Nothing to do: we just want resources to get closed. 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/SearchTestBase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.SessionFactoryBuilder; 7 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 | 9 | import org.junit.jupiter.api.AfterEach; 10 | import org.junit.jupiter.api.BeforeEach; 11 | 12 | public abstract class SearchTestBase { 13 | 14 | private SessionFactory sessionFactory; 15 | private SearchBackendContainer elasticsearchContainer; 16 | 17 | @BeforeEach 18 | public void setUp() { 19 | elasticsearchContainer = new SearchBackendContainer(); 20 | 21 | StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(); 22 | registryBuilder.applySetting( 23 | "hibernate.search.backend.hosts", 24 | elasticsearchContainer.setUp().getHttpHostAddress() 25 | ); 26 | MetadataSources ms = new MetadataSources( registryBuilder.build() ); 27 | Class[] annotatedClasses = getAnnotatedClasses(); 28 | if ( annotatedClasses != null ) { 29 | for ( Class entity : annotatedClasses ) { 30 | ms.addAnnotatedClass( entity ); 31 | } 32 | } 33 | 34 | Metadata metadata = ms.buildMetadata(); 35 | 36 | final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); 37 | this.sessionFactory = sfb.build(); 38 | } 39 | 40 | @AfterEach 41 | public void tearDown() { 42 | try ( SearchBackendContainer esToClose = this.elasticsearchContainer; 43 | SessionFactory sessionFactoryToClose = this.sessionFactory ) { 44 | // Nothing to do: we just want resources to get closed. 45 | } 46 | } 47 | 48 | protected abstract Class[] getAnnotatedClasses(); 49 | 50 | protected SessionFactory getSessionFactory() { 51 | return sessionFactory; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/SearchTestJunit4Base.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.cfg.Configuration; 4 | 5 | import org.hibernate.testing.AfterClassOnce; 6 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 7 | 8 | public abstract class SearchTestJunit4Base extends BaseCoreFunctionalTestCase { 9 | 10 | private SearchBackendContainer elasticsearchContainer; 11 | 12 | @Override 13 | protected final void configure(Configuration configuration) { 14 | super.configure( configuration ); 15 | 16 | this.elasticsearchContainer = new SearchBackendContainer(); 17 | configuration.setProperty( "hibernate.search.backend.hosts", elasticsearchContainer.setUp().getHttpHostAddress() ); 18 | 19 | configureMore( configuration ); 20 | } 21 | 22 | protected void configureMore(Configuration configuration) { 23 | } 24 | 25 | @Override 26 | protected void releaseSessionFactory() { 27 | try ( SearchBackendContainer esToClose = this.elasticsearchContainer; ) { 28 | super.releaseSessionFactory(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/YourAnalysisConfigurer.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurationContext; 4 | import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer; 5 | 6 | public class YourAnalysisConfigurer implements ElasticsearchAnalysisConfigurer { 7 | @Override 8 | public void configure(ElasticsearchAnalysisConfigurationContext context) { 9 | context.analyzer( "nameAnalyzer" ).custom() 10 | .tokenizer( "whitespace" ) 11 | .tokenFilters( "lowercase", "asciifolding" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/YourAnnotatedEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; 4 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; 5 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; 6 | 7 | import javax.persistence.Entity; 8 | import javax.persistence.Id; 9 | 10 | @Entity 11 | @Indexed 12 | public class YourAnnotatedEntity { 13 | 14 | @Id 15 | @DocumentId 16 | private Long id; 17 | 18 | @FullTextField(analyzer = "nameAnalyzer") 19 | private String name; 20 | 21 | protected YourAnnotatedEntity() { 22 | } 23 | 24 | public YourAnnotatedEntity(Long id, String name) { 25 | this.id = id; 26 | this.name = name; 27 | } 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/YourIT.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.List; 6 | 7 | import org.hibernate.Session; 8 | import org.hibernate.Transaction; 9 | import org.hibernate.search.mapper.orm.Search; 10 | import org.hibernate.search.mapper.orm.session.SearchSession; 11 | 12 | import org.junit.jupiter.api.Test; 13 | 14 | public class YourIT extends SearchTestBase { 15 | 16 | @Override 17 | public Class[] getAnnotatedClasses() { 18 | return new Class[] { YourAnnotatedEntity.class }; 19 | } 20 | 21 | @Test 22 | public void testYourBug() { 23 | try ( Session s = getSessionFactory().openSession() ) { 24 | YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" ); 25 | YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" ); 26 | 27 | Transaction tx = s.beginTransaction(); 28 | s.persist( yourEntity1 ); 29 | s.persist( yourEntity2 ); 30 | tx.commit(); 31 | } 32 | 33 | try ( Session session = getSessionFactory().openSession() ) { 34 | SearchSession searchSession = Search.session( session ); 35 | 36 | List hits = searchSession.search( YourAnnotatedEntity.class ) 37 | .where( f -> f.match().field( "name" ).matching( "smith" ) ) 38 | .fetchHits( 20 ); 39 | 40 | assertThat( hits ) 41 | .hasSize( 1 ) 42 | .element( 0 ).extracting( YourAnnotatedEntity::getId ) 43 | .isEqualTo( 1L ); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Hibernate Search with Elasticsearch test case template Persistence Unit 10 | org.hibernate.jpa.HibernatePersistenceProvider 11 | 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | ########################################################### 9 | # Hibernate ORM configuration 10 | ########################################################### 11 | 12 | hibernate.dialect org.hibernate.dialect.H2Dialect 13 | hibernate.connection.driver_class org.h2.Driver 14 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 15 | hibernate.connection.username sa 16 | hibernate.connection.pool_size 5 17 | 18 | # Logs 19 | hibernate.show_sql false 20 | hibernate.format_sql true 21 | 22 | # For tests only 23 | hibernate.hbm2ddl.auto create-drop 24 | 25 | ########################################################### 26 | # Hibernate Search configuration 27 | ########################################################### 28 | 29 | hibernate.search.backend.analysis.configurer org.hibernate.search.bugs.YourAnalysisConfigurer 30 | 31 | # Logs 32 | hibernate.search.backend.log.json_pretty_printing true 33 | 34 | # For tests only 35 | hibernate.search.schema_management.strategy drop-and-create-and-drop 36 | hibernate.search.automatic_indexing.synchronization.strategy sync 37 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-elasticsearch/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger 15 | 16 | logger.es_requests.name=org.hibernate.search.elasticsearch.request 17 | logger.es_requests.level=debug 18 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 6 in Hibernate ORM with Lucene 2 | 3 | This directory contains a test case template for 4 | Hibernate Search 6 in Hibernate ORM backed by an embedded Lucene instance. 5 | 6 | You can run the integration tests: 7 | * either using the command line with: `mvn verify`; 8 | * or directly from your IDE. 9 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-search-6-orm-lucene 7 | 1.0.0.Final 8 | Hibernate Search 6 with Hibernate ORM and Lucene Test Case Template 9 | 10 | 11 | 6.2.4.Final 12 | 5.6.15.Final 13 | 14 | 2.3.232 15 | 5.11.4 16 | 3.27.3 17 | 18 | UTF-8 19 | UTF-8 20 | 21 | 22 | 23 | 24 | 25 | org.junit 26 | junit-bom 27 | ${version.junit-jupiter} 28 | pom 29 | import 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.hibernate.search 37 | hibernate-search-mapper-orm 38 | ${version.org.hibernate.search} 39 | 40 | 41 | org.hibernate.search 42 | hibernate-search-backend-lucene 43 | ${version.org.hibernate.search} 44 | 45 | 46 | 47 | org.hibernate 48 | hibernate-core 49 | ${version.org.hibernate} 50 | 51 | 52 | 53 | com.h2database 54 | h2 55 | ${version.com.h2database} 56 | 57 | 58 | 59 | org.hibernate 60 | hibernate-testing 61 | ${version.org.hibernate} 62 | test 63 | 64 | 65 | org.junit.jupiter 66 | junit-jupiter 67 | test 68 | 69 | 70 | org.junit.platform 71 | junit-platform-launcher 72 | test 73 | 74 | 75 | org.junit.jupiter 76 | junit-jupiter-engine 77 | test 78 | 79 | 80 | org.junit.vintage 81 | junit-vintage-engine 82 | test 83 | 84 | 85 | org.assertj 86 | assertj-core 87 | ${version.org.assertj.assertj-core} 88 | test 89 | 90 | 91 | 92 | 93 | 94 | 95 | org.apache.maven.plugins 96 | maven-compiler-plugin 97 | 3.14.0 98 | 99 | 1.8 100 | 1.8 101 | UTF-8 102 | 103 | 104 | 105 | org.apache.maven.plugins 106 | maven-surefire-plugin 107 | 3.5.3 108 | 109 | 110 | org.apache.maven.plugins 111 | maven-failsafe-plugin 112 | 3.5.3 113 | 114 | 115 | 116 | integration-test 117 | verify 118 | 119 | 120 | 121 | **/*IT.java 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/src/test/java/org/hibernate/search/bugs/SearchTestBase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.SessionFactoryBuilder; 7 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 | 9 | import org.junit.jupiter.api.AfterEach; 10 | import org.junit.jupiter.api.BeforeEach; 11 | 12 | public abstract class SearchTestBase { 13 | 14 | private SessionFactory sessionFactory; 15 | 16 | @BeforeEach 17 | public void setUp() { 18 | StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(); 19 | MetadataSources ms = new MetadataSources( registryBuilder.build() ); 20 | Class[] annotatedClasses = getAnnotatedClasses(); 21 | if ( annotatedClasses != null ) { 22 | for ( Class entity : annotatedClasses ) { 23 | ms.addAnnotatedClass( entity ); 24 | } 25 | } 26 | 27 | Metadata metadata = ms.buildMetadata(); 28 | 29 | final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); 30 | this.sessionFactory = sfb.build(); 31 | } 32 | 33 | @AfterEach 34 | public void tearDown() { 35 | try ( SessionFactory sessionFactoryToClose = this.sessionFactory ) { 36 | // Nothing to do: we just want resources to get closed. 37 | } 38 | } 39 | 40 | protected abstract Class[] getAnnotatedClasses(); 41 | 42 | protected SessionFactory getSessionFactory() { 43 | return sessionFactory; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/src/test/java/org/hibernate/search/bugs/YourAnalysisConfigurer.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.search.backend.lucene.analysis.LuceneAnalysisConfigurationContext; 4 | import org.hibernate.search.backend.lucene.analysis.LuceneAnalysisConfigurer; 5 | 6 | import org.apache.lucene.analysis.core.LowerCaseFilterFactory; 7 | import org.apache.lucene.analysis.core.WhitespaceTokenizerFactory; 8 | import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilterFactory; 9 | 10 | public class YourAnalysisConfigurer implements LuceneAnalysisConfigurer { 11 | @Override 12 | public void configure(LuceneAnalysisConfigurationContext context) { 13 | context.analyzer( "nameAnalyzer" ).custom() 14 | .tokenizer( WhitespaceTokenizerFactory.class ) 15 | .tokenFilter( LowerCaseFilterFactory.class ) 16 | .tokenFilter( ASCIIFoldingFilterFactory.class ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/src/test/java/org/hibernate/search/bugs/YourAnnotatedEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; 4 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; 5 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; 6 | 7 | import javax.persistence.Entity; 8 | import javax.persistence.Id; 9 | 10 | @Entity 11 | @Indexed 12 | public class YourAnnotatedEntity { 13 | 14 | @Id 15 | @DocumentId 16 | private Long id; 17 | 18 | @FullTextField(analyzer = "nameAnalyzer") 19 | private String name; 20 | 21 | protected YourAnnotatedEntity() { 22 | } 23 | 24 | public YourAnnotatedEntity(Long id, String name) { 25 | this.id = id; 26 | this.name = name; 27 | } 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/src/test/java/org/hibernate/search/bugs/YourIT.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.List; 6 | 7 | import org.hibernate.Session; 8 | import org.hibernate.Transaction; 9 | import org.hibernate.search.mapper.orm.Search; 10 | import org.hibernate.search.mapper.orm.session.SearchSession; 11 | 12 | import org.junit.jupiter.api.Test; 13 | 14 | public class YourIT extends SearchTestBase { 15 | 16 | @Override 17 | public Class[] getAnnotatedClasses() { 18 | return new Class[] { YourAnnotatedEntity.class }; 19 | } 20 | 21 | @Test 22 | public void testYourBug() { 23 | try ( Session s = getSessionFactory().openSession() ) { 24 | YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" ); 25 | YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" ); 26 | 27 | Transaction tx = s.beginTransaction(); 28 | s.persist( yourEntity1 ); 29 | s.persist( yourEntity2 ); 30 | tx.commit(); 31 | } 32 | 33 | try ( Session session = getSessionFactory().openSession() ) { 34 | SearchSession searchSession = Search.session( session ); 35 | 36 | List hits = searchSession.search( YourAnnotatedEntity.class ) 37 | .where( f -> f.match().field( "name" ).matching( "smith" ) ) 38 | .fetchHits( 20 ); 39 | 40 | assertThat( hits ) 41 | .hasSize( 1 ) 42 | .element( 0 ).extracting( YourAnnotatedEntity::getId ) 43 | .isEqualTo( 1L ); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Hibernate Search with Lucene test case template Persistence Unit 10 | org.hibernate.jpa.HibernatePersistenceProvider 11 | 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | ########################################################### 9 | # Hibernate ORM configuration 10 | ########################################################### 11 | 12 | hibernate.dialect org.hibernate.dialect.H2Dialect 13 | hibernate.connection.driver_class org.h2.Driver 14 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 15 | hibernate.connection.username sa 16 | hibernate.connection.pool_size 5 17 | 18 | # Logs 19 | hibernate.show_sql false 20 | hibernate.format_sql true 21 | 22 | # For tests only 23 | hibernate.hbm2ddl.auto create-drop 24 | 25 | ########################################################### 26 | # Hibernate Search configuration 27 | ########################################################### 28 | 29 | hibernate.search.backend.directory.root target/test-indexes 30 | hibernate.search.backend.analysis.configurer org.hibernate.search.bugs.YourAnalysisConfigurer 31 | 32 | # For tests only 33 | hibernate.search.schema_management.strategy drop-and-create-and-drop 34 | hibernate.search.automatic_indexing.synchronization.strategy sync 35 | -------------------------------------------------------------------------------- /search/hibernate-search-6/orm-lucene/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /search/hibernate-search-7/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 7 2 | 3 | This directory contains test case templates, useful for reporting bugs against Hibernate Search 7. 4 | 5 | Here's a running list of what's available: 6 | 7 | * `orm-lucene`: a test case template for Hibernate Search 7 in Hibernate ORM backed by an embedded Lucene instance. 8 | * `orm-elasticsearch`: a test case template for Hibernate Search 7 in Hibernate ORM backed by an Elasticsearch cluster. 9 | 10 | Please refer to each subdirectory for instructions on how to run the tests. 11 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 7 in Hibernate ORM with Elasticsearch 2 | 3 | This directory contains a test case template for 4 | Hibernate Search 7 in Hibernate ORM backed by an Elasticsearch cluster. 5 | 6 | You can run the integration tests: 7 | * either using the command line with: `mvn verify`; 8 | * or directly from your IDE. 9 | 10 | Make sure to have `docker` or `podman` installed, 11 | as the test will automatically start an Elasticsearch container using testcontainers. 12 | See `SearchTestBase` for details or to change the version of Elasticsearch to test against. -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/SearchBackendContainer.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import java.io.Closeable; 4 | import java.time.Duration; 5 | 6 | import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; 7 | import org.testcontainers.elasticsearch.ElasticsearchContainer; 8 | import org.testcontainers.utility.DockerImageName; 9 | 10 | class SearchBackendContainer implements Closeable { 11 | 12 | private static final DockerImageName ELASTICSEARCH_IMAGE_NAME = 13 | DockerImageName.parse( "docker.elastic.co/elasticsearch/elasticsearch" ) 14 | .withTag( "8.11.0" ); 15 | 16 | private ElasticsearchContainer elasticsearchContainer; 17 | 18 | public ElasticsearchContainer setUp() { 19 | elasticsearchContainer = new ElasticsearchContainer( ELASTICSEARCH_IMAGE_NAME ) 20 | .withExposedPorts( 9200, 9300 ) 21 | .waitingFor( new HttpWaitStrategy().forPort( 9200 ).forStatusCode( 200 ) ) 22 | .withStartupTimeout( Duration.ofMinutes( 5 ) ) 23 | .withReuse( true ) 24 | .withEnv( "logger.level", "WARN" ) 25 | .withEnv( "discovery.type", "single-node" ) 26 | .withEnv( "xpack.security.enabled", "false" ) 27 | .withEnv( "ES_JAVA_OPTS", "-Xms1g -Xmx1g" ) 28 | .withEnv( "cluster.routing.allocation.disk.threshold_enabled", "false" ); 29 | elasticsearchContainer.start(); 30 | return elasticsearchContainer; 31 | } 32 | 33 | @Override 34 | public void close() { 35 | try ( ElasticsearchContainer esToClose = this.elasticsearchContainer ) { 36 | // Nothing to do: we just want resources to get closed. 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/SearchTestBase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.SessionFactoryBuilder; 7 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 | 9 | import org.junit.jupiter.api.AfterEach; 10 | import org.junit.jupiter.api.BeforeEach; 11 | 12 | public abstract class SearchTestBase { 13 | 14 | private SessionFactory sessionFactory; 15 | private SearchBackendContainer elasticsearchContainer; 16 | 17 | @BeforeEach 18 | public void setUp() { 19 | elasticsearchContainer = new SearchBackendContainer(); 20 | 21 | StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(); 22 | registryBuilder.applySetting( 23 | "hibernate.search.backend.hosts", 24 | elasticsearchContainer.setUp().getHttpHostAddress() 25 | ); 26 | MetadataSources ms = new MetadataSources( registryBuilder.build() ); 27 | Class[] annotatedClasses = getAnnotatedClasses(); 28 | if ( annotatedClasses != null ) { 29 | for ( Class entity : annotatedClasses ) { 30 | ms.addAnnotatedClass( entity ); 31 | } 32 | } 33 | 34 | Metadata metadata = ms.buildMetadata(); 35 | 36 | final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); 37 | this.sessionFactory = sfb.build(); 38 | } 39 | 40 | @AfterEach 41 | public void tearDown() { 42 | try ( SearchBackendContainer esToClose = this.elasticsearchContainer; 43 | SessionFactory sessionFactoryToClose = this.sessionFactory ) { 44 | // Nothing to do: we just want resources to get closed. 45 | } 46 | } 47 | 48 | protected abstract Class[] getAnnotatedClasses(); 49 | 50 | protected SessionFactory getSessionFactory() { 51 | return sessionFactory; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/SearchTestJunit4Base.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.cfg.Configuration; 4 | 5 | import org.hibernate.testing.AfterClassOnce; 6 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 7 | 8 | public abstract class SearchTestJunit4Base extends BaseCoreFunctionalTestCase { 9 | 10 | private SearchBackendContainer elasticsearchContainer; 11 | 12 | @Override 13 | protected final void configure(Configuration configuration) { 14 | super.configure( configuration ); 15 | 16 | this.elasticsearchContainer = new SearchBackendContainer(); 17 | configuration.setProperty( "hibernate.search.backend.hosts", elasticsearchContainer.setUp().getHttpHostAddress() ); 18 | 19 | configureMore( configuration ); 20 | } 21 | 22 | protected void configureMore(Configuration configuration) { 23 | } 24 | 25 | @Override 26 | protected void releaseSessionFactory() { 27 | try ( SearchBackendContainer esToClose = this.elasticsearchContainer; ) { 28 | super.releaseSessionFactory(); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/YourAnalysisConfigurer.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurationContext; 4 | import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer; 5 | 6 | public class YourAnalysisConfigurer implements ElasticsearchAnalysisConfigurer { 7 | @Override 8 | public void configure(ElasticsearchAnalysisConfigurationContext context) { 9 | context.analyzer( "nameAnalyzer" ).custom() 10 | .tokenizer( "whitespace" ) 11 | .tokenFilters( "lowercase", "asciifolding" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/YourAnnotatedEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | 6 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; 7 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; 8 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; 9 | 10 | @Entity 11 | @Indexed 12 | public class YourAnnotatedEntity { 13 | 14 | @Id 15 | @DocumentId 16 | private Long id; 17 | 18 | @FullTextField(analyzer = "nameAnalyzer") 19 | private String name; 20 | 21 | protected YourAnnotatedEntity() { 22 | } 23 | 24 | public YourAnnotatedEntity(Long id, String name) { 25 | this.id = id; 26 | this.name = name; 27 | } 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/YourBytecodeEnhancedIT.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.lang.reflect.Method; 6 | import java.util.List; 7 | 8 | import org.hibernate.Session; 9 | import org.hibernate.Transaction; 10 | import org.hibernate.search.mapper.orm.Search; 11 | import org.hibernate.search.mapper.orm.session.SearchSession; 12 | 13 | import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; 14 | import org.junit.Test; 15 | import org.junit.runner.RunWith; 16 | 17 | /** 18 | * Use this template only if you need Hibernate ORM bytecode enhancement to reproduce your issue. 19 | */ 20 | @RunWith(BytecodeEnhancerRunner.class) // This runner enables bytecode enhancement for your test. 21 | public class YourBytecodeEnhancedIT extends SearchTestJunit4Base { 22 | 23 | @Override 24 | public Class[] getAnnotatedClasses() { 25 | return new Class[] { YourAnnotatedEntity.class }; 26 | } 27 | 28 | @Test 29 | public void testYourBug() { 30 | try ( Session s = openSession() ) { 31 | YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" ); 32 | YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" ); 33 | 34 | Transaction tx = s.beginTransaction(); 35 | s.persist( yourEntity1 ); 36 | s.persist( yourEntity2 ); 37 | tx.commit(); 38 | } 39 | 40 | try ( Session session = openSession() ) { 41 | SearchSession searchSession = Search.session( session ); 42 | 43 | List hits = searchSession.search( YourAnnotatedEntity.class ) 44 | .where( f -> f.match().field( "name" ).matching( "smith" ) ) 45 | .fetchHits( 20 ); 46 | 47 | assertThat( hits ) 48 | .hasSize( 1 ) 49 | .element( 0 ).extracting( YourAnnotatedEntity::getId ) 50 | .isEqualTo( 1L ); 51 | } 52 | } 53 | 54 | @Test 55 | public void testBytecodeEnhancement() { 56 | assertThat( YourAnnotatedEntity.class.getDeclaredMethods() ) 57 | .extracting( Method::getName ) 58 | .anyMatch( name -> name.startsWith( "$$_hibernate_" ) ); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/java/org/hibernate/search/bugs/YourIT.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.List; 6 | 7 | import org.hibernate.Session; 8 | import org.hibernate.Transaction; 9 | import org.hibernate.search.mapper.orm.Search; 10 | import org.hibernate.search.mapper.orm.session.SearchSession; 11 | 12 | import org.junit.jupiter.api.Test; 13 | 14 | public class YourIT extends SearchTestBase { 15 | 16 | @Override 17 | public Class[] getAnnotatedClasses() { 18 | return new Class[] { YourAnnotatedEntity.class }; 19 | } 20 | 21 | @Test 22 | public void testYourBug() { 23 | try ( Session s = getSessionFactory().openSession() ) { 24 | YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" ); 25 | YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" ); 26 | 27 | Transaction tx = s.beginTransaction(); 28 | s.persist( yourEntity1 ); 29 | s.persist( yourEntity2 ); 30 | tx.commit(); 31 | } 32 | 33 | try ( Session session = getSessionFactory().openSession() ) { 34 | SearchSession searchSession = Search.session( session ); 35 | 36 | List hits = searchSession.search( YourAnnotatedEntity.class ) 37 | .where( f -> f.match().field( "name" ).matching( "smith" ) ) 38 | .fetchHits( 20 ); 39 | 40 | assertThat( hits ) 41 | .hasSize( 1 ) 42 | .element( 0 ).extracting( YourAnnotatedEntity::getId ) 43 | .isEqualTo( 1L ); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Hibernate Search with Elasticsearch test case template Persistence Unit 10 | org.hibernate.jpa.HibernatePersistenceProvider 11 | 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | ########################################################### 9 | # Hibernate ORM configuration 10 | ########################################################### 11 | 12 | hibernate.dialect org.hibernate.dialect.H2Dialect 13 | hibernate.connection.driver_class org.h2.Driver 14 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 15 | hibernate.connection.username sa 16 | hibernate.connection.password 17 | hibernate.connection.pool_size 5 18 | 19 | # Logs 20 | hibernate.show_sql false 21 | hibernate.format_sql true 22 | 23 | # For tests only 24 | hibernate.hbm2ddl.auto create-drop 25 | 26 | ########################################################### 27 | # Hibernate Search configuration 28 | ########################################################### 29 | 30 | hibernate.search.backend.analysis.configurer org.hibernate.search.bugs.YourAnalysisConfigurer 31 | 32 | # Logs 33 | hibernate.search.backend.log.json_pretty_printing true 34 | 35 | # For tests only 36 | hibernate.search.schema_management.strategy drop-and-create-and-drop 37 | hibernate.search.indexing.plan.synchronization.strategy sync 38 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-elasticsearch/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger 15 | 16 | logger.es_requests.name=org.hibernate.search.elasticsearch.request 17 | logger.es_requests.level=debug 18 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Search 7 in Hibernate ORM with Lucene 2 | 3 | This directory contains a test case template for 4 | Hibernate Search 7 in Hibernate ORM backed by an embedded Lucene instance. 5 | 6 | You can run the integration tests: 7 | * either using the command line with: `mvn verify`; 8 | * or directly from your IDE. 9 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/src/test/java/org/hibernate/search/bugs/SearchTestBase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.SessionFactory; 4 | import org.hibernate.boot.Metadata; 5 | import org.hibernate.boot.MetadataSources; 6 | import org.hibernate.boot.SessionFactoryBuilder; 7 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 | 9 | import org.junit.jupiter.api.AfterEach; 10 | import org.junit.jupiter.api.BeforeEach; 11 | 12 | public abstract class SearchTestBase { 13 | 14 | private SessionFactory sessionFactory; 15 | 16 | @BeforeEach 17 | public void setUp() { 18 | StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(); 19 | MetadataSources ms = new MetadataSources( registryBuilder.build() ); 20 | Class[] annotatedClasses = getAnnotatedClasses(); 21 | if ( annotatedClasses != null ) { 22 | for ( Class entity : annotatedClasses ) { 23 | ms.addAnnotatedClass( entity ); 24 | } 25 | } 26 | 27 | Metadata metadata = ms.buildMetadata(); 28 | 29 | final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder(); 30 | this.sessionFactory = sfb.build(); 31 | } 32 | 33 | @AfterEach 34 | public void tearDown() { 35 | try ( SessionFactory sessionFactoryToClose = this.sessionFactory ) { 36 | // Nothing to do: we just want resources to get closed. 37 | } 38 | } 39 | 40 | protected abstract Class[] getAnnotatedClasses(); 41 | 42 | protected SessionFactory getSessionFactory() { 43 | return sessionFactory; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/src/test/java/org/hibernate/search/bugs/YourAnalysisConfigurer.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.search.backend.lucene.analysis.LuceneAnalysisConfigurationContext; 4 | import org.hibernate.search.backend.lucene.analysis.LuceneAnalysisConfigurer; 5 | 6 | import org.apache.lucene.analysis.core.LowerCaseFilterFactory; 7 | import org.apache.lucene.analysis.core.WhitespaceTokenizerFactory; 8 | import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilterFactory; 9 | 10 | public class YourAnalysisConfigurer implements LuceneAnalysisConfigurer { 11 | @Override 12 | public void configure(LuceneAnalysisConfigurationContext context) { 13 | context.analyzer( "nameAnalyzer" ).custom() 14 | .tokenizer( WhitespaceTokenizerFactory.class ) 15 | .tokenFilter( LowerCaseFilterFactory.class ) 16 | .tokenFilter( ASCIIFoldingFilterFactory.class ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/src/test/java/org/hibernate/search/bugs/YourAnnotatedEntity.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; 4 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; 5 | import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; 6 | 7 | import jakarta.persistence.Entity; 8 | import jakarta.persistence.Id; 9 | 10 | @Entity 11 | @Indexed 12 | public class YourAnnotatedEntity { 13 | 14 | @Id 15 | @DocumentId 16 | private Long id; 17 | 18 | @FullTextField(analyzer = "nameAnalyzer") 19 | private String name; 20 | 21 | protected YourAnnotatedEntity() { 22 | } 23 | 24 | public YourAnnotatedEntity(Long id, String name) { 25 | this.id = id; 26 | this.name = name; 27 | } 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/src/test/java/org/hibernate/search/bugs/YourBytecodeEnhancedIT.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.lang.reflect.Method; 6 | import java.util.List; 7 | 8 | import org.hibernate.Session; 9 | import org.hibernate.Transaction; 10 | import org.hibernate.search.mapper.orm.Search; 11 | import org.hibernate.search.mapper.orm.session.SearchSession; 12 | 13 | import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; 14 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 15 | import org.junit.Test; 16 | import org.junit.runner.RunWith; 17 | 18 | /** 19 | * Use this template only if you need Hibernate ORM bytecode enhancement to reproduce your issue. 20 | */ 21 | @RunWith(BytecodeEnhancerRunner.class) // This runner enables bytecode enhancement for your test. 22 | public class YourBytecodeEnhancedIT extends BaseCoreFunctionalTestCase { 23 | 24 | @Override 25 | public Class[] getAnnotatedClasses() { 26 | return new Class[] { YourAnnotatedEntity.class }; 27 | } 28 | 29 | @Test 30 | public void testYourBug() { 31 | try ( Session s = openSession() ) { 32 | YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" ); 33 | YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" ); 34 | 35 | Transaction tx = s.beginTransaction(); 36 | s.persist( yourEntity1 ); 37 | s.persist( yourEntity2 ); 38 | tx.commit(); 39 | } 40 | 41 | try ( Session session = openSession() ) { 42 | SearchSession searchSession = Search.session( session ); 43 | 44 | List hits = searchSession.search( YourAnnotatedEntity.class ) 45 | .where( f -> f.match().field( "name" ).matching( "smith" ) ) 46 | .fetchHits( 20 ); 47 | 48 | assertThat( hits ) 49 | .hasSize( 1 ) 50 | .element( 0 ).extracting( YourAnnotatedEntity::getId ) 51 | .isEqualTo( 1L ); 52 | } 53 | } 54 | 55 | @Test 56 | public void testBytecodeEnhancement() { 57 | assertThat( YourAnnotatedEntity.class.getDeclaredMethods() ) 58 | .extracting( Method::getName ) 59 | .anyMatch( name -> name.startsWith( "$$_hibernate_" ) ); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/src/test/java/org/hibernate/search/bugs/YourIT.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.search.bugs; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.List; 6 | 7 | import org.hibernate.Session; 8 | import org.hibernate.Transaction; 9 | import org.hibernate.search.mapper.orm.Search; 10 | import org.hibernate.search.mapper.orm.session.SearchSession; 11 | 12 | import org.junit.jupiter.api.Test; 13 | 14 | public class YourIT extends SearchTestBase { 15 | 16 | @Override 17 | public Class[] getAnnotatedClasses() { 18 | return new Class[] { YourAnnotatedEntity.class }; 19 | } 20 | 21 | @Test 22 | public void testYourBug() { 23 | try ( Session s = getSessionFactory().openSession() ) { 24 | YourAnnotatedEntity yourEntity1 = new YourAnnotatedEntity( 1L, "Jane Smith" ); 25 | YourAnnotatedEntity yourEntity2 = new YourAnnotatedEntity( 2L, "John Doe" ); 26 | 27 | Transaction tx = s.beginTransaction(); 28 | s.persist( yourEntity1 ); 29 | s.persist( yourEntity2 ); 30 | tx.commit(); 31 | } 32 | 33 | try ( Session session = getSessionFactory().openSession() ) { 34 | SearchSession searchSession = Search.session( session ); 35 | 36 | List hits = searchSession.search( YourAnnotatedEntity.class ) 37 | .where( f -> f.match().field( "name" ).matching( "smith" ) ) 38 | .fetchHits( 20 ); 39 | 40 | assertThat( hits ) 41 | .hasSize( 1 ) 42 | .element( 0 ).extracting( YourAnnotatedEntity::getId ) 43 | .isEqualTo( 1L ); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | Hibernate Search with Lucene test case template Persistence Unit 10 | org.hibernate.jpa.HibernatePersistenceProvider 11 | 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/src/test/resources/hibernate.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later. 5 | # See the lgpl.txt file in the root directory or . 6 | # 7 | 8 | ########################################################### 9 | # Hibernate ORM configuration 10 | ########################################################### 11 | 12 | hibernate.dialect org.hibernate.dialect.H2Dialect 13 | hibernate.connection.driver_class org.h2.Driver 14 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 15 | hibernate.connection.username sa 16 | hibernate.connection.password 17 | hibernate.connection.pool_size 5 18 | 19 | # Logs 20 | hibernate.show_sql false 21 | hibernate.format_sql true 22 | 23 | # For tests only 24 | hibernate.hbm2ddl.auto create-drop 25 | 26 | ########################################################### 27 | # Hibernate Search configuration 28 | ########################################################### 29 | 30 | hibernate.search.backend.directory.root target/test-indexes 31 | hibernate.search.backend.analysis.configurer org.hibernate.search.bugs.YourAnalysisConfigurer 32 | 33 | # For tests only 34 | hibernate.search.schema_management.strategy drop-and-create-and-drop 35 | hibernate.search.indexing.plan.synchronization.strategy sync 36 | -------------------------------------------------------------------------------- /search/hibernate-search-7/orm-lucene/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /search/hibernate-search-elasticsearch/README.md: -------------------------------------------------------------------------------- 1 | # Content has moved 2 | 3 | Refer instead: 4 | 5 | * to [search/hibernate-search-6/orm-elasticsearch](../hibernate-search-6/orm-elasticsearch) for Hibernate Search 6 in Hibernate ORM backed by Elasticsearch (any version). 6 | * to [search/hibernate-search-5/elasticsearch-2](../hibernate-search-5/elasticsearch-2) for Hibernate Search 5 in Hibernate ORM backed by Elasticsearch 2. 7 | * to [search/hibernate-search-5/elasticsearch-5](../hibernate-search-5/elasticsearch-5) for Hibernate Search 5 in Hibernate ORM backed by Elasticsearch 5. 8 | -------------------------------------------------------------------------------- /search/hibernate-search-elasticsearch/hibernate-search-elasticsearch-2/README.md: -------------------------------------------------------------------------------- 1 | # Content has moved 2 | 3 | Refer instead: 4 | 5 | * to [search/hibernate-search-6/orm-elasticsearch](../../hibernate-search-6/orm-elasticsearch) for Hibernate Search 6 in Hibernate ORM backed by Elasticsearch (any version). 6 | * to [search/hibernate-search-5/elasticsearch-2](../../hibernate-search-5/elasticsearch-2) for Hibernate Search 5 in Hibernate ORM backed by Elasticsearch 2. 7 | * to [search/hibernate-search-5/elasticsearch-5](../../hibernate-search-5/elasticsearch-5) for Hibernate Search 5 in Hibernate ORM backed by Elasticsearch 5. 8 | 9 | -------------------------------------------------------------------------------- /search/hibernate-search-elasticsearch/hibernate-search-elasticsearch-5/README.md: -------------------------------------------------------------------------------- 1 | # Content has moved 2 | 3 | Refer instead: 4 | 5 | * to [search/hibernate-search-6/orm-elasticsearch](../../hibernate-search-6/orm-elasticsearch) for Hibernate Search 6 in Hibernate ORM backed by Elasticsearch (any version). 6 | * to [search/hibernate-search-5/elasticsearch-2](../../hibernate-search-5/elasticsearch-2) for Hibernate Search 5 in Hibernate ORM backed by Elasticsearch 2. 7 | * to [search/hibernate-search-5/elasticsearch-5](../../hibernate-search-5/elasticsearch-5) for Hibernate Search 5 in Hibernate ORM backed by Elasticsearch 5. 8 | 9 | -------------------------------------------------------------------------------- /search/hibernate-search-lucene/README.md: -------------------------------------------------------------------------------- 1 | # Content has moved 2 | 3 | Refer instead: 4 | 5 | * to [search/hibernate-search-6/orm-lucene](../hibernate-search-6/orm-lucene) for Hibernate Search 6 in Hibernate ORM backed by an embedded Lucene instance. 6 | * to [search/hibernate-search-5/lucene](../hibernate-search-5/lucene) for Hibernate Search 5 in Hibernate ORM backed by an embedded Lucene instance. 7 | -------------------------------------------------------------------------------- /validator/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Validator 2 | 3 | This directory contains test case templates, useful for reporting bugs against Hibernate Validator. 4 | 5 | Here's a running list of what's available: 6 | 7 | * [validator-6](validator-6): a test case template for Hibernate Validator 6 based on Jakarta Bean Validation 2.0 and `javax` namespace. 8 | * [validator-8](validator-8): a test case template for Hibernate Validator 8 based on Jakarta Bean Validation 3.0 and `jakarta` namespace. 9 | * [validator-9](validator-9): a test case template for Hibernate Validator 9 based on Jakarta Bean Validation 3.1. 10 | -------------------------------------------------------------------------------- /validator/validator-6/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Validator 2 | 3 | This repo contains a test case template useful for reporting bugs against Hibernate Validator. 4 | -------------------------------------------------------------------------------- /validator/validator-6/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-validator-6 7 | 1.0.0.Final 8 | Hibernate Validator 6 Test Case Template 9 | 10 | 11 | UTF-8 12 | UTF-8 13 | 6.2.5.Final 14 | 3.0.1-b12 15 | 2.24.3 16 | 5.11.4 17 | 18 | 19 | 20 | 21 | 22 | org.junit 23 | junit-bom 24 | ${version.junit-jupiter} 25 | pom 26 | import 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.hibernate.validator 34 | hibernate-validator 35 | ${version.org.hibernate.validator} 36 | 37 | 38 | org.hibernate.validator 39 | hibernate-validator-test-utils 40 | ${version.org.hibernate.validator} 41 | 42 | 43 | 44 | org.glassfish 45 | javax.el 46 | ${version.javax.el} 47 | 48 | 49 | 50 | org.junit.jupiter 51 | junit-jupiter 52 | test 53 | 54 | 55 | 56 | org.apache.logging.log4j 57 | log4j-core 58 | ${version.log4j} 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-compiler-plugin 68 | 3.14.0 69 | 70 | 1.8 71 | 1.8 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /validator/validator-6/src/test/java/org/hibernate/validator/bugs/YourAnnotatedBean.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.validator.bugs; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | public class YourAnnotatedBean { 6 | 7 | @NotNull 8 | private Long id; 9 | 10 | private String name; 11 | 12 | protected YourAnnotatedBean() { 13 | } 14 | 15 | public YourAnnotatedBean(Long id, String name) { 16 | this.id = id; 17 | this.name = name; 18 | } 19 | 20 | public Long getId() { 21 | return id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /validator/validator-6/src/test/java/org/hibernate/validator/bugs/YourTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.validator.bugs; 2 | 3 | 4 | import static org.junit.jupiter.api.Assertions.assertEquals; 5 | 6 | import java.util.Set; 7 | import javax.validation.ConstraintViolation; 8 | import javax.validation.Validation; 9 | import javax.validation.Validator; 10 | import javax.validation.ValidatorFactory; 11 | 12 | import org.hibernate.validator.testutil.TestForIssue; 13 | 14 | import org.junit.jupiter.api.BeforeAll; 15 | import org.junit.jupiter.api.Test; 16 | 17 | class YourTestCase { 18 | 19 | private static Validator validator; 20 | 21 | @BeforeAll 22 | public static void setUp() { 23 | ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); 24 | validator = factory.getValidator(); 25 | } 26 | 27 | @Test 28 | @TestForIssue(jiraKey = "HV-NNNNN") // Please fill in the JIRA key of your issue 29 | void testYourBug() { 30 | YourAnnotatedBean yourEntity1 = new YourAnnotatedBean( null, "example" ); 31 | 32 | Set> constraintViolations = validator.validate( yourEntity1 ); 33 | assertEquals( 1, constraintViolations.size() ); 34 | assertEquals( 35 | "must not be null", 36 | constraintViolations.iterator().next().getMessage() 37 | ); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /validator/validator-6/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /validator/validator-8/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Validator 2 | 3 | This repo contains a test case template useful for reporting bugs against Hibernate Validator. 4 | -------------------------------------------------------------------------------- /validator/validator-8/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-validator-8 7 | 1.0.0.Final 8 | Hibernate Validator 8 Test Case Template 9 | 10 | 11 | UTF-8 12 | UTF-8 13 | 8.0.2.Final 14 | 5.0.0 15 | 2.24.3 16 | 5.11.4 17 | 18 | 19 | 20 | 21 | 22 | org.junit 23 | junit-bom 24 | ${version.junit-jupiter} 25 | pom 26 | import 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.hibernate.validator 34 | hibernate-validator 35 | ${version.org.hibernate.validator} 36 | 37 | 38 | org.hibernate.validator 39 | hibernate-validator-test-utils 40 | ${version.org.hibernate.validator} 41 | 42 | 43 | 44 | org.glassfish.expressly 45 | expressly 46 | ${version.org.glassfish.expressly} 47 | 48 | 49 | 50 | org.junit.jupiter 51 | junit-jupiter 52 | test 53 | 54 | 55 | 56 | org.apache.logging.log4j 57 | log4j-core 58 | ${version.log4j} 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-compiler-plugin 68 | 3.14.0 69 | 70 | 11 71 | 11 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /validator/validator-8/src/test/java/org/hibernate/validator/bugs/YourAnnotatedBean.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.validator.bugs; 2 | 3 | import jakarta.validation.constraints.NotNull; 4 | 5 | public class YourAnnotatedBean { 6 | 7 | @NotNull 8 | private Long id; 9 | 10 | private String name; 11 | 12 | protected YourAnnotatedBean() { 13 | } 14 | 15 | public YourAnnotatedBean(Long id, String name) { 16 | this.id = id; 17 | this.name = name; 18 | } 19 | 20 | public Long getId() { 21 | return id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /validator/validator-8/src/test/java/org/hibernate/validator/bugs/YourTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.validator.bugs; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import java.util.Set; 6 | 7 | import org.hibernate.validator.testutil.TestForIssue; 8 | 9 | import org.junit.jupiter.api.BeforeAll; 10 | import org.junit.jupiter.api.Test; 11 | 12 | import jakarta.validation.ConstraintViolation; 13 | import jakarta.validation.Validation; 14 | import jakarta.validation.Validator; 15 | import jakarta.validation.ValidatorFactory; 16 | 17 | class YourTestCase { 18 | 19 | private static Validator validator; 20 | 21 | @BeforeAll 22 | public static void setUp() { 23 | ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); 24 | validator = factory.getValidator(); 25 | } 26 | 27 | @Test 28 | @TestForIssue(jiraKey = "HV-NNNNN") // Please fill in the JIRA key of your issue 29 | void testYourBug() { 30 | YourAnnotatedBean yourEntity1 = new YourAnnotatedBean( null, "example" ); 31 | 32 | Set> constraintViolations = validator.validate( yourEntity1 ); 33 | assertEquals( 1, constraintViolations.size() ); 34 | assertEquals( 35 | "must not be null", 36 | constraintViolations.iterator().next().getMessage() 37 | ); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /validator/validator-8/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger -------------------------------------------------------------------------------- /validator/validator-9/README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Test Case Templates: Hibernate Validator 2 | 3 | This repo contains a test case template useful for reporting bugs against Hibernate Validator. 4 | -------------------------------------------------------------------------------- /validator/validator-9/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.hibernate.testcasetemplate 6 | test-case-template-hibernate-validator-9 7 | 1.0.0.Final 8 | Hibernate Validator 9 Test Case Template 9 | 10 | 11 | UTF-8 12 | UTF-8 13 | 9.0.0.Final 14 | 6.0.0 15 | 2.24.3 16 | 3.27.3 17 | 5.11.4 18 | 19 | 20 | 21 | 22 | 23 | org.junit 24 | junit-bom 25 | ${version.junit-jupiter} 26 | pom 27 | import 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.hibernate.validator 35 | hibernate-validator 36 | ${version.org.hibernate.validator} 37 | 38 | 39 | org.hibernate.validator 40 | hibernate-validator-test-utils 41 | ${version.org.hibernate.validator} 42 | 43 | 44 | 45 | org.glassfish.expressly 46 | expressly 47 | ${version.org.glassfish.expressly} 48 | 49 | 50 | 51 | org.junit.jupiter 52 | junit-jupiter 53 | test 54 | 55 | 56 | 57 | org.assertj 58 | assertj-core 59 | ${version.assertj-core} 60 | test 61 | 62 | 63 | 64 | org.apache.logging.log4j 65 | log4j-core 66 | ${version.log4j} 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | org.apache.maven.plugins 75 | maven-compiler-plugin 76 | 3.14.0 77 | 78 | 17 79 | 17 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /validator/validator-9/src/test/java/org/hibernate/validator/bugs/YourAnnotatedBean.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.validator.bugs; 2 | 3 | import jakarta.validation.constraints.NotNull; 4 | 5 | public class YourAnnotatedBean { 6 | 7 | @NotNull 8 | private Long id; 9 | 10 | private String name; 11 | 12 | protected YourAnnotatedBean() { 13 | } 14 | 15 | public YourAnnotatedBean(Long id, String name) { 16 | this.id = id; 17 | this.name = name; 18 | } 19 | 20 | public Long getId() { 21 | return id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /validator/validator-9/src/test/java/org/hibernate/validator/bugs/YourTestCase.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.validator.bugs; 2 | 3 | import static org.hibernate.validator.testutil.ConstraintViolationAssert.assertThat; 4 | import static org.hibernate.validator.testutil.ConstraintViolationAssert.pathWith; 5 | import static org.hibernate.validator.testutil.ConstraintViolationAssert.violationOf; 6 | 7 | import java.util.Set; 8 | 9 | import org.hibernate.validator.testutil.TestForIssue; 10 | 11 | import org.junit.jupiter.api.BeforeAll; 12 | import org.junit.jupiter.api.Test; 13 | 14 | import jakarta.validation.ConstraintViolation; 15 | import jakarta.validation.Validation; 16 | import jakarta.validation.Validator; 17 | import jakarta.validation.ValidatorFactory; 18 | import jakarta.validation.constraints.NotNull; 19 | 20 | class YourTestCase { 21 | 22 | private static Validator validator; 23 | 24 | @BeforeAll 25 | public static void setUp() { 26 | ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); 27 | validator = factory.getValidator(); 28 | } 29 | 30 | @Test 31 | @TestForIssue(jiraKey = "HV-NNNNN") // Please fill in the JIRA key of your issue 32 | void testYourBug() { 33 | YourAnnotatedBean yourEntity1 = new YourAnnotatedBean( null, "example" ); 34 | 35 | Set> constraintViolations = validator.validate( yourEntity1 ); 36 | assertThat( constraintViolations ) 37 | .containsOnlyViolations( violationOf( NotNull.class ) 38 | .withMessage( "must not be null" ) 39 | .withPropertyPath( pathWith().property( "id" ) ) ); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /validator/validator-9/src/test/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | # Set to debug or trace if log4j initialization is failing 2 | status = warn 3 | 4 | # Console appender configuration 5 | appender.console.type = Console 6 | appender.console.name = consoleLogger 7 | appender.console.layout.type = PatternLayout 8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | # Root logger level 11 | rootLogger.level = info 12 | 13 | # Root logger referring to console appender 14 | rootLogger.appenderRef.stdout.ref = consoleLogger --------------------------------------------------------------------------------