Skip to content

Commit 099fe27

Browse files
committed
HBX-3241: Add an Ant integration test for a native configuration and a added hbm.xml file
- Move the existing example for native configuration in subfolder 'default' - Rename 'ExamplesTestIT#testConfiguration()' to 'ExamplesTestIT#testConfigurationDefault()' - Adapt 'ExamplesTestIT#testConfigurationDefault()' to the changes above - Add a new example showing hbm2java based on a hbm.xml file - Add an integration test for the above example Signed-off-by: Koen Aers <koen.aers@gmail.com>
1 parent e4870d1 commit 099fe27

File tree

6 files changed

+108
-13
lines changed

6 files changed

+108
-13
lines changed
File renamed without changes.

ant/docs/examples/configuration/build.xml renamed to ant/docs/examples/configuration/default/build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
<project name="configuration" default="reveng">
1717

1818
<!-- Include the 'hibernatetool' task definition from the file '../common/included.xml' -->
19-
<include file="../common/included.xml"/>
19+
<include file="../../common/included.xml"/>
2020

2121
<target name="reveng" depends="common.clean">
2222
<hibernatetool destdir="generated">
2323
<!-- Native configuration reading properties from '../common/hibernate.properties' -->
24-
<configuration propertyfile="../common/hibernate.properties"/>
24+
<configuration propertyfile="../../common/hibernate.properties"/>
2525
<!-- Transform the 'hibernate.properties' file in 'hibernate.cfg.xml' -->
2626
<hbm2cfgxml/>
2727
</hibernatetool>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
~ Copyright 2004 - 2025 Red Hat, 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+
<project name="configuration" default="reveng">
17+
18+
<!-- Include the 'hibernatetool' task definition from the file '../common/included.xml' -->
19+
<include file="../../common/included.xml"/>
20+
21+
<target name="reveng" depends="common.clean">
22+
<hibernatetool destdir="generated">
23+
<!-- Native configuration reading properties from '../common/hibernate.properties' -->
24+
<configuration propertyfile="hibernate.properties">
25+
<fileset file="simple.hbm.xml"/>
26+
</configuration>
27+
<hbm2java/>
28+
</hibernatetool>
29+
</target>
30+
31+
</project>
32+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
############################################################################
2+
# Hibernate Tools, Tooling for your Hibernate Projects #
3+
# #
4+
# Copyright 2004-2025 Red Hat, Inc. #
5+
# #
6+
# Licensed under the Apache License, Version 2.0 (the "License"); #
7+
# you may not use this file except in compliance with the License. #
8+
# You may obtain a copy of the License at #
9+
# #
10+
# http://www.apache.org/licenses/LICENSE-2.0 #
11+
# #
12+
# Unless required by applicable law or agreed to in writing, software #
13+
# distributed under the License is distributed on an "AS IS" basis, #
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15+
# See the License for the specific language governing permissions and #
16+
# limitations under the License. #
17+
############################################################################
18+
hibernate.connection.url=jdbc:h2:mem:test
19+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2004 - 2025 Red Hat, Inc.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" basis,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<!DOCTYPE hibernate-mapping PUBLIC
18+
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
19+
"https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
20+
<hibernate-mapping>
21+
22+
<class name="Foo">
23+
<id name="id" type="long">
24+
<generator class="assigned"/>
25+
</id>
26+
<property name="name" type="string"/>
27+
</class>
28+
29+
</hibernate-mapping>

ant/src/it/java/org/hibernate/tool/ant/ExamplesTestIT.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.sql.Connection;
1515
import java.sql.DriverManager;
1616
import java.sql.Statement;
17+
import java.util.Objects;
1718

1819
import static org.junit.jupiter.api.Assertions.*;
1920
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -35,7 +36,7 @@ public static void beforeAll() throws Exception {
3536
}
3637

