diff --git a/maven/docs/examples/5-minute-tutorial/README.md b/maven/docs/examples/5-minute-tutorial/README.md index 52dce31ac6..84a3e34535 100644 --- a/maven/docs/examples/5-minute-tutorial/README.md +++ b/maven/docs/examples/5-minute-tutorial/README.md @@ -18,5 +18,4 @@ To run this example: - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running - Issue one of the following commands from a command-line window opened in this folder: - `mvn generate-sources -Dh2.version=${h2.version} -Dproject.version=${hibernate.version}` - - `mvn hbm2java -Dh2.version=${h2.version} -Dproject.version=${hibernate.version}` \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/jpa-default/README.md b/maven/docs/examples/hbm2java/jpa-default/README.md new file mode 100644 index 0000000000..b7b95463cd --- /dev/null +++ b/maven/docs/examples/hbm2java/jpa-default/README.md @@ -0,0 +1,21 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following commands from a command-line window opened in this folder: + `mvn generate-sources -Dh2.version=${h2.version} -Dhibernate.version=${hibernate.version}` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/jpa-default/pom.xml b/maven/docs/examples/hbm2java/jpa-default/pom.xml new file mode 100644 index 0000000000..94ac1fbd9b --- /dev/null +++ b/maven/docs/examples/hbm2java/jpa-default/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-jpa-default + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/jpa-default/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/jpa-default/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..60b2483a2f --- /dev/null +++ b/maven/docs/examples/hbm2java/jpa-default/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + diff --git a/maven/docs/examples/hbm2java/no-annotations/README.md b/maven/docs/examples/hbm2java/no-annotations/README.md new file mode 100644 index 0000000000..b7b95463cd --- /dev/null +++ b/maven/docs/examples/hbm2java/no-annotations/README.md @@ -0,0 +1,21 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following commands from a command-line window opened in this folder: + `mvn generate-sources -Dh2.version=${h2.version} -Dhibernate.version=${hibernate.version}` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/no-annotations/pom.xml b/maven/docs/examples/hbm2java/no-annotations/pom.xml new file mode 100644 index 0000000000..3c007a168b --- /dev/null +++ b/maven/docs/examples/hbm2java/no-annotations/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-no-annotations + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + false + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/no-annotations/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/no-annotations/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..60b2483a2f --- /dev/null +++ b/maven/docs/examples/hbm2java/no-annotations/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + diff --git a/maven/docs/examples/hbm2java/no-generics/README.md b/maven/docs/examples/hbm2java/no-generics/README.md new file mode 100644 index 0000000000..b7b95463cd --- /dev/null +++ b/maven/docs/examples/hbm2java/no-generics/README.md @@ -0,0 +1,21 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following commands from a command-line window opened in this folder: + `mvn generate-sources -Dh2.version=${h2.version} -Dhibernate.version=${hibernate.version}` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/no-generics/pom.xml b/maven/docs/examples/hbm2java/no-generics/pom.xml new file mode 100644 index 0000000000..de0b1216bb --- /dev/null +++ b/maven/docs/examples/hbm2java/no-generics/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-no-generics + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + false + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/no-generics/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/no-generics/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..60b2483a2f --- /dev/null +++ b/maven/docs/examples/hbm2java/no-generics/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + diff --git a/maven/docs/examples/hbm2java/output-directory/README.md b/maven/docs/examples/hbm2java/output-directory/README.md new file mode 100644 index 0000000000..a5b85c8ec8 --- /dev/null +++ b/maven/docs/examples/hbm2java/output-directory/README.md @@ -0,0 +1,26 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following command from a command-line window opened in this folder: +```shell +mvn generate-sources + -Dh2.version=${h2.version} + -Dhibernate.version=${hibernate.version} + -Doutput.dir=./generated-classes +``` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/output-directory/pom.xml b/maven/docs/examples/hbm2java/output-directory/pom.xml new file mode 100644 index 0000000000..1ece83935f --- /dev/null +++ b/maven/docs/examples/hbm2java/output-directory/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-jpa-default + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + ${output.dir} + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/output-directory/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/output-directory/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..60b2483a2f --- /dev/null +++ b/maven/docs/examples/hbm2java/output-directory/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + diff --git a/maven/docs/examples/hbm2java/template-path/README.md b/maven/docs/examples/hbm2java/template-path/README.md new file mode 100644 index 0000000000..fa81c49116 --- /dev/null +++ b/maven/docs/examples/hbm2java/template-path/README.md @@ -0,0 +1,26 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following command from a command-line window opened in this folder: +```shell +mvn generate-sources + -Dh2.version=${h2.version} + -Dhibernate.version=${hibernate.version} + -Dtemplate.dir=./templates +``` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/template-path/pom.xml b/maven/docs/examples/hbm2java/template-path/pom.xml new file mode 100644 index 0000000000..11e23132d6 --- /dev/null +++ b/maven/docs/examples/hbm2java/template-path/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-template-path + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + ${template.dir} + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/template-path/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/template-path/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..60b2483a2f --- /dev/null +++ b/maven/docs/examples/hbm2java/template-path/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + diff --git a/maven/docs/examples/hbm2java/template-path/templates/pojo/Pojo.ftl b/maven/docs/examples/hbm2java/template-path/templates/pojo/Pojo.ftl new file mode 100644 index 0000000000..18f3de1a5a --- /dev/null +++ b/maven/docs/examples/hbm2java/template-path/templates/pojo/Pojo.ftl @@ -0,0 +1,18 @@ + +// This is just an example of a custom template + + diff --git a/maven/docs/examples/hbm2java/use-generics/README.md b/maven/docs/examples/hbm2java/use-generics/README.md new file mode 100644 index 0000000000..b7b95463cd --- /dev/null +++ b/maven/docs/examples/hbm2java/use-generics/README.md @@ -0,0 +1,21 @@ + +To run this example: + - Have [Apache Maven](https://maven.apache.org) installed + - Have [H2 Sakila database](https://github.com/hibernate/sakila-h2) running + - Issue the following commands from a command-line window opened in this folder: + `mvn generate-sources -Dh2.version=${h2.version} -Dhibernate.version=${hibernate.version}` + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/use-generics/pom.xml b/maven/docs/examples/hbm2java/use-generics/pom.xml new file mode 100644 index 0000000000..3a201eb1ff --- /dev/null +++ b/maven/docs/examples/hbm2java/use-generics/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.hibernate.tool.maven.test + hbm2java-use-generics + 0.0.1-SNAPSHOT + + + + com.h2database + h2 + ${h2.version} + + + + + + + org.hibernate.tool + hibernate-tools-maven + ${hibernate.version} + + + Entity generation + generate-sources + + hbm2java + + + + + + + + \ No newline at end of file diff --git a/maven/docs/examples/hbm2java/use-generics/src/main/resources/hibernate.properties b/maven/docs/examples/hbm2java/use-generics/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..60b2483a2f --- /dev/null +++ b/maven/docs/examples/hbm2java/use-generics/src/main/resources/hibernate.properties @@ -0,0 +1,23 @@ +############################################################################ +# Hibernate Tools, Tooling for your Hibernate Projects # +# # +# Copyright 2004-2025 Red Hat, Inc. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" basis, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila +hibernate.connection.username=sa +hibernate.default_catalog=SAKILA +hibernate.default_schema=PUBLIC + diff --git a/maven/pom.xml b/maven/pom.xml index 7a70741dbf..732e3d5f50 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -47,7 +47,7 @@ jakarta.xml.bind jakarta.xml.bind-api - + org.junit.jupiter junit-jupiter-engine @@ -124,8 +124,8 @@ default-descriptor process-classes - hibernate-tools - + hibernate-tools + help-goal @@ -133,8 +133,8 @@ helpmojo - hibernate-tools - + hibernate-tools + @@ -185,19 +185,6 @@ - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - integration-test - verify - - - - org.codehaus.mojo @@ -215,6 +202,7 @@ + add-test-resource generate-test-resources @@ -235,6 +223,8 @@ + org.apache.maven.plugins maven-resources-plugin @@ -256,16 +246,29 @@ - ${*} + ${*.version} + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + - + maven-project-info-reports-plugin diff --git a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java index f29bf73224..b11f0b2c2b 100644 --- a/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java +++ b/maven/src/functionalTest/java/org/hibernate/tool/maven/ExamplesTestIT.java @@ -1,11 +1,13 @@ package org.hibernate.tool.maven; +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 static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + import org.apache.maven.cli.MavenCli; @@ -21,6 +23,17 @@ public class ExamplesTestIT { private static File baseFolder; private static File localRepo; + private File projectFolder; + private MavenCli mavenCli; + + @TempDir + private File tempFolder; + + private String[] databaseCreationScript = new String[] { + // This is the default database which can be overridden per test + "create table PERSON (ID int not null, NAME varchar(20), primary key (ID))" + }; + @BeforeAll public static void beforeAll() throws Exception { // The needed resource for this test are put in place @@ -29,32 +42,92 @@ public static void beforeAll() throws Exception { // See the 'pom.xml' baseFolder = determineBaseFolder(); localRepo = new File(baseFolder.getParentFile(), "local-repo"); - createDatabase(); } - private MavenCli mavenCli; - @Test public void test5MinuteTutorial() throws Exception { - File projectFolder = prepareProjectFolder("5-minute-tutorial"); - File generatedPersonFile = new File(projectFolder, "target/generated-sources/Person.java"); - assertFalse(generatedPersonFile.exists()); - new MavenCli().doMain( - new String[]{"-Dmaven.repo.local=" + localRepo.getAbsolutePath(), "generate-sources"}, - projectFolder.getAbsolutePath(), - null, - null); - assertTrue(generatedPersonFile.exists()); - String personFileContents = new String(Files.readAllBytes(generatedPersonFile.toPath())); - assertTrue(personFileContents.contains("public class Person")); + prepareProject("5-minute-tutorial"); + assertNotGeneratedYet("Person.java"); + runGenerateSources(); + assertNumberOfGeneratedFiles(1); + assertGeneratedContains("Person.java", "public class Person"); + } + + @Test + public void testJpaDefault() throws Exception { + prepareProject("hbm2java/jpa-default"); + assertNotGeneratedYet("Person.java"); + runGenerateSources(); + assertNumberOfGeneratedFiles(1); + assertGeneratedContains("Person.java","import jakarta.persistence.Entity;"); + } + + @Test + public void testNoAnnotations() throws Exception { + prepareProject("hbm2java/no-annotations"); + assertNotGeneratedYet("Person.java"); + runGenerateSources(); + assertNumberOfGeneratedFiles(1); + assertGeneratedDoesNotContain("Person.java", "import jakarta.persistence.Entity;"); + } + + @Test + public void testNoGenerics() throws Exception { + databaseCreationScript = 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))" + }; + prepareProject("hbm2java/no-generics"); + assertNotGeneratedYet("Person.java"); + runGenerateSources(); + assertNumberOfGeneratedFiles(2); + assertGeneratedDoesNotContain("Person.java", "Set"); + } + + @Test + public void testOutputDirectory() throws Exception { + System.setProperty("output.dir", "${project.basedir}/generated-classes"); + prepareProject("hbm2java/output-directory"); + File outputDirectory = new File(projectFolder, "generated-classes"); + File personFile = new File(outputDirectory, "Person.java"); + assertFalse(outputDirectory.exists()); + assertFalse(personFile.exists()); + runGenerateSources(); + assertEquals(1, outputDirectory.list().length); // 1 file is generated in 'generated-classes' + assertTrue(personFile.exists()); // The Person.java file should have been generated } - private File prepareProjectFolder(String projectName) throws Exception { - File projectFolder = new File(baseFolder, projectName); + @Test + public void testTemplatePath() throws Exception { + System.setProperty("template.dir", "${project.basedir}/templates"); + prepareProject("hbm2java/template-path"); + assertNotGeneratedYet("Person.java"); + runGenerateSources(); + assertNumberOfGeneratedFiles(1); + assertGeneratedContains("Person.java", "// This is just an example of a custom template"); + } + + @Test + public void testUseGenerics() throws Exception { + databaseCreationScript = 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))" + }; + prepareProject("hbm2java/use-generics"); + assertNotGeneratedYet("Person.java"); + runGenerateSources(); + assertNumberOfGeneratedFiles(2); + assertGeneratedContains("Person.java", "Set"); + } + + private void prepareProject(String projectName) throws Exception { + projectFolder = new File(baseFolder, projectName); assertTrue(projectFolder.exists()); System.setProperty(MVN_HOME, projectFolder.getAbsolutePath()); createHibernatePropertiesFile(projectFolder); - return projectFolder; + createDatabase(); } private void createHibernatePropertiesFile(File projectFolder) throws Exception { @@ -73,26 +146,58 @@ private void createHibernatePropertiesFile(File projectFolder) throws Exception assertTrue(hibernatePropertiesFile.exists()); } + private void runGenerateSources() { + new MavenCli().doMain( + new String[]{"-Dmaven.repo.local=" + localRepo.getAbsolutePath(), "generate-sources"}, + projectFolder.getAbsolutePath(), + null, + null); + } + + private void assertNotGeneratedYet(String fileName) { + assertFalse(new File(projectFolder, "target/generated-sources/" + fileName).exists()); + } + + private void assertGeneratedContains(String fileName, String contents) throws Exception { + assertTrue(readGeneratedContents(fileName).contains(contents)); + } + + private void assertGeneratedDoesNotContain(String fileName, String contents) throws Exception { + assertFalse(readGeneratedContents(fileName).contains(contents)); + } + + private void assertNumberOfGeneratedFiles(int amount) throws Exception { + assertEquals(amount, new File(projectFolder, "target/generated-sources").list().length); + } + + private String readGeneratedContents(String fileName) throws Exception { + File generatedPersonFile = new File(projectFolder, "target/generated-sources/" + fileName); + assertTrue(generatedPersonFile.exists()); + return new String(Files.readAllBytes(generatedPersonFile.toPath())); + } + private static File determineBaseFolder() throws Exception { return new File(ExamplesTestIT.class.getClassLoader().getResource("5-minute-tutorial/pom.xml").toURI()) .getParentFile().getParentFile(); } - private static void createDatabase() throws Exception { - File databaseFile = new File(baseFolder, "database/test.mv.db"); + private void createDatabase() throws Exception { + File databaseFile = new File(tempFolder, "database/test.mv.db"); assertFalse(databaseFile.exists()); assertFalse(databaseFile.isFile()); Connection connection = DriverManager.getConnection(constructJdbcConnectionString()); Statement statement = connection.createStatement(); - statement.execute("create table PERSON (ID int not null, NAME varchar(20), primary key (ID))"); + for (String s : databaseCreationScript) { + statement.execute(s); + } statement.close(); connection.close(); assertTrue(databaseFile.exists()); assertTrue(databaseFile.isFile()); } - private static String constructJdbcConnectionString() { - return "jdbc:h2:" + baseFolder.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; + private String constructJdbcConnectionString() { + return "jdbc:h2:" + tempFolder.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE"; } }