Skip to content

Commit 310bc35

Browse files
authored
테스트 환경 설정 (#29)
* feat: 라이브러리 추가 * feat: 테스트 컨테이너 환경 세팅 * feat: StrategyService Test 작성 * feat: implement 레이어 테스트 템플릿 추가 * feat: 통합 테스트 설정
1 parent 1080fff commit 310bc35

37 files changed

+1013
-93
lines changed

build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,12 @@ dependencies {
9797
testImplementation 'org.springframework.security:spring-security-test'
9898

9999
// JUnit
100-
testImplementation "org.junit.jupiter:junit-jupiter:5.9.2"
101-
100+
testImplementation 'org.junit.jupiter:junit-jupiter:5.12.2'
102101
// Mockito
103-
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.3.1'
102+
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.17.0'
104103

105104
// AssertJ
106-
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.24.2'
105+
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.6.1'
107106

108107
// MockWebserver
109108
testImplementation group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '4.11.0'
@@ -113,6 +112,8 @@ dependencies {
113112
testImplementation 'org.testcontainers:junit-jupiter:1.18.0'
114113
testImplementation 'org.testcontainers:kafka:1.18.0'
115114
testImplementation 'org.testcontainers:postgresql:1.18.0'
115+
testImplementation 'org.testcontainers:jdbc:1.18.0'
116+
116117
}
117118

118119
dependencyManagement {

src/main/java/com/tradin/common/config/SecurityConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
4646
"/v1/strategies/test/**",
4747
"/v1/strategies/webhook/futures/short-term",
4848
"/v1/subscriptions/activate/accounts/strategies/**",
49-
"/v1/subscriptions/deactivate/accounts/strategies/**"
49+
"/v1/subscriptions/deactivate/accounts/strategies/**",
50+
"/v1/strategies/future",
51+
"/swagger-ui/**",
52+
"/api-docs/**"
5053
)
5154
.permitAll() //TODO
5255

src/main/java/com/tradin/common/jwt/JwtSecretKeyProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class JwtSecretKeyProvider {
1111

1212
private final Key secretKey;
1313

14-
public JwtSecretKeyProvider(@Value("${JWT_SECRET_KEY}") String secretKey) {
14+
public JwtSecretKeyProvider(@Value("${secret.jwt-secret}") String secretKey) {
1515
byte[] keyBytes = Decoders.BASE64.decode(secretKey);
1616
this.secretKey = Keys.hmacShaKeyFor(keyBytes);
1717
}

src/main/java/com/tradin/module/strategy/history/domain/History.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
@Entity
2525
@Getter
26-
@Table(indexes = {@Index(name = "index_strategy_id", columnList = "strategy_id")})
26+
@Table(indexes = {@Index(name = "index_strategy_id", columnList = "strategy_id")}) //TODO
2727
@NoArgsConstructor(access = AccessLevel.PROTECTED)
2828
public class History {
2929

src/main/java/com/tradin/module/strategy/strategy/controller/StrategyController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.tradin.module.strategy.strategy.controller.dto.request.WebHookRequestDto;
55
import com.tradin.module.strategy.strategy.controller.dto.response.FindStrategiesInfoResponseDto;
66
import com.tradin.module.strategy.strategy.service.StrategyService;
7+
import jakarta.validation.Valid;
78
import lombok.RequiredArgsConstructor;
89
import org.springframework.web.bind.annotation.GetMapping;
910
import org.springframework.web.bind.annotation.PostMapping;
@@ -34,7 +35,7 @@ public void createStrategy() {
3435
}
3536

3637
@PostMapping("/webhook/futures/short-term")
37-
public void handleFutureShortTermV1WebHook(@RequestBody WebHookRequestDto request) {
38+
public void handleFutureShortTermV1WebHook(@RequestBody @Valid WebHookRequestDto request) {
3839
strategyService.handleFutureWebHook(request.toServiceDto());
3940
}
4041
}

src/main/java/com/tradin/module/strategy/strategy/controller/dto/request/WebHookRequestDto.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.tradin.module.strategy.strategy.domain.Position;
44
import com.tradin.module.strategy.strategy.service.dto.WebHookDto;
5-
import jakarta.validation.constraints.NotBlank;
5+
import jakarta.validation.constraints.NotNull;
66
import lombok.AllArgsConstructor;
77
import lombok.Getter;
88
import lombok.NoArgsConstructor;
@@ -12,10 +12,10 @@
1212
@Getter
1313
public class WebHookRequestDto {
1414

15-
@NotBlank(message = "id must not be blank")
15+
@NotNull(message = "id must not be blank")
1616
private Long id;
1717

18-
@NotBlank(message = "position must not be blank")
18+
@NotNull(message = "position must not be null")
1919
private Position position;
2020

2121
public WebHookDto toServiceDto() {

src/main/java/com/tradin/module/strategy/strategy/domain/Strategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void updateCurrentPosition(Position position) {
7373
}
7474

7575
public void updateRateAndCount(double entryPrice, LocalDateTime entryTime) {
76-
double profitRate = calculateProfitRate(entryPrice);
76+
double profitRate = calculateProfitRate(entryPrice); //TODO - processor로 이동
7777

7878
if (isWin(profitRate)) {
7979
increaseWinCount();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.tradin.module.strategy.strategy.domain.dao;
2+
3+
import com.querydsl.core.annotations.QueryProjection;
4+
import com.tradin.module.strategy.strategy.domain.CoinType;
5+
import com.tradin.module.strategy.strategy.domain.TradingType;
6+
import io.swagger.v3.oas.annotations.media.Schema;
7+
import java.time.LocalDateTime;
8+
9+
@Schema(description = "전략 정보")
10+
public record StrategyInfoDao(
11+
@Schema(description = "전략Id", example = "1") Long id,
12+
@Schema(description = "전략명", example = "Strategy-1") String name,
13+
@Schema(description = "코인명", example = "BITCOIN") CoinType coinType,
14+
@Schema(description = "수익팩터") double profitFactor,
15+
@Schema(description = "승률") double winningRate,
16+
@Schema(description = "단리 기준 수익률") double simpleProfitRate,
17+
@Schema(description = "복리 기준 수익률 -> 누적 손익률") double compoundProfitRate,
18+
@Schema(description = "총 수익률(수익율+손실율 아님)") double totalProfitRate,
19+
@Schema(description = "총 손실률") double totalLossRate,
20+
@Schema(description = "평균 수익률") double averageProfitRate,
21+
@Schema(description = "총 거래 횟수") int totalTradeCount,
22+
@Schema(description = "승리 횟수") int winCount,
23+
@Schema(description = "패배 횟수") int lossCount,
24+
@Schema(description = "거래 타입", example = "LONG") TradingType tradingType,
25+
@Schema(description = "진입 시간") LocalDateTime time,
26+
@Schema(description = "진입 가격") int price,
27+
@Schema(description = "평균 봉 수") int averageHoldingPeriod) {
28+
29+
@QueryProjection
30+
public StrategyInfoDao(Long id, String name, CoinType coinType, double profitFactor,
31+
double winningRate, double simpleProfitRate, double compoundProfitRate,
32+
double totalProfitRate, double totalLossRate, double averageProfitRate, int totalTradeCount,
33+
int winCount, int lossCount, TradingType tradingType, LocalDateTime time, int price,
34+
int averageHoldingPeriod) {
35+
this.id = id;
36+
this.name = name;
37+
this.coinType = coinType;
38+
this.profitFactor = profitFactor;
39+
this.winningRate = winningRate;
40+
this.simpleProfitRate = simpleProfitRate;
41+
this.compoundProfitRate = compoundProfitRate;
42+
this.totalProfitRate = totalProfitRate;
43+
this.totalLossRate = totalLossRate;
44+
this.averageProfitRate = averageProfitRate;
45+
this.totalTradeCount = totalTradeCount;
46+
this.winCount = winCount;
47+
this.lossCount = lossCount;
48+
this.tradingType = tradingType;
49+
this.time = time;
50+
this.price = price;
51+
this.averageHoldingPeriod = averageHoldingPeriod;
52+
}
53+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.tradin.module.strategy.strategy.domain.dao;
2+
3+
import com.querydsl.core.annotations.QueryProjection;
4+
import com.tradin.module.strategy.strategy.domain.CoinType;
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
import lombok.Getter;
7+
8+
@Getter
9+
public class SubscriptionStrategyInfoDao {
10+
11+
private final long id;
12+
private final String name;
13+
14+
@Schema(description = "코인명", example = "BITCOIN")
15+
private final CoinType coinType;
16+
17+
@Schema(description = "수익팩터")
18+
private final double profitFactor;
19+
20+
@Schema(description = "승률")
21+
private final double winningRate;
22+
23+
@Schema(description = "복리 기준 수익률 -> 누적 손익률")
24+
private final double compoundProfitRate;
25+
26+
@Schema(description = "평균 수익률")
27+
private final double averageProfitRate;
28+
29+
@QueryProjection
30+
public SubscriptionStrategyInfoDao(long id, String name, CoinType coinType, double profitFactor, double winningRate, double compoundProfitRate, double averageProfitRate) {
31+
this.id = id;
32+
this.name = name;
33+
this.coinType = coinType;
34+
this.profitFactor = profitFactor;
35+
this.winningRate = winningRate;
36+
this.compoundProfitRate = compoundProfitRate;
37+
this.averageProfitRate = averageProfitRate;
38+
}
39+
}

src/test/java/TradinTestApplication.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)