Skip to content

Commit

Permalink
[WHD-255] Feat: Setup test context without redis
Browse files Browse the repository at this point in the history
  • Loading branch information
jjunhub committed Dec 2, 2024
1 parent 3c8523f commit 4057311
Show file tree
Hide file tree
Showing 26 changed files with 198 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class GroupServiceTrans {
private final ClubMemberRepository clubMemberRepository;
private final GroupRepository groupRepository;


@Transactional
public void processJoinGroup(Long groupId, LocalDate date) {
Member member = securityUtil.getMember();
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/woohakdong/server/RepositoryTestSetup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package woohakdong.server;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
import woohakdong.server.config.WithMockCustomUser;
import woohakdong.server.config.WithoutRedisConfig;

@ActiveProfiles("test")
@SpringBootTest
@Transactional
@WithMockCustomUser
@WithoutRedisConfig
public abstract class RepositoryTestSetup {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woohakdong.server.api.service;
package woohakdong.server;

import static woohakdong.server.config.TestConstants.TEST_PROVIDE_ID;

Expand All @@ -7,14 +7,16 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
import woohakdong.server.config.WithMockCustomUser;
import woohakdong.server.config.WithoutRedisConfig;
import woohakdong.server.domain.member.Member;
import woohakdong.server.domain.member.MemberRepository;

@ActiveProfiles("test")
@SpringBootTest
@Transactional
@WithMockCustomUser
public abstract class SecurityContextSetUp {
@WithoutRedisConfig
public abstract class SecurityContextSetup {

@Autowired
private MemberRepository memberRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package woohakdong.server;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import woohakdong.server.config.WithoutRedisConfig;

@ActiveProfiles("test")
@SpringBootTest
@WithoutRedisConfig
class WoohakdongServerApplicationTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.common.exception.CustomException;
import woohakdong.server.domain.school.School;
import woohakdong.server.domain.school.SchoolRepository;

class AuthServiceTest extends SecurityContextSetUp {
class AuthServiceTest extends SecurityContextSetup {

@Autowired
private AuthService authService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import woohakdong.server.api.controller.club.dto.ClubAccountValidateRequest;
import woohakdong.server.api.controller.club.dto.ClubAccountValidateResponse;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.common.exception.CustomException;
import woohakdong.server.domain.admin.adminAccount.AdminAccount;
import woohakdong.server.domain.admin.adminAccount.AdminAccountRepository;
Expand All @@ -25,7 +25,7 @@
import woohakdong.server.domain.member.MemberRepository;


class MockBankServiceTest extends SecurityContextSetUp {
class MockBankServiceTest extends SecurityContextSetup {

@Autowired
private MockBankService mockBankService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import woohakdong.server.api.controller.club.dto.ClubSummaryResponse;
import woohakdong.server.api.controller.club.dto.ClubUpdateRequest;
import woohakdong.server.api.controller.group.dto.GroupSummaryResponse;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.common.exception.CustomException;
import woohakdong.server.common.util.date.DateUtil;
import woohakdong.server.domain.club.Club;
Expand All @@ -47,7 +47,7 @@
import woohakdong.server.domain.school.School;
import woohakdong.server.domain.school.SchoolRepository;

class ClubServiceTest extends SecurityContextSetUp {
class ClubServiceTest extends SecurityContextSetup {

@Autowired
private ClubService clubService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import woohakdong.server.api.controller.clubMember.dto.ClubMemberInfoResponse;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.common.exception.CustomErrorInfo;
import woohakdong.server.common.exception.CustomException;
import woohakdong.server.common.util.date.DateUtil;
import woohakdong.server.domain.admin.adminAccount.AccountType;
import woohakdong.server.domain.club.Club;
import woohakdong.server.domain.club.ClubRepository;
import woohakdong.server.domain.clubAccount.ClubAccount;
Expand All @@ -37,7 +36,7 @@
import woohakdong.server.domain.school.SchoolRepository;


class ClubMemberServiceTest extends SecurityContextSetUp {
class ClubMemberServiceTest extends SecurityContextSetup {

@Autowired
private ClubMemberService clubMemberService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.domain.admin.adminAccount.AccountType;
import woohakdong.server.domain.clubAccount.ClubAccount;
import woohakdong.server.domain.clubAccount.ClubAccountRepository;
Expand All @@ -16,7 +16,7 @@

import static org.assertj.core.api.Assertions.assertThat;

class DuesServiceTest extends SecurityContextSetUp {
class DuesServiceTest extends SecurityContextSetup {
@Autowired
private ClubAccountHistoryRepository clubAccountHistoryRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import woohakdong.server.api.controller.group.dto.GroupIdResponse;
import woohakdong.server.api.controller.group.dto.GroupInfoResponse;
import woohakdong.server.api.controller.group.dto.GroupUpdateRequest;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.common.exception.CustomException;
import woohakdong.server.common.util.date.DateUtil;
import woohakdong.server.domain.club.Club;
Expand All @@ -31,7 +31,7 @@
import woohakdong.server.domain.group.GroupType;
import woohakdong.server.domain.member.Member;

class GroupServiceTest extends SecurityContextSetUp {
class GroupServiceTest extends SecurityContextSetup {

@Autowired
private GroupService groupService;
Expand Down Expand Up @@ -178,21 +178,6 @@ void changeAvailabilityOfGroup() {
assertThat(updatedGroup.getGroupIsActivated()).isFalse();
}

@DisplayName("그룹에 참가할 수 있다.")
@Test
void joinGroup() {
// Given
Group group = createNewGroup("동아리 MT", 0, EVENT, true, 0, 999);
LocalDate date = LocalDate.of(2024, 11, 19);

// When
groupService.joinGroup(group.getGroupId(), date);

// Then
Group updatedGroup = groupRepository.getById(group.getGroupId());
assertThat(updatedGroup.getGroupMemberCount()).isEqualTo(1);
}

private Group createNewGroup(String groupName, int groupAmount, GroupType groupType, boolean activated,
int memberCount, int memberLimit) {
Group group = Group.builder()
Expand All @@ -207,7 +192,6 @@ private Group createNewGroup(String groupName, int groupAmount, GroupType groupT
return groupRepository.save(group);
}


private Club createClub() {
Club club = Club.builder()
.clubName("테스트 동아리")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package woohakdong.server.api.service.group;

import static org.assertj.core.api.Assertions.assertThat;
import static woohakdong.server.domain.clubmember.ClubMemberRole.PRESIDENT;
import static woohakdong.server.domain.group.GroupType.EVENT;

import java.time.LocalDate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.common.util.date.DateUtil;
import woohakdong.server.domain.club.Club;
import woohakdong.server.domain.club.ClubRepository;
import woohakdong.server.domain.clubmember.ClubMember;
import woohakdong.server.domain.clubmember.ClubMemberRepository;
import woohakdong.server.domain.clubmember.ClubMemberRole;
import woohakdong.server.domain.group.Group;
import woohakdong.server.domain.group.GroupRepository;
import woohakdong.server.domain.group.GroupType;
import woohakdong.server.domain.member.Member;

class GroupServiceTransTest extends SecurityContextSetup {

@Autowired
private GroupServiceTrans groupServiceTrans;

@Autowired
private ClubRepository clubRepository;

@Autowired
private GroupRepository groupRepository;

@Autowired
private ClubMemberRepository clubMemberRepository;

@Autowired
private DateUtil dateUtil;


@BeforeEach
void setUp() {
club = createClub();
member = createExampleMember();
createClubMember(club, member, PRESIDENT);
}

private Club club;
private Member member;

@DisplayName("그룹에 참가할 수 있다.")
@Test
void processJoinGroup() {
// Given
Group group = createNewGroup("동아리 MT", 0, EVENT, true, 0, 999);
LocalDate date = LocalDate.of(2024, 11, 19);

// When
groupServiceTrans.processJoinGroup(group.getGroupId(), date);

// Then
Group updatedGroup = groupRepository.getById(group.getGroupId());
assertThat(updatedGroup.getGroupMemberCount()).isEqualTo(1);
}

private Club createClub() {
Club club = Club.builder()
.clubName("테스트 동아리")
.clubEnglishName("testClub")
.clubGroupChatLink("https://club-group-chat-link.com")
.clubExpirationDate(LocalDate.of(2024, 11, 19))
.build();
return clubRepository.save(club);
}

private Group createNewGroup(String groupName, int groupAmount, GroupType groupType, boolean activated,
int memberCount, int memberLimit) {
Group group = Group.builder()
.groupName(groupName)
.groupAmount(groupAmount)
.groupType(groupType)
.club(club)
.groupIsActivated(activated)
.groupMemberLimit(memberLimit)
.groupMemberCount(memberCount)
.build();
return groupRepository.save(group);
}

private void createClubMember(Club club, Member member, ClubMemberRole role) {
ClubMember clubMember = ClubMember.builder()
.club(club)
.member(member)
.clubMemberRole(role)
.clubMemberAssignedTerm(dateUtil.getAssignedTerm(LocalDate.of(2024, 11, 19)))
.build();
clubMemberRepository.save(clubMember);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import woohakdong.server.api.controller.inquiry.dto.InquiryRequest;
import woohakdong.server.api.controller.inquiry.dto.InquiryResponse;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.domain.inquiry.Inquiry;
import woohakdong.server.domain.inquiry.InquiryCategory;
import woohakdong.server.domain.inquiry.InquiryRepository;
Expand All @@ -20,7 +20,7 @@
import static org.assertj.core.api.AssertionsForClassTypes.tuple;


class InquiryServiceTest extends SecurityContextSetUp {
class InquiryServiceTest extends SecurityContextSetup {

@Autowired
private InquiryService inquiryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import woohakdong.server.api.controller.item.dto.ItemReturnRequest;
import woohakdong.server.api.controller.item.dto.ItemReturnResponse;
import woohakdong.server.api.controller.item.dto.ItemUpdateRequest;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.common.exception.CustomException;
import woohakdong.server.common.util.date.DateUtil;
import woohakdong.server.domain.ItemHistory.ItemHistory;
Expand All @@ -42,7 +42,7 @@
import woohakdong.server.domain.itemBorrowed.ItemBorrowedRepository;
import woohakdong.server.domain.member.Member;

class ItemServiceTest extends SecurityContextSetUp {
class ItemServiceTest extends SecurityContextSetup {
@Autowired
private ItemService itemService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import woohakdong.server.api.controller.member.dto.CreateMemberRequest;
import woohakdong.server.api.controller.member.dto.MemberInfoResponse;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.common.exception.CustomException;
import woohakdong.server.domain.member.Member;
import woohakdong.server.domain.member.MemberGender;
import woohakdong.server.domain.member.MemberRepository;
import woohakdong.server.domain.school.School;
import woohakdong.server.domain.school.SchoolRepository;

class MemberServiceTest extends SecurityContextSetUp {
class MemberServiceTest extends SecurityContextSetup {

@Autowired
private MemberRepository memberRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import woohakdong.server.api.service.SecurityContextSetUp;
import woohakdong.server.SecurityContextSetup;
import woohakdong.server.api.service.email.EmailClientImpl;
import woohakdong.server.common.util.date.DateUtil;
import woohakdong.server.domain.club.Club;
Expand All @@ -31,7 +31,7 @@
import woohakdong.server.domain.schedule.Schedule;
import woohakdong.server.domain.schedule.ScheduleRepository;

class NotificationServiceTest extends SecurityContextSetUp {
class NotificationServiceTest extends SecurityContextSetup {

@Autowired
private NotificationService notificationService;
Expand Down
Loading

0 comments on commit 4057311

Please sign in to comment.