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 d6f58eda18..98625e2689 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 @@ -3,6 +3,7 @@ import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; +import org.hibernate.tool.it.ant.TestTemplate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -17,10 +18,7 @@ import static org.junit.jupiter.api.Assertions.*; -public class JpaDefaultTestIT { - - @TempDir - private File projectDir; +public class JpaDefaultTestIT extends TestTemplate { private File buildXmlFile; private ByteArrayOutputStream output; @@ -30,9 +28,9 @@ public class JpaDefaultTestIT { @BeforeEach public void beforeEach() { output = new ByteArrayOutputStream(); - databaseFile = new File(projectDir, "database/test.mv.db"); + databaseFile = new File(getProjectDir(), "database/test.mv.db"); assertFalse(databaseFile.exists()); - personFile = new File(projectDir, "generated/Person.java"); + personFile = new File(getProjectDir(), "generated/Person.java"); assertFalse(personFile.exists()); } @@ -46,7 +44,7 @@ public void testJpaDefault() throws Exception { } private void createBuildXmlFile() throws Exception { - buildXmlFile = new File(projectDir, "build.xml"); + buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); } @@ -63,7 +61,7 @@ private void createDatabase() throws Exception { } private void createHibernatePropertiesFile() throws Exception { - File hibernatePropertiesFile = new File(projectDir, "hibernate.properties"); + File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties"); StringBuffer hibernatePropertiesFileContents = new StringBuffer(); hibernatePropertiesFileContents .append("hibernate.connection.driver_class=org.h2.Driver\n") @@ -78,14 +76,14 @@ private void createHibernatePropertiesFile() throws Exception { private void runAntBuild() { Project project = new Project(); - project.setBaseDir(projectDir); + project.setBaseDir(getProjectDir()); project.addBuildListener(getConsoleLogger()); ProjectHelper.getProjectHelper().parse(project, buildXmlFile); project.executeTarget(project.getDefaultTarget()); } private void verifyResult() throws Exception { - File generatedOutputFolder = new File(projectDir, "generated"); + File generatedOutputFolder = new File(getProjectDir(), "generated"); assertTrue(generatedOutputFolder.exists()); assertTrue(generatedOutputFolder.isDirectory()); assertEquals(1, generatedOutputFolder.list().length); @@ -107,7 +105,7 @@ private DefaultLogger getConsoleLogger() { } private String constructJdbcConnectionString() { - return "jdbc:h2:" + projectDir.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; + return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } private static final String buildXmlFileContents = 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 e1cd5cbcb5..dd641f9fbc 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 @@ -3,6 +3,7 @@ import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; +import org.hibernate.tool.it.ant.TestTemplate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -17,10 +18,7 @@ import static org.junit.jupiter.api.Assertions.*; -public class NoAnnotationsTestIT { - - @TempDir - private File projectDir; +public class NoAnnotationsTestIT extends TestTemplate { private File buildXmlFile; private ByteArrayOutputStream output; @@ -30,9 +28,9 @@ public class NoAnnotationsTestIT { @BeforeEach public void beforeEach() { output = new ByteArrayOutputStream(); - databaseFile = new File(projectDir, "database/test.mv.db"); + databaseFile = new File(getProjectDir(), "database/test.mv.db"); assertFalse(databaseFile.exists()); - personFile = new File(projectDir, "generated/Person.java"); + personFile = new File(getProjectDir(), "generated/Person.java"); assertFalse(personFile.exists()); } @@ -46,7 +44,7 @@ public void testNoAnnotations() throws Exception { } private void createBuildXmlFile() throws Exception { - buildXmlFile = new File(projectDir, "build.xml"); + buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); } @@ -63,7 +61,7 @@ private void createDatabase() throws Exception { } private void createHibernatePropertiesFile() throws Exception { - File hibernatePropertiesFile = new File(projectDir, "hibernate.properties"); + File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties"); StringBuffer hibernatePropertiesFileContents = new StringBuffer(); hibernatePropertiesFileContents .append("hibernate.connection.driver_class=org.h2.Driver\n") @@ -78,14 +76,14 @@ private void createHibernatePropertiesFile() throws Exception { private void runAntBuild() { Project project = new Project(); - project.setBaseDir(projectDir); + project.setBaseDir(getProjectDir()); project.addBuildListener(getConsoleLogger()); ProjectHelper.getProjectHelper().parse(project, buildXmlFile); project.executeTarget(project.getDefaultTarget()); } private void verifyResult() throws Exception { - File generatedOutputFolder = new File(projectDir, "generated"); + File generatedOutputFolder = new File(getProjectDir(), "generated"); assertTrue(generatedOutputFolder.exists()); assertTrue(generatedOutputFolder.isDirectory()); assertEquals(1, generatedOutputFolder.list().length); @@ -107,7 +105,7 @@ private DefaultLogger getConsoleLogger() { } private String constructJdbcConnectionString() { - return "jdbc:h2:" + projectDir.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; + return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } private static final String buildXmlFileContents = 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 c53faa107d..c227e04aac 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 @@ -3,6 +3,7 @@ import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; +import org.hibernate.tool.it.ant.TestTemplate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -17,10 +18,7 @@ import static org.junit.jupiter.api.Assertions.*; -public class NoGenericsTestIT { - - @TempDir - private File projectDir; +public class NoGenericsTestIT extends TestTemplate { private File buildXmlFile; private ByteArrayOutputStream output; @@ -30,9 +28,9 @@ public class NoGenericsTestIT { @BeforeEach public void beforeEach() { output = new ByteArrayOutputStream(); - databaseFile = new File(projectDir, "database/test.mv.db"); + databaseFile = new File(getProjectDir(), "database/test.mv.db"); assertFalse(databaseFile.exists()); - personFile = new File(projectDir, "generated/Person.java"); + personFile = new File(getProjectDir(), "generated/Person.java"); assertFalse(personFile.exists()); } @@ -46,7 +44,7 @@ public void testUseGenerics() throws Exception { } private void createBuildXmlFile() throws Exception { - buildXmlFile = new File(projectDir, "build.xml"); + buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); } @@ -67,7 +65,7 @@ private void createDatabase() throws Exception { } private void createHibernatePropertiesFile() throws Exception { - File hibernatePropertiesFile = new File(projectDir, "hibernate.properties"); + File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties"); StringBuffer hibernatePropertiesFileContents = new StringBuffer(); hibernatePropertiesFileContents .append("hibernate.connection.driver_class=org.h2.Driver\n") @@ -82,14 +80,14 @@ private void createHibernatePropertiesFile() throws Exception { private void runAntBuild() { Project project = new Project(); - project.setBaseDir(projectDir); + project.setBaseDir(getProjectDir()); project.addBuildListener(getConsoleLogger()); ProjectHelper.getProjectHelper().parse(project, buildXmlFile); project.executeTarget(project.getDefaultTarget()); } private void verifyResult() throws Exception { - File generatedOutputFolder = new File(projectDir, "generated"); + File generatedOutputFolder = new File(getProjectDir(), "generated"); assertTrue(generatedOutputFolder.exists()); assertTrue(generatedOutputFolder.isDirectory()); assertEquals(2, generatedOutputFolder.list().length); @@ -117,7 +115,7 @@ private DefaultLogger getConsoleLogger() { } private String constructJdbcConnectionString() { - return "jdbc:h2:" + projectDir.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; + return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } private static final String buildXmlFileContents = 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 5f9f317bac..1f5ead9bc9 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 @@ -3,6 +3,7 @@ import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; +import org.hibernate.tool.it.ant.TestTemplate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -17,10 +18,7 @@ import static org.junit.jupiter.api.Assertions.*; -public class UseGenericsTestIT { - - @TempDir - private File projectDir; +public class UseGenericsTestIT extends TestTemplate { private File buildXmlFile; private ByteArrayOutputStream output; @@ -30,9 +28,9 @@ public class UseGenericsTestIT { @BeforeEach public void beforeEach() { output = new ByteArrayOutputStream(); - databaseFile = new File(projectDir, "database/test.mv.db"); + databaseFile = new File(getProjectDir(), "database/test.mv.db"); assertFalse(databaseFile.exists()); - personFile = new File(projectDir, "generated/Person.java"); + personFile = new File(getProjectDir(), "generated/Person.java"); assertFalse(personFile.exists()); } @@ -46,7 +44,7 @@ public void testUseGenerics() throws Exception { } private void createBuildXmlFile() throws Exception { - buildXmlFile = new File(projectDir, "build.xml"); + buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); } @@ -67,7 +65,7 @@ private void createDatabase() throws Exception { } private void createHibernatePropertiesFile() throws Exception { - File hibernatePropertiesFile = new File(projectDir, "hibernate.properties"); + File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties"); StringBuffer hibernatePropertiesFileContents = new StringBuffer(); hibernatePropertiesFileContents .append("hibernate.connection.driver_class=org.h2.Driver\n") @@ -82,14 +80,14 @@ private void createHibernatePropertiesFile() throws Exception { private void runAntBuild() { Project project = new Project(); - project.setBaseDir(projectDir); + project.setBaseDir(getProjectDir()); project.addBuildListener(getConsoleLogger()); ProjectHelper.getProjectHelper().parse(project, buildXmlFile); project.executeTarget(project.getDefaultTarget()); } private void verifyResult() throws Exception { - File generatedOutputFolder = new File(projectDir, "generated"); + File generatedOutputFolder = new File(getProjectDir(), "generated"); assertTrue(generatedOutputFolder.exists()); assertTrue(generatedOutputFolder.isDirectory()); assertEquals(2, generatedOutputFolder.list().length); @@ -117,7 +115,7 @@ private DefaultLogger getConsoleLogger() { } private String constructJdbcConnectionString() { - return "jdbc:h2:" + projectDir.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; + return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } private static final String buildXmlFileContents = 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 257d3d3f4e..3b4a8e9e08 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 @@ -15,14 +15,12 @@ import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; +import org.hibernate.tool.it.ant.TestTemplate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -public class TutorialTestIT { - - @TempDir - private File projectDir; +public class TutorialTestIT extends TestTemplate { private File buildXmlFile; private ByteArrayOutputStream output; @@ -32,9 +30,9 @@ public class TutorialTestIT { @BeforeEach public void beforeEach() { output = new ByteArrayOutputStream(); - databaseFile = new File(projectDir, "database/test.mv.db"); + databaseFile = new File(getProjectDir(), "database/test.mv.db"); assertFalse(databaseFile.exists()); - personFile = new File(projectDir, "generated/Person.java"); + personFile = new File(getProjectDir(), "generated/Person.java"); assertFalse(personFile.exists()); } @@ -48,7 +46,7 @@ public void testTutorial() throws Exception { } private void createBuildXmlFile() throws Exception { - buildXmlFile = new File(projectDir, "build.xml"); + buildXmlFile = new File(getProjectDir(), "build.xml"); assertFalse(buildXmlFile.exists()); Files.writeString(buildXmlFile.toPath(), buildXmlFileContents); } @@ -65,7 +63,7 @@ private void createDatabase() throws Exception { } private void createHibernatePropertiesFile() throws Exception { - File hibernatePropertiesFile = new File(projectDir, "hibernate.properties"); + File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties"); StringBuffer hibernatePropertiesFileContents = new StringBuffer(); hibernatePropertiesFileContents .append("hibernate.connection.driver_class=org.h2.Driver\n") @@ -80,14 +78,14 @@ private void createHibernatePropertiesFile() throws Exception { private void runAntBuild() { Project project = new Project(); - project.setBaseDir(projectDir); + project.setBaseDir(getProjectDir()); project.addBuildListener(getConsoleLogger()); ProjectHelper.getProjectHelper().parse(project, buildXmlFile); project.executeTarget(project.getDefaultTarget()); } private void verifyResult() { - File generatedOutputFolder = new File(projectDir, "generated"); + File generatedOutputFolder = new File(getProjectDir(), "generated"); assertTrue(generatedOutputFolder.exists()); assertTrue(generatedOutputFolder.isDirectory()); assertEquals(1, generatedOutputFolder.list().length); @@ -105,7 +103,7 @@ private DefaultLogger getConsoleLogger() { } private String constructJdbcConnectionString() { - return "jdbc:h2:" + projectDir.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; + return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } private static final String buildXmlFileContents = 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 new file mode 100644 index 0000000000..359941de3c --- /dev/null +++ b/ant/src/it/java/org/hibernate/tool/it/ant/TestTemplate.java @@ -0,0 +1,16 @@ +package org.hibernate.tool.it.ant; + +import org.junit.jupiter.api.io.TempDir; + +import java.io.File; + +public class TestTemplate { + + @TempDir + private File projectDir; + + protected File getProjectDir() { + return projectDir; + } + +}