From 5b4cf737739d08a9ea6aae2b91cc4c0eccbee50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EB=93=A0?= <67811880+nathan29849@users.noreply.github.com> Date: Wed, 8 Feb 2023 19:24:30 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AA=A9=ED=91=9C=20=EB=B0=8F=20=EC=A3=BC?= =?UTF-8?q?=EC=A0=9C=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=99=84=EB=A3=8C=20(#103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: [#101] Goal 전체 조회 기능 구현 및 테스트 완료 `` * feat: [#101] Subject 전체 조회 기능 구현 및 테스트 완료 --- .../response/ResponseCodeAndMessages.java | 6 ++ .../dto/response/SubjectResponse.java | 10 ++- .../core/application/member/GoalService.java | 29 +++++++ .../{ => member}/MemberService.java | 2 +- .../application/member/SubjectService.java | 28 +++++++ .../core/domain/member/subject/Subject.java | 6 +- .../be/core/web/member/GoalController.java | 30 ++++++++ .../web/{ => member}/MemberController.java | 4 +- .../be/core/web/member/SubjectController.java | 30 ++++++++ .../be/oauth/provider/LoginService.java | 2 +- .../goal_subject/GoalFindAllTest.java | 45 +++++++++++ .../goal_subject/SubjectFindAllTest.java | 47 +++++++++++ .../application/member/MemberFollowTest.java | 1 - .../application/member/MemberModifyTest.java | 2 - .../application/member/MemberMyPageTest.java | 2 - .../application/member/MemberSignUpTest.java | 1 - .../GoalControllerFindAllTest.java | 71 +++++++++++++++++ .../SubjectControllerFindAllTest.java | 77 +++++++++++++++++++ .../member/MemberControllerFollowTest.java | 3 +- .../member/MemberControllerModifyTest.java | 12 +-- .../member/MemberControllerMyPageTest.java | 12 +-- .../member/MemberControllerSignUpTest.java | 13 ++-- .../example/be/tool/DataBaseConfigurator.java | 20 ++--- 23 files changed, 412 insertions(+), 41 deletions(-) create mode 100644 be/src/main/java/com/example/be/core/application/member/GoalService.java rename be/src/main/java/com/example/be/core/application/{ => member}/MemberService.java (99%) create mode 100644 be/src/main/java/com/example/be/core/application/member/SubjectService.java create mode 100644 be/src/main/java/com/example/be/core/web/member/GoalController.java rename be/src/main/java/com/example/be/core/web/{ => member}/MemberController.java (97%) create mode 100644 be/src/main/java/com/example/be/core/web/member/SubjectController.java create mode 100644 be/src/test/java/com/example/be/core/application/goal_subject/GoalFindAllTest.java create mode 100644 be/src/test/java/com/example/be/core/application/goal_subject/SubjectFindAllTest.java create mode 100644 be/src/test/java/com/example/be/core/web/goal_subject/GoalControllerFindAllTest.java create mode 100644 be/src/test/java/com/example/be/core/web/goal_subject/SubjectControllerFindAllTest.java diff --git a/be/src/main/java/com/example/be/common/response/ResponseCodeAndMessages.java b/be/src/main/java/com/example/be/common/response/ResponseCodeAndMessages.java index a4642fbb..a548516d 100644 --- a/be/src/main/java/com/example/be/common/response/ResponseCodeAndMessages.java +++ b/be/src/main/java/com/example/be/common/response/ResponseCodeAndMessages.java @@ -58,6 +58,12 @@ public enum ResponseCodeAndMessages implements CodeAndMessages { FIND_DETAIL_ASSIGNMENT_SUCCESS("S-A003", "과제 개별 조회를 성공했습니다."), MODIFY_ASSIGNMENT_SUCCESS("S-A004", "과제 수정을 성공했습니다"), DELETE_ASSIGNMENT_SUCCESS("S-A005", "과제 삭제를 성공했습니다"), + + /** + * Goal & Subject + */ + FIND_ALL_GOALS_SUCCESS("S-GS001", "목표 조회를 성공했습니다."), + FIND_ALL_SUBJECTS_SUCCESS("S-GS002", "주제 조회를 성공했습니다."), ; private final String code; diff --git a/be/src/main/java/com/example/be/core/application/dto/response/SubjectResponse.java b/be/src/main/java/com/example/be/core/application/dto/response/SubjectResponse.java index c7a61947..44010a95 100644 --- a/be/src/main/java/com/example/be/core/application/dto/response/SubjectResponse.java +++ b/be/src/main/java/com/example/be/core/application/dto/response/SubjectResponse.java @@ -8,13 +8,19 @@ public class SubjectResponse { private final Long subjectId; private final String content; + private final String image; - private SubjectResponse(Long subjectId, String content) { + private SubjectResponse(Long subjectId, String content, String image) { this.subjectId = subjectId; this.content = content; + this.image = image; } public static SubjectResponse of(Subject subject) { - return new SubjectResponse(subject.getId(), subject.getContent()); + return new SubjectResponse( + subject.getId(), + subject.getContent(), + subject.getImage() + ); } } diff --git a/be/src/main/java/com/example/be/core/application/member/GoalService.java b/be/src/main/java/com/example/be/core/application/member/GoalService.java new file mode 100644 index 00000000..190d7ace --- /dev/null +++ b/be/src/main/java/com/example/be/core/application/member/GoalService.java @@ -0,0 +1,29 @@ +package com.example.be.core.application.member; + +import com.example.be.core.application.dto.response.GoalResponse; +import com.example.be.core.domain.member.goal.Goal; +import com.example.be.core.repository.member.goal.GoalRepository; +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +public class GoalService { + + private final GoalRepository goalRepository; + + public GoalService(GoalRepository goalRepository) { + this.goalRepository = goalRepository; + } + + + public List findAll() { + + List goals = goalRepository.findAll(); + return goals.stream() + .map(GoalResponse::of) + .collect(Collectors.toList()); + } +} diff --git a/be/src/main/java/com/example/be/core/application/MemberService.java b/be/src/main/java/com/example/be/core/application/member/MemberService.java similarity index 99% rename from be/src/main/java/com/example/be/core/application/MemberService.java rename to be/src/main/java/com/example/be/core/application/member/MemberService.java index 8cf6d795..0da8c6e4 100644 --- a/be/src/main/java/com/example/be/core/application/MemberService.java +++ b/be/src/main/java/com/example/be/core/application/member/MemberService.java @@ -1,4 +1,4 @@ -package com.example.be.core.application; +package com.example.be.core.application.member; import static com.example.be.core.domain.member.grade.SpeakingGradeType.GIVER; import static com.example.be.core.domain.member.grade.SpeakingGradeType.LEARNER; diff --git a/be/src/main/java/com/example/be/core/application/member/SubjectService.java b/be/src/main/java/com/example/be/core/application/member/SubjectService.java new file mode 100644 index 00000000..832b3cb1 --- /dev/null +++ b/be/src/main/java/com/example/be/core/application/member/SubjectService.java @@ -0,0 +1,28 @@ +package com.example.be.core.application.member; + +import com.example.be.core.application.dto.response.SubjectResponse; +import com.example.be.core.domain.member.subject.Subject; +import com.example.be.core.repository.member.subject.SubjectRepository; +import java.util.List; +import java.util.stream.Collectors; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +public class SubjectService { + + private final SubjectRepository subjectRepository; + + public SubjectService(SubjectRepository subjectRepository) { + this.subjectRepository = subjectRepository; + } + + public List findAll() { + List subjects = subjectRepository.findAll(); + return subjects.stream() + .map(SubjectResponse::of) + .collect(Collectors.toList()); + } + +} diff --git a/be/src/main/java/com/example/be/core/domain/member/subject/Subject.java b/be/src/main/java/com/example/be/core/domain/member/subject/Subject.java index dcb3c578..6141b7da 100644 --- a/be/src/main/java/com/example/be/core/domain/member/subject/Subject.java +++ b/be/src/main/java/com/example/be/core/domain/member/subject/Subject.java @@ -3,7 +3,6 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; import javax.persistence.Id; import lombok.AccessLevel; import lombok.Getter; @@ -21,8 +20,11 @@ public class Subject { private String content; - public Subject(Long id, String content) { + private String image; + + public Subject(Long id, String content, String image) { this.id = id; this.content = content; + this.image = image; } } diff --git a/be/src/main/java/com/example/be/core/web/member/GoalController.java b/be/src/main/java/com/example/be/core/web/member/GoalController.java new file mode 100644 index 00000000..eaf04428 --- /dev/null +++ b/be/src/main/java/com/example/be/core/web/member/GoalController.java @@ -0,0 +1,30 @@ +package com.example.be.core.web.member; + +import static com.example.be.common.response.ResponseCodeAndMessages.FIND_ALL_GOALS_SUCCESS; + +import com.example.be.common.response.BaseResponse; +import com.example.be.core.application.member.GoalService; +import com.example.be.core.application.dto.response.GoalResponse; +import io.swagger.annotations.ApiOperation; +import java.util.List; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/goal") +public class GoalController { + + private final GoalService goalService; + + public GoalController(GoalService goalService) { + this.goalService = goalService; + } + + @GetMapping + @ApiOperation(value = "목표 전체 조회입니다.") + public BaseResponse> findAll() { + List response = goalService.findAll(); + return new BaseResponse<>(FIND_ALL_GOALS_SUCCESS, response); + } +} diff --git a/be/src/main/java/com/example/be/core/web/MemberController.java b/be/src/main/java/com/example/be/core/web/member/MemberController.java similarity index 97% rename from be/src/main/java/com/example/be/core/web/MemberController.java rename to be/src/main/java/com/example/be/core/web/member/MemberController.java index 69a221f5..0e2dded9 100644 --- a/be/src/main/java/com/example/be/core/web/MemberController.java +++ b/be/src/main/java/com/example/be/core/web/member/MemberController.java @@ -1,4 +1,4 @@ -package com.example.be.core.web; +package com.example.be.core.web.member; import static com.example.be.common.response.ResponseCodeAndMessages.CANCEL_FOLLOW_MEMBER_SUCCESS; import static com.example.be.common.response.ResponseCodeAndMessages.FIND_MEMBER_INFO_SUCCESS; @@ -7,7 +7,7 @@ import static com.example.be.common.response.ResponseCodeAndMessages.SIGN_UP_MEMBER_SUCCESS; import com.example.be.common.response.BaseResponse; -import com.example.be.core.application.MemberService; +import com.example.be.core.application.member.MemberService; import com.example.be.core.application.dto.request.MemberModifyRequest; import com.example.be.core.application.dto.request.MemberSignUpRequest; import com.example.be.core.application.dto.response.FollowResponse; diff --git a/be/src/main/java/com/example/be/core/web/member/SubjectController.java b/be/src/main/java/com/example/be/core/web/member/SubjectController.java new file mode 100644 index 00000000..12a17747 --- /dev/null +++ b/be/src/main/java/com/example/be/core/web/member/SubjectController.java @@ -0,0 +1,30 @@ +package com.example.be.core.web.member; + +import static com.example.be.common.response.ResponseCodeAndMessages.FIND_ALL_SUBJECTS_SUCCESS; + +import com.example.be.common.response.BaseResponse; +import com.example.be.core.application.dto.response.SubjectResponse; +import com.example.be.core.application.member.SubjectService; +import io.swagger.annotations.ApiOperation; +import java.util.List; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/subject") +public class SubjectController { + + private final SubjectService subjectService; + + public SubjectController(SubjectService subjectService) { + this.subjectService = subjectService; + } + + @GetMapping + @ApiOperation(value = "주제 전체 조회입니다.") + public BaseResponse> findAll() { + List response = subjectService.findAll(); + return new BaseResponse<>(FIND_ALL_SUBJECTS_SUCCESS, response); + } +} diff --git a/be/src/main/java/com/example/be/oauth/provider/LoginService.java b/be/src/main/java/com/example/be/oauth/provider/LoginService.java index 31e884e2..9f66473e 100644 --- a/be/src/main/java/com/example/be/oauth/provider/LoginService.java +++ b/be/src/main/java/com/example/be/oauth/provider/LoginService.java @@ -13,7 +13,7 @@ @Transactional(readOnly = true) public class LoginService { - private static final String BASIC_PROFILE_IMAGE = "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/b5ddbdeb-00bf-425a-9321-e36d25323bc0.jpg"; + private static final String BASIC_PROFILE_IMAGE = "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/basic_profile_image.jpg"; private final KakaoProvider kakaoProvider; private final JwtProvider jwtProvider; private final MemberRepository memberRepository; diff --git a/be/src/test/java/com/example/be/core/application/goal_subject/GoalFindAllTest.java b/be/src/test/java/com/example/be/core/application/goal_subject/GoalFindAllTest.java new file mode 100644 index 00000000..27320094 --- /dev/null +++ b/be/src/test/java/com/example/be/core/application/goal_subject/GoalFindAllTest.java @@ -0,0 +1,45 @@ +package com.example.be.core.application.goal_subject; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.example.be.core.application.member.GoalService; +import com.example.be.core.application.InitServiceTest; +import com.example.be.core.application.dto.response.GoalResponse; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +@DisplayName("서비스 테스트 : Goal 전체 조회") +class GoalFindAllTest extends InitServiceTest { + + @Autowired + private GoalService goalService; + + @Nested + @DisplayName("목표를 전체 조회할 때") + class FindAllTest { + + @Nested + @DisplayName("정상적인 요청이라면") + class NormalTest { + + @Test + void find_all_goals_test(){ + //given & when + List goals = goalService.findAll(); + + //then + assertThat(goals).hasSize(5); + assertThat(goals.get(0).getGoalId()).isEqualTo(1L); + assertThat(goals.get(1).getGoalId()).isEqualTo(2L); + assertThat(goals.get(2).getGoalId()).isEqualTo(3L); + assertThat(goals.get(3).getGoalId()).isEqualTo(4L); + assertThat(goals.get(4).getGoalId()).isEqualTo(5L); + assertThat(goals.get(1).getContent()).isEqualTo("다른 사람들의 피드백!"); + } + } + } + +} diff --git a/be/src/test/java/com/example/be/core/application/goal_subject/SubjectFindAllTest.java b/be/src/test/java/com/example/be/core/application/goal_subject/SubjectFindAllTest.java new file mode 100644 index 00000000..ab912d21 --- /dev/null +++ b/be/src/test/java/com/example/be/core/application/goal_subject/SubjectFindAllTest.java @@ -0,0 +1,47 @@ +package com.example.be.core.application.goal_subject; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.example.be.core.application.InitServiceTest; +import com.example.be.core.application.dto.response.SubjectResponse; +import com.example.be.core.application.member.SubjectService; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +@DisplayName("서비스 테스트 : Subject 전체 조회") +class SubjectFindAllTest extends InitServiceTest { + + @Autowired + private SubjectService subjectService; + + @Nested + @DisplayName("주제를 전체 조회할 때") + class FindAllTest { + + @Nested + @DisplayName("정상적인 요청이라면") + class NormalTest { + + @Test + void find_all_subjects_test() { + //give & when + List subjects = subjectService.findAll(); + + //then + assertThat(subjects).hasSize(9); + assertThat(subjects.get(0).getSubjectId()).isEqualTo(1L); + assertThat(subjects.get(1).getSubjectId()).isEqualTo(2L); + assertThat(subjects.get(2).getSubjectId()).isEqualTo(3L); + assertThat(subjects.get(3).getSubjectId()).isEqualTo(4L); + assertThat(subjects.get(4).getSubjectId()).isEqualTo(5L); + assertThat(subjects.get(5).getSubjectId()).isEqualTo(6L); + assertThat(subjects.get(6).getSubjectId()).isEqualTo(7L); + assertThat(subjects.get(7).getSubjectId()).isEqualTo(8L); + assertThat(subjects.get(8).getSubjectId()).isEqualTo(9L); + } + } + } +} diff --git a/be/src/test/java/com/example/be/core/application/member/MemberFollowTest.java b/be/src/test/java/com/example/be/core/application/member/MemberFollowTest.java index 260ed990..7ead1701 100644 --- a/be/src/test/java/com/example/be/core/application/member/MemberFollowTest.java +++ b/be/src/test/java/com/example/be/core/application/member/MemberFollowTest.java @@ -8,7 +8,6 @@ import com.example.be.common.exception.member.NotFoundFollowRelationshipException; import com.example.be.common.exception.member.NotFoundMemberIdException; import com.example.be.core.application.InitServiceTest; -import com.example.be.core.application.MemberService; import com.example.be.core.application.dto.response.FollowResponse; import com.example.be.core.domain.member.Follow; import com.example.be.core.repository.member.FollowRepository; diff --git a/be/src/test/java/com/example/be/core/application/member/MemberModifyTest.java b/be/src/test/java/com/example/be/core/application/member/MemberModifyTest.java index 23561b7d..7a14d24e 100644 --- a/be/src/test/java/com/example/be/core/application/member/MemberModifyTest.java +++ b/be/src/test/java/com/example/be/core/application/member/MemberModifyTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import com.example.be.core.application.InitServiceTest; -import com.example.be.core.application.MemberService; import com.example.be.core.application.dto.request.MemberModifyRequest; import com.example.be.core.application.dto.request.MemberSignUpRequest; import com.example.be.core.application.dto.response.MemberResponse; @@ -13,7 +12,6 @@ import com.example.be.core.domain.member.grade.SpeakingGradeLevel; import java.util.Arrays; import java.util.List; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; diff --git a/be/src/test/java/com/example/be/core/application/member/MemberMyPageTest.java b/be/src/test/java/com/example/be/core/application/member/MemberMyPageTest.java index 9a226275..f05820ff 100644 --- a/be/src/test/java/com/example/be/core/application/member/MemberMyPageTest.java +++ b/be/src/test/java/com/example/be/core/application/member/MemberMyPageTest.java @@ -3,11 +3,9 @@ import static org.assertj.core.api.Assertions.assertThat; import com.example.be.core.application.InitServiceTest; -import com.example.be.core.application.MemberService; import com.example.be.core.application.dto.request.MemberSignUpRequest; import com.example.be.core.application.dto.response.MemberResponse; import com.example.be.core.domain.member.MemberType; -import com.example.be.core.domain.member.SpeakingTestType; import com.example.be.core.domain.member.grade.SpeakingGradeLanguage; import com.example.be.core.domain.member.grade.SpeakingGradeLevel; import java.util.Arrays; diff --git a/be/src/test/java/com/example/be/core/application/member/MemberSignUpTest.java b/be/src/test/java/com/example/be/core/application/member/MemberSignUpTest.java index fa9545a8..c2014099 100644 --- a/be/src/test/java/com/example/be/core/application/member/MemberSignUpTest.java +++ b/be/src/test/java/com/example/be/core/application/member/MemberSignUpTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import com.example.be.core.application.InitServiceTest; -import com.example.be.core.application.MemberService; import com.example.be.core.application.dto.request.MemberSignUpRequest; import com.example.be.core.application.dto.response.MemberSignUpResponse; import com.example.be.core.domain.member.MemberType; diff --git a/be/src/test/java/com/example/be/core/web/goal_subject/GoalControllerFindAllTest.java b/be/src/test/java/com/example/be/core/web/goal_subject/GoalControllerFindAllTest.java new file mode 100644 index 00000000..cc18f77d --- /dev/null +++ b/be/src/test/java/com/example/be/core/web/goal_subject/GoalControllerFindAllTest.java @@ -0,0 +1,71 @@ +package com.example.be.core.web.goal_subject; + +import static com.example.be.common.response.ResponseCodeAndMessages.FIND_ALL_GOALS_SUCCESS; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.example.be.common.response.BaseResponse; +import com.example.be.core.application.dto.response.GoalResponse; +import com.example.be.core.application.member.GoalService; +import com.example.be.core.domain.member.goal.Goal; +import com.example.be.core.web.InitControllerTest; +import com.example.be.core.web.member.GoalController; +import java.util.Arrays; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +@WebMvcTest(GoalController.class) +@DisplayName("컨트롤러 테스트 : Goal 전체 조회") +class GoalControllerFindAllTest extends InitControllerTest { + + @MockBean + private GoalService goalService; + + private static final List goals = Arrays.asList( + GoalResponse.of(new Goal(1L, "일상 속 유용한 표현 배우기!")), + GoalResponse.of(new Goal(2L, "다른 사람들의 피드백!")), + GoalResponse.of(new Goal(3L, "듣기 능력 키우기!")), + GoalResponse.of(new Goal(4L, "함께 공부할 스터디 찾기!")), + GoalResponse.of(new Goal(5L, "어학 자격증 따기!")) + ); + + @Nested + @DisplayName("Goal 전체 조회를 할 때") + class RetrieveAllTest { + + @Nested + @DisplayName("정상적인 요청이라면") + class NormalTest { + + @Test + @DisplayName("모든 Goal들이 조회된다.") + void find_all_goals() throws Exception { + //given + Long memberId = 1L; + BaseResponse> baseResponse = new BaseResponse<>(FIND_ALL_GOALS_SUCCESS, goals); + when(goalService.findAll()).thenReturn(goals); + + //when + ResultActions resultActions = mockMvc.perform(get("/goal") + .header("Authorization", "Bearer " + jwtProvider.generateAccessToken(memberId)) + .accept(MediaType.APPLICATION_JSON_VALUE) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andDo(print()); + + //then + resultActions.andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(baseResponse))); + } + } + } + +} diff --git a/be/src/test/java/com/example/be/core/web/goal_subject/SubjectControllerFindAllTest.java b/be/src/test/java/com/example/be/core/web/goal_subject/SubjectControllerFindAllTest.java new file mode 100644 index 00000000..7d23d3bd --- /dev/null +++ b/be/src/test/java/com/example/be/core/web/goal_subject/SubjectControllerFindAllTest.java @@ -0,0 +1,77 @@ +package com.example.be.core.web.goal_subject; + +import static com.example.be.common.response.ResponseCodeAndMessages.FIND_ALL_SUBJECTS_SUCCESS; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.example.be.common.response.BaseResponse; +import com.example.be.core.application.dto.response.SubjectResponse; +import com.example.be.core.application.member.SubjectService; +import com.example.be.core.domain.member.subject.Subject; +import com.example.be.core.web.InitControllerTest; +import com.example.be.core.web.member.SubjectController; +import java.util.Arrays; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +@WebMvcTest(SubjectController.class) +@DisplayName("컨트롤러 테스트 : Subject 전체 조회") +class SubjectControllerFindAllTest extends InitControllerTest { + + @MockBean + private SubjectService subjectService; + + private static final String staticImageUrl = "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/"; + private static final String staticImageExt = ".png"; + private static final List subjects = Arrays.asList( + SubjectResponse.of(new Subject(1L, "여행", staticImageUrl + "travle" + staticImageExt)), + SubjectResponse.of(new Subject(2L, "영화&음악", staticImageUrl + "movie_music" + staticImageExt)), + SubjectResponse.of(new Subject(3L, "일&회사", staticImageUrl + "company" + staticImageExt)), + SubjectResponse.of(new Subject(4L, "쇼핑", staticImageUrl + "shopping" + staticImageExt)), + SubjectResponse.of(new Subject(5L, "음식", staticImageUrl + "food" + staticImageExt)), + SubjectResponse.of(new Subject(6L, "가족&친구", staticImageUrl + "family" + staticImageExt)), + SubjectResponse.of(new Subject(7L, "운동&건강", staticImageUrl + "workout" + staticImageExt)), + SubjectResponse.of(new Subject(8L, "동네", staticImageUrl + "town" + staticImageExt)), + SubjectResponse.of(new Subject(9L, "연애", staticImageUrl + "love" + staticImageExt)) + ); + + @Nested + @DisplayName("Subject 전체 조회를 할 때") + class RetrieveAllTest { + + @Nested + @DisplayName("정상적인 요청이라면") + class NormalTest { + + @Test + @DisplayName("모든 Subject들이 조회된다.") + void find_all_subjects() throws Exception { + //given + Long memberId = 1L; + BaseResponse> baseResponse = new BaseResponse<>(FIND_ALL_SUBJECTS_SUCCESS, subjects); + when(subjectService.findAll()).thenReturn(subjects); + + //when + ResultActions resultActions = mockMvc.perform(get("/subject") + .header("Authorization", "Bearer " + jwtProvider.generateAccessToken(memberId)) + .accept(MediaType.APPLICATION_JSON_VALUE) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andDo(print()); + + //then + resultActions.andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(baseResponse))); + } + } + } + +} diff --git a/be/src/test/java/com/example/be/core/web/member/MemberControllerFollowTest.java b/be/src/test/java/com/example/be/core/web/member/MemberControllerFollowTest.java index 67293cbd..419d0075 100644 --- a/be/src/test/java/com/example/be/core/web/member/MemberControllerFollowTest.java +++ b/be/src/test/java/com/example/be/core/web/member/MemberControllerFollowTest.java @@ -12,10 +12,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.be.common.response.BaseResponse; -import com.example.be.core.application.MemberService; +import com.example.be.core.application.member.MemberService; import com.example.be.core.application.dto.response.FollowResponse; import com.example.be.core.web.InitControllerTest; -import com.example.be.core.web.MemberController; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; diff --git a/be/src/test/java/com/example/be/core/web/member/MemberControllerModifyTest.java b/be/src/test/java/com/example/be/core/web/member/MemberControllerModifyTest.java index f9035781..cf7a4872 100644 --- a/be/src/test/java/com/example/be/core/web/member/MemberControllerModifyTest.java +++ b/be/src/test/java/com/example/be/core/web/member/MemberControllerModifyTest.java @@ -9,7 +9,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.be.common.response.BaseResponse; -import com.example.be.core.application.MemberService; +import com.example.be.core.application.member.MemberService; import com.example.be.core.application.dto.request.MemberModifyRequest; import com.example.be.core.application.dto.response.GoalResponse; import com.example.be.core.application.dto.response.MemberResponse; @@ -21,7 +21,6 @@ import com.example.be.core.domain.member.grade.SpeakingGradeLevel; import com.example.be.core.domain.member.subject.Subject; import com.example.be.core.web.InitControllerTest; -import com.example.be.core.web.MemberController; import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -66,9 +65,12 @@ void modify_member() throws Exception { GoalResponse.of(new Goal(2L, "다른 사람들의 피드백!")) ); List subjectResponses = Arrays.asList( - SubjectResponse.of(new Subject(2L, "영화&음악")), - SubjectResponse.of(new Subject(7L, "운동&건강")), - SubjectResponse.of(new Subject(8L, "동네")) + SubjectResponse.of(new Subject(2L, "영화&음악", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/movie_music.png")), + SubjectResponse.of(new Subject(7L, "운동&건강", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/workout.png")), + SubjectResponse.of(new Subject(8L, "동네", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/town.png")) ); MemberResponse response = new MemberResponse( diff --git a/be/src/test/java/com/example/be/core/web/member/MemberControllerMyPageTest.java b/be/src/test/java/com/example/be/core/web/member/MemberControllerMyPageTest.java index 53144e14..7dec0025 100644 --- a/be/src/test/java/com/example/be/core/web/member/MemberControllerMyPageTest.java +++ b/be/src/test/java/com/example/be/core/web/member/MemberControllerMyPageTest.java @@ -9,7 +9,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.be.common.response.BaseResponse; -import com.example.be.core.application.MemberService; +import com.example.be.core.application.member.MemberService; import com.example.be.core.application.dto.response.GoalResponse; import com.example.be.core.application.dto.response.MemberResponse; import com.example.be.core.application.dto.response.SubjectResponse; @@ -20,7 +20,6 @@ import com.example.be.core.domain.member.grade.SpeakingGradeLevel; import com.example.be.core.domain.member.subject.Subject; import com.example.be.core.web.InitControllerTest; -import com.example.be.core.web.MemberController; import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -56,9 +55,12 @@ void modify_member() throws Exception { GoalResponse.of(new Goal(2L, "다른 사람들의 피드백!")) ); List subjectResponses = Arrays.asList( - SubjectResponse.of(new Subject(2L, "영화&음악")), - SubjectResponse.of(new Subject(7L, "운동&건강")), - SubjectResponse.of(new Subject(8L, "동네")) + SubjectResponse.of(new Subject(2L, "영화&음악", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/movie_music.png")), + SubjectResponse.of(new Subject(7L, "운동&건강", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/workout.png")), + SubjectResponse.of(new Subject(8L, "동네", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/town.png")) ); MemberResponse response = new MemberResponse( diff --git a/be/src/test/java/com/example/be/core/web/member/MemberControllerSignUpTest.java b/be/src/test/java/com/example/be/core/web/member/MemberControllerSignUpTest.java index 15bfa793..1e46c410 100644 --- a/be/src/test/java/com/example/be/core/web/member/MemberControllerSignUpTest.java +++ b/be/src/test/java/com/example/be/core/web/member/MemberControllerSignUpTest.java @@ -9,19 +9,17 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.be.common.response.BaseResponse; -import com.example.be.core.application.MemberService; +import com.example.be.core.application.member.MemberService; import com.example.be.core.application.dto.request.MemberSignUpRequest; import com.example.be.core.application.dto.response.GoalResponse; import com.example.be.core.application.dto.response.MemberSignUpResponse; import com.example.be.core.application.dto.response.SubjectResponse; import com.example.be.core.domain.member.MemberType; -import com.example.be.core.domain.member.SpeakingTestType; import com.example.be.core.domain.member.goal.Goal; import com.example.be.core.domain.member.grade.SpeakingGradeLanguage; import com.example.be.core.domain.member.grade.SpeakingGradeLevel; import com.example.be.core.domain.member.subject.Subject; import com.example.be.core.web.InitControllerTest; -import com.example.be.core.web.MemberController; import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -64,9 +62,12 @@ void sign_up_member() throws Exception { GoalResponse.of(new Goal(2L, "다른 사람들의 피드백!")) ); List subjectResponses = Arrays.asList( - SubjectResponse.of(new Subject(2L, "영화&음악")), - SubjectResponse.of(new Subject(7L, "운동&건강")), - SubjectResponse.of(new Subject(8L, "동네")) + SubjectResponse.of(new Subject(2L, "영화&음악", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/movie_music.png")), + SubjectResponse.of(new Subject(7L, "운동&건강", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/workout.png")), + SubjectResponse.of(new Subject(8L, "동네", + "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/town.png")) ); MemberSignUpResponse response = new MemberSignUpResponse( diff --git a/be/src/test/java/com/example/be/tool/DataBaseConfigurator.java b/be/src/test/java/com/example/be/tool/DataBaseConfigurator.java index d078b7b4..fd11b088 100644 --- a/be/src/test/java/com/example/be/tool/DataBaseConfigurator.java +++ b/be/src/test/java/com/example/be/tool/DataBaseConfigurator.java @@ -41,6 +41,8 @@ public class DataBaseConfigurator implements InitializingBean { private static final String TRUNCATE_TABLE = "TRUNCATE TABLE "; private static final String TABLE = "TABLE"; private static final String TABLE_NAME = "table_name"; + private static final String staticImageUrl = "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/"; + private static final String staticImageExt = ".png"; private static final int NUMBER_OF_MEMBER = 5; private static final int NUMBER_OF_SPEAKING_LOG = 3; @@ -240,14 +242,14 @@ private void initGoal() { */ private void initSubject() { - subjectRepository.save(new Subject(1L, "여행")); - subjectRepository.save(new Subject(2L, "영화&음악")); - subjectRepository.save(new Subject(3L, "일&회사")); - subjectRepository.save(new Subject(4L, "쇼핑")); - subjectRepository.save(new Subject(5L, "음식")); - subjectRepository.save(new Subject(6L, "가족&친구")); - subjectRepository.save(new Subject(7L, "운동&건강")); - subjectRepository.save(new Subject(8L, "동네")); - subjectRepository.save(new Subject(9L, "연애")); + subjectRepository.save(new Subject(1L, "여행", staticImageUrl + "travle" + staticImageExt)); + subjectRepository.save(new Subject(2L, "영화&음악", staticImageUrl + "movie_music" + staticImageExt)); + subjectRepository.save(new Subject(3L, "일&회사", staticImageUrl + "company" + staticImageExt)); + subjectRepository.save(new Subject(4L, "쇼핑", staticImageUrl + "shopping" + staticImageExt)); + subjectRepository.save(new Subject(5L, "음식", staticImageUrl + "food" + staticImageExt)); + subjectRepository.save(new Subject(6L, "가족&친구", staticImageUrl + "family" + staticImageExt)); + subjectRepository.save(new Subject(7L, "운동&건강", staticImageUrl + "workout" + staticImageExt)); + subjectRepository.save(new Subject(8L, "동네", staticImageUrl + "town" + staticImageExt)); + subjectRepository.save(new Subject(9L, "연애", staticImageUrl + "love" + staticImageExt)); } }