Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.5.6'
id 'org.springframework.boot' version '3.5.9'
id 'io.spring.dependency-management' version '1.1.7'
}

Expand Down Expand Up @@ -35,8 +35,8 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// Testcontainers for integration tests
testImplementation 'org.testcontainers:testcontainers:1.19.3'
// Test Containers
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:mysql:1.19.3'
testImplementation 'org.testcontainers:junit-jupiter:1.19.3'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import java.util.List;

@Slf4j
@Configuration
@RequiredArgsConstructor
@Profile({"local", "local-tunnel", "dev"})
public class InitialDataConfig {

private final TechBlogRepository techBlogRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import com.techfork.domain.post.repository.PostRepository;
import com.techfork.domain.source.entity.TechBlog;
import com.techfork.domain.source.repository.TechBlogRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -37,22 +37,13 @@
*/
@SpringBootTest
@AutoConfigureMockMvc
@Transactional
@Testcontainers
@ActiveProfiles("integrationtest")
class PostControllerIntegrationTest {

@Container
static MySQLContainer<?> mysql = new MySQLContainer<>("mysql:8.0")
.withDatabaseName("testdb")
.withUsername("test")
.withPassword("test");

@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", mysql::getJdbcUrl);
registry.add("spring.datasource.username", mysql::getUsername);
registry.add("spring.datasource.password", mysql::getPassword);
}
@ServiceConnection
static MySQLContainer<?> mysql = new MySQLContainer<>("mysql:8.0");

@Autowired
private MockMvc mockMvc;
Expand Down Expand Up @@ -113,6 +104,14 @@ void setUp() {
postKeywordRepository.save(keyword3);
}

@AfterEach
void tearDown() {
// 테스트 데이터 정리 (외래키 제약조건 순서 고려)
postKeywordRepository.deleteAll();
postRepository.deleteAll();
techBlogRepository.deleteAll();
}

@Test
@DisplayName("GET /api/v1/posts/{postId} - 게시글 상세 조회 성공")
void getPostDetail_Success() throws Exception {
Expand Down
39 changes: 39 additions & 0 deletions src/test/resources/application-integrationtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
spring:
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
format_sql: true
highlight_sql: true
dialect: org.hibernate.dialect.MySQL8Dialect

batch:
jdbc:
initialize-schema: always
job:
names: ''

ai:
anthropic:
api-key: test-dummy-key
chat:
options:
model: claude-3-5-haiku-20241022
temperature: 0.3
max-tokens: 8192
openai:
api-key: test-dummy-key
timeout: 60
chat:
options:
model: gpt-4o-mini
temperature: 0.3
max-tokens: 8192

logging:
level:
com.techfork: DEBUG
org.springframework.batch: INFO
org.hibernate.SQL: DEBUG
org.hibernate.tool.schema: ERROR
Loading