From bd635efce2767d9c68cb1af308de600dbfa0b4e6 Mon Sep 17 00:00:00 2001 From: hann Date: Sun, 3 Mar 2024 13:46:26 +0900 Subject: [PATCH] remove all of test code --- .../board/help/service/HelpServiceTest.java | 199 ------------- .../repository/AnswerRepositoryTest.java | 60 ---- .../repository/QuestionRepositoryTest.java | 118 -------- .../question/service/QuestionServiceTest.java | 263 ----------------- .../story/controller/StoryControllerTest.java | 44 --- .../story/repository/BoardRepositoryTest.java | 88 ------ .../story/repository/StoryRepositoryTest.java | 70 ----- .../board/story/service/StoryServiceTest.java | 234 --------------- .../repository/CommentRepositoryTest.java | 23 -- .../comment/service/CommentServiceTest.java | 211 -------------- .../service/ScheduleCommandServiceTest.java | 173 ----------- .../service/ScheduleQueryServiceTest.java | 187 ------------ .../service/TeamCommandServiceTest.java | 269 ----------------- .../service/TeamQueryServiceTest.java | 134 --------- .../follow/service/FollowServiceTest.java | 171 ----------- .../controller/MemberControllerTest.java | 71 ----- .../member/service/MemberServiceImplTest.java | 269 ----------------- .../waggle/pet/service/PetServiceTest.java | 149 ---------- .../repository/RecommendRepositoryTest.java | 120 -------- .../service/RecommendServiceTest.java | 193 ------------- .../reply/service/ReplyServiceTest.java | 271 ------------------ .../web/dto/global/LazyLoadingTest.java | 63 ---- .../withMockUser/WithMockCustomUser.java | 14 - ...hMockCustomUserSecurityContextFactory.java | 21 -- 24 files changed, 3415 deletions(-) delete mode 100644 src/test/java/com/example/waggle/board/help/service/HelpServiceTest.java delete mode 100644 src/test/java/com/example/waggle/board/question/repository/AnswerRepositoryTest.java delete mode 100644 src/test/java/com/example/waggle/board/question/repository/QuestionRepositoryTest.java delete mode 100644 src/test/java/com/example/waggle/board/question/service/QuestionServiceTest.java delete mode 100644 src/test/java/com/example/waggle/board/story/controller/StoryControllerTest.java delete mode 100644 src/test/java/com/example/waggle/board/story/repository/BoardRepositoryTest.java delete mode 100644 src/test/java/com/example/waggle/board/story/repository/StoryRepositoryTest.java delete mode 100644 src/test/java/com/example/waggle/board/story/service/StoryServiceTest.java delete mode 100644 src/test/java/com/example/waggle/comment/repository/CommentRepositoryTest.java delete mode 100644 src/test/java/com/example/waggle/comment/service/CommentServiceTest.java delete mode 100644 src/test/java/com/example/waggle/domain/schedule/service/ScheduleCommandServiceTest.java delete mode 100644 src/test/java/com/example/waggle/domain/schedule/service/ScheduleQueryServiceTest.java delete mode 100644 src/test/java/com/example/waggle/domain/schedule/service/TeamCommandServiceTest.java delete mode 100644 src/test/java/com/example/waggle/domain/schedule/service/TeamQueryServiceTest.java delete mode 100644 src/test/java/com/example/waggle/follow/service/FollowServiceTest.java delete mode 100644 src/test/java/com/example/waggle/member/controller/MemberControllerTest.java delete mode 100644 src/test/java/com/example/waggle/member/service/MemberServiceImplTest.java delete mode 100644 src/test/java/com/example/waggle/pet/service/PetServiceTest.java delete mode 100644 src/test/java/com/example/waggle/recommend/repository/RecommendRepositoryTest.java delete mode 100644 src/test/java/com/example/waggle/recommend/service/RecommendServiceTest.java delete mode 100644 src/test/java/com/example/waggle/reply/service/ReplyServiceTest.java delete mode 100644 src/test/java/com/example/waggle/web/dto/global/LazyLoadingTest.java delete mode 100644 src/test/java/com/example/waggle/web/dto/global/annotation/withMockUser/WithMockCustomUser.java delete mode 100644 src/test/java/com/example/waggle/web/dto/global/annotation/withMockUser/WithMockCustomUserSecurityContextFactory.java diff --git a/src/test/java/com/example/waggle/board/help/service/HelpServiceTest.java b/src/test/java/com/example/waggle/board/help/service/HelpServiceTest.java deleted file mode 100644 index 08969725..00000000 --- a/src/test/java/com/example/waggle/board/help/service/HelpServiceTest.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.example.waggle.board.help.service; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.example.waggle.domain.board.siren.entity.Siren; -import com.example.waggle.domain.board.siren.entity.SirenCategory; -import com.example.waggle.domain.board.siren.service.SirenCommandService; -import com.example.waggle.domain.board.siren.service.SirenQueryService; -import com.example.waggle.domain.member.entity.Gender; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.siren.SirenRequest.SirenCreateDto; -======= -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.siren.SirenRequest; ->>>>>>> develop -import java.io.IOException; -import java.time.LocalDateTime; -import java.util.List; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -@Slf4j -@SpringBootTest -class HelpServiceTest { - - @Autowired - private SirenCommandService sirenCommandService; - @Autowired - private SirenQueryService sirenQueryService; - @Autowired - private MemberCommandService memberCommandService; - @Autowired - private MemberQueryService memberQueryService; - @Autowired - DatabaseCleanUp databaseCleanUp; - - SirenCreateDto hwd1; - SirenCreateDto hwd2; - SirenCreateDto hwd3; - SirenCreateDto hwd4; - -<<<<<<< HEAD - MemberCredentialsDto signUpDto1; -======= - MemberRequest.AccessDto signUpDto1; ->>>>>>> develop - - - void setting() { - hwd1 = SirenCreateDto.builder() - .title("this is title") - .content("help page. hi") - .contact("01025522972") - .lostDate(LocalDateTime.of(2023, 1, 1, 1, 1)) - .lostLocate("Seoul") - .petGender(Gender.MALE) - .category(SirenCategory.FIND_PET) - .build(); - hwd2 = SirenCreateDto.builder() - .title("this is title") - .content("help page. hi") - .contact("01025522972") - .lostDate(LocalDateTime.of(2023, 1, 1, 1, 1)) - .lostLocate("Seoul") - .petGender(Gender.MALE) - .category(SirenCategory.FIND_PET) - .build(); - hwd3 = SirenCreateDto.builder() - .title("this is title") - .content("help page. hi") - .contact("01025522972") - .lostDate(LocalDateTime.of(2023, 1, 1, 1, 1)) - .lostLocate("Seoul") - .petGender(Gender.MALE) - .category(SirenCategory.FIND_PET) - .build(); - hwd4 = SirenCreateDto.builder() - .title("this is title") - .content("help page4. hi") - .contact("01025522972") - .lostDate(LocalDateTime.of(2023, 1, 1, 1, 1)) - .lostLocate("Seoul") - .petGender(Gender.MALE) - .category(SirenCategory.FIND_PET) - .build(); -<<<<<<< HEAD - signUpDto1 = MemberCredentialsDto.builder() -======= - signUpDto1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("email1@naver.com") - .password("password1") - .build(); - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - @Test - void help_create_service() { - setting(); - Long memberId = memberCommandService.signUp(signUpDto1); - - Member member = memberQueryService.getMemberById(memberId); - Long helpId = sirenCommandService.createSirenByUsername(hwd1, null, member.getUsername()); - - List allHelp = sirenQueryService.getAllSiren(); - assertThat(allHelp.size()).isEqualTo(1); - } - - @Test - void help_read_All_ByPaging_service() { - setting(); - Long memberId = memberCommandService.signUp(signUpDto1); - Member member = memberQueryService.getMemberById(memberId); - - sirenCommandService.createSirenByUsername(hwd1, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd2, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd3, null, member.getUsername()); - - //List allhelp = helpService.getAllhelp(); - Pageable pageable = PageRequest.of(0, 2); - Page pagedHelpList = sirenQueryService.getPagedSirenList(pageable); - assertThat(pagedHelpList.getContent().size()).isEqualTo(2); - } - - @Test - void help_read_Mine_ByPaging_service() { - setting(); - Long memberId = memberCommandService.signUp(signUpDto1); - Member member = memberQueryService.getMemberById(memberId); - - sirenCommandService.createSirenByUsername(hwd1, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd2, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd3, null, member.getUsername()); - - //List allhelp = helpService.getAllhelp(); - Pageable pageable = PageRequest.of(0, 2); - Page member1 = sirenQueryService.getPagedSirenListByMemberId(memberId, pageable); - assertThat(member1.getContent().size()).isEqualTo(2); - } - - @Test - void help_read_One_service() throws IOException { - setting(); - Long memberId = memberCommandService.signUp(signUpDto1); - Member member = memberQueryService.getMemberById(memberId); - - Long helpId = sirenCommandService.createSirenByUsername(hwd1, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd2, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd3, null, member.getUsername()); - - Siren siren = sirenQueryService.getSirenByBoardId(helpId); - assertThat(siren.getContent()).isEqualTo("help page. hi"); - } - - @Test - void help_update_One_service() { - setting(); - Long memberId = memberCommandService.signUp(signUpDto1); - Member member = memberQueryService.getMemberById(memberId); - - Long helpId = sirenCommandService.createSirenByUsername(hwd1, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd2, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd3, null, member.getUsername()); - - Long aLong = sirenCommandService.updateSirenByUsername(helpId, member.getUsername(), hwd4, null, null); - Siren help = sirenQueryService.getSirenByBoardId(aLong); - assertThat(help.getContent()).isEqualTo("help page4. hi"); - } - - @Test - void help_delete_One_service() throws IOException { - setting(); - Long memberId = memberCommandService.signUp(signUpDto1); - Member member = memberQueryService.getMemberById(memberId); - - sirenCommandService.createSirenByUsername(hwd1, null, member.getUsername()); - sirenCommandService.createSirenByUsername(hwd2, null, member.getUsername()); - Long help = sirenCommandService.createSirenByUsername(hwd3, null, member.getUsername()); - - sirenCommandService.deleteSirenByUsername(help, member.getUsername()); - List allHelp = sirenQueryService.getAllSiren(); - assertThat(allHelp.size()).isEqualTo(2); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/board/question/repository/AnswerRepositoryTest.java b/src/test/java/com/example/waggle/board/question/repository/AnswerRepositoryTest.java deleted file mode 100644 index ec70dc31..00000000 --- a/src/test/java/com/example/waggle/board/question/repository/AnswerRepositoryTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.example.waggle.board.question.repository; - -import com.example.waggle.domain.board.answer.entity.Answer; -import com.example.waggle.domain.board.answer.repository.AnswerRepository; -import com.example.waggle.domain.board.question.entity.Question; -import com.example.waggle.domain.board.question.repository.QuestionRepository; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.repository.MemberRepository; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; - -@SpringBootTest -class AnswerRepositoryTest { - - @Autowired - private MemberRepository memberRepository; - @Autowired - private QuestionRepository questionRepository; - @Autowired - private AnswerRepository answerRepository; - - @Test - @Transactional - void findByQuestionIdTest() { - Member member = Member.builder() - .username("username") - .password("password").build(); - Member savedMember = memberRepository.save(member); - - Question question1 = Question.builder() - .title("question1") - .content("i have a question sir.") - .member(member) - .createdDate(LocalDateTime.now()) - .createdBy("username").build(); - - Answer answer1 = Answer.builder() - .content("answer1") - .member(member) - .createdDate(LocalDateTime.now()) - .createdBy("username").build(); - - Answer answer2 = Answer.builder() - .content("answer2") - .member(member) - .createdDate(LocalDateTime.now()) - .createdBy("username").build(); - - //save - Question save = questionRepository.save(question1); - - //find - - } - -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/board/question/repository/QuestionRepositoryTest.java b/src/test/java/com/example/waggle/board/question/repository/QuestionRepositoryTest.java deleted file mode 100644 index 723a3c96..00000000 --- a/src/test/java/com/example/waggle/board/question/repository/QuestionRepositoryTest.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.example.waggle.board.question.repository; - - -import com.example.waggle.domain.board.answer.entity.Answer; -import com.example.waggle.domain.board.answer.repository.AnswerRepository; -import com.example.waggle.domain.board.question.entity.Question; -import com.example.waggle.domain.board.question.repository.QuestionRepository; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.repository.MemberRepository; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -@Slf4j -class QuestionRepositoryTest { - - @Autowired - MemberRepository memberRepository; - @Autowired - QuestionRepository questionRepository; - @Autowired - AnswerRepository answerRepository; - - @Test - @Transactional - void test() { - Question question = Question.builder() - .title("question") - .content("i have a question sir.") - .status(Question.Status.UNRESOLVED) - .build(); - questionRepository.save(question); - - - Optional byBoardId = questionRepository.findById(question.getId()); - - } - - @Test - @Transactional - void findByMemberUsernameTest() { - // given - Member member = Member.builder() - .username("username") - .password("password") - .nickname("nickname") - .userUrl("hi") - .email("email") - .build(); - Member savedMember = memberRepository.save(member); - - Question question1 = Question.builder() - .title("question1") - .content("i have a question sir.") - .member(member) - .status(Question.Status.UNRESOLVED) - .createdDate(LocalDateTime.now()) - .createdBy("username").build(); - - Question question2 = Question.builder() - .title("question2") - .content("i have a question sir.") - .member(member) - .status(Question.Status.UNRESOLVED) - .createdDate(LocalDateTime.now()) - .createdBy("username").build(); - - Answer answer1 = Answer.builder() - .content("answer1") - .member(member) - .createdDate(LocalDateTime.now()) - .createdBy("username").build(); - - Answer answer2 = Answer.builder() - .content("answer2") - .member(member) - .createdDate(LocalDateTime.now()) - .createdBy("username").build(); - - Answer answer3 = Answer.builder() - .content("answer3") - .member(member) - .createdDate(LocalDateTime.now()) - .createdBy("username").build(); - - // when - Question savedQuestion1 = questionRepository.save(question1); - Question savedQuestion2 = questionRepository.save(question2); - - - answerRepository.save(answer1); - answerRepository.save(answer2); - answerRepository.save(answer3); - - - // then - Pageable pageable = PageRequest.of(0, 3); - Page questionByUsername = questionRepository - .findByMemberUsername(savedMember.getUsername(), pageable); - - assertThat(questionByUsername.getContent().size()).isEqualTo(2); - for (Question questionCheck : questionByUsername.getContent()) { - log.info("question = {}", questionCheck.getContent()); - } - } - -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/board/question/service/QuestionServiceTest.java b/src/test/java/com/example/waggle/board/question/service/QuestionServiceTest.java deleted file mode 100644 index ae780620..00000000 --- a/src/test/java/com/example/waggle/board/question/service/QuestionServiceTest.java +++ /dev/null @@ -1,263 +0,0 @@ -package com.example.waggle.board.question.service; - -import com.example.waggle.domain.board.answer.entity.Answer; -import com.example.waggle.domain.board.answer.service.AnswerCommandService; -import com.example.waggle.domain.board.answer.service.AnswerQueryService; -import com.example.waggle.domain.board.question.entity.Question; -import com.example.waggle.domain.board.question.service.QuestionCommandService; -import com.example.waggle.domain.board.question.service.QuestionQueryService; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.answer.AnswerRequest.AnswerCreateDto; -import com.example.waggle.web.dto.media.MediaRequest.MediaUpdateDto; -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.question.QuestionRequest.QuestionCreateDto; -======= -import com.example.waggle.web.dto.answer.AnswerRequest; -import com.example.waggle.web.dto.media.MediaRequest; -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.question.QuestionRequest; ->>>>>>> develop -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -class QuestionServiceTest { - - @Autowired - QuestionCommandService questionCommandService; - @Autowired - private QuestionQueryService questionQueryService; - @Autowired - private MemberCommandService memberService; - @Autowired - private MemberQueryService memberQueryService; - @Autowired - private AnswerCommandService answerService; - @Autowired - private AnswerQueryService answerQueryService; - @Autowired - DatabaseCleanUp databaseCleanUp; - -<<<<<<< HEAD - MemberCredentialsDto signUpDto1; - MemberCredentialsDto signUpDto2; -======= - MemberRequest.AccessDto signUpDto1; - MemberRequest.AccessDto signUpDto2; ->>>>>>> develop - - QuestionCreateDto questionWriteDto1; - QuestionCreateDto questionWriteDto2; - QuestionCreateDto questionEditDto1; - AnswerCreateDto answerWriteDto1; - AnswerCreateDto answerWriteDto2; - AnswerCreateDto answerEditDto1; - - - List tags1 = new ArrayList<>(); - List tags2 = new ArrayList<>(); - - Pageable pageable = PageRequest.of(0, 2); - - Long memberId1; - Long memberId2; - String member1; - String member2; - - - @BeforeEach - void setDto() { - tags1.add("choco"); - tags1.add("poodle"); - tags2.add("poodle"); - -<<<<<<< HEAD - signUpDto1 = MemberCredentialsDto.builder() -======= - signUpDto1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("email1@naver.com") - .password("password1") - .build(); - -<<<<<<< HEAD - signUpDto2 = MemberCredentialsDto.builder() -======= - signUpDto2 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("email2@naver.com") - .password("password2") - .build(); - - questionWriteDto1 = QuestionCreateDto.builder() - .title("question1") - .content("I have a question") - .hashtagList(tags1) - .status(Question.Status.UNRESOLVED) - .build(); - - questionWriteDto2 = QuestionCreateDto.builder() - .title("question2") - .content("I have a question!") - .hashtagList(tags2) - .status(Question.Status.UNRESOLVED) - .build(); - - questionEditDto1 = QuestionCreateDto.builder() - .title("EditQuestion") - .content("I wanna know that what it is") - .hashtagList(tags2) - .status(Question.Status.UNRESOLVED) - .build(); - - answerWriteDto1 = AnswerCreateDto.builder() - .content("i don't know that") - .build(); - - answerWriteDto2 = AnswerCreateDto.builder() - .content("i know that!") - .build(); - - answerEditDto1 = AnswerCreateDto.builder() - .content("EditAnswer") - .build(); - - memberId1 = memberService.signUp(signUpDto1); - memberId2 = memberService.signUp(signUpDto2); - Member member = memberQueryService.getMemberById(memberId1); - Member memberAnother = memberQueryService.getMemberById(memberId2); - member1 = member.getUsername(); - member2 = memberAnother.getUsername(); - - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - private void setQAndA() { - Member member1 = memberQueryService.getMemberById(memberId1); - Member member2 = memberQueryService.getMemberById(memberId2); - -<<<<<<< HEAD - Long question1 = questionCommandService.createQuestionByUsername(questionWriteDto1, null, - member1.getUsername()); - Long question2 = questionCommandService.createQuestionByUsername(questionWriteDto2, null, - member1.getUsername()); -======= - Long question1 = questionCommandService.createQuestionByUsername(questionWriteDto1, null, member1.getUsername()); - Long question2 = questionCommandService.createQuestionByUsername(questionWriteDto2, null, member1.getUsername()); ->>>>>>> develop - - answerService.createAnswerByUsername(question1, answerWriteDto1, null, member2.getUsername()); - answerService.createAnswerByUsername(question1, answerWriteDto2, null, member1.getUsername()); - } - - @Test - void findAllQuestionByUsername() { - //given - setQAndA(); - //when - Page member1 = questionQueryService - .getPagedQuestionByMemberId(memberId1, pageable); - - //then - assertThat(member1.getContent().size()).isEqualTo(2); - } - - @Test - void findQuestionByBoardId() { - //given - setQAndA(); - //when - Page pagedQuestions = questionQueryService.getPagedQuestions(pageable); - Question questionByBoardId = questionQueryService - .getQuestionByBoardId(pagedQuestions.getContent().get(0).getId()); - //then - assertThat(questionByBoardId.getTitle()).isEqualTo("question1"); - assertThat(pagedQuestions.getSize()).isEqualTo(2); - } - - @Test - void changeQuestion() { - //given - setQAndA(); - //when - Page pagedQuestions = questionQueryService.getPagedQuestions(pageable); - Long aLong = questionCommandService - .updateQuestionByUsername(pagedQuestions.getContent().get(0).getId(), - member1, - questionEditDto1, -<<<<<<< HEAD - new MediaUpdateDto(), -======= - new MediaRequest.Put(), ->>>>>>> develop - null); - //then - Question question = questionQueryService.getQuestionByBoardId(aLong); - assertThat(question.getTitle()).isEqualTo("EditQuestion"); - } - - @Test - void changeAnswer() { - //given - setQAndA(); - Page pagedQuestions = questionQueryService.getPagedQuestions(pageable); - Question question = pagedQuestions.getContent().get(0); - //when - Page pagedAnswers = answerQueryService.getPagedAnswers(question.getId(), pageable); - Long aLong = answerService.updateAnswer(pagedAnswers.getContent().get(0).getId(), answerEditDto1, null, null); - Answer answerByBoardId = answerQueryService.getAnswerByBoardId(aLong); - //then - assertThat(answerByBoardId.getContent()).isEqualTo("EditAnswer"); - } - - @Test - //cannot resolve -> need to add delete logic - @Disabled - void deleteQuestion() { - //given - setQAndA(); - //when - Page pagedQuestions = questionQueryService.getPagedQuestions(pageable); - Question question = pagedQuestions.getContent().get(0); - questionCommandService.deleteQuestionByUsername(question.getId(), member1); - Page pagedAnswers = answerQueryService.getPagedAnswers(question.getId(), pageable); - List allQuestion = questionQueryService.getAllQuestion(); - //then - assertThat(allQuestion.size()).isEqualTo(1); - assertThat(pagedAnswers.getContent().size()).isEqualTo(0); - } - - @Test - void deleteAnswer() { - //given - setQAndA(); - List allQuestion = questionQueryService.getAllQuestion(); - //when - List answers = answerQueryService.getAnswersByQuestion(allQuestion.get(0).getId()); - answerService.deleteAnswerByUsername(answers.get(0).getId(), member2); - Page pagedAnswers = answerQueryService.getPagedAnswers(allQuestion.get(0).getId(), pageable); - //then - assertThat(pagedAnswers.getContent().size()).isEqualTo(1); - } - -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/board/story/controller/StoryControllerTest.java b/src/test/java/com/example/waggle/board/story/controller/StoryControllerTest.java deleted file mode 100644 index d86cb19d..00000000 --- a/src/test/java/com/example/waggle/board/story/controller/StoryControllerTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.example.waggle.board.story.controller; - -import com.example.waggle.web.controller.StoryApiController; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; - -//@SpringBootTest (webEnvironment = SpringBootTest.WebEnvironment.MOCK) -//@AutoConfigureMockMvc -@Slf4j -//@Import(GlobalModelExceptionHandler.class) -@WebAppConfiguration -class StoryControllerTest { - - MockMvc mvc; - @InjectMocks - StoryApiController storyController; - -// @Mock -// StoryService storyService; - - ObjectMapper objectMapper = new ObjectMapper(); - - @Test - void errorTestController() throws Exception { - // Mocking the behavior of storyService.saveStory(storyDto) to throw CustomException -// StoryWriteDto testStory = StoryWriteDto.builder().content("test story").build(); -// when(storyController.singleStoryWrite(testStory)).thenThrow(new CustomException(REFRESH_TOKEN_NOT_FOUND)); -// -// -// mvc.perform(MockMvcRequestBuilders.post("/write") -// .content(objectMapper.writeValueAsString(testStory)) -// .contentType(APPLICATION_JSON_UTF8)) -// .andExpect(status().is4xxClientError()) // HTTP 4xx Client Error is expected due to exception -// .andExpect(view().name("error")) // Expected error view name -// .andExpect(model().attributeExists("errorMessage")) // Model attribute should exist -// .andExpect(model().attribute("errorMessage", Matchers.instanceOf(ErrorDto.class))); // Verify the attribute type - - } -} - diff --git a/src/test/java/com/example/waggle/board/story/repository/BoardRepositoryTest.java b/src/test/java/com/example/waggle/board/story/repository/BoardRepositoryTest.java deleted file mode 100644 index a28b396c..00000000 --- a/src/test/java/com/example/waggle/board/story/repository/BoardRepositoryTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.example.waggle.board.story.repository; - -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.board.story.repository.StoryRepository; -import com.example.waggle.domain.hashtag.entity.BoardHashtag; -import com.example.waggle.domain.hashtag.entity.Hashtag; -import com.example.waggle.domain.hashtag.repository.HashtagRepository; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.repository.MemberRepository; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -class BoardRepositoryTest { - - @Autowired - HashtagRepository hashtagRepository; - @Autowired - StoryRepository storyRepository; - @Autowired - MemberRepository memberRepository; - - - @Test - @Transactional - void test() { - Member member = Member.builder().email("34567").nickname("234289").username("238387384").userUrl("hi").password("78y93284").build(); - memberRepository.save(member); - - Story testStory = Story.builder().content("Board test Repository").member(member).build(); - - Hashtag hashtag1 = Hashtag.builder().content("trip").build(); - Hashtag hashtag2 = Hashtag.builder().content("vacation").build(); - - List hashtags = new ArrayList<>(); - hashtags.add(hashtag1); - hashtags.add(hashtag2); - - for (Hashtag hashtag : hashtags) { - BoardHashtag.builder().board(testStory).hashtag(hashtag).build().link(testStory, hashtag); - //build.addHashtag(testStory,hashtag); - } - - storyRepository.save(testStory); - for (Hashtag hashtag : hashtags) { - hashtagRepository.save(hashtag); - } - - - List all = storyRepository.findAll(); - assertThat(all.size()).isEqualTo(1); - assertThat(all.get(0).getBoardHashtags().size()).isEqualTo(2); - } - - @Test - @Transactional - void testFindByHashtag() { - - Story testStory = Story.builder().content("Board test Repository").build(); - storyRepository.save(testStory); - - - Hashtag hashtag1 = Hashtag.builder().content("trip").build(); - Hashtag hashtag2 = Hashtag.builder().content("vacation").build(); - - - List hashtags = new ArrayList<>(); - hashtags.add(hashtag1); - hashtags.add(hashtag2); - for (Hashtag hashtag : hashtags) { - hashtagRepository.save(hashtag); - } - - for (Hashtag hashtag : hashtags) { - BoardHashtag build = BoardHashtag.builder().board(testStory).hashtag(hashtag).build(); - } - - - } - -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/board/story/repository/StoryRepositoryTest.java b/src/test/java/com/example/waggle/board/story/repository/StoryRepositoryTest.java deleted file mode 100644 index f0d8fcff..00000000 --- a/src/test/java/com/example/waggle/board/story/repository/StoryRepositoryTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.example.waggle.board.story.repository; - -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.board.story.repository.StoryRepository; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.repository.MemberRepository; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@SpringBootTest -@Slf4j -class StoryRepositoryTest { - - @Autowired - StoryRepository storyRepository; - @Autowired - MemberRepository memberRepository; - - - @Test - @Transactional - void 생성_내림차순_정렬() { - - Member member = Member.builder().email("34567").nickname("234289").userUrl("hi").username("238387384").password("78y93284").build(); - memberRepository.save(member); - - Story test1 = Story.builder().content("dkdkdk").member(member).build(); - Story test2 = Story.builder().content("33333").member(member).build(); - Story test3 = Story.builder().content("dlwjdgks").member(member).build(); - storyRepository.save(test1); - storyRepository.save(test2); - storyRepository.save(test3); - - List allByOrderByCreatedDateDesc = storyRepository.findAllByOrderByCreatedDateDesc(); - for (Story story : allByOrderByCreatedDateDesc) { - log.info("story content = {}", story.getContent()); - log.info("story createDate = {}", story.getCreatedDate()); - } - } - - @Test - @Transactional - void 페이징_내림차순_정렬() { - Member member = Member.builder().email("34567").nickname("234289").username("238387384").userUrl("hi").password("78y93284").build(); - memberRepository.save(member); - - for (int i = 0; i < 20; i++) { - String content = Integer.toString(i); - Story story = Story.builder().content(content).member(member).build(); - storyRepository.save(story); - } - Sort createdDate = Sort.by("createdDate").descending(); - Pageable pageable = PageRequest.of(0, 10, createdDate); - - Page all = storyRepository.findAll(pageable); - System.out.println("all.getTotalElements() = " + all.getTotalElements()); - for (Story story : all) { - System.out.println("story.getContent() = " + story.getContent()); - } - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/board/story/service/StoryServiceTest.java b/src/test/java/com/example/waggle/board/story/service/StoryServiceTest.java deleted file mode 100644 index 659fc8d6..00000000 --- a/src/test/java/com/example/waggle/board/story/service/StoryServiceTest.java +++ /dev/null @@ -1,234 +0,0 @@ -package com.example.waggle.board.story.service; - -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.board.story.service.StoryCommandService; -import com.example.waggle.domain.board.story.service.StoryQueryService; -import com.example.waggle.domain.hashtag.entity.Hashtag; -import com.example.waggle.domain.hashtag.service.HashtagQueryService; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.story.StoryRequest.StoryCreateDto; -======= -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.story.StoryRequest; ->>>>>>> develop -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -@Slf4j -class StoryServiceTest { - - @Autowired - private StoryQueryService storyService; - @Autowired - StoryCommandService storyCommandService; - @Autowired - private MemberCommandService memberService; - @Autowired - private MemberQueryService memberQueryService; - @Autowired - private HashtagQueryService hashtagQueryService; - - @Autowired - DatabaseCleanUp databaseCleanUp; - - -<<<<<<< HEAD - MemberCredentialsDto signUpDto1; - MemberCredentialsDto signUpDto2; -======= - MemberRequest.AccessDto signUpDto1; - MemberRequest.AccessDto signUpDto2; ->>>>>>> develop - - StoryCreateDto storyWriteDto1; - StoryCreateDto storyWriteDto2; - StoryCreateDto storyWriteDto3; - StoryCreateDto storyWriteDto4; - - List tags1 = new ArrayList<>(); - List tags2 = new ArrayList<>(); - List medias1 = new ArrayList<>(); - List medias2 = new ArrayList<>(); - - Pageable pageable = PageRequest.of(0, 3); - - Long memberId1; - Long memberId2; - - - @BeforeEach - void setDto() { - tags1.add("choco"); - tags1.add("poodle"); - tags2.add("poodle"); - - medias1.add("media1"); - medias1.add("mediamedia1"); - medias2.add("media2"); - medias2.add("mediamedia2"); - -<<<<<<< HEAD - signUpDto1 = MemberCredentialsDto.builder() -======= - - signUpDto1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("email1@naver.com") - .password("password") - .build(); - -<<<<<<< HEAD - signUpDto2 = MemberCredentialsDto.builder() -======= - signUpDto2 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("email2@naver.com") - .password("password") - .build(); - - storyWriteDto1 = StoryCreateDto.builder() - .content("i love my choco") - .hashtagList(tags1) - .mediaList(medias1) - .build(); - - storyWriteDto2 = StoryCreateDto.builder() - .content("how can i do make he is happy?") - .hashtagList(tags2) - .mediaList(medias2) - .build(); - - storyWriteDto3 = StoryCreateDto.builder() - .content("how can i do make he is happy?") - .hashtagList(tags2) - .mediaList(medias2) - .build(); - storyWriteDto4 = StoryCreateDto.builder() - .content("how can i do make he is happy?") - .hashtagList(tags2) - .mediaList(medias2) - .build(); - - - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - private void setBoardAndMember() { - //member set - memberId1 = memberService.signUp(signUpDto1); - memberId2 = memberService.signUp(signUpDto2); - Member member1 = memberQueryService.getMemberById(memberId1); - Member member2 = memberQueryService.getMemberById(memberId2); - - //story set - storyCommandService.createStoryByUsername(storyWriteDto1, null, member1.getUsername()); - storyCommandService.createStoryByUsername(storyWriteDto2, null, member2.getUsername()); - } - - - @Test - void findAll() { - //given - setBoardAndMember(); - - //when - List stories = storyService.getStories(); - - //then - assertThat(stories.size()).isEqualTo(2); - } - - @Test - void findAllStoryByMember() { - //given - setBoardAndMember(); - - //when - Page member1 = storyService.getPagedStoriesByMemberId(memberId1, pageable); - //List user1 = storyService.findAllStoryByUsername("user1"); - - //then - assertThat(member1.getContent().size()).isEqualTo(1); - //assertThat(user1.size()).isEqualTo(1); - } - - @Test - void findStoryViewByBoardId() { - //given - setBoardAndMember(); - - //when - List stories = storyService.getStories(); - Story storyByBoardId = storyService.getStoryByBoardId(stories.get(0).getId()); - - //then - assertThat(storyByBoardId.getContent()).isEqualTo("i love my choco"); - } - - @Test - void changeStory() { - //given - setBoardAndMember(); - Long id = storyService.getStories().get(0).getId(); - List tags = new ArrayList<>(); - tags.add("poodle"); - tags.add("cute"); -<<<<<<< HEAD - StoryCreateDto editDto = StoryCreateDto.builder() -======= - StoryRequest.Post editDto = StoryRequest.Post.builder() ->>>>>>> develop - .content("edit edit edit") - .hashtagList(tags) - .mediaList(medias2) - .build(); - //when -// boolean isSameUser = storyCommandService.validateMember(id); - Member member = memberQueryService.getMemberById(memberId1); - storyCommandService.updateStoryByUsername(id, member.getUsername(), editDto, null, null); - Story storyByBoardId = storyService.getStoryByBoardId(id); - - //then -// assertThat(isSameUser).isTrue(); - assertThat(storyByBoardId.getContent()).isEqualTo("edit edit edit"); - } - - @Test - void deleteStory() { - //given - setBoardAndMember(); - List stories = storyService.getStories(); - Story storyByBoardId = storyService.getStoryByBoardId(stories.get(0).getId()); - //when - Member member = memberQueryService.getMemberById(memberId1); - storyCommandService.deleteStoryByUsername(storyByBoardId.getId(), member.getUsername()); - List allHashtags = hashtagQueryService.getAllHashtags(); - Page pagedStories = storyService.getPagedStories(pageable); - //then - assertThat(pagedStories.getContent().size()).isEqualTo(1); - assertThat(allHashtags.size()).isEqualTo(2); - } - -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/comment/repository/CommentRepositoryTest.java b/src/test/java/com/example/waggle/comment/repository/CommentRepositoryTest.java deleted file mode 100644 index 68488e37..00000000 --- a/src/test/java/com/example/waggle/comment/repository/CommentRepositoryTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.example.waggle.comment.repository; - -import com.example.waggle.domain.board.story.repository.StoryRepository; -import com.example.waggle.domain.conversation.repository.CommentRepository; -import com.example.waggle.domain.conversation.repository.ReplyRepository; -import com.example.waggle.domain.mention.repository.MentionRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class CommentRepositoryTest { - - @Autowired - StoryRepository storyRepository; - @Autowired - CommentRepository commentRepository; - @Autowired - ReplyRepository replyRepository; - @Autowired - MentionRepository mentionRepository; - - -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/comment/service/CommentServiceTest.java b/src/test/java/com/example/waggle/comment/service/CommentServiceTest.java deleted file mode 100644 index f3c2f082..00000000 --- a/src/test/java/com/example/waggle/comment/service/CommentServiceTest.java +++ /dev/null @@ -1,211 +0,0 @@ -package com.example.waggle.comment.service; - -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.board.story.service.StoryCommandService; -import com.example.waggle.domain.board.story.service.StoryQueryService; -import com.example.waggle.domain.conversation.entity.Comment; -import com.example.waggle.domain.conversation.service.comment.CommentCommandService; -import com.example.waggle.domain.conversation.service.comment.CommentQueryService; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.comment.CommentRequest.CommentCreateDto; -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.story.StoryRequest.StoryCreateDto; -======= -import com.example.waggle.web.dto.comment.CommentRequest; -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.story.StoryRequest; ->>>>>>> develop -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -@Slf4j -class CommentServiceTest { - - @Autowired - private StoryQueryService storyService; - @Autowired - private StoryCommandService storyCommandService; - @Autowired - private MemberCommandService memberService; - @Autowired - private MemberQueryService memberQueryService; - @Autowired - private CommentQueryService commentService; - @Autowired - private CommentCommandService commentCommandService; - @Autowired - DatabaseCleanUp databaseCleanUp; - - -<<<<<<< HEAD - MemberCredentialsDto signUpDto1; - MemberCredentialsDto signUpDto2; -======= - MemberRequest.AccessDto signUpDto1; - MemberRequest.AccessDto signUpDto2; ->>>>>>> develop - - - StoryCreateDto storyWriteDto1; - StoryCreateDto storyWriteDto2; - - CommentCreateDto commentWriteDto1; - CommentCreateDto commentWriteDto2; - - List tags1 = new ArrayList<>(); - List tags2 = new ArrayList<>(); - List medias1 = new ArrayList<>(); - List medias2 = new ArrayList<>(); - Long memberId1; - Long memberId2; - Member member1; - Member member2; - - - @BeforeEach - void setDto() { - tags1.add("choco"); - tags1.add("poodle"); - tags2.add("poodle"); - - medias1.add("media1"); - medias1.add("mediamedia1"); - medias2.add("media2"); - medias2.add("mediamedia2"); - -<<<<<<< HEAD - signUpDto1 = MemberCredentialsDto.builder() -======= - signUpDto1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("ertyuio") - .password("string") - .build(); - -<<<<<<< HEAD - signUpDto2 = MemberCredentialsDto.builder() -======= - signUpDto2 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("78347dj") - .password("string") - .build(); - - storyWriteDto1 = StoryCreateDto.builder() - .content("i love my choco") - .hashtagList(tags1) - .mediaList(medias1) - .build(); - - storyWriteDto2 = StoryCreateDto.builder() - .content("how can i do make he is happy?") - .hashtagList(tags2) - .mediaList(medias2) - .build(); - - commentWriteDto1 = CommentCreateDto.builder() - .content("comment1") - .build(); - - commentWriteDto2 = CommentCreateDto.builder() - .content("comment2") - .build(); - - - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - private void setBoardAndMember() { - //member set - memberId1 = memberService.signUp(signUpDto1); - memberId2 = memberService.signUp(signUpDto2); - member1 = memberQueryService.getMemberById(memberId1); - member2 = memberQueryService.getMemberById(memberId2); - - //story set - storyCommandService.createStoryByUsername(storyWriteDto1, null, member1.getUsername()); - storyCommandService.createStoryByUsername(storyWriteDto2, null, member2.getUsername()); - } - - @Test - void saveComment() { - //given - setBoardAndMember(); - Story story = storyService.getStories().get(0); - - //when - commentCommandService.createCommentByUsername(story.getId(), commentWriteDto1, member1.getUsername()); - List comments = commentService.getComments(story.getId()); - //then - assertThat(comments.size()).isEqualTo(1); - assertThat(comments.get(0).getContent()).isEqualTo("comment1"); - } - - @Test - void editCommentV1() { - //given - setBoardAndMember(); - Story story = storyService.getStories().get(0); - commentCommandService.createCommentByUsername(story.getId(), commentWriteDto1, member1.getUsername()); - List comments = commentService.getComments(story.getId()); - - //when - commentCommandService.updateCommentByUsername(comments.get(0).getId(), member1.getUsername(), commentWriteDto2); - List commentList = commentService.getComments(story.getId()); - - //then - assertThat(commentList.get(0).getContent()).isEqualTo("comment2"); - } - - - @Test - void deleteComment() { - //given - setBoardAndMember(); - Story story = storyService.getStories().get(0); - - //when - commentCommandService.createCommentByUsername(story.getId(), commentWriteDto1, member1.getUsername()); - List comments = commentService.getComments(story.getId()); - commentCommandService.deleteCommentByUsername(comments.get(0).getId(), member1.getUsername()); - List commentList = commentService.getComments(story.getId()); - - //then - assertThat(commentList.size()).isEqualTo(0); - - } - - @Test - void deleteStory() { - //given - setBoardAndMember(); - Story story = storyService.getStories().get(0); - - //when - commentCommandService.createCommentByUsername(story.getId(), commentWriteDto1, member1.getUsername()); - storyCommandService.deleteStoryByUsername(story.getId(), member1.getUsername()); - - List comments = commentService.getComments(story.getId()); - //then - assertThat(comments.size()).isEqualTo(0); - - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/domain/schedule/service/ScheduleCommandServiceTest.java b/src/test/java/com/example/waggle/domain/schedule/service/ScheduleCommandServiceTest.java deleted file mode 100644 index b3764d90..00000000 --- a/src/test/java/com/example/waggle/domain/schedule/service/ScheduleCommandServiceTest.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.example.waggle.domain.schedule.service; - -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.domain.schedule.entity.Schedule; -import com.example.waggle.domain.schedule.service.schedule.ScheduleCommandService; -import com.example.waggle.domain.schedule.service.schedule.ScheduleQueryService; -import com.example.waggle.domain.schedule.service.team.TeamCommandService; -import com.example.waggle.domain.schedule.service.team.TeamQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -import com.example.waggle.global.exception.handler.ScheduleHandler; -<<<<<<< HEAD -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.schedule.ScheduleRequest.ScheduleCreateDto; -import com.example.waggle.web.dto.schedule.TeamRequest.TeamCreateDto; -======= -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.schedule.ScheduleRequest; -import com.example.waggle.web.dto.schedule.TeamRequest; ->>>>>>> develop -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.time.LocalDateTime; - -import static org.assertj.core.api.Assertions.assertThat; - -@Slf4j -@SpringBootTest -class ScheduleCommandServiceTest { - - @Autowired - ScheduleCommandService scheduleCommandService; - @Autowired - ScheduleQueryService scheduleQueryService; - @Autowired - MemberCommandService memberCommandService; - @Autowired - MemberQueryService memberQueryService; - @Autowired - TeamCommandService teamCommandService; - @Autowired - TeamQueryService teamQueryService; - @PersistenceContext - EntityManager em; - @Autowired - DatabaseCleanUp databaseCleanUp; - -<<<<<<< HEAD - private MemberCredentialsDto member1; - private MemberCredentialsDto member2; - private TeamCreateDto team; - private ScheduleCreateDto schedule; -======= - private MemberRequest.AccessDto member1; - private MemberRequest.AccessDto member2; - private TeamRequest.Post team; - private ScheduleRequest.Post schedule; ->>>>>>> develop - - private Long teamId; - private Long scheduleId; - private String username; - - - @BeforeEach - void setUp() { - // Setup member -<<<<<<< HEAD - member1 = MemberCredentialsDto.builder() -======= - member1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("member1") - .password("12345678") - .build(); - -<<<<<<< HEAD - member2 = MemberCredentialsDto.builder() -======= - member2 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("email2") - .build(); - Long memberId = memberCommandService.signUp(member1); - memberCommandService.signUp(member2); - Member member = memberQueryService.getMemberById(memberId); - username = member.getUsername(); - - // Setup team - team = TeamCreateDto.builder() - .name("team1") - .description("team1 description") - .maxTeamSize(4) - .teamColor("team_3") - .build(); - teamId = teamCommandService.createTeam(team, username); - - // Setup Schedule - schedule = ScheduleCreateDto.builder() - .title("schedule1") - .content("schedule1 content") - .startTime(LocalDateTime.of(2023, 12, 12, 9, 30)) - .endTime(LocalDateTime.of(2024, 1, 12, 9, 30)) - .build(); - scheduleId = scheduleCommandService.createSchedule(teamId, schedule, username); - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - - @Test - void createSchedule() { - // given - ScheduleCreateDto createRequest = ScheduleCreateDto.builder() - .title("test title") - .content("test content") - .startTime(LocalDateTime.of(2023, 12, 12, 9, 30)) - .endTime(LocalDateTime.of(2023, 12, 13, 19, 30)) - .build(); - - // when - Long createdScheduleId = scheduleCommandService.createSchedule(teamId, createRequest, username); - - // then - Schedule createdSchedule = scheduleQueryService.getScheduleById(createdScheduleId); - assertThat(createdSchedule.getTitle()).isEqualTo(createRequest.getTitle()); - assertThat(createdSchedule.getContent()).isEqualTo(createRequest.getContent()); - assertThat(createdSchedule.getStartTime()).isEqualTo(createRequest.getStartTime()); - assertThat(createdSchedule.getEndTime()).isEqualTo(createRequest.getEndTime()); - } - - @Test - void updateSchedule() { - // given - ScheduleCreateDto updateRequest = ScheduleCreateDto.builder() - .title("updated title") - .content("updated content") - .startTime(LocalDateTime.of(2023, 12, 1, 9, 30)) - .endTime(LocalDateTime.of(2023, 12, 2, 19, 30)) - .build(); - - // when - Long updatedScheduleId = scheduleCommandService.updateScheduleByUsername(scheduleId, username, updateRequest); - - // then - Schedule updatedSchedule = scheduleQueryService.getScheduleById(updatedScheduleId); - assertThat(updatedSchedule.getTitle()).isEqualTo(updateRequest.getTitle()); - assertThat(updatedSchedule.getContent()).isEqualTo(updateRequest.getContent()); - assertThat(updatedSchedule.getStartTime()).isEqualTo(updateRequest.getStartTime()); - assertThat(updatedSchedule.getEndTime()).isEqualTo(updateRequest.getEndTime()); - } - - @Test - void deleteSchedule() { - // when - scheduleCommandService.deleteScheduleByUsername(scheduleId, username); - //then - Assertions.assertThrows(ScheduleHandler.class, () -> scheduleQueryService.getScheduleById(scheduleId)); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/domain/schedule/service/ScheduleQueryServiceTest.java b/src/test/java/com/example/waggle/domain/schedule/service/ScheduleQueryServiceTest.java deleted file mode 100644 index 79f8349d..00000000 --- a/src/test/java/com/example/waggle/domain/schedule/service/ScheduleQueryServiceTest.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.example.waggle.domain.schedule.service; - -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.domain.schedule.entity.Schedule; -import com.example.waggle.domain.schedule.service.schedule.ScheduleCommandService; -import com.example.waggle.domain.schedule.service.schedule.ScheduleQueryService; -import com.example.waggle.domain.schedule.service.team.TeamCommandService; -import com.example.waggle.domain.schedule.service.team.TeamQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.schedule.ScheduleRequest.ScheduleCreateDto; -import com.example.waggle.web.dto.schedule.TeamRequest.TeamCreateDto; -======= -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.schedule.ScheduleRequest; -import com.example.waggle.web.dto.schedule.TeamRequest; ->>>>>>> develop -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.time.LocalDateTime; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -class ScheduleQueryServiceTest { - - @Autowired - ScheduleQueryService scheduleQueryService; - @Autowired - MemberCommandService memberCommandService; - @Autowired - MemberQueryService memberQueryService; - @Autowired - TeamCommandService teamCommandService; - @Autowired - TeamQueryService teamQueryService; - @Autowired - ScheduleCommandService scheduleCommandService; - @Autowired - DatabaseCleanUp databaseCleanUp; - - private Member member1; - private Member member2; - private Long teamId; - private Long scheduleId; - - @BeforeEach - void setUp() { - // Setup member -<<<<<<< HEAD - MemberCredentialsDto A = MemberCredentialsDto.builder() - .password("password") - .email("email") - .build(); - MemberCredentialsDto B = MemberCredentialsDto.builder() -======= - MemberRequest.AccessDto A = MemberRequest.AccessDto.builder() - .password("password") - .email("email") - .build(); - MemberRequest.AccessDto B = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("password") - .email("email1") - .build(); - Long memberA = memberCommandService.signUp(A); - Long memberB = memberCommandService.signUp(B); - member1 = memberQueryService.getMemberById(memberA); - member2 = memberQueryService.getMemberById(memberB); -<<<<<<< HEAD - TeamCreateDto build = TeamCreateDto.builder() -======= - TeamRequest.Post build = TeamRequest.Post.builder() ->>>>>>> develop - .teamColor("team_3") - .maxTeamSize(5) - .name("team") - .description("hello") - .build(); - teamId = teamCommandService.createTeam(build, member1.getUsername()); -<<<<<<< HEAD - ScheduleCreateDto schedule = ScheduleCreateDto.builder() -======= - ScheduleRequest.Post schedule = ScheduleRequest.Post.builder() ->>>>>>> develop - .title("schedule1") - .content("hi") - .startTime(LocalDateTime.now()) - .endTime(LocalDateTime.now()) - .build(); - scheduleId = scheduleCommandService.createSchedule(teamId, schedule, member1.getUsername()); - - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - @Test - void getScheduleById() { - // when - Schedule scheduleById = scheduleQueryService.getScheduleById(scheduleId); - - // then - assertThat(scheduleById.getContent()).isEqualTo("hi"); - } - - @Test - void getSchedulesByTeamId() { - // given -<<<<<<< HEAD - ScheduleCreateDto schedule2 = ScheduleCreateDto.builder() -======= - ScheduleRequest.Post schedule2 = ScheduleRequest.Post.builder() ->>>>>>> develop - .title("schedule1") - .content("hi") - .startTime(LocalDateTime.now()) - .endTime(LocalDateTime.now()) - .build(); - Long schedule = scheduleCommandService.createSchedule(teamId, schedule2, member1.getUsername()); - - // when - List schedules = scheduleQueryService.getTeamSchedules(teamId); - - // then - assertThat(schedules.size()).isEqualTo(2); - } - - @Test - void getSchedulesByMember() { - // given -<<<<<<< HEAD - ScheduleCreateDto schedule2 = ScheduleCreateDto.builder() -======= - ScheduleRequest.Post schedule2 = ScheduleRequest.Post.builder() ->>>>>>> develop - .title("schedule1") - .content("hi") - .startTime(LocalDateTime.now()) - .endTime(LocalDateTime.now()) - .build(); - Long schedule = scheduleCommandService.createSchedule(teamId, schedule2, member1.getUsername()); - - // when - List schedules = scheduleQueryService.getSchedulesByMember(member1.getId()); - - // then - assertThat(schedules.size()).isEqualTo(2); - } - - @Test - void getMonthlySchedulesByMember() { - // given - - // Setup team1 schedules - for (int i = 2; i <= 10; i++) { -<<<<<<< HEAD - ScheduleCreateDto newSchedule = ScheduleCreateDto.builder() -======= - ScheduleRequest.Post newSchedule = ScheduleRequest.Post.builder() ->>>>>>> develop - .title("team1 schedule" + i) - .content("team1 schedule" + i + " content") - .startTime(LocalDateTime.of(2023, i, 12, 9, 30)) - .endTime(LocalDateTime.of(2023, i + 1, 12, 9, 30)) - .build(); - scheduleCommandService.createSchedule(teamId, newSchedule, member1.getUsername()); - } - - // when - List monthlySchedules = scheduleQueryService.getMonthlySchedulesByMember( - member1.getId(), 2023, 10); - - // then - assertThat(monthlySchedules.size()).isEqualTo(2); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/domain/schedule/service/TeamCommandServiceTest.java b/src/test/java/com/example/waggle/domain/schedule/service/TeamCommandServiceTest.java deleted file mode 100644 index b948112e..00000000 --- a/src/test/java/com/example/waggle/domain/schedule/service/TeamCommandServiceTest.java +++ /dev/null @@ -1,269 +0,0 @@ -package com.example.waggle.domain.schedule.service; - -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.repository.MemberRepository; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.domain.schedule.entity.Participation; -import com.example.waggle.domain.schedule.entity.Participation.ParticipationStatus; -import com.example.waggle.domain.schedule.entity.Team; -import com.example.waggle.domain.schedule.entity.TeamMember; -import com.example.waggle.domain.schedule.repository.ParticipationRepository; -import com.example.waggle.domain.schedule.repository.TeamMemberRepository; -import com.example.waggle.domain.schedule.repository.TeamRepository; -import com.example.waggle.domain.schedule.service.team.TeamCommandService; -import com.example.waggle.domain.schedule.service.team.TeamQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.schedule.TeamRequest.TeamCreateDto; -======= -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.schedule.TeamRequest; ->>>>>>> develop -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@Slf4j -@SpringBootTest -class TeamCommandServiceTest { - - @Autowired - TeamCommandService teamCommandService; - @Autowired - TeamQueryService teamQueryService; - @Autowired - MemberCommandService memberCommandService; - @Autowired - MemberQueryService memberQueryService; - @Autowired - MemberRepository memberRepository; - @Autowired - TeamRepository teamRepository; - @Autowired - TeamMemberRepository teamMemberRepository; - @Autowired - ParticipationRepository participationRepository; - @Autowired - DatabaseCleanUp databaseCleanUp; - -<<<<<<< HEAD - private MemberCredentialsDto member1; - - private MemberCredentialsDto member2; - - private MemberCredentialsDto member3; -======= - private MemberRequest.AccessDto member1; - - private MemberRequest.AccessDto member2; - - private MemberRequest.AccessDto member3; ->>>>>>> develop - - private TeamCreateDto team; - - private Long teamId; - private Long member2Id; - - private Member member; - - - @BeforeEach - void setUp() { - // Setup member -<<<<<<< HEAD - member1 = MemberCredentialsDto.builder() -======= - member1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("dasfk") - .build(); - -<<<<<<< HEAD - member2 = MemberCredentialsDto.builder() -======= - member2 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("aksdfhsafa") - .build(); - -<<<<<<< HEAD - member3 = MemberCredentialsDto.builder() -======= - member3 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("wldkfjk") - .build(); - -<<<<<<< HEAD - team = TeamCreateDto.builder() -======= - team = TeamRequest.Post.builder() ->>>>>>> develop - .teamColor("team_4") - .maxTeamSize(4) - .name("team") - .description("team") - .build(); - Long member1 = memberCommandService.signUp(this.member1); - member2Id = memberCommandService.signUp(member2); - memberCommandService.signUp(member3); - member = memberQueryService.getMemberById(member1); - teamId = teamCommandService.createTeam(team, member.getUsername()); - } - - private void addMemberToTeam(Team team, Member member) { - TeamMember teamMember = TeamMember.builder() - .team(team) - .member(member) - .build(); - teamMember.addTeamMember(team, member); - teamMemberRepository.save(teamMember); - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - - @Test - void createTeam() { - // given - TeamCreateDto createRequest = TeamCreateDto.builder() - .name("test name") - .description("test description") - .maxTeamSize(10) - .teamColor("team_1") - .build(); - - // when - log.info("member username = {}", member.getUsername()); - Long createdTeamId = teamCommandService.createTeam(createRequest, member.getUsername()); - - // then - Team createdTeam = teamQueryService.getTeamById(createdTeamId); - assertThat(createdTeam.getName()).isEqualTo(createRequest.getName()); - assertThat(createdTeam.getDescription()).isEqualTo(createRequest.getDescription()); - assertThat(createdTeam.getMaxTeamSize()).isEqualTo(createRequest.getMaxTeamSize()); - } - - - @Test - void updateTeam() { - // given - TeamCreateDto updateRequest = TeamCreateDto.builder() - .name("updated name") - .description("updated description") - .teamColor("team_3") - .maxTeamSize(15) - .build(); - - // when - Long updatedTeamId = teamCommandService.updateTeam(teamId, member.getUsername(), updateRequest); - - // then - Team updatedTeam = teamRepository.findById(updatedTeamId).get(); - assertThat(updatedTeam.getName()).isEqualTo(updateRequest.getName()); - assertThat(updatedTeam.getDescription()).isEqualTo(updateRequest.getDescription()); - assertThat(updatedTeam.getMaxTeamSize()).isEqualTo(updateRequest.getMaxTeamSize()); - } - - @Test - void deleteTeam() { - // when - teamCommandService.deleteTeam(teamId, member.getUsername()); - - // then - assertThat(teamRepository.existsById(teamId)).isEqualTo(false); - } - - - @Test - void addTeamMember() { - - // when - Long updatedTeamId = teamCommandService.addTeamMember(teamId, member2Id); - - // then - List teamById = teamMemberRepository.findTeamMemberByTeamId(updatedTeamId); - assertThat(teamById.size()).isEqualTo(2); - } - - - @Test - @Transactional - void deleteTeamMember() { - // given - Long teamMember = teamCommandService.addTeamMember(teamId, member2Id); - // when - Team teamById = teamQueryService.getTeamById(teamId); - Member memberById = memberQueryService.getMemberById(member2Id); - teamCommandService.deleteTeamMemberByMyself(teamId, memberById.getUsername()); - - // then - List teamMemberByTeamId = teamMemberRepository.findTeamMemberByTeamId(teamId); - assertThat(teamMemberByTeamId.size()).isEqualTo(1); - } - - - @Test - @Transactional - void changeTeamLeader() { - // given - Long updatedTeamId = teamCommandService.addTeamMember(teamId, member2Id); - - // when - teamCommandService.changeTeamLeader(teamId, member2Id, member.getUsername()); - - // then - Team teamById = teamQueryService.getTeamById(teamId); - Member memberById = memberQueryService.getMemberById(member2Id); - assertThat(teamById.getLeader().getUsername()).isEqualTo(memberById.getUsername()); - } - - @Test - void requestParticipation() { - // when - Member memberById = memberQueryService.getMemberById(member2Id); - teamCommandService.requestParticipation(teamId, memberById.getUsername()); - - // then - Participation participation = participationRepository.findByTeamIdAndUsername(teamId, - memberById.getUsername()).get(); - assertThat(participation.getTeamId()).isEqualTo(teamId); - assertThat(participation.getUsername()).isEqualTo(memberById.getUsername()); - assertThat(participation.getStatus()).isEqualTo(ParticipationStatus.PENDING); - } - - @Test - void respondToParticipation() { - // given - Member memberById = memberQueryService.getMemberById(member2Id); - teamCommandService.requestParticipation(teamId, memberById.getUsername()); - - // when - teamCommandService.respondToParticipation(teamId, member2Id, member.getUsername(), true); - - // then - Participation participationOfMember2 = participationRepository.findByTeamIdAndUsername(teamId, - memberById.getUsername()).get(); - - assertThat(participationOfMember2.getTeamId()).isEqualTo(teamId); - assertThat(participationOfMember2.getUsername()).isEqualTo(memberById.getUsername()); - assertThat(participationOfMember2.getStatus()).isEqualTo(ParticipationStatus.ACCEPTED); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/domain/schedule/service/TeamQueryServiceTest.java b/src/test/java/com/example/waggle/domain/schedule/service/TeamQueryServiceTest.java deleted file mode 100644 index 4ed6d840..00000000 --- a/src/test/java/com/example/waggle/domain/schedule/service/TeamQueryServiceTest.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.example.waggle.domain.schedule.service; - -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.repository.MemberRepository; -import com.example.waggle.domain.schedule.entity.Team; -import com.example.waggle.domain.schedule.entity.TeamColor; -import com.example.waggle.domain.schedule.entity.TeamMember; -import com.example.waggle.domain.schedule.repository.TeamMemberRepository; -import com.example.waggle.domain.schedule.repository.TeamRepository; -import com.example.waggle.domain.schedule.service.team.TeamQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -class TeamQueryServiceTest { - - @Autowired - TeamQueryService teamQueryService; - @Autowired - MemberRepository memberRepository; - @Autowired - TeamRepository teamRepository; - @Autowired - TeamMemberRepository teamMemberRepository; - @Autowired - DatabaseCleanUp databaseCleanUp; - - private Member member1; - private Member member2; - private Team team1; - private Team team2; - - - @BeforeEach - void setUp() { - // Setup member - member1 = Member.builder() - .username("member1") - .userUrl("hi1") - .password("12345678") - .nickname("hi") - .email("wjdgks@naver.com") - .build(); - memberRepository.save(member1); - - member2 = Member.builder() - .username("member2") - .userUrl("hi2") - .password("12345678") - .nickname("hoe") - .email("wjdgks3264@naver.com") - .build(); - memberRepository.save(member2); - - // Setup team - team1 = Team.builder() - .name("team1") - .description("team1 description") - .leader(member1) - .maxTeamSize(4) - .teamColor(TeamColor.team_1) - .build(); - teamRepository.save(team1); - - team2 = Team.builder() - .name("team2") - .description("team2 description") - .leader(member1) - .maxTeamSize(4) - .teamColor(TeamColor.team_6) - .build(); - teamRepository.save(team2); - - // Setup teamMember - addMemberToTeam(team1, member1); - addMemberToTeam(team2, member1); - addMemberToTeam(team1, member2); - } - - private void addMemberToTeam(Team team, Member member) { - TeamMember teamMember = TeamMember.builder() - .team(team) - .member(member) - .build(); - teamMember.addTeamMember(team, member); - teamMemberRepository.save(teamMember); - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - @Test - void getTeamsByUsername() { - // when - Pageable pageable = PageRequest.of(0, 5); - List teams = teamQueryService.getPagingTeamByUsername(member1.getUsername(), pageable).getContent(); - - // then - assertThat(teams.size()).isEqualTo(2); - assertThat(teams).contains(team1, team2); - } - - @Test - void getTeamById() { - // when - Team teamById = teamQueryService.getTeamById(team1.getId()); - - // then - assertThat(teamById).isEqualTo(team1); - } - - @Test - void isTeamLeader() { - // when - boolean isMember1TeamLeader = teamQueryService.isTeamLeader(team1.getId(), member1.getUsername()); - boolean isMember2TeamLeader = teamQueryService.isTeamLeader(team1.getId(), member2.getUsername()); - - // then - assertThat(isMember1TeamLeader).isEqualTo(true); - assertThat(isMember2TeamLeader).isEqualTo(false); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/follow/service/FollowServiceTest.java b/src/test/java/com/example/waggle/follow/service/FollowServiceTest.java deleted file mode 100644 index 92344ab7..00000000 --- a/src/test/java/com/example/waggle/follow/service/FollowServiceTest.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.example.waggle.follow.service; - -import com.example.waggle.domain.follow.entity.Follow; -import com.example.waggle.domain.follow.service.FollowCommandService; -import com.example.waggle.domain.follow.service.FollowQueryService; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -import com.example.waggle.global.exception.handler.FollowHandler; -<<<<<<< HEAD -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -======= -import com.example.waggle.web.dto.member.MemberRequest; ->>>>>>> develop -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -public class FollowServiceTest { - @Autowired - FollowQueryService followQueryService; - @Autowired - FollowCommandService followCommandService; - @Autowired - MemberCommandService memberCommandService; - @Autowired - MemberQueryService memberQueryService; - @Autowired - DatabaseCleanUp databaseCleanUp; - -<<<<<<< HEAD - MemberCredentialsDto signUpDto1; - MemberCredentialsDto signUpDto2; - MemberCredentialsDto signUpDto3; - MemberCredentialsDto signUpDto4; -======= - MemberRequest.AccessDto signUpDto1; - MemberRequest.AccessDto signUpDto2; - MemberRequest.AccessDto signUpDto3; - MemberRequest.AccessDto signUpDto4; ->>>>>>> develop - - Long memberId1; - Long memberId2; - Long memberId3; - Long memberId4; - - - @AfterEach - void afterEach() { - databaseCleanUp.truncateAllEntity(); - } - - void setUp() { -<<<<<<< HEAD - signUpDto1 = MemberCredentialsDto.builder() -======= - signUpDto1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("wjdgks3264@naver.com") - .build(); - -<<<<<<< HEAD - signUpDto2 = MemberCredentialsDto.builder() -======= - signUpDto2 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("wjdgks2972@naver.com") - .build(); - -<<<<<<< HEAD - signUpDto3 = MemberCredentialsDto.builder() -======= - signUpDto3 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("wjdgksdfs@naver.com") - .build(); - -<<<<<<< HEAD - signUpDto4 = MemberCredentialsDto.builder() -======= - signUpDto4 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("hi@naver.com") - .build(); - - memberId1 = memberCommandService.signUp(signUpDto1); - memberId2 = memberCommandService.signUp(signUpDto2); - memberId3 = memberCommandService.signUp(signUpDto3); - memberId4 = memberCommandService.signUp(signUpDto4); - - } - - @Test - void follow() { - //given - setUp(); - //when - Member A = memberQueryService.getMemberById(memberId1); - Member B = memberQueryService.getMemberById(memberId2); - followCommandService.follow(A.getUsername(), B.getNickname()); - List followingsByUser = followQueryService.getFollowings(memberId1); - //then - assertThat(followingsByUser.size()).isEqualTo(1); - } - - @Test - void unfollow() { - //given - setUp(); - //when - Member A = memberQueryService.getMemberById(memberId1); - Member B = memberQueryService.getMemberById(memberId2); - Member C = memberQueryService.getMemberById(memberId3); - followCommandService.follow(A.getUsername(), B.getNickname()); - followCommandService.follow(A.getUsername(), C.getNickname()); - followCommandService.unFollow(A.getUsername(), B.getNickname()); - List followingsByUser = followQueryService.getFollowings(memberId1); - //then - assertThat(followingsByUser.size()).isEqualTo(1); - } - - @Test - void follow_exception() { - //given - setUp(); - //when - Member A = memberQueryService.getMemberById(memberId1); - Member B = memberQueryService.getMemberById(memberId2); - followCommandService.follow(A.getUsername(), B.getNickname()); - //then -<<<<<<< HEAD - Assertions.assertThrows(FollowHandler.class, - () -> followCommandService.follow(A.getUsername(), B.getNickname())); -======= - Assertions.assertThrows(FollowHandler.class, () -> followCommandService.follow(A.getUsername(), B.getNickname())); ->>>>>>> develop - } - - @Test - void unfollow_exception() { - //given - setUp(); - //when - Member A = memberQueryService.getMemberById(memberId1); - Member B = memberQueryService.getMemberById(memberId2); - Member C = memberQueryService.getMemberById(memberId3); - Long followId = followCommandService.follow(A.getUsername(), B.getNickname()); - followCommandService.follow(A.getUsername(), C.getNickname()); - followCommandService.unFollow(A.getUsername(), B.getNickname()); - //then -<<<<<<< HEAD - Assertions.assertThrows(FollowHandler.class, - () -> followCommandService.unFollow(A.getUsername(), B.getNickname())); -======= - Assertions.assertThrows(FollowHandler.class, () -> followCommandService.unFollow(A.getUsername(), B.getNickname())); ->>>>>>> develop - } -} diff --git a/src/test/java/com/example/waggle/member/controller/MemberControllerTest.java b/src/test/java/com/example/waggle/member/controller/MemberControllerTest.java deleted file mode 100644 index 06ab8bb1..00000000 --- a/src/test/java/com/example/waggle/member/controller/MemberControllerTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.example.waggle.member.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.test.web.server.LocalServerPort; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@Slf4j -public class MemberControllerTest { - - @Autowired - TestRestTemplate testRestTemplate; - @Autowired - ObjectMapper objectMapper; - @LocalServerPort - int randomServerPort; - - @Test - public void signUpTest() throws Exception { - // header -// String url = "http://localhost:" + randomServerPort + "/member/sign-up"; -// HttpHeaders headers = new HttpHeaders(); -// headers.setContentType(MediaType.APPLICATION_JSON); -// -// // body -// SignUpDto signUpDto = SignUpDto.builder() -// .username("test") -// .password("12345678") -// .phone("01012345678") -// .nickname("test") -// .build(); -// String body = objectMapper.writeValueAsString(signUpDto); -// -// // API 요청 설정 -// ResponseEntity responseEntity = testRestTemplate.postForEntity(url, new HttpEntity<>(body, headers), String.class); -// -// assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); -// assertThat(responseEntity.getBody()).isEqualTo(signUpDto.getUsername()); - } - - - @Test - public void signIn() { - -// SignInDto signInDto = SignInDto.builder() -// .username("member1") -// .password("12345678").build(); -// -// -// // HttpHeaders 객체 생성 및 토큰 추가 -// HttpHeaders httpHeaders = new HttpHeaders(); -// httpHeaders.setBearerAuth(jwtToken.getAccessToken()); -// httpHeaders.setContentType(MediaType.APPLICATION_JSON); -// -// log.info("httpHeaders = {}", httpHeaders); -// -// // API 요청 설정 -// String url = "http://localhost:" + randomServerPort + "/members/test"; -// ResponseEntity responseEntity = testRestTemplate.postForEntity(url, new HttpEntity<>(httpHeaders), String.class); -// assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); -// assertThat(responseEntity.getBody()).isEqualTo(signInDto.getUsername()); -// -//// assertThat(SecurityUtil.getCurrentUsername()).isEqualTo(signInDto.getUsername()); // -> 테스트 코드에서는 인증을 위한 절차를 거치지 X. SecurityContextHolder 에 인증 정보가 존재하지 않는다. -// - - } -} diff --git a/src/test/java/com/example/waggle/member/service/MemberServiceImplTest.java b/src/test/java/com/example/waggle/member/service/MemberServiceImplTest.java deleted file mode 100644 index c9f324e7..00000000 --- a/src/test/java/com/example/waggle/member/service/MemberServiceImplTest.java +++ /dev/null @@ -1,269 +0,0 @@ -package com.example.waggle.member.service; - -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.board.story.service.StoryCommandService; -import com.example.waggle.domain.board.story.service.StoryQueryService; -import com.example.waggle.domain.conversation.entity.Comment; -import com.example.waggle.domain.conversation.entity.Reply; -import com.example.waggle.domain.conversation.service.comment.CommentCommandService; -import com.example.waggle.domain.conversation.service.comment.CommentQueryService; -import com.example.waggle.domain.conversation.service.reply.ReplyCommandService; -import com.example.waggle.domain.conversation.service.reply.ReplyQueryService; -import com.example.waggle.domain.follow.entity.Follow; -import com.example.waggle.domain.follow.service.FollowCommandService; -import com.example.waggle.domain.follow.service.FollowQueryService; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.repository.MemberRepository; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.domain.pet.entity.Pet; -import com.example.waggle.domain.pet.service.PetCommandService; -import com.example.waggle.domain.pet.service.PetQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.comment.CommentRequest.CommentCreateDto; -import com.example.waggle.web.dto.member.MemberRequest.MemberUpdateDto; -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.pet.PetRequest.PetCreateDto; -import com.example.waggle.web.dto.reply.ReplyRequest.ReplyCreateDto; -import com.example.waggle.web.dto.story.StoryRequest.StoryCreateDto; -======= -import com.example.waggle.web.dto.comment.CommentRequest; -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.pet.PetRequest; -import com.example.waggle.web.dto.reply.ReplyRequest; -import com.example.waggle.web.dto.story.StoryRequest; ->>>>>>> develop -import jakarta.persistence.EntityManager; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.http.*; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@Slf4j -class MemberServiceImplTest { - @Autowired - DatabaseCleanUp databaseCleanUp; - @Autowired - MemberRepository memberRepository; - @Autowired - MemberCommandService memberService; - @Autowired - MemberQueryService memberQueryService; - @Autowired - StoryCommandService storyCommandService; - @Autowired - StoryQueryService storyQueryService; - @Autowired - CommentCommandService commentCommandService; - @Autowired - CommentQueryService commentQueryService; - @Autowired - ReplyCommandService replyCommandService; - @Autowired - ReplyQueryService replyQueryService; - @Autowired - FollowCommandService followCommandService; - @Autowired - FollowQueryService followQueryService; - @Autowired - PetCommandService petService; - @Autowired - PetQueryService petQueryService; - @Autowired - TestRestTemplate testRestTemplate; - @LocalServerPort - int randomServerPort; - @Autowired - EntityManager entityManager; - - -<<<<<<< HEAD - private MemberCredentialsDto signUpDto1; - private MemberCredentialsDto signUpDto2; - private MemberCredentialsDto signUpDto3; - private PetCreateDto petRequest; -======= - private MemberRequest.AccessDto signUpDto1; - private MemberRequest.AccessDto signUpDto2; - private MemberRequest.AccessDto signUpDto3; - private PetRequest.Post petRequest; ->>>>>>> develop - - private StoryCreateDto storyRequest; - private CommentCreateDto commentRequest; - private CommentCreateDto commentRequest2; - private ReplyCreateDto replyRequest; - - private MemberUpdateDto updateDto; - - - @BeforeEach - void beforeEach() { - // Member 회원가입 -<<<<<<< HEAD - signUpDto1 = MemberCredentialsDto.builder() -======= - signUpDto1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("asdklfj") - .build(); - -<<<<<<< HEAD - signUpDto2 = MemberCredentialsDto.builder() -======= - - signUpDto2 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("sdlfkjsalkfj") - .build(); - -<<<<<<< HEAD - signUpDto3 = MemberCredentialsDto.builder() -======= - signUpDto3 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("asdklfj") - .build(); - - petRequest = PetCreateDto.builder().name("chococococo").build(); - - updateDto = MemberUpdateDto.builder() - .password("34567898765") - .nickname("hann.o_i") - .build(); - - storyRequest = StoryCreateDto.builder() - .content("hi") - .build(); - commentRequest = CommentCreateDto.builder() - .content("hi this is comment") - .build(); - commentRequest2 = CommentCreateDto.builder() - .content("member2 write comment") - .build(); - - replyRequest = ReplyCreateDto.builder() - .content("hi this is reply") - .build(); - } - - @AfterEach - void afterEach() { - databaseCleanUp.truncateAllEntity(); - } - - @Test - public void signUp() { - Long memberId = memberService.signUp(signUpDto1); - - Member member = memberQueryService.getMemberById(memberId); - - assertThat(member.getEmail()).isEqualTo(signUpDto1.getEmail()); - } - -// @Test -// public void 중복_회원_예외() { -// // savedMemberDto1와 savedMemberDto3의 username 중복 ➡︎ IllegalArgumentException 발생해야 함. -// memberService.signUp(signUpDto1); -// memberService.signUp(signUpDto2); -// Assertions.assertThrows(MemberHandler.class, () -> memberService.signUp(signUpDto3)); -// } - - @Test - @Disabled - public void signIn() { - memberService.signUp(signUpDto1); - memberService.signUp(signUpDto2); - -<<<<<<< HEAD - MemberCredentialsDto signInDto = MemberCredentialsDto.builder() -======= - MemberRequest.AccessDto signInDto = MemberRequest.AccessDto.builder() ->>>>>>> develop - .email("member1") - .password("12345678").build(); - - // 로그인 요청 - - // HttpHeaders 객체 생성 및 토큰 추가 - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setContentType(MediaType.APPLICATION_JSON); - - // API 요청 설정 - String url = "http://localhost:" + randomServerPort + "/member/test"; - ResponseEntity responseEntity = testRestTemplate.postForEntity(url, new HttpEntity<>(httpHeaders), - String.class); - log.info("responseEntity = {}", responseEntity); - - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(responseEntity.getBody()).isEqualTo(signInDto.getEmail()); - } - - @Test - void member_Information_update() { - //given - Long aLong = memberService.signUp(signUpDto1); - Member member1 = memberQueryService.getMemberById(aLong); - //when -<<<<<<< HEAD - Long aLong1 = memberService.updateMemberProfile(member1.getUsername(), updateDto); -======= - Long aLong1 = memberService.updateMemberInfo(member1.getUsername(), updateDto); ->>>>>>> develop - Member member = memberQueryService.getMemberById(aLong); - Member memberByUsername = memberQueryService.getMemberByUsername(member.getUsername()); - //then - assertThat(memberByUsername.getNickname()).isEqualTo(updateDto.getNickname()); - } - - @Test - // pass - @Disabled - void member_delete_hardReset() { - //given - Long member1 = memberService.signUp(signUpDto1); - Long member2 = memberService.signUp(signUpDto2); - Member A = memberQueryService.getMemberById(member1); - Member B = memberQueryService.getMemberById(member2); - - Long story = storyCommandService.createStoryByUsername(storyRequest, null, A.getUsername()); - Long comment = commentCommandService.createCommentByUsername(story, commentRequest, A.getUsername()); - replyCommandService.createReplyByUsername(comment, replyRequest, A.getUsername()); - commentCommandService.createCommentByUsername(story, commentRequest2, A.getUsername()); - followCommandService.follow(A.getUsername(), B.getUsername()); - Long pet = petService.createPetByUsername(petRequest, A.getUsername()); - Member member = memberQueryService.getMemberByUsername(A.getUsername()); - - //when - memberService.deleteMember(member1); - - //then - List stories = storyQueryService.getStories(); - List comments = commentQueryService.getComments(story); - List replies = replyQueryService.getReplies(comment); - List follows = followQueryService.getFollowings(A.getId()); - List pets = petQueryService.getPetsByUsername(A.getUsername()); - - assertThat(stories.size()).isEqualTo(0); - assertThat(comments.size()).isEqualTo(0); - assertThat(replies.size()).isEqualTo(0); - assertThat(follows.size()).isEqualTo(0); - assertThat(pets.size()).isEqualTo(0); - - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/pet/service/PetServiceTest.java b/src/test/java/com/example/waggle/pet/service/PetServiceTest.java deleted file mode 100644 index d0081951..00000000 --- a/src/test/java/com/example/waggle/pet/service/PetServiceTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.example.waggle.pet.service; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.example.waggle.domain.member.entity.Gender; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.domain.pet.entity.Pet; -import com.example.waggle.domain.pet.repository.PetRepository; -import com.example.waggle.domain.pet.service.PetCommandService; -import com.example.waggle.domain.pet.service.PetQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -import com.example.waggle.global.exception.handler.PetHandler; -<<<<<<< HEAD -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.member.MemberResponse.MemberSummaryDto; -======= -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.member.MemberResponse; ->>>>>>> develop -import com.example.waggle.web.dto.pet.PetRequest; -import java.util.List; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -@Slf4j -class PetServiceTest { - @Autowired - DatabaseCleanUp databaseCleanUp; - @Autowired - PetRepository petRepository; - - @Autowired - MemberCommandService memberCommandService; - @Autowired - MemberQueryService memberQueryService; - @Autowired - PetCommandService petService; - @Autowired - PetQueryService petQueryService; - - - private MemberSummaryDto memberSummaryDto; - private Long savedPetId; - Member member; - - - @BeforeEach - void beforeEach() { - // member 저장 -<<<<<<< HEAD - MemberCredentialsDto signUpDto = MemberCredentialsDto.builder() -======= - MemberRequest.AccessDto signUpDto = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("dslkajflk") - .build(); - Long memberId = memberCommandService.signUp(signUpDto); - member = memberQueryService.getMemberById(memberId); - - // pet 저장 - PetRequest petDto = PetRequest.builder() - .name("루이") - .breed("포메라니안") - .gender(Gender.MALE.toString()) - .age("now").build(); - - savedPetId = petService.createPetByUsername(petDto, member.getUsername()); - } - - @AfterEach - void afterEach() { - databaseCleanUp.truncateAllEntity(); - } - - @Test - void findByPetId() { - // petId로 조회 - Pet petById = petQueryService.getPetById(savedPetId); - assertThat(savedPetId).isEqualTo(petById.getId()); - } - - @Test - void findByUsername() { - //given - PetRequest build = PetRequest.builder() - .name("hi") - .gender(Gender.MALE.toString()) - .build(); - Long pet = petService.createPetByUsername(build, member.getUsername()); - //when - List petsByUsername = petQueryService.getPetsByUsername(member.getUsername()); - //then - assertThat(petsByUsername.size()).isEqualTo(2); - - } - - @Test - void updatePet() { - // pet 수정 (변경 사항만 수정하는 건 컨트롤러 계층에서 처리) - PetRequest updatePetDto = PetRequest.builder() - .name("루이2") - .breed("포메라니안2") - .gender(Gender.MALE.toString()) - .age("now").build(); - - Long updatedPetId = petService.updatePetByUsername(savedPetId, member.getUsername(), updatePetDto); - Pet petById = petQueryService.getPetById(updatedPetId); - assertThat(petById.getName()).isEqualTo(updatePetDto.getName()); - - // repository에서 member 조회시 펫 수정 확인 -// List petDtoList = petService.findByUsername(savedMemberDto.getUsername()); -// log.info(petDtoList.get(0).getName()); - } - - @Test - void removePet() { - // pet 삭제 - petService.deletePetByUsername(savedPetId, member.getUsername()); - - Assertions.assertThrows(PetHandler.class, () -> petQueryService.getPetById(savedPetId)); - -// List tmp = petService.findByMemberId(savedMemberDto.getId()); -// assertThat(tmp.size()).isEqualTo(0); - } - - @Test - void remove_All_Pet_user_have() { - //given - PetRequest build = PetRequest.builder() - .name("hi") - .gender(Gender.MALE.toString()) - .build(); - Long pet = petService.createPetByUsername(build, member.getUsername()); - //when - petService.deleteAllPetByUser(member.getUsername()); - //then - List petsByUsername = petQueryService.getPetsByUsername("member1"); - assertThat(petsByUsername.size()).isEqualTo(0); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/recommend/repository/RecommendRepositoryTest.java b/src/test/java/com/example/waggle/recommend/repository/RecommendRepositoryTest.java deleted file mode 100644 index beee80dd..00000000 --- a/src/test/java/com/example/waggle/recommend/repository/RecommendRepositoryTest.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.example.waggle.recommend.repository; - -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.board.story.repository.StoryRepository; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.repository.MemberRepository; -import com.example.waggle.domain.recommend.entity.Recommend; -import com.example.waggle.domain.recommend.repository.RecommendRepository; -import com.example.waggle.global.component.DatabaseCleanUp; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -class RecommendRepositoryTest { - - @Autowired - private MemberRepository memberRepository; - @Autowired - private RecommendRepository recommendRepository; - @Autowired - private StoryRepository storyRepository; - @Autowired - DatabaseCleanUp databaseCleanUp; - - Story story1; - //who write board - Member member; - //who recommend board x 2 - Member member1; - Member member2; - - // member made(2) -> story made -> recommend -> counting - - void setting() { - member = Member.builder() - .username("username") - .password("password") - .userUrl("hi1") - .nickname("nickname") - .email("email") - .build(); - member1 = Member.builder() - .username("username1") - .userUrl("hi2") - .password("password1") - .nickname("nickname1") - .email("email1") - .build(); - member2 = Member.builder() - .username("username2") - .userUrl("hi3") - .password("password2") - .nickname("nickname2") - .email("email2") - .build(); - memberRepository.save(member); - memberRepository.save(member1); - memberRepository.save(member2); - - story1 = Story.builder().content("chochoco").member(member).build(); - storyRepository.save(story1); - - Recommend recommend1 = Recommend.builder().board(story1).member(member1).build(); - Recommend recommend2 = Recommend.builder().board(story1).member(member2).build(); - - recommendRepository.save(recommend1); - recommendRepository.save(recommend2); - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - @Test - @Transactional - void countByBoardId() { - setting(); - int countRecommend = recommendRepository.countByBoardId(story1.getId()); - assertThat(countRecommend).isEqualTo(2); - } - - @Test - @Transactional - void existsByMemberIdAndBoardId() { - setting(); - - Long member1Id = member1.getId(); - Long memberId = member.getId(); - Long storyId = story1.getId(); - - boolean expectFalse = recommendRepository.existsByMemberIdAndBoardId(memberId, storyId); - boolean expectTrue = recommendRepository.existsByMemberIdAndBoardId(member1Id, storyId); - - assertThat(expectFalse).isFalse(); - assertThat(expectTrue).isTrue(); - - - } - - @Test - @Transactional - void findRecommendByMemberIdAndBoardId() { - setting(); - Long member1Id = member1.getId(); - Long storyId = story1.getId(); - - Optional recommendByMemberIdAndBoardId = recommendRepository.findRecommendByMemberIdAndBoardId(member1Id, storyId); - - assertThat(recommendByMemberIdAndBoardId.isPresent()).isTrue(); - assertThat(recommendByMemberIdAndBoardId.get().getMember().getUsername()).isEqualTo("username1"); - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/recommend/service/RecommendServiceTest.java b/src/test/java/com/example/waggle/recommend/service/RecommendServiceTest.java deleted file mode 100644 index 372185a0..00000000 --- a/src/test/java/com/example/waggle/recommend/service/RecommendServiceTest.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.example.waggle.recommend.service; - -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.board.story.service.StoryCommandService; -import com.example.waggle.domain.board.story.service.StoryQueryService; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.domain.recommend.service.RecommendCommandService; -import com.example.waggle.domain.recommend.service.RecommendQueryService; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.story.StoryRequest.StoryCreateDto; -======= -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.story.StoryRequest; ->>>>>>> develop -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -@SpringBootTest -@Slf4j -class RecommendServiceTest { - - @Autowired - private StoryCommandService storyService; - @Autowired - private StoryQueryService storyQueryService; - @Autowired - private MemberCommandService memberService; - @Autowired - private MemberQueryService memberQueryService; - @Autowired - private RecommendCommandService recommendService; - @Autowired - private RecommendQueryService recommendQueryService; - @Autowired - DatabaseCleanUp databaseCleanUp; - - -<<<<<<< HEAD - MemberCredentialsDto signUpDto1; - MemberCredentialsDto signUpDto2; -======= - MemberRequest.AccessDto signUpDto1; - MemberRequest.AccessDto signUpDto2; ->>>>>>> develop - - StoryCreateDto storyWriteDto1; - StoryCreateDto storyWriteDto2; - - List tags1 = new ArrayList<>(); - List tags2 = new ArrayList<>(); - List medias1 = new ArrayList<>(); - List medias2 = new ArrayList<>(); - - Member member; - Member recommendMember; - - - @BeforeEach - void setDto() { - tags1.add("choco"); - tags1.add("poodle"); - tags2.add("poodle"); - - medias1.add("media1"); - medias1.add("mediamedia1"); - medias2.add("media2"); - medias2.add("mediamedia2"); - -<<<<<<< HEAD - signUpDto1 = MemberCredentialsDto.builder() -======= - signUpDto1 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("hi") - .build(); - -<<<<<<< HEAD - signUpDto2 = MemberCredentialsDto.builder() -======= - signUpDto2 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("hoe") - .build(); - - storyWriteDto1 = StoryCreateDto.builder() - .content("i love my choco") - .hashtagList(tags1) - .build(); - - storyWriteDto2 = StoryCreateDto.builder() - .content("how can i do make he is happy?") - .hashtagList(tags2) - .build(); - - - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - void setBoardAndMember() { - - //member set - Long memberId = memberService.signUp(signUpDto1); - Long recommendMemberId = memberService.signUp(signUpDto2); - member = memberQueryService.getMemberById(memberId); - recommendMember = memberQueryService.getMemberById(recommendMemberId); - - //story set - storyService.createStoryByUsername(storyWriteDto1, null, member.getUsername()); - } - - @Test - void recommendBoard() { - //given - setBoardAndMember(); - Story story = storyQueryService.getStories().get(0); - - //when - recommendService.handleRecommendationByUsername(story.getId(), recommendMember.getUsername()); - Story storyByBoardId = storyQueryService.getStoryByBoardId(story.getId()); - int count = recommendQueryService.countRecommend(storyByBoardId.getId()); - - //then - assertThat(count).isEqualTo(1); - } - - @Test - void cancelRecommendBoard() { - //given - setBoardAndMember(); - Story story = storyQueryService.getStories().get(0); - recommendService.handleRecommendationByUsername(story.getId(), recommendMember.getUsername()); - recommendService.handleRecommendationByUsername(story.getId(), recommendMember.getUsername()); - - //when - Story storyByBoardId = storyQueryService.getStoryByBoardId(story.getId()); - boolean recommend = recommendQueryService.checkRecommend(storyByBoardId.getId(), member.getId()); - - //then - assertThat(recommend).isFalse(); - } - - @Test - void cannot_recommend_Mine() { - //given - setBoardAndMember(); - Story story = storyQueryService.getStories().get(0); - //then - assertThatThrownBy(() -> recommendService.handleRecommendationByUsername(story.getId(), member.getUsername())); - } - - @Test - void story_remove_result_recommendEntity() { - //given - Long member1Id = memberService.signUp(signUpDto1); - Long member2Id = memberService.signUp(signUpDto2); - Member memberById = memberQueryService.getMemberById(member1Id); - Member memberById1 = memberQueryService.getMemberById(member2Id); - - StoryCreateDto request = StoryCreateDto.builder() - .content("hi") - .build(); - - storyService.createStoryByUsername(request, null, memberById.getUsername()); - Story story = storyQueryService.getStories().get(0); - recommendService.handleRecommendationByUsername(story.getId(), memberById1.getUsername()); - //when - storyService.deleteStoryByUsername(story.getId(), memberById.getUsername()); - int size = recommendQueryService.getRecommendingMembers(story.getId()).size(); - //then - assertThat(size).isEqualTo(0); - } - -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/reply/service/ReplyServiceTest.java b/src/test/java/com/example/waggle/reply/service/ReplyServiceTest.java deleted file mode 100644 index 80264f6f..00000000 --- a/src/test/java/com/example/waggle/reply/service/ReplyServiceTest.java +++ /dev/null @@ -1,271 +0,0 @@ -package com.example.waggle.reply.service; - -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.board.story.service.StoryCommandService; -import com.example.waggle.domain.board.story.service.StoryQueryService; -import com.example.waggle.domain.conversation.entity.Comment; -import com.example.waggle.domain.conversation.entity.Reply; -import com.example.waggle.domain.conversation.service.comment.CommentCommandService; -import com.example.waggle.domain.conversation.service.comment.CommentQueryService; -import com.example.waggle.domain.conversation.service.reply.ReplyCommandService; -import com.example.waggle.domain.conversation.service.reply.ReplyQueryService; -import com.example.waggle.domain.member.entity.Member; -import com.example.waggle.domain.member.service.MemberCommandService; -import com.example.waggle.domain.member.service.MemberQueryService; -import com.example.waggle.domain.mention.repository.MentionRepository; -import com.example.waggle.global.component.DatabaseCleanUp; -<<<<<<< HEAD -import com.example.waggle.web.dto.comment.CommentRequest.CommentCreateDto; -import com.example.waggle.web.dto.member.MemberRequest.MemberCredentialsDto; -import com.example.waggle.web.dto.reply.ReplyRequest.ReplyCreateDto; -import com.example.waggle.web.dto.story.StoryRequest.StoryCreateDto; -======= -import com.example.waggle.web.dto.comment.CommentRequest; -import com.example.waggle.web.dto.member.MemberRequest; -import com.example.waggle.web.dto.reply.ReplyRequest; -import com.example.waggle.web.dto.story.StoryRequest; ->>>>>>> develop -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -@Slf4j -class ReplyServiceTest { - - @Autowired - private StoryCommandService storyService; - @Autowired - private StoryQueryService storyQueryService; - @Autowired - private MemberCommandService memberService; - @Autowired - private CommentCommandService commentService; - @Autowired - private CommentQueryService commentQueryService; - @Autowired - private ReplyCommandService replyService; - @Autowired - private ReplyQueryService replyQueryService; - @Autowired - private MentionRepository mentionRepository; - @Autowired - private MemberQueryService memberQueryService; - @Autowired - DatabaseCleanUp databaseCleanUp; - - -<<<<<<< HEAD - MemberCredentialsDto signUpDto1; - MemberCredentialsDto signUpDto2; - MemberCredentialsDto signUpDto3; - MemberCredentialsDto signUpDto4; - MemberCredentialsDto signUpDto5; -======= - MemberRequest.AccessDto signUpDto1; - MemberRequest.AccessDto signUpDto2; - MemberRequest.AccessDto signUpDto3; - MemberRequest.AccessDto signUpDto4; - MemberRequest.AccessDto signUpDto5; ->>>>>>> develop - - - StoryCreateDto storyWriteDto1; - StoryCreateDto storyWriteDto2; - - CommentCreateDto commentWriteDto1; - ReplyCreateDto replyWriteDto1; - ReplyCreateDto replyWriteDto2; - - List mentions1 = new ArrayList<>(); - List mentions2 = new ArrayList<>(); - Member member; - - - @BeforeEach - void setDto() { - - mentions1.add("member1"); - mentions1.add("user2"); - mentions2.add("user3"); - mentions2.add("user4"); - -<<<<<<< HEAD - signUpDto1 = MemberCredentialsDto.builder() - .password("12345678") - .email("hi") - .build(); - signUpDto2 = MemberCredentialsDto.builder() - .password("12345678") - .email("hoe") - .build(); - signUpDto3 = MemberCredentialsDto.builder() -======= - signUpDto1 = MemberRequest.AccessDto.builder() - .password("12345678") - .email("hi") - .build(); - signUpDto2 = MemberRequest.AccessDto.builder() - .password("12345678") - .email("hoe") - .build(); - signUpDto3 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("zz") - .build(); - -<<<<<<< HEAD - signUpDto4 = MemberCredentialsDto.builder() - .password("12345678") - .email("haha") - .build(); - signUpDto5 = MemberCredentialsDto.builder() -======= - signUpDto4 = MemberRequest.AccessDto.builder() - .password("12345678") - .email("haha") - .build(); - signUpDto5 = MemberRequest.AccessDto.builder() ->>>>>>> develop - .password("12345678") - .email("ez") - .build(); - - storyWriteDto1 = StoryCreateDto.builder() - .content("i love my choco") - .build(); - - storyWriteDto2 = StoryCreateDto.builder() - .content("how can i do make he is happy?") - .build(); - - commentWriteDto1 = CommentCreateDto.builder() - .content("comment1") - .build(); - - replyWriteDto1 = ReplyCreateDto.builder() - .content("reply1") - .build(); - - replyWriteDto2 = ReplyCreateDto.builder() - .content("reply2") - .build(); - - - } - - @AfterEach - void clean() { - databaseCleanUp.truncateAllEntity(); - } - - private void setAll() { - //member set - Long memberId = memberService.signUp(signUpDto1); - memberService.signUp(signUpDto2); - memberService.signUp(signUpDto3); - memberService.signUp(signUpDto4); - memberService.signUp(signUpDto5); - member = memberQueryService.getMemberById(memberId); - - //story set - storyService.createStoryByUsername(storyWriteDto1, null, member.getUsername()); - storyService.createStoryByUsername(storyWriteDto2, null, member.getUsername()); - - Story story = storyQueryService.getStories().get(0); - - //comment set - commentService.createCommentByUsername(story.getId(), commentWriteDto1, member.getUsername()); - //reply set - List comments = commentQueryService.getComments(story.getId()); - replyService.createReplyByUsername(comments.get(0).getId(), replyWriteDto1, member.getUsername()); - replyService.createReplyByUsername(comments.get(0).getId(), replyWriteDto2, member.getUsername()); - - } - - - @Test - void findReplies() { - //given - setAll(); - Story story = storyQueryService.getStories().get(0); - List comments = commentQueryService.getComments(story.getId()); - //when - List replies = replyQueryService.getReplies(comments.get(0).getId()); - //then - assertThat(replies.size()).isEqualTo(2); - } - - - @Test - void changeReply() { - //given - setAll(); - Story story = storyQueryService.getStories().get(0); - List comments = commentQueryService.getComments(story.getId()); - List replies = replyQueryService.getReplies(comments.get(0).getId()); - //when - replyService.updateReplyByUsername(replies.get(0).getId(), member.getUsername(), replyWriteDto2); - List replyList = replyQueryService.getReplies(comments.get(0).getId()); - //then - assertThat(replyList.get(0).getContent()).isEqualTo("reply2"); - } - - @Test - void deleteReply() { - //given - setAll(); - Story story = storyQueryService.getStories().get(0); - List comments = commentQueryService.getComments(story.getId()); - List replies = replyQueryService.getReplies(comments.get(0).getId()); - - //when - replyService.deleteReply(replies.get(0).getId(), member.getUsername()); - List replyList = replyQueryService.getReplies(comments.get(0).getId()); - //then - assertThat(replyList.size()).isEqualTo(1); - } - - @Test - void deleteComments() { - //given - setAll(); - Story story = storyQueryService.getStories().get(0); - List comments = commentQueryService.getComments(story.getId()); - Long id = comments.get(0).getId(); - - //when - commentService.deleteCommentByUsername(id, member.getUsername()); - List replies = replyQueryService.getReplies(id); - - //then - assertThat(replies.size()).isEqualTo(0); - - } - - @Test - void deleteBoards() { - //given - setAll(); - Story story = storyQueryService.getStories().get(0); - List comments = commentQueryService.getComments(story.getId()); - Long id = comments.get(0).getId(); - - //when - storyService.deleteStoryByUsername(story.getId(), member.getUsername()); - List replies = replyQueryService.getReplies(id); - - //then - assertThat(replies.size()).isEqualTo(0); - - } -} \ No newline at end of file diff --git a/src/test/java/com/example/waggle/web/dto/global/LazyLoadingTest.java b/src/test/java/com/example/waggle/web/dto/global/LazyLoadingTest.java deleted file mode 100644 index 67062b73..00000000 --- a/src/test/java/com/example/waggle/web/dto/global/LazyLoadingTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.example.waggle.web.dto.global; - -import com.example.waggle.domain.board.Board; -import com.example.waggle.domain.board.story.entity.Story; -import com.example.waggle.domain.hashtag.entity.BoardHashtag; -import com.example.waggle.domain.hashtag.entity.Hashtag; -import jakarta.persistence.EntityManager; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@SpringBootTest -@Slf4j -public class LazyLoadingTest { - - @Autowired - EntityManager em; - - @Test - @Transactional - @Disabled - public void proxyTest() { - // data initialize - Board board = Story.builder() - .content("content") - .build(); - - Hashtag hashtag = Hashtag.builder() - .content("hashtag").build(); - - BoardHashtag boardHashtag = BoardHashtag.builder() - .board(board) - .hashtag(hashtag).build(); - - - em.persist(board); - em.persist(hashtag); - em.persist(boardHashtag); - - em.flush(); - em.clear(); - - - // Board 엔티티 조회 - Board findBoard = em.find(Board.class, 1L); - - // boardHashtags 필드 접근 - List boardHashtags = findBoard.getBoardHashtags(); - log.info("boardHashtags = {}", boardHashtags.getClass().getName()); // boardHashtags = org.hibernate.collection.spi.PersistentBag - - // 실제 데이터 로딩 - log.info("boardHashtag = {}", boardHashtags.get(0).getClass().getName()); // boardHashtag = com.example.waggle.hashtag.domain.BoardHashtag - - log.info("hashtag = {}", hashtag.getContent()); - - } - -} diff --git a/src/test/java/com/example/waggle/web/dto/global/annotation/withMockUser/WithMockCustomUser.java b/src/test/java/com/example/waggle/web/dto/global/annotation/withMockUser/WithMockCustomUser.java deleted file mode 100644 index 8e595268..00000000 --- a/src/test/java/com/example/waggle/web/dto/global/annotation/withMockUser/WithMockCustomUser.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.example.waggle.web.dto.global.annotation.withMockUser; - -import org.springframework.security.test.context.support.WithSecurityContext; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -@WithSecurityContext(factory = WithMockCustomUserSecurityContextFactory.class) -public @interface WithMockCustomUser { - String username() default "member1"; - - String password() default "12345678"; -} diff --git a/src/test/java/com/example/waggle/web/dto/global/annotation/withMockUser/WithMockCustomUserSecurityContextFactory.java b/src/test/java/com/example/waggle/web/dto/global/annotation/withMockUser/WithMockCustomUserSecurityContextFactory.java deleted file mode 100644 index 2b426791..00000000 --- a/src/test/java/com/example/waggle/web/dto/global/annotation/withMockUser/WithMockCustomUserSecurityContextFactory.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.waggle.web.dto.global.annotation.withMockUser; - -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.test.context.support.WithSecurityContextFactory; - -public class WithMockCustomUserSecurityContextFactory implements WithSecurityContextFactory { - @Override - public SecurityContext createSecurityContext(WithMockCustomUser annotation) { - - final SecurityContext securityContext = SecurityContextHolder.createEmptyContext(); - - final UsernamePasswordAuthenticationToken authenticationToken - = new UsernamePasswordAuthenticationToken - (annotation.username(), "password"); - - securityContext.setAuthentication(authenticationToken); - return securityContext; - } -}