-
Notifications
You must be signed in to change notification settings - Fork 1
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
218 additions
and
34 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
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
59 changes: 59 additions & 0 deletions
59
...code-for-deploy/src/test/java/com/example/seminar/repository/MemberJpaRepositoryTest.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 |
---|---|---|
@@ -1,10 +1,69 @@ | ||
package com.example.seminar.repository; | ||
|
||
import com.example.seminar.domain.Member; | ||
import com.example.seminar.domain.Part; | ||
import com.example.seminar.domain.SOPT; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterEach; | ||
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.test.context.ActiveProfiles; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@DataJpaTest | ||
@ActiveProfiles("test") | ||
public class MemberJpaRepositoryTest { | ||
|
||
@Autowired | ||
MemberJpaRepository memberJpaRepository; | ||
|
||
@Test | ||
@DisplayName("사용자 정보를 입력하면 회원을 등록할 수 있다.") | ||
void save() { | ||
// given | ||
SOPT sopt = SOPT.builder() | ||
.part(Part.SERVER) | ||
.build(); | ||
|
||
Member member = Member.builder() | ||
.age(99) | ||
.name("오해영") | ||
.sopt(sopt) | ||
.nickname("5hae0") | ||
.build(); | ||
|
||
// when | ||
Member savedMember = memberJpaRepository.save(member); | ||
|
||
// then | ||
Assertions.assertThat(savedMember) | ||
.extracting("age", "name", "sopt", "nickname") | ||
.containsExactly(99, "오해영", sopt, "5hae0"); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName("사용자 id를 입력하면 회원을 조회할 수 있다. 존재하지 않는 사용자는 조회할 수 없다.") | ||
void findByIdOrThrow() { | ||
SOPT sopt = SOPT.builder() | ||
.part(Part.SERVER) | ||
.build(); | ||
|
||
Member member = Member.builder() | ||
.age(99) | ||
.name("오해영") | ||
.sopt(sopt) | ||
.nickname("5hae0") | ||
.build(); | ||
|
||
Member savedMember = memberJpaRepository.save(member); | ||
Member findMember = memberJpaRepository.findByIdOrThrow(savedMember.getId()); | ||
|
||
Assertions.assertThat(findMember) | ||
.extracting("id", "age", "name", "sopt", "nickname") | ||
.containsExactly(savedMember.getId(), 99, "오해영", sopt, "5hae0"); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...g-code-for-deploy/src/test/java/com/example/seminar/repository/PostJpaRepositoryTest.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 |
---|---|---|
@@ -1,4 +1,73 @@ | ||
package com.example.seminar.repository; | ||
|
||
import com.example.seminar.domain.Member; | ||
import com.example.seminar.domain.Part; | ||
import com.example.seminar.domain.Post; | ||
import com.example.seminar.domain.SOPT; | ||
import org.assertj.core.api.Assertions; | ||
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.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
|
||
@DataJpaTest | ||
@ActiveProfiles("test") | ||
public class PostJpaRepositoryTest { | ||
|
||
@Autowired | ||
PostJpaRepository postJpaRepository; | ||
|
||
@Autowired | ||
MemberJpaRepository memberJpaRepository; | ||
|
||
@Test | ||
@DisplayName("사용자 이름으로 작성한 게시글을 모두 조회할 수 있다.") | ||
void findAllByMemberNameIn() { | ||
// given | ||
Member member1 = createMember("오해영"); | ||
Member member2 = createMember("또오해영"); | ||
memberJpaRepository.save(member1); | ||
memberJpaRepository.save(member2); | ||
Post post1 = createPost("제목1", "내용1", member1); | ||
Post post2 = createPost("제목2", "내용2", member1); | ||
Post post3 = createPost("제목3", "내용3", member2); | ||
postJpaRepository.saveAll(List.of(post1, post2, post3)); | ||
|
||
// when | ||
List<Post> findPosts = postJpaRepository.findAllByMemberNameIn(List.of("오해영", "또오해영")); | ||
|
||
// then | ||
Assertions.assertThat(findPosts) | ||
.extracting("title", "content") | ||
.containsExactlyInAnyOrder( | ||
Assertions.tuple("제목1", "내용1"), | ||
Assertions.tuple("제목2", "내용2"), | ||
Assertions.tuple("제목3", "내용3") | ||
); | ||
} | ||
|
||
private Post createPost(String title, String content, Member member) { | ||
return Post.builder() | ||
.title(title) | ||
.content(content) | ||
.member(member) | ||
.build(); | ||
} | ||
|
||
private Member createMember(String name) { | ||
SOPT sopt = SOPT.builder() | ||
.part(Part.SERVER) | ||
.build(); | ||
return Member.builder() | ||
.age(99) | ||
.name(name) | ||
.sopt(sopt) | ||
.nickname("5hae0") | ||
.build(); | ||
} | ||
|
||
|
||
} |
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