Skip to content

Commit

Permalink
[BE] refactor: MockData 설정 로직 리팩터링 및 테스트 속도 개선 (#839) (#860)
Browse files Browse the repository at this point in the history
* fix: 중복으로 실행되는 Mock Data 설정 수정

- MockScheduler initialDelay 추가
- CommandLineAppStartupRunner MockScheduler 의존 제거

* refactor: Mock 아티스트, 학교 생성 로직 분리

* test: 테스트 코드 개선

- 일부 테스트 로직 간결하게 변경
- 트랜잭션 제거

* feat: 도메인 엔티티를 반환하는 MockGenerator 구현

* refactor: Mock 생성 로직 MockGenerator를 사용하도록 리팩터링

* refactor: 패키지 위치 정리, MockDataServiceIntegrationTest 검증 로직 정리

* refactor: 사용하지 않는 클래스 제거

* refactor: 어플리케이션 실행마다 축제 생성 방지

* refactor: 클래스, 메서드 명 명확하게 변경

* fix: 스케줄러 TimeUnit 수정

* feat: MockDataStartupInitializer 트랜잭션 적용하여 원자성 보장

* chore: 메서드명 수정

* chore: 학교 이름 뒤 추가하는 인덱스 제거

* refactor: 축제 생성 시 이름 "테코대학교 20770630 축제" 와 같은 포맷으로 변경

* test: given-when-then 잘못된 위치 수정

* chore: MockStageArtistsGenerator Javadoc 추가

* feat: MockFestivalDurationGenerator 추가

* refactor: 비즈니스 로직에 사용되는 변수 도메인으로 이동 및 MockFestivalDurationGenerator 사용하도록 변경

* feat: StageArtist notNull 검증 추가

- stageId, artistId
  • Loading branch information
seokjin8678 authored Apr 18, 2024
1 parent 7a9ada4 commit 4f6db52
Show file tree
Hide file tree
Showing 27 changed files with 695 additions and 650 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.festago.festival.domain;

import com.festago.common.exception.BadRequestException;
import com.festago.common.exception.ErrorCode;
import com.festago.common.util.Validator;
import jakarta.persistence.Embeddable;
import java.time.LocalDate;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@Embeddable
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class FestivalDuration {

private LocalDate startDate;
private LocalDate endDate;

public FestivalDuration(LocalDate startDate, LocalDate endDate) {
validate(startDate, endDate);
this.startDate = startDate;
this.endDate = endDate;
}

private void validate(LocalDate startDate, LocalDate endDate) {
Validator.notNull(startDate, "startDate");
Validator.notNull(endDate, "endDate");
if (startDate.isAfter(endDate)) {
throw new BadRequestException(ErrorCode.INVALID_FESTIVAL_DURATION);
}
}

public boolean isBeforeStartDate(LocalDate date) {
return startDate.isBefore(date);
}

public boolean isNotInDuration(LocalDate date) {
return date.isBefore(startDate) || date.isAfter(endDate);
}

public LocalDate getStartDate() {
return startDate;
}

public LocalDate getEndDate() {
return endDate;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.festago.mock;

import com.festago.mock.application.MockDataService;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Profile("dev")
@Profile({"dev"})
@Component
@RequiredArgsConstructor
public class MockScheduler {
public class MockDataInitialScheduler {

private static final long SCHEDULER_CYCLE = 7;
private static final long DAYS_OF_WEEK = 7L;
private final MockDataService mockDataService;

@Scheduled(fixedDelay = SCHEDULER_CYCLE, timeUnit = TimeUnit.DAYS)
public void run() {
mockDataService.makeMockFestivals((int) SCHEDULER_CYCLE);
@Scheduled(initialDelay = DAYS_OF_WEEK, fixedDelay = DAYS_OF_WEEK, timeUnit = TimeUnit.DAYS)
public void createMockFestivals() {
mockDataService.makeMockFestivals();
}
}
216 changes: 0 additions & 216 deletions backend/src/main/java/com/festago/mock/MockDataService.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.festago.mock;

import com.festago.mock.application.MockDataService;
import com.festago.mock.repository.ForMockSchoolRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Profile({"dev"})
@Component
@RequiredArgsConstructor
public class MockDataStartupInitializer {

private final ForMockSchoolRepository forMockSchoolRepository;
private final MockDataService mockDataService;

@Transactional
@EventListener(ApplicationReadyEvent.class)
public void initialize() {
if (forMockSchoolRepository.count() == 0) {
mockDataService.makeMockArtists();
mockDataService.makeMockSchools();
mockDataService.makeMockFestivals();
}
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4f6db52

Please sign in to comment.