Add test infrastructure and common module
- Testcontainers 2.0.4 (PostgreSQL) for repository integration tests - AbstractIntegrationTest base class with shared Postgres container - application-test.yml for test profile - Common module: ApiResponse/ApiError envelopes, GlobalExceptionHandler, ResourceNotFoundException, ConflictException, ValidationException, HouseholdContext record Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.recipeapp;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
@SpringBootTest
|
||||
@Testcontainers
|
||||
@ActiveProfiles("test")
|
||||
public abstract class AbstractIntegrationTest {
|
||||
|
||||
@Container
|
||||
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16-alpine")
|
||||
.withDatabaseName("mealprep")
|
||||
.withUsername("mealprep")
|
||||
.withPassword("mealprep");
|
||||
|
||||
@DynamicPropertySource
|
||||
static void configureProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.datasource.url", postgres::getJdbcUrl);
|
||||
registry.add("spring.datasource.username", postgres::getUsername);
|
||||
registry.add("spring.datasource.password", postgres::getPassword);
|
||||
}
|
||||
}
|
||||
12
backend/src/test/resources/application-test.yml
Normal file
12
backend/src/test/resources/application-test.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:tc:postgresql:16-alpine:///mealprep
|
||||
username: mealprep
|
||||
password: mealprep
|
||||
jpa:
|
||||
open-in-view: false
|
||||
hibernate:
|
||||
ddl-auto: validate
|
||||
flyway:
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
Reference in New Issue
Block a user