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 @@ -13,37 +13,22 @@ public class JpaDefaultTestIT extends TestTemplate {

@Test
public void testJpaDefault() throws Exception {
setHibernateToolTaskXml(
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java/> \n" +
" </hibernatetool> \n"
);
setDatabaseCreationScript(new String[] {
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
});
createBuildXmlFile();
createDatabase();
createHibernatePropertiesFile();
runAntBuild();
verifyResult();
}

protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

protected String[] createDatabaseScript() {
return new String[] {
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
};
}

private void createHibernatePropertiesFile() throws Exception {
File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties");
StringBuffer hibernatePropertiesFileContents = new StringBuffer();
hibernatePropertiesFileContents
.append("hibernate.connection.driver_class=org.h2.Driver\n")
.append("hibernate.connection.url=" + constructJdbcConnectionString() + "\n")
.append("hibernate.connection.username=\n")
.append("hibernate.connection.password=\n")
.append("hibernate.default_catalog=TEST\n")
.append("hibernate.default_schema=PUBLIC\n");
Files.writeString(hibernatePropertiesFile.toPath(), hibernatePropertiesFileContents.toString());
assertTrue(hibernatePropertiesFile.exists());
}

private void verifyResult() throws Exception {
File generatedOutputFolder = new File(getProjectDir(), "generated");
assertTrue(generatedOutputFolder.exists());
Expand All @@ -58,10 +43,4 @@ private void verifyResult() throws Exception {
assertTrue(generatedPersonJavaFileContents.contains("public class Person "));
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java/> \n" +
" </hibernatetool> \n" ;

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,22 @@ public class NoAnnotationsTestIT extends TestTemplate {

@Test
public void testNoAnnotations() throws Exception {
setHibernateToolTaskXml(
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java ejb3='false'/> \n" +
" </hibernatetool> \n"
);
setDatabaseCreationScript(new String[] {
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
});
createBuildXmlFile();
createDatabase();
createHibernatePropertiesFile();
runAntBuild();
verifyResult();
}

protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

protected String[] createDatabaseScript() {
return new String[] {
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
};
}

private void createHibernatePropertiesFile() throws Exception {
File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties");
StringBuffer hibernatePropertiesFileContents = new StringBuffer();
hibernatePropertiesFileContents
.append("hibernate.connection.driver_class=org.h2.Driver\n")
.append("hibernate.connection.url=" + constructJdbcConnectionString() + "\n")
.append("hibernate.connection.username=\n")
.append("hibernate.connection.password=\n")
.append("hibernate.default_catalog=TEST\n")
.append("hibernate.default_schema=PUBLIC\n");
Files.writeString(hibernatePropertiesFile.toPath(), hibernatePropertiesFileContents.toString());
assertTrue(hibernatePropertiesFile.exists());
}

private void verifyResult() throws Exception {
File generatedOutputFolder = new File(getProjectDir(), "generated");
assertTrue(generatedOutputFolder.exists());
Expand All @@ -59,9 +44,4 @@ private void verifyResult() throws Exception {
assertTrue(generatedPersonJavaFileContents.contains("public class Person "));
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java ejb3='false'/> \n" +
" </hibernatetool> \n" ;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,25 @@ public class NoGenericsTestIT extends TestTemplate {

@Test
public void testUseGenerics() throws Exception {
setHibernateToolTaskXml(
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java jdk5='false'/> \n" +
" </hibernatetool> \n"
);
setDatabaseCreationScript(new String[] {
"create table PERSON (ID int not null, NAME varchar(20), " +
"primary key (ID))",
"create table ITEM (ID int not null, NAME varchar(20), OWNER_ID int not null, " +
"primary key (ID), foreign key (OWNER_ID) references PERSON(ID))"
});
createBuildXmlFile();
createDatabase();
createHibernatePropertiesFile();
runAntBuild();
verifyResult();
}

protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

protected String[] createDatabaseScript() {
return new String[] {
"create table PERSON (ID int not null, NAME varchar(20), " +
"primary key (ID))",
"create table ITEM (ID int not null, NAME varchar(20), OWNER_ID int not null, " +
"primary key (ID), foreign key (OWNER_ID) references PERSON(ID))"
};
}

private void createHibernatePropertiesFile() throws Exception {
File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties");
StringBuffer hibernatePropertiesFileContents = new StringBuffer();
hibernatePropertiesFileContents
.append("hibernate.connection.driver_class=org.h2.Driver\n")
.append("hibernate.connection.url=" + constructJdbcConnectionString() + "\n")
.append("hibernate.connection.username=\n")
.append("hibernate.connection.password=\n")
.append("hibernate.default_catalog=TEST\n")
.append("hibernate.default_schema=PUBLIC\n");
Files.writeString(hibernatePropertiesFile.toPath(), hibernatePropertiesFileContents.toString());
assertTrue(hibernatePropertiesFile.exists());
}

private void verifyResult() throws Exception {
File generatedOutputFolder = new File(getProjectDir(), "generated");
assertTrue(generatedOutputFolder.exists());
Expand All @@ -68,10 +53,4 @@ private void verifyResult() throws Exception {
assertTrue(generatedItemJavaFileContents.contains("public class Item "));
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java jdk5='false'/> \n" +
" </hibernatetool> \n" ;

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,25 @@ public class UseGenericsTestIT extends TestTemplate {

@Test
public void testUseGenerics() throws Exception {
setHibernateToolTaskXml(
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java/> \n" +
" </hibernatetool> \n"
);
setDatabaseCreationScript(new String[] {
"create table PERSON (ID int not null, NAME varchar(20), " +
"primary key (ID))",
"create table ITEM (ID int not null, NAME varchar(20), OWNER_ID int not null, " +
"primary key (ID), foreign key (OWNER_ID) references PERSON(ID))"
});
createBuildXmlFile();
createDatabase();
createHibernatePropertiesFile();
runAntBuild();
verifyResult();
}

protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

protected String[] createDatabaseScript() {
return new String[] {
"create table PERSON (ID int not null, NAME varchar(20), " +
"primary key (ID))",
"create table ITEM (ID int not null, NAME varchar(20), OWNER_ID int not null, " +
"primary key (ID), foreign key (OWNER_ID) references PERSON(ID))"
};
}

private void createHibernatePropertiesFile() throws Exception {
File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties");
StringBuffer hibernatePropertiesFileContents = new StringBuffer();
hibernatePropertiesFileContents
.append("hibernate.connection.driver_class=org.h2.Driver\n")
.append("hibernate.connection.url=" + constructJdbcConnectionString() + "\n")
.append("hibernate.connection.username=\n")
.append("hibernate.connection.password=\n")
.append("hibernate.default_catalog=TEST\n")
.append("hibernate.default_schema=PUBLIC\n");
Files.writeString(hibernatePropertiesFile.toPath(), hibernatePropertiesFileContents.toString());
assertTrue(hibernatePropertiesFile.exists());
}

private void verifyResult() throws Exception {
File generatedOutputFolder = new File(getProjectDir(), "generated");
assertTrue(generatedOutputFolder.exists());
Expand All @@ -67,9 +52,4 @@ private void verifyResult() throws Exception {
assertTrue(generatedItemJavaFileContents.contains("public class Item "));
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java/> \n" +
" </hibernatetool> \n" ;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,22 @@ public class TutorialTestIT extends TestTemplate {

@Test
public void testTutorial() throws Exception {
setHibernateToolTaskXml(
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java/> \n" +
" </hibernatetool> \n"
);
setDatabaseCreationScript(new String[] {
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
});
createBuildXmlFile();
createDatabase();
createHibernatePropertiesFile();
runAntBuild();
verifyResult();
}

protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

protected String[] createDatabaseScript() {
return new String[] {
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"
};
}

private void createHibernatePropertiesFile() throws Exception {
File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties");
StringBuffer hibernatePropertiesFileContents = new StringBuffer();
hibernatePropertiesFileContents
.append("hibernate.connection.driver_class=org.h2.Driver\n")
.append("hibernate.connection.url=" + constructJdbcConnectionString() + "\n")
.append("hibernate.connection.username=\n")
.append("hibernate.connection.password=\n")
.append("hibernate.default_catalog=TEST\n")
.append("hibernate.default_schema=PUBLIC\n");
Files.writeString(hibernatePropertiesFile.toPath(), hibernatePropertiesFileContents.toString());
assertTrue(hibernatePropertiesFile.exists());
}

private void verifyResult() {
File generatedOutputFolder = new File(getProjectDir(), "generated");
assertTrue(generatedOutputFolder.exists());
Expand All @@ -54,9 +39,4 @@ private void verifyResult() {
assertTrue(generatedPersonJavaFile.isFile());
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
" <hbm2java/> \n" +
" </hibernatetool> \n" ;
}
32 changes: 26 additions & 6 deletions ant/src/it/java/org/hibernate/tool/it/ant/TestTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,31 @@
import java.sql.DriverManager;
import java.sql.Statement;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

public abstract class TestTemplate {

@TempDir
private File projectDir;

private String hibernateToolTaskXml;
private String[] databaseCreationScript;

protected File getProjectDir() {
return projectDir;
}

protected abstract String hibernateToolTaskXml();
protected void setHibernateToolTaskXml(String xml) {
this.hibernateToolTaskXml = xml;
}

protected abstract String[] createDatabaseScript();
protected void setDatabaseCreationScript(String[] sqls) {
this.databaseCreationScript = sqls;
}

protected String constructBuildXmlFileContents() {
return buildXmlFileContents.replace("@hibernateToolTaskXml@", hibernateToolTaskXml());
assertNotNull(hibernateToolTaskXml);
return buildXmlFileContents.replace("@hibernateToolTaskXml@", hibernateToolTaskXml);
}

protected void runAntBuild() {
Expand Down Expand Up @@ -57,7 +64,7 @@ protected void createDatabase() throws Exception {
assertFalse(databaseFile.isFile());
Connection connection = DriverManager.getConnection(constructJdbcConnectionString());
Statement statement = connection.createStatement();
for (String sql : createDatabaseScript()) {
for (String sql : databaseCreationScript) {
statement.execute(sql);
}
statement.close();
Expand All @@ -66,6 +73,19 @@ protected void createDatabase() throws Exception {
assertTrue(databaseFile.isFile());
}

protected void createHibernatePropertiesFile() throws Exception {
File hibernatePropertiesFile = new File(getProjectDir(), "hibernate.properties");
String hibernatePropertiesFileContents =
"hibernate.connection.driver_class=org.h2.Driver\n" +
"hibernate.connection.url=" + constructJdbcConnectionString() + "\n" +
"hibernate.connection.username=\n" +
"hibernate.connection.password=\n" +
"hibernate.default_catalog=TEST\n" +
"hibernate.default_schema=PUBLIC\n";
Files.writeString(hibernatePropertiesFile.toPath(), hibernatePropertiesFileContents);
assertTrue(hibernatePropertiesFile.exists());
}

private DefaultLogger getConsoleLogger() {
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
Expand Down