Skip to content

Commit

Permalink
test : PayService @SpringBootTest 로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
seongjunnoh committed Nov 16, 2024
1 parent c08d85c commit 8a04697
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 36 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ out/
src/main/resource/application-local.yml
/**/application-local.yml
src/main/resource/application-dev.yml
/**/application-dev.yml
/**/application-dev.yml

### test yml file ###
src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import space.space_spring.entity.BaseEntity;
import space.space_spring.domain.space.model.entity.Space;

import java.util.ArrayList;
import java.util.List;

@Getter
Expand Down Expand Up @@ -47,8 +48,8 @@ public class PayRequest extends BaseEntity {
@Column(name = "is_complete")
private boolean isComplete;

@OneToMany(mappedBy = "payRequest")
private List<PayRequestTarget> payRequestTargets;
@OneToMany(mappedBy = "payRequest", cascade = CascadeType.ALL, orphanRemoval = true)
private List<PayRequestTarget> payRequestTargets = new ArrayList<>();
// PayRequestTarget list를 양방향 매핑으로 참조하는것이 더 좋을까?


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ private PayRequestTarget(PayRequest payRequest, Long targetUserId, int requested
}

public static PayRequestTarget create(PayRequest payRequest, Long targetUserId, int requestedAmount) {
return PayRequestTarget.builder()
PayRequestTarget build = PayRequestTarget.builder()
.payRequest(payRequest)
.targetUserId(targetUserId)
.requestedAmount(requestedAmount)
.build();

payRequest.getPayRequestTargets().add(build);

return build;
}

public void changeCompleteStatus(boolean isComplete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
import space.space_spring.domain.pay.model.dto.PayTargetInfoDto;
import space.space_spring.domain.pay.model.mapper.PayMapper;
import space.space_spring.domain.space.repository.SpaceRepository;
Expand All @@ -31,11 +29,9 @@
import static org.assertj.core.api.Assertions.*;
import static space.space_spring.response.status.BaseExceptionResponseStatus.USER_IS_NOT_IN_SPACE;

@DataJpaTest
@Import({PayService.class, PayMapper.class})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Transactional
@ActiveProfiles("test")
@EnableJpaRepositories(basePackageClasses = {PayRequestRepository.class, PayRequestTargetRepository.class, UserRepository.class, SpaceRepository.class, UserSpaceRepository.class})
@EntityScan(basePackageClasses = {PayRequest.class, PayRequestTarget.class, User.class, Space.class, UserSpace.class})
class PayServiceTest {

@Autowired
Expand All @@ -56,9 +52,6 @@ class PayServiceTest {
@Autowired
private UserSpaceRepository userSpaceRepository;

@Autowired
private PayMapper payMapper;

@Test
@DisplayName("유저가 요청한 정산들 중 완료되지 않은 정산 정보들과, 요청받은 정산들 중 완료되지 않은 정산 정보들을 return 한다.")
void getPayHomeInfos1() throws Exception {
Expand Down
94 changes: 73 additions & 21 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,77 @@
spring:
h2:
console:
enabled: true
path: /h2-console
datasource:
url: jdbc:h2:mem:~/space_spring
driver-class-name: org.h2.Driver
username: sa
password:
jpa:
# 서버 포트 설정
server:
port: 8080

# H2 인메모리 데이터베이스 설정
datasource:
url: jdbc:h2:mem:space_testdb
driver-class-name: org.h2.Driver
username: sa
password:

# JPA 설정
jpa:
hibernate:
ddl-auto: create-drop # 테스트 시작 시 테이블 생성, 종료 시 삭제
show-sql: true
properties:
hibernate:
ddl-auto: create
show-sql: true
properties:
hibernate:
format_sql: true
format_sql: true
use_sql_comments: true

sql:
init:
mode: never # sql initialization 을 사용하지 않겠다
# MongoDB 설정 (embedded MongoDB 사용 또는 목 처리)
data:
mongodb:
uri: mongodb://localhost:27017/test_db # 테스트용 로컬 MongoDB

# AWS S3 설정 (로컬 스토리지로 대체하거나 목 처리)
cloud:
aws:
credentials:
access-key: test-access-key
secret-key: test-secret-key
s3:
bucket: test-bucket
region:
static: us-east-1
stack:
auto: false

server:
port: 8080
# JWT 시크릿 키 설정
secret:
jwt:
access-secret-key: test-access-secret-key
refresh-secret-key: test-refresh-secret-key
access-expired-in: 30000
refresh-expired-in: 60000

# OAuth 설정 (테스트용으로 대체)
oauth:
kakao:
client:
id: test-client-id
secret: test-client-secret
redirect:
uri: http://localhost:8080/oauth/callback/kakao

# LiveKit 설정 (테스트용으로 대체)
livekit:
project:
host: https://test-livekit-host
id: test-project-id
api:
key: test-api-key
secretKey: test-api-secret

# 멀티파트 설정
spring:
servlet:
multipart:
max-file-size: 5MB
max-request-size: 5MB

# 기타 설정
logging:
level:
org.hibernate.SQL: debug
org.hibernate.type.descriptor.sql.BasicBinder: trace

0 comments on commit 8a04697

Please sign in to comment.