Skip to content

Commit e4b02c9

Browse files
Update javadoc (#5)
1 parent 024ec9e commit e4b02c9

File tree

8 files changed

+216
-15
lines changed

8 files changed

+216
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.gradle
22
build
3+
release.sh
4+
.env.release

build.gradle.kts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ subprojects {
4343
from(project.the<SourceSetContainer>()["main"].allSource)
4444
}
4545

46+
val javadocJar by tasks.registering(Jar::class) {
47+
archiveClassifier.set("javadoc")
48+
from(tasks.named("javadoc"))
49+
}
50+
4651
extensions.configure<PublishingExtension>("publishing") {
4752
publications {
4853
create<MavenPublication>("mavenJava") {
4954
from(components["java"])
5055
artifact(sourcesJar.get())
56+
artifact(javadocJar.get())
5157

5258
pom {
5359
name.set("Spring Test Containers")
@@ -81,7 +87,8 @@ subprojects {
8187
repositories {
8288
mavenLocal()
8389
maven {
84-
url = layout.buildDirectory.dir("staging-deploy").get().asFile.toURI()
90+
name = "staging"
91+
url = rootProject.layout.buildDirectory.dir("staging-deploy").get().asFile.toURI()
8592
}
8693
}
8794
}
@@ -106,3 +113,34 @@ jreleaser {
106113
}
107114
}
108115
}
116+
117+
val installGitHooks by tasks.registering {
118+
doLast {
119+
val gitDir = File(rootDir, ".git")
120+
val hooksDir = File(gitDir, "hooks")
121+
val hookSource = File(rootDir, "scripts/git-hooks/pre-commit")
122+
val hookTarget = File(hooksDir, "pre-commit")
123+
124+
if (!hookSource.exists()) {
125+
println("No pre-commit script found at ${hookSource.path}. Skipping hook installation.")
126+
return@doLast
127+
}
128+
129+
if (!gitDir.exists()) {
130+
println("Not a Git repository. Skipping Git hook installation.")
131+
return@doLast
132+
}
133+
134+
println("Installing Git pre-commit hook...")
135+
hookSource.copyTo(hookTarget, overwrite = true)
136+
hookTarget.setExecutable(true)
137+
println("✅ Git hook installed at: ${hookTarget.path}")
138+
}
139+
}
140+
141+
// Automatically install Git hooks on project evaluation
142+
if (System.getenv("CI") != "true") {
143+
gradle.projectsEvaluated {
144+
tasks.findByName("build")?.dependsOn("installGitHooks")
145+
}
146+
}

git-hooks/install-hooks.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

modules/mysql/src/main/java/io/flowinquiry/testcontainers/jdbc/mysql/MySqlContainerProvider.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,55 @@
44
import io.flowinquiry.testcontainers.jdbc.SpringAwareJdbcContainerProvider;
55
import org.testcontainers.containers.MySQLContainer;
66

7+
/**
8+
* MySQL-specific implementation of the {@link SpringAwareJdbcContainerProvider}.
9+
*
10+
* <p>This class provides support for MySQL database containers in the Spring TestContainers
11+
* framework. It creates and manages a {@link MySQLContainer} instance, which is a TestContainers
12+
* implementation for MySQL databases.
13+
*
14+
* <p>This provider is automatically discovered by the {@link
15+
* io.flowinquiry.testcontainers.jdbc.JdbcContainerProviderFactory} using Java's ServiceLoader
16+
* mechanism when a test class is annotated with {@code @EnableMySQL}.
17+
*
18+
* <p>The provider handles:
19+
*
20+
* <ul>
21+
* <li>Creating a MySQL container with the specified Docker image and version
22+
* <li>Starting and stopping the container
23+
* <li>Integrating the container with Spring's environment configuration
24+
* </ul>
25+
*
26+
* @see SpringAwareJdbcContainerProvider
27+
* @see MySQLContainer
28+
* @see io.flowinquiry.testcontainers.jdbc.EnableMySQL
29+
*/
730
public class MySqlContainerProvider extends SpringAwareJdbcContainerProvider {
831

32+
/**
33+
* Returns the type of database managed by this provider.
34+
*
35+
* <p>This implementation returns {@link Rdbms#MYSQL}, indicating that this provider supports
36+
* MySQL databases.
37+
*
38+
* @return {@link Rdbms#MYSQL} as the supported database type
39+
*/
940
@Override
1041
public Rdbms getType() {
1142
return Rdbms.MYSQL;
1243
}
1344

45+
/**
46+
* Creates a new MySQL database container.
47+
*
48+
* <p>This method creates a {@link MySQLContainer} instance configured with the Docker image and
49+
* version specified in the {@code @EnableMySQL} annotation on the test class.
50+
*
51+
* <p>The container is created but not started. The {@link #start()} method must be called to
52+
* start the container before it can be used.
53+
*
54+
* @return a new {@link MySQLContainer} instance
55+
*/
1456
@Override
1557
protected MySQLContainer<?> createJdbcDatabaseContainer() {
1658
return new MySQLContainer<>(dockerImage + ":" + version);

modules/postgresql/src/main/java/io/flowinquiry/testcontainers/jdbc/postgresql/PostgreSqlContainerProvider.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,55 @@
55
import org.testcontainers.containers.JdbcDatabaseContainer;
66
import org.testcontainers.containers.PostgreSQLContainer;
77

8+
/**
9+
* PostgreSQL-specific implementation of the {@link SpringAwareJdbcContainerProvider}.
10+
*
11+
* <p>This class provides support for PostgreSQL database containers in the Spring TestContainers
12+
* framework. It creates and manages a {@link PostgreSQLContainer} instance, which is a
13+
* TestContainers implementation for PostgreSQL databases.
14+
*
15+
* <p>This provider is automatically discovered by the {@link
16+
* io.flowinquiry.testcontainers.jdbc.JdbcContainerProviderFactory} using Java's ServiceLoader
17+
* mechanism when a test class is annotated with {@code @EnablePostgreSQL}.
18+
*
19+
* <p>The provider handles:
20+
*
21+
* <ul>
22+
* <li>Creating a PostgreSQL container with the specified Docker image and version
23+
* <li>Starting and stopping the container
24+
* <li>Integrating the container with Spring's environment configuration
25+
* </ul>
26+
*
27+
* @see SpringAwareJdbcContainerProvider
28+
* @see PostgreSQLContainer
29+
* @see io.flowinquiry.testcontainers.jdbc.EnablePostgreSQL
30+
*/
831
public class PostgreSqlContainerProvider extends SpringAwareJdbcContainerProvider {
932

33+
/**
34+
* Returns the type of database managed by this provider.
35+
*
36+
* <p>This implementation returns {@link Rdbms#POSTGRESQL}, indicating that this provider supports
37+
* PostgreSQL databases.
38+
*
39+
* @return {@link Rdbms#POSTGRESQL} as the supported database type
40+
*/
1041
@Override
1142
public Rdbms getType() {
1243
return Rdbms.POSTGRESQL;
1344
}
1445

46+
/**
47+
* Creates a new PostgreSQL database container.
48+
*
49+
* <p>This method creates a {@link PostgreSQLContainer} instance configured with the Docker image
50+
* and version specified in the {@code @EnablePostgreSQL} annotation on the test class.
51+
*
52+
* <p>The container is created but not started. The {@link #start()} method must be called to
53+
* start the container before it can be used.
54+
*
55+
* @return a new {@link PostgreSQLContainer} instance
56+
*/
1557
@Override
1658
protected JdbcDatabaseContainer<?> createJdbcDatabaseContainer() {
1759
return new PostgreSQLContainer<>(dockerImage + ":" + version);
File renamed without changes.

spring-testcontainers/src/main/java/io/flowinquiry/testcontainers/jdbc/JdbcContainerProviderFactory.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,45 @@
22

33
import java.util.ServiceLoader;
44

5+
/**
6+
* Factory class for creating and configuring JDBC container providers.
7+
*
8+
* <p>This factory is responsible for discovering and initializing the appropriate {@link
9+
* JdbcContainerProvider} implementation based on the database type specified in the {@link
10+
* EnableJdbcContainer} annotation.
11+
*
12+
* <p>The factory uses Java's {@link ServiceLoader} mechanism to discover available provider
13+
* implementations. It selects the provider that matches the requested database type, initializes it
14+
* with the specified Docker image and version, and prepares it for use in tests.
15+
*
16+
* <p>This class is primarily used by the {@link JdbcExtension} to create container providers for
17+
* test classes annotated with database-specific annotations like {@code @EnablePostgreSQL} or
18+
* {@code @EnableMySQL}.
19+
*
20+
* @see JdbcContainerProvider
21+
* @see EnableJdbcContainer
22+
* @see ServiceLoader
23+
*/
524
public class JdbcContainerProviderFactory {
625

26+
/**
27+
* Creates and initializes a JDBC container provider for the specified configuration.
28+
*
29+
* <p>This method:
30+
*
31+
* <ol>
32+
* <li>Discovers all available {@link JdbcContainerProvider} implementations using the {@link
33+
* ServiceLoader} mechanism
34+
* <li>Selects the provider that supports the database type specified in the {@link
35+
* EnableJdbcContainer} annotation
36+
* <li>Initializes the provider with the specified Docker image and version
37+
* <li>Creates the JDBC database container
38+
* </ol>
39+
*
40+
* @param enableJdbcContainer the annotation containing the database configuration
41+
* @return a fully initialized JDBC container provider ready for use in tests
42+
* @throws IllegalStateException if no provider is found for the specified database type
43+
*/
744
public static JdbcContainerProvider getProvider(EnableJdbcContainer enableJdbcContainer) {
845
SpringAwareJdbcContainerProvider provider =
946
(SpringAwareJdbcContainerProvider)

spring-testcontainers/src/main/java/io/flowinquiry/testcontainers/jdbc/JdbcExtension.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,45 @@
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
1212

13+
/**
14+
* A JUnit 5 extension that manages JDBC database containers for integration testing.
15+
*
16+
* <p>This extension automatically starts and stops database containers based on annotations present
17+
* on the test class. It works with meta-annotations that are themselves annotated with {@link
18+
* EnableJdbcContainer}, such as {@code @EnablePostgreSQL}, {@code @EnableMySQL}, etc.
19+
*
20+
* <p>The extension handles the lifecycle of database containers:
21+
*
22+
* <ul>
23+
* <li>Before all tests: Detects database configuration from annotations and starts the
24+
* appropriate container
25+
* <li>After all tests: Stops the container and cleans up resources
26+
* </ul>
27+
*
28+
* <p>Usage example:
29+
*
30+
* <pre>{@code
31+
* @EnablePostgreSQL
32+
* class MyIntegrationTest {
33+
* // Test methods that require a PostgreSQL database
34+
* }
35+
* }</pre>
36+
*/
1337
public class JdbcExtension implements BeforeAllCallback, AfterAllCallback {
1438

1539
private static final Logger log = LoggerFactory.getLogger(JdbcExtension.class);
1640

1741
private JdbcContainerProvider provider;
1842

43+
/**
44+
* Called before all tests in the current test class.
45+
*
46+
* <p>This method detects the database configuration from annotations on the test class, creates
47+
* the appropriate container provider, and starts the database container if needed. If a container
48+
* for this test class is already running, it reuses the existing container.
49+
*
50+
* @param context the extension context for the test class
51+
*/
1952
@Override
2053
public void beforeAll(ExtensionContext context) {
2154
Class<?> testClass = context.getRequiredTestClass();
@@ -33,6 +66,14 @@ public void beforeAll(ExtensionContext context) {
3366
}
3467
}
3568

69+
/**
70+
* Called after all tests in the current test class have completed.
71+
*
72+
* <p>This method stops the database container if it was started by this extension and removes the
73+
* container reference from the registry to allow proper cleanup.
74+
*
75+
* @param context the extension context for the test class
76+
*/
3677
@Override
3778
public void afterAll(ExtensionContext context) {
3879
if (provider != null) {
@@ -88,6 +129,19 @@ private Annotation findNearestAnnotationWith(
88129
return null;
89130
}
90131

132+
/**
133+
* Builds a resolved JDBC container configuration from a source annotation and its
134+
* meta-annotation.
135+
*
136+
* <p>This method extracts configuration values (version and dockerImage) from the source
137+
* annotation and combines them with the database type (rdbms) from the meta-annotation to create
138+
* a complete {@link EnableJdbcContainer} configuration.
139+
*
140+
* @param sourceAnnotation the source annotation containing version and dockerImage values
141+
* @param meta the meta-annotation containing the database type (rdbms)
142+
* @return a resolved {@link EnableJdbcContainer} configuration
143+
* @throws IllegalStateException if reflection fails to extract values from the source annotation
144+
*/
91145
private EnableJdbcContainer buildResolvedJdbcConfig(
92146
Annotation sourceAnnotation, EnableJdbcContainer meta) {
93147
try {

0 commit comments

Comments
 (0)