Skip to content

20260125 #196 백테스팅 dto 예외처리 테스트 리팩토링#197

Merged
ykh4663 merged 5 commits intomainfrom
20260125_#196_백테스팅_DTO_예외처리_테스트_리팩토링
Jan 31, 2026

Hidden character warning

The head ref may contain hidden characters: "20260125_#196_\ubc31\ud14c\uc2a4\ud305_DTO_\uc608\uc678\ucc98\ub9ac_\ud14c\uc2a4\ud2b8_\ub9ac\ud329\ud1a0\ub9c1"
Merged

20260125 #196 백테스팅 dto 예외처리 테스트 리팩토링#197
ykh4663 merged 5 commits intomainfrom
20260125_#196_백테스팅_DTO_예외처리_테스트_리팩토링

Conversation

@ykh4663
Copy link
Contributor

@ykh4663 ykh4663 commented Jan 25, 2026

Refactor

  • DTO 구조 개선 (Java Record 도입): StrategyCondition, StrategyOperand, TradeLog, BacktestRunMetricsResponse 등을 record로 변환하여 코드를 간소화했습니다.

  • Enum 분리: TradeLog 내부에 있던 거래 유형을 TradeType Enum으로 분리하여 가독성과 재사용성을 높였습니다.

  • 서비스 로직 동기화: Record 변환에 맞춰 Ta4jHelperService와 BacktestingEngine의 데이터 접근 방식(Getter)을 수정했습니다 (getXXX() → XXX()).

예외 처리 표준화: Ta4jHelperService에서 발생하던 IllegalArgumentException을 CustomException(ErrorCode)으로 교체하여 에러 응답을 통일했습니다.(500->400)

Test

  • 단위 테스트 추가: 리팩토링된 Ta4jHelperService의 데이터 변환 로직과 예외 처리가 정상적으로 동작하는지 검증하는 Ta4jHelperServiceTest를 작성했습니다.(실제 테스트 코드 돌리는 부분은 타 도메인 테스트 코드 오류로 인해 추후 검증 예정)

Summary by CodeRabbit

  • Bug Fixes / Chores

    • 백테스트 파라미터 검증 강화 및 구체적인 오류 메시지 제공
    • 지원하지 않는 지표·피연산자 입력 시 명확한 에러 응답 개선
    • 거래 로그 및 관련 데이터 구조 정리로 안정성 향상
    • 내부 불필요 코드 정리 및 예외 처리 표준화
  • Tests

    • 백테스트 관련 핵심 기능과 오류 처리에 대한 단위 테스트 추가 및 보강

✏️ Tip: You can customize this high-level summary in your review settings.

@ykh4663 ykh4663 requested a review from discipline24 as a code owner January 25, 2026 04:31
@ykh4663 ykh4663 added the BE 백엔드 이슈 label Jan 25, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 25, 2026

Walkthrough

여러 백테스트 DTO를 클래스에서 Java 레코드로 전환하고, TradeType enum을 도입했으며, Ta4jHelperService 및 BacktestingEngine에서 레코드 접근자와 CustomException 기반 예외 처리를 적용하고 관련 테스트를 추가/수정했습니다.

Changes

