Skip to content

Commit 99c6b4f

Browse files
committed
The bulk of my integration tests are outdated and still assume outdated architecture from previous stages of this project. Fixing some issues w/ how my container base files are setup so the Integration Tests can start and pass w/o issue. (Flesh out more modern Integration Tests later).
1 parent 9b20038 commit 99c6b4f

6 files changed

Lines changed: 55 additions & 10 deletions

File tree

springqpro-backend/src/test/java/com/springqprobackend/springqpro/SpringQueueProApplicationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.springqprobackend.springqpro;
22

3+
import com.springqprobackend.springqpro.testcontainers.IntegrationTestBase;
34
import org.junit.jupiter.api.Test;
45
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
56
import org.springframework.boot.test.context.SpringBootTest;
67

78
@SpringBootTest
8-
class SpringQueueProApplicationTests {
9+
class SpringQueueProApplicationTests extends IntegrationTestBase {
910

1011
@Test
1112
void contextLoads() {

springqpro-backend/src/test/java/com/springqprobackend/springqpro/integration/CreateAndProcessTaskIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void sweepQueuedTasks() {
5454
- Uses Awaitility to wait for ProcessingService's asynchronous processing.
5555
*/
5656
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
57-
@Tag("disable_temp")
57+
//@Tag("disable_temp")
5858
class CreateAndProcessTaskIntegrationTest extends IntegrationTestBase {
5959
@Autowired
6060
private TestRestTemplate rest;

springqpro-backend/src/test/java/com/springqprobackend/springqpro/testcontainers/BasePostgresContainer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
*/
1717
// CENTRAL PostgreSQL Testcontainer USED FOR ALL MY INTEGRATION TESTS:
1818
public abstract class BasePostgresContainer {
19+
/*@Container
1920
@ServiceConnection
2021
protected static final PostgreSQLContainer<?> POSTGRES =
2122
new PostgreSQLContainer<>("postgres:18")
2223
.withDatabaseName("springqpro")
2324
.withUsername("springqpro")
2425
.withPassword("springqpro")
25-
.withReuse(true);
26+
.withReuse(true);*/
2627
// 2025-11-23-DEBUG: TEMP BELOW.
27-
@Container
28+
/*@Container
2829
@ServiceConnection
2930
static final RedisContainer REDIS =
3031
new RedisContainer(DockerImageName.parse("redis:7.2"));
@@ -33,5 +34,5 @@ public abstract class BasePostgresContainer {
3334
static {
3435
POSTGRES.start(); // This is meant to boot once for the entire Integration Test Suite.
3536
REDIS.start(); // 2025-11-23-DEBUG: TEMP.
36-
}
37+
}*/
3738
}

springqpro-backend/src/test/java/com/springqprobackend/springqpro/testcontainers/BaseRedisContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import org.testcontainers.containers.GenericContainer;
55

66
public abstract class BaseRedisContainer {
7-
@ServiceConnection
7+
/*@ServiceConnection
88
protected static final GenericContainer<?> REDIS
99
= new GenericContainer<>("redis:7-alpine")
1010
.withExposedPorts(6379)
1111
.withReuse(true);
1212
static {
1313
REDIS.start();
14-
}
14+
}*/
1515
}
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package com.springqprobackend.springqpro.testcontainers;
22

33
import org.springframework.boot.test.context.SpringBootTest;
4+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
5+
import org.springframework.test.context.ActiveProfiles;
6+
import org.springframework.test.context.DynamicPropertyRegistry;
7+
import org.springframework.test.context.DynamicPropertySource;
8+
import org.testcontainers.containers.GenericContainer;
9+
import org.testcontainers.containers.PostgreSQLContainer;
10+
import org.testcontainers.junit.jupiter.Container;
411
import org.testcontainers.junit.jupiter.Testcontainers;
512

613
/* BASE CLASS FOR ALL MY INTEGRATION TESTS THAT PROVIDES:
@@ -9,7 +16,35 @@
916
- Testcontainers lifecycle.
1017
- PostgreSQL datasource auto-wiring from BasePostgresContainer.
1118
*/
19+
//public abstract class IntegrationTestBase extends BasePostgresContainer {
1220
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "spring.main.allow-bean-definition-overriding=true")
1321
@Testcontainers
14-
public abstract class IntegrationTestBase extends BasePostgresContainer {
22+
@ActiveProfiles("test")
23+
public abstract class IntegrationTestBase {
24+
25+
@Container
26+
static final PostgreSQLContainer<?> POSTGRES =
27+
new PostgreSQLContainer<>("postgres:18")
28+
.withDatabaseName("springqpro")
29+
.withUsername("springqpro")
30+
.withPassword("springqpro")
31+
.withReuse(true);
32+
33+
@Container
34+
static final GenericContainer<?> REDIS =
35+
new GenericContainer<>("redis:7-alpine")
36+
.withExposedPorts(6379)
37+
.withReuse(true);
38+
39+
@DynamicPropertySource
40+
static void registerDynamicProps(DynamicPropertyRegistry registry) {
41+
// postgres
42+
registry.add("spring.datasource.url", POSTGRES::getJdbcUrl);
43+
registry.add("spring.datasource.username", POSTGRES::getUsername);
44+
registry.add("spring.datasource.password", POSTGRES::getPassword);
45+
46+
// redis
47+
registry.add("spring.redis.host", REDIS::getHost);
48+
registry.add("spring.redis.port", () -> REDIS.getMappedPort(6379));
49+
}
1550
}

springqpro-backend/src/test/java/com/springqprobackend/springqpro/testcontainers/RedisIntegrationTestBase.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.springframework.context.annotation.Import;
88
import org.springframework.test.context.DynamicPropertyRegistry;
99
import org.springframework.test.context.DynamicPropertySource;
10+
import org.testcontainers.containers.GenericContainer;
11+
import org.testcontainers.junit.jupiter.Container;
1012
import org.testcontainers.junit.jupiter.Testcontainers;
1113

1214
@DataRedisTest
@@ -17,9 +19,15 @@
1719
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.class,
1820
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration.class
1921
})
20-
public abstract class RedisIntegrationTestBase extends BaseRedisContainer {
22+
public abstract class RedisIntegrationTestBase {
23+
@Container
24+
static final GenericContainer<?> REDIS =
25+
new GenericContainer<>("redis:7-alpine")
26+
.withExposedPorts(6379)
27+
.withReuse(true);
28+
2129
@DynamicPropertySource
22-
static void overrideRedisProps(DynamicPropertyRegistry registry) {
30+
static void redisProps(DynamicPropertyRegistry registry) {
2331
registry.add("spring.redis.host", REDIS::getHost);
2432
registry.add("spring.redis.port", () -> REDIS.getMappedPort(6379));
2533
}

0 commit comments

Comments
 (0)