Skip to content

Commit 2e6e428

Browse files
marko-bekhtayrodiere
authored andcommitted
Add ORM (+Envers) 7 templates
1 parent 0080d72 commit 2e6e428

File tree

18 files changed

+631
-8
lines changed

18 files changed

+631
-8
lines changed

envers/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ This repo contains test case templates, useful for reporting bugs against Hibern
66
that is required is your entities, logic, and any necessary settings. Since we nearly always include a regression
77
test with bug fixes, providing your reproducer using this class simplifies that process. We can then directly add
88
it, without having to mold it into our existing framework. You're also welcomed to fork hibernate-orm itself, add
9-
your test case direectly to the Enver's module test cases (using the template class), then submit it as a pull
10-
request.
9+
your test case directly to the Enver's module test cases (using the template class), then submit it as a pull
10+
request.

envers/envers-7/pom.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.hibernate.testcasetemplate</groupId>
6+
<artifactId>test-case-template-hibernate-envers-7</artifactId>
7+
<version>1.0.0.Final</version>
8+
<name>Hibernate Envers 7 Test Case Template</name>
9+
10+
<properties>
11+
<version.com.h2database>2.3.232</version.com.h2database>
12+
<version.junit>4.13.2</version.junit>
13+
<version.org.hibernate.orm>7.0.0.Final</version.org.hibernate.orm>
14+
</properties>
15+
16+
<dependencyManagement>
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.hibernate.orm</groupId>
20+
<artifactId>hibernate-platform</artifactId>
21+
<version>${version.org.hibernate.orm}</version>
22+
<type>pom</type>
23+
<scope>import</scope>
24+
</dependency>
25+
</dependencies>
26+
</dependencyManagement>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.hibernate.orm</groupId>
31+
<artifactId>hibernate-envers</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.h2database</groupId>
35+
<artifactId>h2</artifactId>
36+
<version>${version.com.h2database}</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.hibernate.orm</groupId>
41+
<artifactId>hibernate-testing</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>junit</groupId>
46+
<artifactId>junit</artifactId>
47+
<version>${version.junit}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
</dependencies>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-compiler-plugin</artifactId>
57+
<version>3.14.0</version>
58+
<configuration>
59+
<release>17</release>
60+
</configuration>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_2.xsd"
4+
version="3.2">
5+
6+
<persistence-unit name="templatePU" transaction-type="RESOURCE_LOCAL">
7+
8+
<description>Hibernate test case template Persistence Unit</description>
9+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
10+
11+
<exclude-unlisted-classes>false</exclude-unlisted-classes>
12+
13+
<properties>
14+
<property name="hibernate.archive.autodetection" value="class, hbm"/>
15+
16+
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
17+
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
18+
<property name="hibernate.connection.url" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1"/>
19+
<property name="hibernate.connection.username" value="sa"/>
20+
21+
<property name="hibernate.connection.pool_size" value="5"/>
22+
23+
<property name="hibernate.show_sql" value="true"/>
24+
<property name="hibernate.format_sql" value="true"/>
25+
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
26+
27+
<property name="hibernate.max_fetch_depth" value="5"/>
28+
29+
<property name="hibernate.cache.region_prefix" value="hibernate.test"/>
30+
<property name="hibernate.cache.region.factory_class"
31+
value="org.hibernate.testing.cache.CachingRegionFactory"/>
32+
33+
<!--NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle-->
34+
<property name="hibernate.jdbc.batch_versioned_data" value="true"/>
35+
36+
<property name="jakarta.persistence.validation.mode" value="NONE"/>
37+
<property name="hibernate.service.allow_crawling" value="false"/>
38+
<property name="hibernate.session.events.log" value="true"/>
39+
</properties>
40+
41+
</persistence-unit>
42+
</persistence>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
This repo contains test case templates, useful for reporting bugs against Hibernate ORM.
44

5-
Here's a running list of what's available (there are two versions of each test case template, one is for Hibernate ORM 5,
6-
one for Hibernate ORM 6):
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):
76

8-
* ORMUnitTestCase: By far, this one's the most helpful. ORM includes a built-in unit test framework that does much
7+
* `ORMUnitTestCase`: By far, this one's the most helpful. ORM includes a built-in unit test framework that does much
98
of the heavy lifting for you. All that's required is your entities, logic, and any necessary settings. Since we nearly
109
always include a regression test with bug fixes, providing your reproducer using this method simplifies the process. We
1110
can then directly commit it, without having to mold it in first. What's even better? Fork hibernate-orm itself,
1211
add your test case directly to a module's unit tests (using the template class), then submit it as a PR!
13-
* ORMStandaloneTestCase: This template is standalone and will look familiar. It simply uses a run-of-the-mill ORM setup.
14-
Although it's perfectly acceptable as a reproducer, lean towards ORMUnitTestCase whenever possible.
15-
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.
1615
**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/)**.

orm/hibernate-orm-7/pom.xml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.hibernate.testcasetemplate</groupId>
6+
<artifactId>test-case-template-hibernate-orm-7</artifactId>
7+
<version>1.0.0.Final</version>
8+
<name>Hibernate ORM 7 Test Case Template</name>
9+
10+
<properties>
11+
<version.com.h2database>2.3.232</version.com.h2database>
12+
<version.junit-jupiter>5.12.2</version.junit-jupiter>
13+
<version.org.hibernate.orm>7.0.0.Final</version.org.hibernate.orm>
14+
<version.org.assertj.assertj-core>3.27.3</version.org.assertj.assertj-core>
15+
</properties>
16+
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.hibernate.orm</groupId>
21+
<artifactId>hibernate-platform</artifactId>
22+
<version>${version.org.hibernate.orm}</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.junit</groupId>
28+
<artifactId>junit-bom</artifactId>
29+
<version>${version.junit-jupiter}</version>
30+
<type>pom</type>
31+
<scope>import</scope>
32+
</dependency>
33+
</dependencies>
34+
</dependencyManagement>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.hibernate.orm</groupId>
39+
<artifactId>hibernate-core</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.h2database</groupId>
43+
<artifactId>h2</artifactId>
44+
<version>${version.com.h2database}</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.hibernate.orm</groupId>
49+
<artifactId>hibernate-testing</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.junit.jupiter</groupId>
54+
<artifactId>junit-jupiter</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.junit.platform</groupId>
59+
<artifactId>junit-platform-launcher</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.junit.jupiter</groupId>
64+
<artifactId>junit-jupiter-engine</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.assertj</groupId>
69+
<artifactId>assertj-core</artifactId>
70+
<version>${version.org.assertj.assertj-core}</version>
71+
<scope>test</scope>
72+
</dependency>
73+
</dependencies>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>3.14.0</version>
81+
<configuration>
82+
<release>17</release>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.hibernate.orm</groupId>
87+
<artifactId>hibernate-maven-plugin</artifactId>
88+
<version>${version.org.hibernate.orm}</version>
89+
<executions>
90+
<execution>
91+
<configuration>
92+
<base>${project.build.testOutputDirectory}</base>
93+
<dir>${project.build.testOutputDirectory}</dir>
94+
<enableAssociationManagement>false</enableAssociationManagement>
95+
<enableDirtyTracking>false</enableDirtyTracking>
96+
<enableExtendedEnhancement>false</enableExtendedEnhancement>
97+
<enableLazyInitialization>false</enableLazyInitialization>
98+
</configuration>
99+
<phase>test-compile</phase>
100+
<goals>
101+
<goal>enhance</goal>
102+
</goals>
103+
</execution>
104+
</executions>
105+
</plugin>
106+
</plugins>
107+
</build>
108+
</project>

0 commit comments

Comments
 (0)