Skip to content

Commit

Permalink
[TEST] test 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Mar 8, 2024
1 parent 57104f8 commit 063b523
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-gcp-storage:1.2.5.RELEASE'
implementation 'com.google.firebase:firebase-admin:6.8.1'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation 'org.redisson:redisson-spring-boot-starter:3.18.0'
implementation 'org.redisson:redisson-spring-data-30:3.27.1'

annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ private Friend getFriendById(final UUID loginMemberId, final UUID memberId) {
.orElseThrow(EntityNotFoundException::new);
}

public String getMemberIdValue() {
return authService.getMemberIdValue();
}

@CacheEvict(
value = "getFriendsWithCache",
key = "'getFriendsWithCache'.concat(#root.target.authService.getMemberIdValue())",
key = "'getFriendsWithCache'.concat(#root.target.getMemberIdValue())",
cacheManager = "cacheManager")
@Transactional(readOnly = true)
public List<FriendResponse> getFriends() {
Expand All @@ -92,7 +96,7 @@ public List<FriendResponse> getFriends() {

@Cacheable(
value = "getFriendsWithCache",
key = "'getFriendsWithCache'.concat(#root.target.authService.getMemberIdValue())",
key = "'getFriendsWithCache'.concat(#root.target.getMemberIdValue())",
cacheManager = "cacheManager",
unless = "#result.size() <= 0")
@Transactional(readOnly = true)
Expand All @@ -112,7 +116,7 @@ private List<FriendResponse> getFriendResponses() {

@CacheEvict(
value = "getFriendsByStatusWithCache",
key = "'getFriendsWithCache'.concat(#root.target.authService.getMemberIdValue()).concat(#friendStatus.name())",
key = "'getFriendsWithCache'.concat(#root.target.getMemberIdValue()).concat(#friendStatus.name())",
cacheManager = "cacheManager")
@Transactional(readOnly = true)
public List<FriendResponse> getFriendsByStatus(final FriendStatus friendStatus) {
Expand All @@ -121,7 +125,7 @@ public List<FriendResponse> getFriendsByStatus(final FriendStatus friendStatus)

@Cacheable(
value = "getFriendsByStatusWithCache",
key = "'getFriendsWithCache'.concat(#root.target.authService.getMemberIdValue()).concat(#friendStatus.name())",
key = "'getFriendsWithCache'.concat(#root.target.getMemberIdValue()).concat(#friendStatus.name())",
cacheManager = "cacheManager",
unless = "#result.size() <= 0")
@Transactional(readOnly = true)
Expand All @@ -141,7 +145,7 @@ private List<FriendResponse> getFriendResponsesByStatus(final FriendStatus frien

@CacheEvict(
value = "getFriendsByNicknameWithCache",
key = "'getFriendsWithCache'.concat(#root.target.authService.getMemberIdValue()).concat(#nickname)",
key = "'getFriendsWithCache'.concat(#root.target.getMemberIdValue()).concat(#nickname)",
cacheManager = "cacheManager")
@Transactional(readOnly = true)
public List<FriendResponse> getFriendByNickname(final String nickname) {
Expand All @@ -150,7 +154,7 @@ public List<FriendResponse> getFriendByNickname(final String nickname) {

@Cacheable(
value = "getFriendsByNicknameWithCache",
key = "'getFriendsWithCache'.concat(#root.target.authService.getMemberIdValue()).concat(#nickname)",
key = "'getFriendsWithCache'.concat(#root.target.getMemberIdValue()).concat(#nickname)",
cacheManager = "cacheManager",
unless = "#result.size() <= 0")
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.twtw.backend.domain.friend.service;

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

import com.twtw.backend.domain.friend.dto.request.FriendRequest;
import com.twtw.backend.domain.friend.dto.request.FriendUpdateRequest;
import com.twtw.backend.domain.friend.dto.response.FriendResponse;
Expand All @@ -12,14 +10,16 @@
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.member.entity.OAuth2Info;
import com.twtw.backend.support.service.LoginTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

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

@DisplayName("FriendService의")
class FriendServiceTest extends LoginTest {

Expand Down Expand Up @@ -69,6 +69,7 @@ void updateStatus() {
}

@Test
@Transactional
@DisplayName("친구 목록 조회가 수행되는가")
void getFriends() {
// given
Expand Down Expand Up @@ -106,6 +107,7 @@ void getFriendsByStatus() {
}

@Test
@Transactional
@DisplayName("닉네임을 통한 친구 조회가 수행되는가")
void getFriendByNickname() {
// given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.twtw.backend.domain.group.service;

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

import com.twtw.backend.domain.group.dto.request.InviteGroupRequest;
import com.twtw.backend.domain.group.dto.request.JoinGroupRequest;
import com.twtw.backend.domain.group.dto.request.MakeGroupRequest;
Expand All @@ -14,13 +12,15 @@
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.fixture.member.MemberEntityFixture;
import com.twtw.backend.support.service.LoginTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

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

@DisplayName("GroupService의")
class GroupServiceTest extends LoginTest {
@Autowired private GroupService groupService;
Expand Down Expand Up @@ -87,6 +87,7 @@ void inviteGroup() {
}

@Test
@Transactional
@DisplayName("위치 공유를 공개 -> 비공개 변경이 가능한가")
void changeShare() {
// given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.twtw.backend.domain.plan.service;

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

import com.twtw.backend.domain.group.repository.GroupRepository;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.place.entity.CategoryGroupCode;
Expand All @@ -19,16 +17,18 @@
import com.twtw.backend.fixture.place.PlaceEntityFixture;
import com.twtw.backend.fixture.plan.PlanEntityFixture;
import com.twtw.backend.support.service.LoginTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

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

@DisplayName("PlanService의")
class PlanServiceTest extends LoginTest {

Expand Down Expand Up @@ -73,6 +73,7 @@ void savePlan() {
}

@Test
@Transactional
@DisplayName("계획 참여가 수행되는가")
void joinPlan() {
// given
Expand All @@ -98,6 +99,7 @@ void joinPlan() {
}

@Test
@Transactional
@DisplayName("계획 나가기가 수행되는가") // TODO: 계획에 1명 있는데 나가는 경우 생각해보기
void outPlan() {
// given
Expand Down Expand Up @@ -161,6 +163,7 @@ void deletePlan() {
}

@Test
@Transactional
@DisplayName("수정이 수행되는가")
void updatePlan() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Transactional
@ActiveProfiles("test")
@Target(ElementType.TYPE)
@Import(QuerydslConfig.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.lang.annotation.Target;

@DataJpaTest
@ActiveProfiles("test")
@Target(ElementType.TYPE)
@Import(QuerydslConfig.class)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void setup() {
final Member member = MemberEntityFixture.LOGIN_MEMBER.toEntity();
loginUser = memberRepository.save(member);
when(authService.getMemberByJwt()).thenReturn(loginUser);
when(authService.getMemberIdValue()).thenReturn("123123123.123123123.123123123");
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public class ContainerTest implements
}

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
public void initialize(final ConfigurableApplicationContext applicationContext) {
TestPropertyValues.of(
"spring.data.redis.host=" + REDIS_CONTAINER.getHost(),
"spring.data.redis.port=" + REDIS_CONTAINER.getFirstMappedPort(),
"spring.rabbitmq.host=" + RABBIT_MQ_CONTAINER.getHost(),
"spring.rabbitmq.port=" + RABBIT_MQ_CONTAINER.getAmqpPort(),
"spring.rabbitmq.port=" + RABBIT_MQ_CONTAINER.getMappedPort(5672),
"spring.rabbitmq.stomp.port=" + RABBIT_MQ_CONTAINER.getMappedPort(61613),
"spring.rabbitmq.username=guest",
"spring.rabbitmq.password=guest"
).applyTo(applicationContext.getEnvironment());
}
}
}

0 comments on commit 063b523

Please sign in to comment.