-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEST(project) :: ProjectRepositoryTest 작성
- Loading branch information
1 parent
47b870a
commit 2f0c284
Showing
6 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
...eya/zoing/project/domain/ProjectTest.java → ...ng/domain/project/domain/ProjectTest.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
22 changes: 22 additions & 0 deletions
22
src/test/java/com/woongeya/zoing/domain/project/domain/fixture/ProjectFixture.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,22 @@ | ||
package com.woongeya.zoing.domain.project.domain.fixture; | ||
|
||
import java.time.LocalDate; | ||
|
||
import com.woongeya.zoing.domain.project.domain.Project; | ||
import com.woongeya.zoing.domain.project.domain.type.ProjectState; | ||
|
||
public class ProjectFixture { | ||
|
||
public static Project 프로젝트() { | ||
return Project.builder() | ||
.name("쪼잉") | ||
.content("쪼잉으로 오세용") | ||
.imgUrl("iamge") | ||
.viewCount(0L) | ||
.state(ProjectState.FINDING) | ||
.requiredPeople(4) | ||
.currentPeople(1) | ||
.endDate(LocalDate.now()) | ||
.build(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/com/woongeya/zoing/domain/project/domain/repository/ProjectRepositoryTest.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,63 @@ | ||
package com.woongeya.zoing.domain.project.domain.repository; | ||
|
||
import static com.woongeya.zoing.domain.project.domain.fixture.ProjectFixture.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.woongeya.zoing.domain.project.domain.Project; | ||
import com.woongeya.zoing.global.repository.RepositoryTest; | ||
|
||
public class ProjectRepositoryTest extends RepositoryTest { | ||
|
||
@Autowired | ||
private ProjectRepository projectRepository; | ||
|
||
@Test | ||
void 모든_프로젝트를_조회할_수_있다() { | ||
// given | ||
Project 저장된_프로젝트1 = 프로젝트_저장(프로젝트()); | ||
Project 저장된_프로젝트2 = 프로젝트_저장(프로젝트()); | ||
|
||
// when | ||
List<Project> 조회된_프로젝트들 = projectRepository.findAll(); | ||
|
||
// then | ||
assertThat(조회된_프로젝트들).contains(저장된_프로젝트1, 저장된_프로젝트2); | ||
} | ||
|
||
@Test | ||
void 아이디로_프로젝트를_조회할_수_있다() { | ||
// given | ||
Project 저장된_프로젝트 = 프로젝트_저장(프로젝트()); | ||
Long 아이디 = 저장된_프로젝트.getId(); | ||
|
||
// when | ||
Project 조회된_프로젝트 = projectRepository.findById(아이디).get(); | ||
|
||
// then | ||
assertThat(조회된_프로젝트).isEqualTo(저장된_프로젝트); | ||
} | ||
|
||
@Test | ||
void 프로젝트를_삭제할_수_있다() { | ||
// given | ||
Project 저장된_프로젝트 = 프로젝트_저장(프로젝트()); | ||
Long 아이디 = 저장된_프로젝트.getId(); | ||
|
||
// when | ||
projectRepository.delete(저장된_프로젝트); | ||
|
||
// then | ||
assertThatThrownBy(() -> projectRepository.findById(아이디).get()) | ||
.isInstanceOf(NoSuchElementException.class); | ||
} | ||
|
||
private Project 프로젝트_저장(Project project) { | ||
return projectRepository.save(project); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/woongeya/zoing/global/config/QueryDslTestConfig.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,21 @@ | ||
package com.woongeya.zoing.global.config; | ||
|
||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
|
||
@TestConfiguration | ||
public class QueryDslTestConfig { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/com/woongeya/zoing/global/repository/RepositoryTest.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,15 @@ | ||
package com.woongeya.zoing.global.repository; | ||
|
||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import com.woongeya.zoing.global.config.JpaConfig; | ||
import com.woongeya.zoing.global.config.QueryDslTestConfig; | ||
|
||
@DataJpaTest | ||
@Import({JpaConfig.class, QueryDslTestConfig.class}) | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
public abstract class RepositoryTest { | ||
} |
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