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
@@ -1,31 +1,16 @@
package org.hibernate.tool.ant.hbm2java;

import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import static org.junit.jupiter.api.Assertions.*;
import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.Test;

public class JpaDefaultTestIT extends TestTemplate {

private File buildXmlFile;
private File databaseFile;
private File personFile;

@BeforeEach
public void beforeEach() {
databaseFile = new File(getProjectDir(), "database/test.mv.db");
assertFalse(databaseFile.exists());
personFile = new File(getProjectDir(), "generated/Person.java");
assertFalse(personFile.exists());
}


@Test
public void testJpaDefault() throws Exception {
createBuildXmlFile();
Expand All @@ -39,23 +24,12 @@ protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

private void createBuildXmlFile() throws Exception {
buildXmlFile = new File(getProjectDir(), "build.xml");
assertFalse(buildXmlFile.exists());
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
}

private void createDatabase() throws Exception {
String CREATE_PERSON_TABLE = "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))";
Connection connection = DriverManager.getConnection(constructJdbcConnectionString());
Statement statement = connection.createStatement();
statement.execute(CREATE_PERSON_TABLE);
statement.close();
connection.close();
assertTrue(databaseFile.exists());
assertTrue(databaseFile.isFile());
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();
Expand Down Expand Up @@ -84,10 +58,6 @@ private void verifyResult() throws Exception {
assertTrue(generatedPersonJavaFileContents.contains("public class Person "));
}

private String constructJdbcConnectionString() {
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
package org.hibernate.tool.ant.hbm2java;

import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import static org.junit.jupiter.api.Assertions.*;
import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.Test;

public class NoAnnotationsTestIT extends TestTemplate {

private File buildXmlFile;
private File databaseFile;
private File personFile;

@BeforeEach
public void beforeEach() {
databaseFile = new File(getProjectDir(), "database/test.mv.db");
assertFalse(databaseFile.exists());
personFile = new File(getProjectDir(), "generated/Person.java");
assertFalse(personFile.exists());
}

@Test
public void testNoAnnotations() throws Exception {
createBuildXmlFile();
Expand All @@ -39,23 +25,12 @@ protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

private void createBuildXmlFile() throws Exception {
buildXmlFile = new File(getProjectDir(), "build.xml");
assertFalse(buildXmlFile.exists());
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
}

private void createDatabase() throws Exception {
String CREATE_PERSON_TABLE = "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))";
Connection connection = DriverManager.getConnection(constructJdbcConnectionString());
Statement statement = connection.createStatement();
statement.execute(CREATE_PERSON_TABLE);
statement.close();
connection.close();
assertTrue(databaseFile.exists());
assertTrue(databaseFile.isFile());
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();
Expand Down Expand Up @@ -84,10 +59,6 @@ private void verifyResult() throws Exception {
assertTrue(generatedPersonJavaFileContents.contains("public class Person "));
}

private String constructJdbcConnectionString() {
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
package org.hibernate.tool.ant.hbm2java;

import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import static org.junit.jupiter.api.Assertions.*;
import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.Test;

public class NoGenericsTestIT extends TestTemplate {

private File buildXmlFile;
private File databaseFile;
private File personFile;

@BeforeEach
public void beforeEach() {
databaseFile = new File(getProjectDir(), "database/test.mv.db");
assertFalse(databaseFile.exists());
personFile = new File(getProjectDir(), "generated/Person.java");
assertFalse(personFile.exists());
}

@Test
public void testUseGenerics() throws Exception {
createBuildXmlFile();
Expand All @@ -39,27 +25,15 @@ protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

private void createBuildXmlFile() throws Exception {
buildXmlFile = new File(getProjectDir(), "build.xml");
assertFalse(buildXmlFile.exists());
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
}

private void createDatabase() throws Exception {
String CREATE_PERSON_TABLE = "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))";
String CREATE_ITEM_TABLE =
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))";
Connection connection = DriverManager.getConnection(constructJdbcConnectionString());
Statement statement = connection.createStatement();
statement.execute(CREATE_PERSON_TABLE);
statement.execute(CREATE_ITEM_TABLE);
statement.close();
connection.close();
assertTrue(databaseFile.exists());
assertTrue(databaseFile.isFile());
"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();
Expand Down Expand Up @@ -94,10 +68,6 @@ private void verifyResult() throws Exception {
assertTrue(generatedItemJavaFileContents.contains("public class Item "));
}

private String constructJdbcConnectionString() {
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
package org.hibernate.tool.ant.hbm2java;

import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import static org.junit.jupiter.api.Assertions.*;
import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.Test;

public class UseGenericsTestIT extends TestTemplate {

private File buildXmlFile;
private File databaseFile;
private File personFile;

@BeforeEach
public void beforeEach() {
databaseFile = new File(getProjectDir(), "database/test.mv.db");
assertFalse(databaseFile.exists());
personFile = new File(getProjectDir(), "generated/Person.java");
assertFalse(personFile.exists());
}

@Test
public void testUseGenerics() throws Exception {
createBuildXmlFile();
Expand All @@ -39,27 +24,15 @@ protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

private void createBuildXmlFile() throws Exception {
buildXmlFile = new File(getProjectDir(), "build.xml");
assertFalse(buildXmlFile.exists());
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
}

private void createDatabase() throws Exception {
String CREATE_PERSON_TABLE = "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))";
String CREATE_ITEM_TABLE =
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))";
Connection connection = DriverManager.getConnection(constructJdbcConnectionString());
Statement statement = connection.createStatement();
statement.execute(CREATE_PERSON_TABLE);
statement.execute(CREATE_ITEM_TABLE);
statement.close();
connection.close();
assertTrue(databaseFile.exists());
assertTrue(databaseFile.isFile());
"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();
Expand Down Expand Up @@ -94,10 +67,6 @@ private void verifyResult() throws Exception {
assertTrue(generatedItemJavaFileContents.contains("public class Item "));
}

private String constructJdbcConnectionString() {
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
}

private static final String hibernateToolTaskXml =
" <hibernatetool destdir='generated'> \n" +
" <jdbcconfiguration propertyfile='hibernate.properties'/> \n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
package org.hibernate.tool.ant.tutorial;

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

import java.io.File;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import org.hibernate.tool.it.ant.TestTemplate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TutorialTestIT extends TestTemplate {

private File buildXmlFile;
private File databaseFile;
private File personFile;

@BeforeEach
public void beforeEach() {
databaseFile = new File(getProjectDir(), "database/test.mv.db");
assertFalse(databaseFile.exists());
personFile = new File(getProjectDir(), "generated/Person.java");
assertFalse(personFile.exists());
}

@Test
public void testTutorial() throws Exception {
createBuildXmlFile();
Expand All @@ -41,23 +24,12 @@ protected String hibernateToolTaskXml() {
return hibernateToolTaskXml;
}

private void createBuildXmlFile() throws Exception {
buildXmlFile = new File(getProjectDir(), "build.xml");
assertFalse(buildXmlFile.exists());
Files.writeString(buildXmlFile.toPath(), constructBuildXmlFileContents());
}

private void createDatabase() throws Exception {
String CREATE_PERSON_TABLE = "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))";
Connection connection = DriverManager.getConnection(constructJdbcConnectionString());
Statement statement = connection.createStatement();
statement.execute(CREATE_PERSON_TABLE);
statement.close();
connection.close();
assertTrue(databaseFile.exists());
assertTrue(databaseFile.isFile());
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();
Expand All @@ -82,10 +54,6 @@ private void verifyResult() {
assertTrue(generatedPersonJavaFile.isFile());
}

private String constructJdbcConnectionString() {
return "jdbc:h2:" + getProjectDir().getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
}

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