Skip to content

Commit e1db9e6

Browse files
committed
HBX-3068: Refactor the Ant integration tests to factor out common code
- Create a new private static variable 'hibernateToolTaskXml' in the test classes with the specifics for each test - Pull up the private static variable 'buildXmlFileContents' and provide a placeholder for the Hibernate Tool task xml - Create a protected method 'constructBuildXmlFileContents' that performs the substitution of the placeholder above - Create an abstract method 'hibernateToolTaskXml()' that is used in the substitution above and implement in all the subclasses Signed-off-by: Koen Aers <[email protected]>
1 parent a9bd44a commit e1db9e6

File tree

6 files changed

+76
-83
lines changed

6 files changed

+76
-83
lines changed

ant/src/it/java/org/hibernate/tool/ant/hbm2java/JpaDefaultTestIT.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ public void testJpaDefault() throws Exception {
4242
runAntBuild();
4343
verifyResult();
4444
}
45-
45+
46+
protected String hibernateToolTaskXml() {
47+
return hibernateToolTaskXml;
48+
}
49+
4650
private void createBuildXmlFile() throws Exception {
4751
buildXmlFile = new File(getProjectDir(), "build.xml");
4852
assertFalse(buildXmlFile.exists());
49-
Files.writeString(buildXmlFile.toPath(), buildXmlFileContents);
53+
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
5054
}
5155

