1- package com . example . demo .common ;
1+ package info . jab . ms .common ;
22
3+ import java .time .Duration ;
4+
5+ import org .springframework .boot .test .context .SpringBootTest ;
36import org .springframework .boot .testcontainers .service .connection .ServiceConnection ;
4- import org .springframework .test .context .ActiveProfiles ;
57import org .testcontainers .containers .PostgreSQLContainer ;
68import org .testcontainers .junit .jupiter .Container ;
79import org .testcontainers .junit .jupiter .Testcontainers ;
810import org .testcontainers .utility .MountableFile ;
911
10- import java .time .Duration ;
11-
1212/**
13- * Base class for tests that require a PostgreSQL TestContainer with Sakila schema.
13+ * PostgreSQLTestBase - Base class for integration tests with PostgreSQL TestContainer
1414 *
15- * This class provides a common PostgreSQL container setup that can be extended by
16- * integration and acceptance tests. It includes:
17- * - PostgreSQL 15 container with consistent database configuration
18- * - Sakila schema and test data initialization
19- * - Automatic Spring Boot configuration via @ServiceConnection
20- * - Container logging for debugging purposes
15+ * This class provides common setup for all integration tests that need
16+ * PostgreSQL database connectivity using TestContainers.
2117 *
22- * Usage: Extend this class and add @SpringBootTest, @Testcontainers annotations
23- * to your test class as needed.
18+ * Features:
19+ * - Shared PostgreSQL TestContainer for all test classes
20+ * - Pre-loaded with Sakila schema and data
21+ * - Automatic Spring Boot configuration via @ServiceConnection
22+ * - Proper startup and shutdown lifecycle management
2423 */
2524@ Testcontainers
26- @ ActiveProfiles ( "test" )
25+ @ SpringBootTest
2726public abstract class PostgreSQLTestBase {
2827
29- /**
30- * PostgreSQL TestContainer configured with Sakila schema and test data.
31- *
32- * Features:
33- * - Uses PostgreSQL 15 for consistency with production
34- * - Loads Sakila-compatible schema for production-like testing
35- * - Includes focused test data (51 films, 46 starting with 'A')
36- * - Automatic Spring Boot configuration via @ServiceConnection
37- * - Container logging enabled for debugging
38- * - 2-minute startup timeout for reliable CI/CD environments
39- */
4028 @ Container
4129 @ ServiceConnection (name = "postgres" )
4230 protected static PostgreSQLContainer <?> postgres = new PostgreSQLContainer <>("postgres:15" )
@@ -56,13 +44,6 @@ public abstract class PostgreSQLTestBase {
5644 System .out .print ("[POSTGRES] " + outputFrame .getUtf8String ());
5745 });
5846
59- /**
60- * Get the PostgreSQL container instance for direct access if needed.
61- * Useful for executing queries directly against the container or
62- * accessing connection details.
63- *
64- * @return The PostgreSQL container instance
65- */
6647 protected static PostgreSQLContainer <?> getPostgresContainer () {
6748 return postgres ;
6849 }
0 commit comments