Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}

Expand All @@ -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);
}
Expand All @@ -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")
Expand All @@ -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);
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}

Expand All @@ -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);
}
Expand All @@ -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")
Expand All @@ -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);
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}

Expand All @@ -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);
}
Expand All @@ -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")
Expand All @@ -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);
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}

Expand All @@ -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);
}
Expand All @@ -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")
Expand All @@ -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);
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}

Expand All @@ -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);
}
Expand All @@ -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")
Expand All @@ -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);
Expand All @@ -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 =
Expand Down
16 changes: 16 additions & 0 deletions ant/src/it/java/org/hibernate/tool/it/ant/TestTemplate.java
Original file line number Diff line number Diff line change
@@ -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;
}

}