Skip to content

Commit

Permalink
refactor: querydsl config 테스트용 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
shb03323 committed Oct 5, 2023
1 parent ab0172f commit 209ef3a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package touch.baton.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import touch.baton.domain.runnerpost.query.repository.RunnerPostPageRepository;

@TestConfiguration
public class QueryDslRepositoryTestConfig {

@PersistenceContext
private EntityManager em;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(em);
}

@Bean
public RunnerPostPageRepository runnerPostPageRepository() {
return new RunnerPostPageRepository(jpaQueryFactory());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package touch.baton.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
Expand All @@ -24,16 +23,13 @@
import static touch.baton.fixture.vo.DeadlineFixture.deadline;
import static touch.baton.fixture.vo.TagNameFixture.tagName;

@Import({JpaConfig.class, QuerydslConfig.class})
@Import({JpaConfig.class, QueryDslRepositoryTestConfig.class})
@DataJpaTest
public abstract class RepositoryTestConfig {

@Autowired
protected EntityManager em;

@Autowired
protected JPAQueryFactory jpaQueryFactory;

protected Runner persistRunner(final Member member) {
em.persist(member);
final Runner runner = RunnerFixture.createRunner(member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import touch.baton.domain.member.query.repository.SupporterQueryRepository;
import touch.baton.domain.member.query.repository.SupporterRunnerPostQueryRepository;
import touch.baton.domain.runnerpost.command.repository.RunnerPostCommandRepository;
import touch.baton.domain.runnerpost.query.repository.RunnerPostPageRepository;
import touch.baton.domain.runnerpost.query.repository.RunnerPostQueryRepository;
import touch.baton.domain.tag.command.repository.TagCommandRepository;
import touch.baton.domain.tag.query.repository.RunnerPostTagQueryRepository;
Expand All @@ -31,6 +32,9 @@ public abstract class ServiceTestConfig extends RepositoryTestConfig {
@Autowired
protected RunnerPostQueryRepository runnerPostQueryRepository;

@Autowired
protected RunnerPostPageRepository runnerPostPageRepository;

@Autowired
protected SupporterRunnerPostQueryRepository supporterRunnerPostQueryRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -74,8 +75,7 @@ void readRunnerPostByLoginedRunnerAndReviewStatus() throws Exception {

final Runner spyLoginedRunner = spy(loginedRunner);
given(oauthRunnerCommandRepository.joinByMemberSocialId(any())).willReturn(Optional.ofNullable(spyLoginedRunner));
assert spyLoginedRunner != null;
given(spyLoginedRunner.getId()).willReturn(1L);
given(Objects.requireNonNull(spyLoginedRunner).getId()).willReturn(1L);
final RunnerPost spyRunnerPost = spy(runnerPost);
given(spyRunnerPost.getId()).willReturn(1L);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -79,8 +80,7 @@ void readRunnerPostByLoginedSupporterAndReviewStatus() throws Exception {

final Supporter spyLoginedSupporter = spy(loginedSupporter);
given(oauthSupporterCommandRepository.joinByMemberSocialId(any())).willReturn(Optional.ofNullable(spyLoginedSupporter));
assert spyLoginedSupporter != null;
given(spyLoginedSupporter.getId()).willReturn(1L);
given(Objects.requireNonNull(spyLoginedSupporter).getId()).willReturn(1L);
final RunnerPost spyRunnerPost = spy(runnerPost);
given(spyRunnerPost.getId()).willReturn(1L);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package touch.baton.domain.runnerpost.query.repository;

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 touch.baton.config.RepositoryTestConfig;
import touch.baton.domain.member.command.Runner;
import touch.baton.domain.member.command.Supporter;
Expand All @@ -27,13 +27,9 @@

class RunnerPostPageRepositoryTest extends RepositoryTestConfig {

@Autowired
private RunnerPostPageRepository runnerPostPageRepository;

@BeforeEach
void setUp() {
runnerPostPageRepository = new RunnerPostPageRepository(jpaQueryFactory);
}

@DisplayName("러너 게시글을 페이징 조회한다 (중간 페이지 조회)")
@Test
void findByPageInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import touch.baton.domain.runnerpost.command.vo.Title;
import touch.baton.domain.runnerpost.command.vo.WatchedCount;
import touch.baton.domain.runnerpost.query.controller.response.RunnerPostResponse;
import touch.baton.domain.runnerpost.query.repository.RunnerPostPageRepository;
import touch.baton.domain.runnerpost.query.service.dto.PageParams;
import touch.baton.domain.tag.command.RunnerPostTag;
import touch.baton.domain.tag.command.RunnerPostTags;
Expand Down Expand Up @@ -64,7 +63,7 @@ class RunnerPostQueryServiceTest extends ServiceTestConfig {
void setUp() {
runnerPostQueryService = new RunnerPostQueryService(
runnerPostQueryRepository,
new RunnerPostPageRepository(jpaQueryFactory),
runnerPostPageRepository,
runnerPostTagQueryRepository,
supporterRunnerPostQueryRepository);
}
Expand Down

0 comments on commit 209ef3a

Please sign in to comment.