-
Notifications
You must be signed in to change notification settings - Fork 3
[Board] 1차 제출입니다! #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
95886ea
docs: 기능 구현 목록 작성 및 member 도메인 exception 뼈대 구현
moonwhistle efe1e89
feat: 회원 가입 기능 구현
moonwhistle d35c083
feat: 로그인 기능 구현
moonwhistle 10c682d
feat: interceptor 기능 구현
moonwhistle 242e533
feat: 리졸버 구현
moonwhistle 0a4e8bb
feat: 리졸버 등록
moonwhistle 66961ed
feat: 마이페이지 회원 조회 기능 구현
moonwhistle aa4cf67
feat: 마이페이지 유저 정보 수정 기능 구현
moonwhistle 6d60d48
feat: 마이페이지 계정 탈퇴 기능 구현
moonwhistle 8d6a824
feat: 게시글 생성 기능 구현
moonwhistle 278f6bc
feat: api 테스트를 위한 더미 데이터 추가 기능 구현
moonwhistle 56e5bda
feat: 모든 게시글 조회 기능 구현
moonwhistle e2c2fac
feat: 게시글 단건 조회 기능 구현
moonwhistle 8c4ab2e
feat: 유저 게시글 조회 기능 구현
moonwhistle a4d046b
feat: 게시글 수정 기능 구현
moonwhistle 8c76392
feat: 게시글 삭제 기능 구현
moonwhistle 45e43f5
feat: 댓글 등록 기능 구현
moonwhistle 71d4d4c
feat: 특정 게시글 댓글 조회 기능 구현
moonwhistle 65c75e4
feat: 특정 유저의 댓글 조회 기능 구현
moonwhistle 3f8b554
feat: 댓글 수정 기능 구현
moonwhistle 1ee872c
feat: 댓글 삭제 기능 구현
moonwhistle f2e6d77
feat: swagger 세팅
moonwhistle 5205805
feat: ArticleRepositoryTest 구현
moonwhistle 77fffbb
feat: MemberRepositoryTest 구현
moonwhistle 90637c5
feat: CommentRepositoryTest 구현
moonwhistle 73545cc
refactor: prefix endpoint 를 위한 .yml 파일 작성 및 그에 따른 코드 수정
moonwhistle 9e49589
refactor: error 코드 재사용성을 위한 전체적인 error 코드 구조 수정
moonwhistle 1b81f17
feat: memberServiceTest 구현
moonwhistle ba530b0
feat: CommentServiceTest 구현
moonwhistle 00747c4
feat: ArticleServiceTest 구현
moonwhistle 8d5944b
refactor: 토큰 로직 관련 책임에 따라 메서드 분리
moonwhistle 912c548
feat: AuthServiceTest 구현
moonwhistle 7ae9e51
feat: MemberControllerTest 구현
moonwhistle 12703b3
feat: AuthControllerTest 구현
moonwhistle a8fedce
feat: ArticleControllerTest 구현
moonwhistle d91b26e
feat: CommentControllerTest 구현
moonwhistle 56eb314
feat: offset paging 기능 구현
moonwhistle 37b8313
feat: no-offset paging 기능 구현
moonwhistle 34eaf88
fix: http method 검증을 통해 비회원도 게시글을 조회할 수 있도록 로직 수정
moonwhistle 3537df3
refactor: interceptor allow uri 명시적으로 변경
moonwhistle 4b913db
feat: 비밀번호 암호화 기능 구현
moonwhistle 07cb5e0
refactor: DDD 설계를 통한 로직 구조 변경
moonwhistle c4b57e4
refactor: Member 역참조 수정 및 테스트 코드 수정
moonwhistle 78137cc
refactor: Comment 역참조 수정 및 테스트 코드 수정
moonwhistle b9430f7
refactor: Article 역참조 수정 및 테스트 코드 수정
moonwhistle fcc6f76
feat: Article 삭제 시, Comment 도 같이 삭제되는 기능 구현
moonwhistle 3eabf85
feat: Member 삭제 시, Article 작성자와 Comment 작성자 알 수 없음 처리 기능 구현
moonwhistle d0b81ea
refactor: get / find 컨벤션에 따라 네이밍 리팩토링
moonwhistle 5e146bc
refactor: article paging 반환값을 페이지 정보를 포함해서 반환하도록 리팩토링
moonwhistle e1c23f1
refactor: comment paging 반환값을 페이지 정보를 포함해서 반환하도록 리팩토링
moonwhistle aaade75
docs: 코드 리뷰 생각 정리
moonwhistle be18184
feat: article / comment 객체 연관관계를 간접참조로 수정 및 article 삭제 시, comment 도 삭…
moonwhistle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # Spring Test | ||
|
|
||
| --- | ||
|
|
||
| ## @DataJpaTest와 JUnit을 사용한 Repository 테스트 | ||
|
|
||
| --- | ||
|
|
||
| ### 개요 | ||
|
|
||
| * Spring Boot 애플리케이션에서 Spring Data JPA를 사용하여 데이터베이스를 다룰 때, JPA Repository가 제대로 동작하는지 테스트하는 것이 중요합니다. | ||
|
|
||
| ---- | ||
|
|
||
| ### @DataJpaTest | ||
|
|
||
| * @DataJpaTest 란? -> JPA Repository 테스트를 위한 애너테이션입니다. | ||
| * 최소한의 Spring 컨텍스트만 로드하여 테스트 속도를 높이고, EntityManager와 TestEntityManager를 자동 제공합니다. | ||
| ~~~ | ||
| EntityManager란? | ||
|
|
||
| -> JPA(Java Persistence API)에서 제공하는 기본적인 데이터베이스 관리 도구입니다. | ||
| Spring Boot에서 JPA를 사용할 때, 일반적으로 EntityManager를 사용하여 데이터베이스 작업을 수행합니다. | ||
|
|
||
| EntityManager의 주요 기능 | ||
|
|
||
| 1. 엔티티 저장: persist(entity) | ||
| 2. 엔티티 수정: merge(entity) | ||
| 3. 엔티티 삭제: remove(entity) | ||
| 4. 엔티티 조회: find(Class<T>, primaryKey), createQuery() | ||
|
|
||
| ----------------------------------------------------------------------------------------- | ||
| EntityTestManager란? | ||
|
|
||
| -> 테스트용으로 제공되는 EntityManager입니다. | ||
| Spring Boot의 @DataJpaTest에서 사용할 수 있으며, 일반 EntityManager보다 테스트에 최적화되어 있습니다. | ||
|
|
||
| TestEntityManager의 특징 | ||
|
|
||
| 1. 테스트 중 사용할 수 있도록 간편한 메서드 제공 | ||
| 2. 트랜잭션이 자동 롤백되어 데이터가 남지 않음 | ||
| 3. flush()를 명시적으로 호출하여 즉시 쿼리를 실행 가능 | ||
|
|
||
| ~~~ | ||
| * 애플리케이션 전체를 로드하지 않고, JPA 관련 Bean들만 로드하여 테스트 성능을 최적화합니다. | ||
|
|
||
| --- | ||
|
|
||
| ### @DataJpaTest의 선택적 파라미터 | ||
|
|
||
| **properties 속성** | ||
| * 테스트 환경에서 특정 Spring Boot 설정 값을 변경할 수 있습니다. | ||
| ~~~ | ||
| @DataJpaTest(properties = { | ||
| "spring.datasource.url=jdbc:h2:mem:testdb", | ||
| "spring.jpa.hibernate.ddl-auto=create-drop" | ||
| }) | ||
| public class UserRepositoryTest { | ||
| // 테스트 메서드 작성 | ||
| } | ||
| ~~~ | ||
|
|
||
| **showSql 속성** | ||
| * SQL 쿼리 로그를 출력할지 설정하는 옵션입니다. | ||
| ~~~ | ||
| @DataJpaTest(showSql = false) | ||
| public class UserRepositoryTest { | ||
| // 테스트 메서드 작성 | ||
| } | ||
| ~~~ | ||
|
|
||
| **includeFilters와 excludeFilters** | ||
| * 테스트할 컴포넌트(클래스)를 선택적으로 포함하거나 제외할 수 있습니다. | ||
|
|
||
| --- | ||
|
|
||
| ### 주요 기능 | ||
|
|
||
| * 테스트 환경 구성 | ||
| * @DataJpaTest는 테스트를 위한 DB 환경을 자동으로 구성해줍니다. | ||
| * 일반적으로 H2 인메모리 데이터베이스를 사용하여, 테스트 후 자동으로 데이터가 삭제됩니다. | ||
|
|
||
| * 의존성 주입 | ||
| * @DataJpaTest를 사용하면 Repository 빈이 자동으로 주입되어 테스트할 수 있습니다. | ||
|
|
||
| * 기본적으로 트랜잭션 롤백 | ||
| * 각 테스트 메서드는 트랜잭션 내부에서 실행되며, 테스트가 끝나면 데이터가 자동으로 롤백됩니다. | ||
| * 테스트 간 데이터가 격리(독립적) 되므로, 테스트 실행 순서에 영향을 받지 않습니다. | ||
|
|
||
| --- | ||
|
|
||
| ### Repository 테스트 구현 | ||
|
|
||
| * 테스트 라이프사이클 관리 | ||
| ~~~ | ||
| private User testUser; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| testUser = new User(); | ||
| testUser.setUsername("testuser"); | ||
| testUser.setPassword("password"); | ||
| userRepository.save(testUser); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| userRepository.delete(testUser); | ||
| } | ||
| ~~~ | ||
| 1. @BeforeEach : 각 테스트 시작 전 실행 → 테스트 데이터를 초기화 | ||
| 2. @AfterEach : 각 테스트 종료 후 실행 → 테스트 데이터 정리(삭제) | ||
|
|
||
|
|
||
| 출처: baeldung | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
25 changes: 25 additions & 0 deletions
25
src/test/java/com/board/article/loader/ArticleTestDataLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.board.article.loader; | ||
|
|
||
| import com.board.article.domain.Article; | ||
| import com.board.article.repository.ArticleRepository; | ||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.boot.test.context.TestConfiguration; | ||
| import org.springframework.context.annotation.Bean; | ||
|
|
||
| @TestConfiguration | ||
| public class ArticleTestDataLoader { | ||
|
|
||
| private final ArticleRepository repository; | ||
|
|
||
| public ArticleTestDataLoader(ArticleRepository repository) { | ||
| this.repository = repository; | ||
| } | ||
|
|
||
| @Bean | ||
| public CommandLineRunner testData() { | ||
| return args -> { | ||
| repository.save(new Article(1L, "신형만에 관하여", "아내는 신봉선")); | ||
| repository.save(new Article(1L, "신짱구", "바보")); | ||
| }; | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/test/java/com/board/article/repository/ArticleRepositoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.board.article.repository; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.board.article.domain.Article; | ||
| import com.board.article.loader.ArticleTestDataLoader; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| @DataJpaTest | ||
| @Import(ArticleTestDataLoader.class) | ||
| class ArticleRepositoryTest { | ||
|
|
||
| @Autowired | ||
| private ArticleRepository articleRepository; | ||
|
|
||
| @Test | ||
| @DisplayName("멤버 아이디에 해당하는 게시글을 가져온다.") | ||
| void findArticleByMemberId() { | ||
| // given | ||
| Long memberId = 1L; | ||
|
|
||
| // when | ||
| List<Article> articles = articleRepository.findArticleByMemberId(memberId); | ||
|
|
||
| // then | ||
| assertThat(articles).hasSize(2); | ||
| assertThat(articles).extracting(Article::getTitle) | ||
| .containsExactly("신형만에 관하여", "신짱구"); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.