From 6b9f2a6f7a0fc6260894f7d5f1a4bab3810f7235 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Thu, 31 Jul 2025 12:50:28 +0300 Subject: [PATCH] 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 --- .../tool/ant/hbm2java/JpaDefaultTestIT.java | 26 +++++++---------- .../ant/hbm2java/NoAnnotationsTestIT.java | 29 ++++++++----------- .../tool/ant/hbm2java/NoGenericsTestIT.java | 28 ++++++++---------- .../tool/ant/hbm2java/UseGenericsTestIT.java | 29 ++++++++----------- .../tool/ant/tutorial/TutorialTestIT.java | 29 ++++++++----------- .../hibernate/tool/it/ant/TestTemplate.java | 18 +++++++++++- 6 files changed, 76 insertions(+), 83 deletions(-) diff --git a/ant/src/it/java/org/hibernate/tool/ant/hbm2java/JpaDefaultTestIT.java b/ant/src/it/java/org/hibernate/tool/ant/hbm2java/JpaDefaultTestIT.java index 98625e2689..09f109034b 100644 --- a/ant/src/it/java/org/hibernate/tool/ant/hbm2java/JpaDefaultTestIT.java +++ b/ant/src/it/java/org/hibernate/tool/ant/hbm2java/JpaDefaultTestIT.java @@ -42,11 +42,15 @@ public void testJpaDefault() throws Exception { runAntBuild(); verifyResult(); } - + + protected String hibernateToolTaskXml() { + return hibernateToolTaskXml; + } + private void createBuildXmlFile() throws Exception { buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); - Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); + Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents()); } private void createDatabase() throws Exception { @@ -108,18 +112,10 @@ private String constructJdbcConnectionString() { return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } - private static final String buildXmlFileContents = - - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" ; + private static final String hibernateToolTaskXml = + " \n" + + " \n" + + " \n" + + " \n" ; } diff --git a/ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoAnnotationsTestIT.java b/ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoAnnotationsTestIT.java index dd641f9fbc..d0536b93d2 100644 --- a/ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoAnnotationsTestIT.java +++ b/ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoAnnotationsTestIT.java @@ -42,11 +42,15 @@ public void testNoAnnotations() throws Exception { runAntBuild(); verifyResult(); } - - private void createBuildXmlFile() throws Exception { + + protected String hibernateToolTaskXml() { + return hibernateToolTaskXml; + } + + private void createBuildXmlFile() throws Exception { buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); - Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); + Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents()); } private void createDatabase() throws Exception { @@ -108,18 +112,9 @@ private String constructJdbcConnectionString() { return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } - private static final String buildXmlFileContents = - - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" ; - + private static final String hibernateToolTaskXml = + " \n" + + " \n" + + " \n" + + " \n" ; } diff --git a/ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoGenericsTestIT.java b/ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoGenericsTestIT.java index c227e04aac..baf55e3704 100644 --- a/ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoGenericsTestIT.java +++ b/ant/src/it/java/org/hibernate/tool/ant/hbm2java/NoGenericsTestIT.java @@ -42,11 +42,15 @@ public void testUseGenerics() throws Exception { runAntBuild(); verifyResult(); } - - private void createBuildXmlFile() throws Exception { + + protected String hibernateToolTaskXml() { + return hibernateToolTaskXml; + } + + private void createBuildXmlFile() throws Exception { buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); - Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); + Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents()); } private void createDatabase() throws Exception { @@ -118,18 +122,10 @@ private String constructJdbcConnectionString() { return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } - private static final String buildXmlFileContents = - - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" ; + private static final String hibernateToolTaskXml = + " \n" + + " \n" + + " \n" + + " \n" ; } diff --git a/ant/src/it/java/org/hibernate/tool/ant/hbm2java/UseGenericsTestIT.java b/ant/src/it/java/org/hibernate/tool/ant/hbm2java/UseGenericsTestIT.java index 1f5ead9bc9..93cddd071c 100644 --- a/ant/src/it/java/org/hibernate/tool/ant/hbm2java/UseGenericsTestIT.java +++ b/ant/src/it/java/org/hibernate/tool/ant/hbm2java/UseGenericsTestIT.java @@ -42,11 +42,15 @@ public void testUseGenerics() throws Exception { runAntBuild(); verifyResult(); } - - private void createBuildXmlFile() throws Exception { + + protected String hibernateToolTaskXml() { + return hibernateToolTaskXml; + } + + private void createBuildXmlFile() throws Exception { buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); - Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); + Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents()); } private void createDatabase() throws Exception { @@ -118,18 +122,9 @@ private String constructJdbcConnectionString() { return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } - private static final String buildXmlFileContents = - - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" ; - + private static final String hibernateToolTaskXml = + " \n" + + " \n" + + " \n" + + " \n" ; } diff --git a/ant/src/it/java/org/hibernate/tool/ant/tutorial/TutorialTestIT.java b/ant/src/it/java/org/hibernate/tool/ant/tutorial/TutorialTestIT.java index 3b4a8e9e08..f616e148e5 100644 --- a/ant/src/it/java/org/hibernate/tool/ant/tutorial/TutorialTestIT.java +++ b/ant/src/it/java/org/hibernate/tool/ant/tutorial/TutorialTestIT.java @@ -44,11 +44,15 @@ public void testTutorial() throws Exception { runAntBuild(); verifyResult(); } - - private void createBuildXmlFile() throws Exception { + + protected String hibernateToolTaskXml() { + return hibernateToolTaskXml; + } + + private void createBuildXmlFile() throws Exception { buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); - Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); + Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents()); } private void createDatabase() throws Exception { @@ -106,18 +110,9 @@ private String constructJdbcConnectionString() { return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } - private static final String buildXmlFileContents = - - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" ; - + private static final String hibernateToolTaskXml = + " \n" + + " \n" + + " \n" + + " \n" ; } diff --git a/ant/src/it/java/org/hibernate/tool/it/ant/TestTemplate.java b/ant/src/it/java/org/hibernate/tool/it/ant/TestTemplate.java index 359941de3c..943e8d094c 100644 --- a/ant/src/it/java/org/hibernate/tool/it/ant/TestTemplate.java +++ b/ant/src/it/java/org/hibernate/tool/it/ant/TestTemplate.java @@ -4,7 +4,7 @@ import java.io.File; -public class TestTemplate { +public abstract class TestTemplate { @TempDir private File projectDir; @@ -13,4 +13,20 @@ protected File getProjectDir() { return projectDir; } + protected abstract String hibernateToolTaskXml(); + + protected String constructBuildXmlFileContents() { + return buildXmlFileContents.replace("@hibernateToolTaskXml@", hibernateToolTaskXml()); + } + + private static final String buildXmlFileContents = + " \n" + + " \n" + + " \n" + + "@hibernateToolTaskXml@" + + " \n" + + " \n" ; + }