Skip to content

Commit 2fd1b60

Browse files
committed
make the testing dependency graph stricter and safer
1 parent 73734c6 commit 2fd1b60

File tree

20 files changed

+315
-19
lines changed

20 files changed

+315
-19
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins {
2+
id("framefork.java")
3+
}
4+
5+
dependencies {
6+
api(project(":typed-ids-testing"))
7+
8+
api(libs.hibernate.orm.v62)
9+
api(libs.hypersistence.utils.hibernate62)
10+
}

modules/typed-ids-hibernate-62/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies {
1212
compileOnly(libs.autoService.annotations)
1313
annotationProcessor(libs.autoService.processor)
1414

15-
testImplementation(project(":typed-ids-testing"))
15+
testImplementation(project(":typed-ids-hibernate-62-testing"))
1616
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
1717
}
1818

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins {
2+
id("framefork.java")
3+
}
4+
5+
dependencies {
6+
api(project(":typed-ids-testing"))
7+
8+
api(libs.hibernate.orm.v63)
9+
api(libs.hypersistence.utils.hibernate63)
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.framefork.typedIds.hibernate.tests;
2+
3+
import io.hypersistence.utils.test.providers.DataSourceProvider;
4+
import org.testcontainers.containers.JdbcDatabaseContainer;
5+
6+
import javax.sql.DataSource;
7+
import java.util.Objects;
8+
import java.util.concurrent.atomic.AtomicReference;
9+
10+
public abstract class AbstractContainerDataSourceProvider implements DataSourceProvider
11+
{
12+
13+
private final AtomicReference<JdbcDatabaseContainer<?>> container = new AtomicReference<>();
14+
15+
public JdbcDatabaseContainer<?> getContainer()
16+
{
17+
if (container.get() == null) {
18+
synchronized (container) {
19+
if (container.get() == null) {
20+
container.set(initContainer());
21+
}
22+
}
23+
}
24+
25+
return Objects.requireNonNull(container.get(), "database container must not be null");
26+
}
27+
28+
private JdbcDatabaseContainer<?> initContainer()
29+
{
30+
var newContainer = (JdbcDatabaseContainer<?>) newJdbcDatabaseContainer();
31+
32+
if (supportsDatabaseName()) {
33+
newContainer.withDatabaseName(databaseName());
34+
}
35+
if (supportsCredentials()) {
36+
newContainer.withUsername(username()).withPassword(password());
37+
}
38+
39+
newContainer.withReuse(true).start();
40+
41+
return newContainer;
42+
}
43+
44+
@Override
45+
public final DataSource dataSource()
46+
{
47+
getContainer(); // force init
48+
return newDataSource();
49+
}
50+
51+
@Override
52+
public final String url()
53+
{
54+
return getContainer().getJdbcUrl();
55+
}
56+
57+
public String databaseName()
58+
{
59+
return "framefork";
60+
}
61+
62+
protected abstract DataSource newDataSource();
63+
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.framefork.typedIds.hibernate.tests;
2+
3+
import io.hypersistence.utils.test.AbstractHibernateTest;
4+
import io.hypersistence.utils.test.providers.DataSourceProvider;
5+
import org.junit.jupiter.api.AfterEach;
6+
import org.junit.jupiter.api.BeforeEach;
7+
8+
public abstract class AbstractMySQLIntegrationTest extends AbstractHibernateTest
9+
{
10+
11+
@BeforeEach
12+
@Override
13+
public void init()
14+
{
15+
super.init();
16+
}
17+
18+
@AfterEach
19+
@Override
20+
public void destroy()
21+
{
22+
super.destroy();
23+
}
24+
25+
@Override
26+
protected DataSourceProvider dataSourceProvider()
27+
{
28+
return MySQLDataSourceProvider.V8;
29+
}
30+
31+
}

0 commit comments

Comments
 (0)