Skip to content

Commit 72f6994

Browse files
committed
HBX-3073: Make the database creation in GenerateJavaMojoTest more robust
Signed-off-by: Koen Aers <[email protected]>
1 parent e5aee12 commit 72f6994

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

maven/src/test/java/org/hibernate/tool/maven/GenerateJavaMojoTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
import org.hibernate.tool.api.metadata.MetadataDescriptorFactory;
1717
import org.junit.jupiter.api.AfterEach;
1818
import org.junit.jupiter.api.BeforeEach;
19+
import org.junit.jupiter.api.Disabled;
1920
import org.junit.jupiter.api.Test;
2021
import org.junit.jupiter.api.io.TempDir;
2122

2223
public class GenerateJavaMojoTest {
2324

24-
private static final String JDBC_CONNECTION = "jdbc:h2:mem:test";
2525
private static final String CREATE_PERSON_TABLE =
2626
"create table PERSON (ID int not null, NAME varchar(20), primary key (ID))";
2727
private static final String CREATE_ITEM_TABLE =
@@ -122,17 +122,21 @@ public void testGenerateJavaWithoutGenerics() throws Exception {
122122
}
123123

124124
private void createDatabase() throws Exception {
125-
Connection connection = DriverManager.getConnection(JDBC_CONNECTION);
125+
Connection connection = DriverManager.getConnection(constructJdbcConnectionString());
126126
Statement statement = connection.createStatement();
127127
statement.execute(CREATE_PERSON_TABLE);
128128
statement.execute(CREATE_ITEM_TABLE);
129+
statement.close();
130+
connection.close();
129131
}
130132

131133
private void dropDatabase() throws Exception {
132-
Connection connection = DriverManager.getConnection(JDBC_CONNECTION);
134+
Connection connection = DriverManager.getConnection(constructJdbcConnectionString());
133135
Statement statement = connection.createStatement();
134136
statement.execute(DROP_ITEM_TABLE);
135137
statement.execute(DROP_PERSON_TABLE);
138+
statement.close();
139+
connection.close();
136140
}
137141

138142
private void createGenerateJavaMojo() throws Exception {
@@ -161,10 +165,14 @@ private MetadataDescriptor createMetadataDescriptor() {
161165

162166
private Properties createProperties() {
163167
Properties result = new Properties();
164-
result.put("hibernate.connection.url", JDBC_CONNECTION);
168+
result.put("hibernate.connection.url", constructJdbcConnectionString());
165169
result.put("hibernate.default_catalog", "TEST");
166170
result.put("hibernate.default_schema", "PUBLIC");
167171
return result;
168172
}
169173

174+
private String constructJdbcConnectionString() {
175+
return "jdbc:h2:" + tempDir.getAbsolutePath() + "/database/test;AUTO_SERVER=TRUE";
176+
}
177+
170178
}

0 commit comments

Comments
 (0)