3738
@Test
38-
public void test5MinuteTutorial() throws Exception {
39+
public void test5MinuteTutorial() {
3940
File buildFile = new File(baseFolder, "5-minute-tutorial/build.xml");
4041
Project project = createProject(buildFile);
4142
assertNotNull(project);
@@ -63,7 +64,7 @@ public void testCfgXml() throws Exception {
6364
}
6465

6566
@Test
66-
public void testClasspath() throws Exception {
67+
public void testClasspath() {
6768
PrintStream savedOut = System.out;
6869
try {
6970
File buildFile = new File(baseFolder, "classpath/build.xml");
@@ -80,18 +81,29 @@ public void testClasspath() throws Exception {
8081
}
8182

8283
@Test
83-
public void testConfiguration() throws Exception {
84-
File buildFile = new File(baseFolder, "configuration/build.xml");
84+
public void testConfigurationDefault() {
85+
File buildFile = new File(baseFolder, "configuration/default/build.xml");
8586
Project project = createProject(buildFile);
8687
assertNotNull(project);
87-
File cfgXmlFile = new File(baseFolder, "configuration/generated/hibernate.cfg.xml");
88+
File cfgXmlFile = new File(baseFolder, "configuration/default/generated/hibernate.cfg.xml");
8889
assertFalse(cfgXmlFile.exists());
8990
project.executeTarget("reveng");
9091
assertTrue(cfgXmlFile.exists());
9192
}
9293

9394
@Test
94-
public void testJpa() throws Exception {
95+
public void testConfigurationFileset() {
96+
File buildFile = new File(baseFolder, "configuration/fileset/build.xml");
97+
Project project = createProject(buildFile);
98+
assertNotNull(project);
99+
File cfgXmlFile = new File(baseFolder, "configuration/fileset/generated/Foo.java");
100+
assertFalse(cfgXmlFile.exists());
101+
project.executeTarget("reveng");
102+
assertTrue(cfgXmlFile.exists());
103+
}
104+
105+
@Test
106+
public void testJpa() {
95107
File buildFile = new File(baseFolder, "jpa/build.xml");
96108
Project project = createProject(buildFile);
97109
assertNotNull(project);
@@ -102,7 +114,7 @@ public void testJpa() throws Exception {
102114
}
103115

104116
@Test
105-
public void testNative() throws Exception {
117+
public void testNative() {
106118
File buildFile = new File(baseFolder, "native/build.xml");
107119
Project project = createProject(buildFile);
108120
assertNotNull(project);
@@ -113,7 +125,7 @@ public void testNative() throws Exception {
113125
}
114126

115127
@Test
116-
public void testProperties() throws Exception {
128+
public void testProperties() {
117129
PrintStream savedOut = System.out;
118130
try {
119131
File buildFile = new File(baseFolder, "properties/build.xml");
@@ -146,7 +158,7 @@ public void testTemplatePath() throws Exception {
146158
assertTrue(personFileContents.contains("// This is just an example of a custom template"));
147159
}
148160

149-
private Project createProject(File buildXmlFile) throws Exception {
161+
private Project createProject(File buildXmlFile) {
150162
Project result = new Project();
151163
ProjectHelper projectHelper = ProjectHelper.getProjectHelper();
152164
result.addReference(MagicNames.REFID_PROJECT_HELPER, projectHelper);
@@ -166,7 +178,7 @@ private DefaultLogger createConsoleLogger() {
166178

167179
private static void editIncludedXml() throws Exception {
168180
File xmlFile = new File(baseFolder, "common/included.xml");
169-
StringBuffer xmlFileContents = new StringBuffer(
181+
StringBuilder xmlFileContents = new StringBuilder(
170182
new String(Files.readAllBytes(xmlFile.toPath())));
171183
int start = xmlFileContents.indexOf("<ivy:cachepath");
172184
int end = xmlFileContents.indexOf("<ivy:cachepath", start + 1);
@@ -207,7 +219,10 @@ private static String constructJdbcConnectionString() {
207219
}
208220

209221
private static File determineBaseFolder() throws Exception {
210-
return new File(ExamplesTestIT.class.getClassLoader().getResource("common/included.xml").toURI())
222+
return new File(
223+
Objects.requireNonNull(
224+
ExamplesTestIT.class.getClassLoader().getResource(
225+
"common/included.xml")).toURI())
211226
.getParentFile().getParentFile();
212227
}
213228

0 commit comments

Comments
 (0)