-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
378 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
66 changes: 66 additions & 0 deletions
66
community/src/test/java/efub/assignment/community/account/AccountRepositoryTest.java
This file contains 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,66 @@ | ||
package efub.assignment.community.account; | ||
|
||
import efub.assignment.community.account.domain.Account; | ||
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.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@DataJpaTest | ||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
@ActiveProfiles("test") | ||
class AccountRepositoryTest { | ||
|
||
@Autowired | ||
private AccountRepository accountRepository; | ||
|
||
@Test | ||
@DisplayName("이메일 중복 확인 - 성공") | ||
void validateEmail() { | ||
// given | ||
Account account = Account.builder() | ||
.email("[email protected]") | ||
.password("password123") | ||
.nickname("fubie") | ||
.university("이화여자대학교") | ||
.studentId("1234567") | ||
.build(); | ||
accountRepository.save(account); | ||
|
||
// when | ||
Boolean exists = accountRepository.existsByEmail("[email protected]"); | ||
|
||
// then | ||
assertTrue(exists, "이메일이 존재합니다."); | ||
} | ||
|
||
@Test | ||
@DisplayName("닉네임으로 계정 조회 - 실패") | ||
void findByNickname() { | ||
// given | ||
Account account = Account.builder() | ||
.email("[email protected]") | ||
.password("password123") | ||
.nickname("fubie") | ||
.university("이화여자대학교") | ||
.studentId("1234567") | ||
.build(); | ||
accountRepository.save(account); | ||
String searchNickname = "iamfubie"; | ||
|
||
// when | ||
Optional<Account> searchAccount = accountRepository.findByNickname(searchNickname); | ||
|
||
// then | ||
assertFalse(searchAccount.isPresent(), "존재하지 않는 닉네임입니다."); | ||
} | ||
|
||
|
||
} |
65 changes: 65 additions & 0 deletions
65
community/src/test/java/efub/assignment/community/account/domain/AccountTest.java
This file contains 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,65 @@ | ||
package efub.assignment.community.account.domain; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@DataJpaTest | ||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
@ActiveProfiles("test") | ||
class AccountTest { | ||
|
||
@Test | ||
@DisplayName("Account 생성 - 성공") | ||
void createAccount() { | ||
// given | ||
String email = "[email protected]"; | ||
String password = "password123"; | ||
String nickname = "fubie"; | ||
String university = "이화여자대학교"; | ||
String studentId = "1234567"; | ||
|
||
// when | ||
Account account = Account.builder() | ||
.email(email) | ||
.password(password) | ||
.nickname(nickname) | ||
.university(university) | ||
.studentId(studentId) | ||
.build(); | ||
|
||
// then | ||
assertAll("Account 필드 값 검증", | ||
() -> assertEquals(email, account.getEmail()), | ||
() -> assertEquals(password, account.getPassword()), | ||
() -> assertEquals(nickname, account.getNickname()), | ||
() -> assertEquals(university, account.getUniversity()), | ||
() -> assertEquals(studentId, account.getStudentId()), | ||
() -> assertEquals(AccountStatus.REGISTERED, account.getStatus()) | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("비어 있는 닉네임으로 업데이트 - 실패") | ||
void updateAccount(){ | ||
// given | ||
Account account = Account.builder() | ||
.email("[email protected]") | ||
.password("password123") | ||
.nickname("fubie") | ||
.university("이화여자대학교") | ||
.studentId("1234567") | ||
.build(); | ||
|
||
// when | ||
String newNickname = ""; | ||
|
||
// then | ||
assertTrue(newNickname.isEmpty(), "닉네임은 비어 있을 수 없습니다."); | ||
} | ||
|
||
} |
127 changes: 127 additions & 0 deletions
127
community/src/test/java/efub/assignment/community/post/PostRepositoryTest.java
This file contains 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,127 @@ | ||
package efub.assignment.community.post; | ||
|
||
import efub.assignment.community.account.AccountRepository; | ||
import efub.assignment.community.account.domain.Account; | ||
import efub.assignment.community.board.BoardRepository; | ||
import efub.assignment.community.board.domain.Board; | ||
import efub.assignment.community.post.domain.Post; | ||
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 org.springframework.boot.jdbc.EmbeddedDatabaseConnection; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@DataJpaTest | ||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
@ActiveProfiles("test") | ||
class PostRepositoryTest { | ||
@Autowired | ||
private TestEntityManager testEntityManager; | ||
|
||
@Autowired | ||
private PostRepository postRepository; | ||
|
||
@Autowired | ||
private AccountRepository accountRepository; | ||
|
||
@Autowired | ||
private BoardRepository boardRepository; | ||
|
||
private Account account; | ||
private Board board; | ||
|
||
@BeforeEach | ||
void setup() { | ||
account = Account.builder() | ||
.email("[email protected]") | ||
.password("password123") | ||
.nickname("fubie") | ||
.university("이화여자대학교") | ||
.studentId("1234567") | ||
.build(); | ||
testEntityManager.persist(account); | ||
|
||
board = Board.builder() | ||
.account(account) | ||
.boardName("테스트 게시판") | ||
.boardDescription("테스트 설명") | ||
.boardNotice("테스트 공지사항") | ||
.build(); | ||
testEntityManager.persist(board); | ||
testEntityManager.flush(); | ||
} | ||
|
||
@Test | ||
@DisplayName("writerOpen이 true인 Post 조회 - 성공") | ||
void findPublicPost() { | ||
// given | ||
String title1 = "공개 게시글"; | ||
String content1 = "이건 보여야 함"; | ||
Boolean writerOpen1 = true; | ||
|
||
String title2 = "비공개 게시글"; | ||
String content2 = "이건 안 보여야 함"; | ||
Boolean writerOpen2 = false; | ||
|
||
Post publicPost = Post.builder() | ||
.account(account) | ||
.board(board) | ||
.title(title1) | ||
.content(content1) | ||
.writerOpen(writerOpen1) | ||
.build(); | ||
testEntityManager.persist(publicPost); | ||
|
||
Post privatePost = Post.builder() | ||
.account(account) | ||
.board(board) | ||
.title(title2) | ||
.content(content2) | ||
.writerOpen(writerOpen2) | ||
.build(); | ||
testEntityManager.persist(privatePost); | ||
testEntityManager.flush(); | ||
|
||
// when | ||
List<Post> openPosts = postRepository.findByWriterOpen(true); | ||
|
||
// then | ||
assertEquals(1, openPosts.size(), "writerOpen이 true인 게시글이 하나여야 합니다."); | ||
assertEquals(title1, openPosts.get(0).getTitle(), "조회된 게시글의 제목이 일치해야 합니다."); | ||
} | ||
|
||
|
||
@Test | ||
@DisplayName("Post 조회 실패 - 존재하지 않는 ID") | ||
void findPostByDeletedId() { | ||
// given | ||
Post post = Post.builder() | ||
.account(account) | ||
.board(board) | ||
.title("제목") | ||
.content("내용") | ||
.writerOpen(true) | ||
.build(); | ||
testEntityManager.persist(post); | ||
testEntityManager.flush(); | ||
Long deletedId = post.getPostId(); | ||
postRepository.delete(post); | ||
testEntityManager.flush(); | ||
|
||
// when | ||
Optional<Post> searchPost = postRepository.findById(deletedId); | ||
|
||
// then | ||
assertFalse(searchPost.isPresent(), "존재하지 않는 ID로 Post를 조회할 수 없습니다. "); | ||
} | ||
|
||
} |
Oops, something went wrong.