Cohort / File(s) Summary
DTO → record 변환
backend/src/main/java/org/sejongisc/backend/backtest/dto/BacktestRunMetricsResponse.java, backend/src/main/java/org/sejongisc/backend/backtest/dto/StrategyCondition.java, backend/src/main/java/org/sejongisc/backend/backtest/dto/StrategyOperand.java, backend/src/main/java/org/sejongisc/backend/backtest/dto/TradeLog.java
Lombok 기반 가변 클래스들을 불변 Java 레코드로 변경. 접근자 메서드가 게터 스타일에서 레코드 컴포넌트 스타일로 바뀜; 일부 유효성(@NotNull) 및 Schema 주석 이동.
새 Enum 추출
backend/src/main/java/org/sejongisc/backend/backtest/dto/TradeType.java
TradeLog 내부 enum을 별도 public enum TradeType(BUY, SELL, SELL_FORCED)로 추가.
서비스·핵심 로직 업데이트
backend/src/main/java/org/sejongisc/backend/backtest/service/Ta4jHelperService.java, backend/src/main/java/org/sejongisc/backend/backtest/service/BacktestingEngine.java
DTO 레코드 접근자 호출로 코드 전환, TradeType 사용으로 로그 생성 변경, 예외 처리 경로를 IllegalArgumentException → CustomException(ErrorCode.*)로 표준화.
공통 에러 코드 확장
backend/src/main/java/org/sejongisc/backend/common/exception/ErrorCode.java
백테스트 관련 ErrorCode 4개 추가(INVALID_BACKTEST_PARAMS, BACKTEST_INDICATOR_NOT_FOUND, BACKTEST_OPERAND_INVALID, BACKTEST_EXECUTION_FAILED).
엔티티 보조 변경
backend/src/main/java/org/sejongisc/backend/stock/entity/PriceData.java
@AllArgsConstructor, @Builder 어노테이션 추가(빌더/전체 인자 생성자 생성).
임포트 정리 및 소규모 수정
backend/src/main/java/org/sejongisc/backend/backtest/dto/BacktestRequest.java, .../BacktestResponse.java, .../BacktestRunRequest.java
사용되지 않는 import 제거.
테스트 추가/수정
backend/src/test/java/org/sejongisc/backend/backtest/service/Ta4jHelperServiceTest.java, backend/src/test/java/org/sejongisc/backend/backtest/service/BacktestServiceTest.java
Ta4jHelperService에 대한 단위 테스트 추가 및 BacktestServiceTest에서 레코드 접근자명(sharpeRatio())에 맞춰 수정.

Sequence Diagram(s)

(생성 조건 미충족 — 생략)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • Kosw6
  • ochanhyeok

Poem

🐰 레코드로 변신한 DTO, 가볍게 폴짝폴짝
오류는 정리하고, 타입은 빳빳하게
서비스는 더 단정히 규칙을 지키고
테스트도 함께 뛰놀며 확인했네
토끼가 축하하네, 커밋에 당근 한 송이 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 주요 변경사항인 DTO 리팩토링(클래스 → 레코드 변환), 예외 처리 표준화, 테스트 추가를 명확하게 요약하고 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 20260125_#196_백테스팅_DTO_예외처리_테스트_리팩토링

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ykh4663 ykh4663 linked an issue Jan 25, 2026 that may be closed by this pull request
3 tasks
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/src/main/java/org/sejongisc/backend/backtest/service/Ta4jHelperService.java (1)

207-212: MACD 지표의 output이 null일 때 NullPointerException 발생 위험

StrategyOperand의 output 필드는 선택사항이며 null 값이 가능합니다. 현재 코드는 207-212줄의 switch 문에서 직접 operand.output()을 사용하여 null일 경우 NPE가 발생합니다. 같은 파일의 BB 지표(227줄)처럼 null을 처리하여 기본값을 제공해야 합니다.

🛠️ 수정 제안
-                return switch (operand.output()) {
+                String output = operand.output();
+                return switch (output == null ? "macd" : output) {
                     case "macd" -> macd;
                     case "signal" -> signalLine;
                     case "hist" -> new ManualMACDHistogramIndicator(macd, signalLine);
                     default -> macd;
                 };
🤖 Fix all issues with AI agents
In
`@backend/src/test/java/org/sejongisc/backend/backtest/service/Ta4jHelperServiceTest.java`:
- Around line 71-73: The right StrategyOperand is being constructed with null
for its params but the StrategyOperand.params field is `@NotNull` and should
receive an empty map when there are no params; update the right StrategyOperand
construction to pass Map.of() instead of null (mirroring how the left operand is
created) so the params constraint and the comment "비어있더라도 {} 전달" are satisfied.

@cksdid202
Copy link
Contributor

고생하셨습니다 ! 토끼 리뷰만 반영하면 될 것 같아용 ~~

cksdid202
cksdid202 previously approved these changes Jan 28, 2026
discipline24
discipline24 previously approved these changes Jan 28, 2026
Copy link
Contributor

@discipline24 discipline24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~

Yooonjeong
Yooonjeong previously approved these changes Jan 28, 2026
Copy link
Contributor

@Yooonjeong Yooonjeong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

record로 변경하니 깔끔하고 좋네여 고생하셨습니당~

@ykh4663 ykh4663 dismissed stale reviews from Yooonjeong, discipline24, and cksdid202 via efbfa0a January 31, 2026 02:15
@ykh4663 ykh4663 merged commit 8d6f5d3 into main Jan 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BE 백엔드 이슈

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[기능개선][BE] 백테스팅 엔진 구조 개선 및 테스트 코드 작성

4 participants