5256
private void createDatabase() throws Exception {
@@ -108,18 +112,10 @@ private String constructJdbcConnectionString() {
108112
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
109113
}
110114

111-
private static final String buildXmlFileContents =
112-
113-
"<project name='tutorial' default='reveng'> \n" +
114-
" <taskdef \n" +
115-
" name='hibernatetool' \n" +
116-
" classname='org.hibernate.tool.ant.HibernateToolTask'/> \n" +
117-
" <target name='reveng'> \n" +
118-
" <hibernatetool destdir='generated'> \n" +
119-
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
120-
" <hbm2java/> \n" +
121-
" </hibernatetool> \n" +
122-
" </target> \n" +
123-
"</project> \n" ;
115+
private static final String hibernateToolTaskXml =
116+
" <hibernatetool destdir='generated'> \n" +
117+
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
118+
" <hbm2java/> \n" +
119+
" </hibernatetool> \n" ;
124120

125121
}

ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoAnnotationsTestIT.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ public void testNoAnnotations() throws Exception {
4242
runAntBuild();
4343
verifyResult();
4444
}
45-
46-
private void createBuildXmlFile() throws Exception {
45+
46+
protected String hibernateToolTaskXml() {
47+
return hibernateToolTaskXml;
48+
}
49+
50+
private void createBuildXmlFile() throws Exception {
4751
buildXmlFile = new File(getProjectDir(), "build.xml");
4852
assertFalse(buildXmlFile.exists());
49-
Files.writeString(buildXmlFile.toPath(), buildXmlFileContents);
53+
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
5054
}
5155

5256
private void createDatabase() throws Exception {
@@ -108,18 +112,9 @@ private String constructJdbcConnectionString() {
108112
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
109113
}
110114

111-
private static final String buildXmlFileContents =
112-
113-
"<project name='tutorial' default='reveng'> \n" +
114-
" <taskdef \n" +
115-
" name='hibernatetool' \n" +
116-
" classname='org.hibernate.tool.ant.HibernateToolTask'/> \n" +
117-
" <target name='reveng'> \n" +
118-
" <hibernatetool destdir='generated'> \n" +
119-
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
120-
" <hbm2java ejb3='false'/> \n" +
121-
" </hibernatetool> \n" +
122-
" </target> \n" +
123-
"</project> \n" ;
124-
115+
private static final String hibernateToolTaskXml =
116+
" <hibernatetool destdir='generated'> \n" +
117+
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
118+
" <hbm2java ejb3='false'/> \n" +
119+
" </hibernatetool> \n" ;
125120
}

ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoGenericsTestIT.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ public void testUseGenerics() throws Exception {
4242
runAntBuild();
4343
verifyResult();
4444
}
45-
46-
private void createBuildXmlFile() throws Exception {
45+
46+
protected String hibernateToolTaskXml() {
47+
return hibernateToolTaskXml;
48+
}
49+
50+
private void createBuildXmlFile() throws Exception {
4751
buildXmlFile = new File(getProjectDir(), "build.xml");
4852
assertFalse(buildXmlFile.exists());
49-
Files.writeString(buildXmlFile.toPath(), buildXmlFileContents);
53+
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
5054
}
5155

5256
private void createDatabase() throws Exception {
@@ -118,18 +122,10 @@ private String constructJdbcConnectionString() {
118122
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
119123
}
120124

121-
private static final String buildXmlFileContents =
122-
123-
"<project name='tutorial' default='reveng'> \n" +
124-
" <taskdef \n" +
125-
" name='hibernatetool' \n" +
126-
" classname='org.hibernate.tool.ant.HibernateToolTask'/> \n" +
127-
" <target name='reveng'> \n" +
128-
" <hibernatetool destdir='generated'> \n" +
129-
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
130-
" <hbm2java jdk5='false'/> \n" +
131-
" </hibernatetool> \n" +
132-
" </target> \n" +
133-
"</project> \n" ;
125+
private static final String hibernateToolTaskXml =
126+
" <hibernatetool destdir='generated'> \n" +
127+
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
128+
" <hbm2java jdk5='false'/> \n" +
129+
" </hibernatetool> \n" ;
134130

135131
}

ant/src/it/java/org/hibernate/tool/ant/hbm2java/UseGenericsTestIT.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ public void testUseGenerics() throws Exception {
4242
runAntBuild();
4343
verifyResult();
4444
}
45-
46-
private void createBuildXmlFile() throws Exception {
45+
46+
protected String hibernateToolTaskXml() {
47+
return hibernateToolTaskXml;
48+
}
49+
50+
private void createBuildXmlFile() throws Exception {
4751
buildXmlFile = new File(getProjectDir(), "build.xml");
4852
assertFalse(buildXmlFile.exists());
49-
Files.writeString(buildXmlFile.toPath(), buildXmlFileContents);
53+
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
5054
}
5155

5256
private void createDatabase() throws Exception {
@@ -118,18 +122,9 @@ private String constructJdbcConnectionString() {
118122
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
119123
}
120124

121-
private static final String buildXmlFileContents =
122-
123-
"<project name='tutorial' default='reveng'> \n" +
124-
" <taskdef \n" +
125-
" name='hibernatetool' \n" +
126-
" classname='org.hibernate.tool.ant.HibernateToolTask'/> \n" +
127-
" <target name='reveng'> \n" +
128-
" <hibernatetool destdir='generated'> \n" +
129-
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
130-
" <hbm2java/> \n" +
131-
" </hibernatetool> \n" +
132-
" </target> \n" +
133-
"</project> \n" ;
134-
125+
private static final String hibernateToolTaskXml =
126+
" <hibernatetool destdir='generated'> \n" +
127+
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
128+
" <hbm2java/> \n" +
129+
" </hibernatetool> \n" ;
135130
}

ant/src/it/java/org/hibernate/tool/ant/tutorial/TutorialTestIT.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ public void testTutorial() throws Exception {
4444
runAntBuild();
4545
verifyResult();
4646
}
47-
48-
private void createBuildXmlFile() throws Exception {
47+
48+
protected String hibernateToolTaskXml() {
49+
return hibernateToolTaskXml;
50+
}
51+
52+
private void createBuildXmlFile() throws Exception {
4953
buildXmlFile = new File(getProjectDir(), "build.xml");
5054
assertFalse(buildXmlFile.exists());
51-
Files.writeString(buildXmlFile.toPath(), buildXmlFileContents);
55+
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
5256
}
5357

5458
private void createDatabase() throws Exception {
@@ -106,18 +110,9 @@ private String constructJdbcConnectionString() {
106110
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
107111
}
108112

109-
private static final String buildXmlFileContents =
110-
111-
"<project name='tutorial' default='reveng'> \n" +
112-
" <taskdef \n" +
113-
" name='hibernatetool' \n" +
114-
" classname='org.hibernate.tool.ant.HibernateToolTask'/> \n" +
115-
" <target name='reveng'> \n" +
116-
" <hibernatetool destdir='generated'> \n" +
117-
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
118-
" <hbm2java/> \n" +
119-
" </hibernatetool> \n" +
120-
" </target> \n" +
121-
"</project> \n" ;
122-
113+
private static final String hibernateToolTaskXml =
114+
" <hibernatetool destdir='generated'> \n" +
115+
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
116+
" <hbm2java/> \n" +
117+
" </hibernatetool> \n" ;
123118
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.io.File;
66

7-
public class TestTemplate {
7+
public abstract class TestTemplate {
88

99
@TempDir
1010
private File projectDir;
@@ -13,4 +13,20 @@ protected File getProjectDir() {
1313
return projectDir;
1414
}
1515

16+
protected abstract String hibernateToolTaskXml();
17+
18+
protected String constructBuildXmlFileContents() {
19+
return buildXmlFileContents.replace("@hibernateToolTaskXml@", hibernateToolTaskXml());
20+
}
21+
22+
private static final String buildXmlFileContents =
23+
"<project name='tutorial' default='reveng'> \n" +
24+
" <taskdef \n" +
25+
" name='hibernatetool' \n" +
26+
" classname='org.hibernate.tool.ant.HibernateToolTask'/> \n" +
27+
" <target name='reveng'> \n" +
28+
"@hibernateToolTaskXml@" +
29+
" </target> \n" +
30+
"</project> \n" ;
31+
1632
}

0 commit comments

Comments
 (0)