From 03f80d7ed33d4137f91bbffaa108362d917b47e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=ED=99=8D=EC=A0=9C?= Date: Tue, 14 Jan 2025 16:43:31 +0900 Subject: [PATCH] =?UTF-8?q?MATE-150=20:=20[REFACTOR]=20=EA=B5=BF=EC=A6=88?= =?UTF-8?q?=EA=B1=B0=EB=9E=98=20=EC=B1=84=ED=8C=85=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20MongoDB=EB=A1=9C=20=EB=A7=88=EC=9D=B4=EA=B7=B8?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=85=98=20(#136)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MATE-150 : [FEAT] 굿즈거래 채팅 엔티티를 MongoDB 도큐먼트로 변경 * MATE-150 : [FEAT] 굿즈거래 채팅 레포지토리 리팩토링 - MongoRepository 구현체로 변경 - 채팅 조회 메서드(쿼리) 구현 - Spring Data MongoDB 를 사용해 채팅 삭제 기능 구현 * MATE-150 : [REFACTOR] 엔티티 변경에 따른 DTO 및 Service 레이어 리팩토링 * MATE-150 : [FEAT] 테스트용 인메모리 MongoDB 사용을 위한 bwaldvogel 의존성 추가 * MATE-150 : [TEST] 인메모리 MongoDB 사용을 위한 설정 클래스 구현 - 가짜 MongoDB 서버 설정 정보를 담는 MongoTestServerConfig 클래스 구현 - MongoTestServerConfig 를 Import 하는 EnableMongoTestServer 어노테이션 구현 * MATE-150 : [TEST] MongoDB 통합테스트에 사용하는 AcceptanceTestWithMongo 추상 클래스 구현 * MATE-150 : [CHORE] 시큐리티 관련 테스트 설정 클래스를 securityConfig 패키지로 이관 * MATE-150 : [TEST] 패키지 이관 및 DB 변경에 따른 테스트 코드 수정 * MATE-150 : [REFACTOR] GoodsChatMessageService 클래스에서 GoodsParts 엔티티 의존성 제거 * MATE-150 : [TEST] 의존성 제거에 따른 테스트 코드 수정 * MATE-150 : [!BUGFIX] 코드 충돌 해결 --- build.gradle | 1 + .../controller/GoodsChatRoomController.java | 4 +- .../goodsChat/document/GoodsChatMessage.java | 39 ++++++++ .../response/GoodsChatMessageResponse.java | 12 +-- .../goodsChat/entity/GoodsChatMessage.java | 60 ------------- .../goodsChat/entity/GoodsChatPart.java | 8 -- .../GoodsChatMessageRepository.java | 24 ++--- .../service/GoodsChatMessageService.java | 48 +++++----- .../goodsChat/service/GoodsChatService.java | 89 +++++++++++-------- .../mongoConfig/AcceptanceTestWithMongo.java | 20 +++++ .../mongoConfig/EnableMongoTestServer.java | 12 +++ .../mongoConfig/MongoTestServerConfig.java | 30 +++++++ .../{ => securityConfig}/WithAuthMember.java | 2 +- .../WithAuthMemberSecurityContextFactory.java | 2 +- .../GoodsChatRoomControllerTest.java | 31 ++++--- .../integration/GoodsChatIntegrationTest.java | 32 ++++--- .../service/GoodsChatMessageServiceTest.java | 52 ++--------- .../service/GoodsChatServiceTest.java | 61 +++++++------ .../controller/GoodsPostControllerTest.java | 2 +- .../integration/GoodsPostIntegrationTest.java | 2 +- .../controller/GoodsReviewControllerTest.java | 2 +- .../GoodsReviewIntegrationTest.java | 2 +- .../controller/MateChatControllerTest.java | 2 +- .../controller/MatePostControllerTest.java | 2 +- .../controller/MateStatusControllerTest.java | 2 +- .../integration/MatePostIntegrationTest.java | 2 +- .../MatePostStatusIntegrationTest.java | 2 +- .../controller/MateReviewControllerTest.java | 2 +- .../MateReviewIntegrationTest.java | 2 +- .../controller/FollowControllerTest.java | 2 +- .../controller/MemberControllerTest.java | 2 +- .../controller/ProfileControllerTest.java | 2 +- .../integration/FollowIntegrationTest.java | 6 +- .../integration/MemberIntegrationTest.java | 2 +- .../integration/ProfileIntegrationTest.java | 2 +- .../NotificationControllerTest.java | 2 +- .../NotificationIntegrationTest.java | 2 +- 37 files changed, 284 insertions(+), 285 deletions(-) create mode 100644 src/main/java/com/example/mate/domain/goodsChat/document/GoodsChatMessage.java delete mode 100644 src/main/java/com/example/mate/domain/goodsChat/entity/GoodsChatMessage.java create mode 100644 src/test/java/com/example/mate/config/mongoConfig/AcceptanceTestWithMongo.java create mode 100644 src/test/java/com/example/mate/config/mongoConfig/EnableMongoTestServer.java create mode 100644 src/test/java/com/example/mate/config/mongoConfig/MongoTestServerConfig.java rename src/test/java/com/example/mate/config/{ => securityConfig}/WithAuthMember.java (89%) rename src/test/java/com/example/mate/config/{ => securityConfig}/WithAuthMemberSecurityContextFactory.java (96%) diff --git a/build.gradle b/build.gradle index ca72d6fb..f3ffd978 100644 --- a/build.gradle +++ b/build.gradle @@ -63,6 +63,7 @@ dependencies { testImplementation 'org.springframework.security:spring-security-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testImplementation 'org.assertj:assertj-core:3.24.2' + testImplementation 'de.bwaldvogel:mongo-java-server:1.46.0' // querydsl for spring boot 3.x implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' diff --git a/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java b/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java index 6cb85166..724f8520 100644 --- a/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java +++ b/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java @@ -50,7 +50,7 @@ public ResponseEntity>> getGo @Parameter(description = "채팅방 ID", required = true) @PathVariable Long chatRoomId, @Parameter(description = "페이징 정보") @ValidPageable(page = 1, size = 20) Pageable pageable ) { - PageResponse response = goodsChatService.getMessagesForChatRoom(chatRoomId, member.getMemberId(), pageable); + PageResponse response = goodsChatService.getChatRoomMessages(chatRoomId, member.getMemberId(), pageable); return ResponseEntity.ok(ApiResponse.success(response)); } @@ -90,7 +90,7 @@ public ResponseEntity>> getGoodsChatRoom @AuthenticationPrincipal AuthMember member, @Parameter(description = "채팅방 ID", required = true) @PathVariable Long chatRoomId ) { - List responses = goodsChatService.getChatRoomMembers(member.getMemberId(), chatRoomId); + List responses = goodsChatService.getMembersInChatRoom(member.getMemberId(), chatRoomId); return ResponseEntity.ok(ApiResponse.success(responses)); } } diff --git a/src/main/java/com/example/mate/domain/goodsChat/document/GoodsChatMessage.java b/src/main/java/com/example/mate/domain/goodsChat/document/GoodsChatMessage.java new file mode 100644 index 00000000..932577be --- /dev/null +++ b/src/main/java/com/example/mate/domain/goodsChat/document/GoodsChatMessage.java @@ -0,0 +1,39 @@ +package com.example.mate.domain.goodsChat.document; + +import com.example.mate.domain.constant.MessageType; +import java.time.LocalDateTime; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.Field; + +@Getter +@Builder +@Document(collection = "goods_chat_message") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class GoodsChatMessage { + + @Id + private String id; + + @Field(name = "chat_room_id") + private Long chatRoomId; + + @Field(name = "member_id") + private Long memberId; + + @Field(name = "content") + private String content; + + @Field(name = "sent_at") + private LocalDateTime sentAt; + + @Field(name = "message_type") + private MessageType messageType; + +} diff --git a/src/main/java/com/example/mate/domain/goodsChat/dto/response/GoodsChatMessageResponse.java b/src/main/java/com/example/mate/domain/goodsChat/dto/response/GoodsChatMessageResponse.java index e1b52d2e..4e31e16b 100644 --- a/src/main/java/com/example/mate/domain/goodsChat/dto/response/GoodsChatMessageResponse.java +++ b/src/main/java/com/example/mate/domain/goodsChat/dto/response/GoodsChatMessageResponse.java @@ -1,8 +1,7 @@ package com.example.mate.domain.goodsChat.dto.response; import com.example.mate.domain.file.FileUtils; -import com.example.mate.domain.goodsChat.entity.GoodsChatMessage; -import com.example.mate.domain.goodsChat.entity.GoodsChatPart; +import com.example.mate.domain.goodsChat.document.GoodsChatMessage; import com.example.mate.domain.member.entity.Member; import java.time.LocalDateTime; import lombok.Builder; @@ -14,7 +13,7 @@ @RequiredArgsConstructor public class GoodsChatMessageResponse { - private final Long chatMessageId; + private final String chatMessageId; private final Long roomId; private final Long senderId; private final String senderNickname; @@ -23,13 +22,10 @@ public class GoodsChatMessageResponse { private final String senderImageUrl; private final LocalDateTime sentAt; - public static GoodsChatMessageResponse of(GoodsChatMessage chatMessage) { - GoodsChatPart goodsChatPart = chatMessage.getGoodsChatPart(); - Member sender = goodsChatPart.getMember(); - + public static GoodsChatMessageResponse of(GoodsChatMessage chatMessage, Member sender) { return GoodsChatMessageResponse.builder() .chatMessageId(chatMessage.getId()) - .roomId(goodsChatPart.getGoodsChatRoom().getId()) + .roomId(chatMessage.getChatRoomId()) .senderId(sender.getId()) .senderNickname(sender.getNickname()) .senderImageUrl(FileUtils.getThumbnailImageUrl(sender.getImageUrl())) diff --git a/src/main/java/com/example/mate/domain/goodsChat/entity/GoodsChatMessage.java b/src/main/java/com/example/mate/domain/goodsChat/entity/GoodsChatMessage.java deleted file mode 100644 index b68ed7ab..00000000 --- a/src/main/java/com/example/mate/domain/goodsChat/entity/GoodsChatMessage.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.example.mate.domain.goodsChat.entity; - -import com.example.mate.domain.constant.MessageType; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.JoinColumns; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.PrePersist; -import jakarta.persistence.Table; -import java.time.LocalDateTime; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; - -@Entity -@Table(name = "goods_chat_message") -@Getter -@Builder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor(access = AccessLevel.PRIVATE) -public class GoodsChatMessage { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumns({ - @JoinColumn(name = "member_id", referencedColumnName = "member_id"), - @JoinColumn(name = "chat_room_id", referencedColumnName = "chat_room_id") - }) - @OnDelete(action = OnDeleteAction.CASCADE) - private GoodsChatPart goodsChatPart; - - @Column(name = "content", nullable = false, columnDefinition = "TEXT") - private String content; - - @Column(name = "sent_at", nullable = false) - private LocalDateTime sentAt; - - @Enumerated(EnumType.STRING) - @Column(name = "message_type", nullable = false) - private MessageType messageType; - - @PrePersist - public void prePersist() { - this.sentAt = LocalDateTime.now(); - } -} diff --git a/src/main/java/com/example/mate/domain/goodsChat/entity/GoodsChatPart.java b/src/main/java/com/example/mate/domain/goodsChat/entity/GoodsChatPart.java index ea9800f1..8e41c4c3 100644 --- a/src/main/java/com/example/mate/domain/goodsChat/entity/GoodsChatPart.java +++ b/src/main/java/com/example/mate/domain/goodsChat/entity/GoodsChatPart.java @@ -2,7 +2,6 @@ import com.example.mate.domain.goodsPost.entity.Role; import com.example.mate.domain.member.entity.Member; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -12,10 +11,7 @@ import jakarta.persistence.IdClass; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import java.util.ArrayList; -import java.util.List; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -48,10 +44,6 @@ public class GoodsChatPart { @Builder.Default private Boolean isActive = true; - @OneToMany(mappedBy = "goodsChatPart", cascade = CascadeType.ALL, orphanRemoval = true) - @Builder.Default - List goodsChatMessages = new ArrayList<>(); - public boolean leaveAndCheckRoomStatus() { if (!goodsChatRoom.isRoomActive()) { return true; diff --git a/src/main/java/com/example/mate/domain/goodsChat/repository/GoodsChatMessageRepository.java b/src/main/java/com/example/mate/domain/goodsChat/repository/GoodsChatMessageRepository.java index 087d8c7b..7ef5af6c 100644 --- a/src/main/java/com/example/mate/domain/goodsChat/repository/GoodsChatMessageRepository.java +++ b/src/main/java/com/example/mate/domain/goodsChat/repository/GoodsChatMessageRepository.java @@ -1,19 +1,19 @@ package com.example.mate.domain.goodsChat.repository; -import com.example.mate.domain.goodsChat.entity.GoodsChatMessage; +import com.example.mate.domain.goodsChat.document.GoodsChatMessage; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.data.mongodb.repository.Query; -public interface GoodsChatMessageRepository extends JpaRepository { +public interface GoodsChatMessageRepository extends MongoRepository { - @Query(""" - SELECT cm - FROM GoodsChatMessage cm - WHERE cm.goodsChatPart.goodsChatRoom.id = :chatRoomId - ORDER BY cm.sentAt DESC - """) - Page getChatMessages(@Param("chatRoomId") Long chatRoomId, Pageable pageable); + /** + * 특정 채팅방의 메시지를 페이징 처리하여 조회합니다. + * 메시지는 전송된 시간(sent_at) 기준으로 오름차순으로 정렬됩니다. + */ + @Query(value = "{ 'chat_room_id': ?0 }", sort = "{ 'sent_at': -1 }") + Page getChatMessages(Long chatRoomId, Pageable pageable); + + void deleteAllByChatRoomId(Long chatRoomId); } diff --git a/src/main/java/com/example/mate/domain/goodsChat/service/GoodsChatMessageService.java b/src/main/java/com/example/mate/domain/goodsChat/service/GoodsChatMessageService.java index cabb3dc9..8016dda8 100644 --- a/src/main/java/com/example/mate/domain/goodsChat/service/GoodsChatMessageService.java +++ b/src/main/java/com/example/mate/domain/goodsChat/service/GoodsChatMessageService.java @@ -3,18 +3,16 @@ import com.example.mate.common.error.CustomException; import com.example.mate.common.error.ErrorCode; import com.example.mate.domain.constant.MessageType; -import com.example.mate.domain.goodsChat.event.GoodsChatEvent; +import com.example.mate.domain.goodsChat.document.GoodsChatMessage; import com.example.mate.domain.goodsChat.dto.request.GoodsChatMessageRequest; import com.example.mate.domain.goodsChat.dto.response.GoodsChatMessageResponse; -import com.example.mate.domain.goodsChat.entity.GoodsChatMessage; -import com.example.mate.domain.goodsChat.entity.GoodsChatPart; -import com.example.mate.domain.goodsChat.entity.GoodsChatPartId; import com.example.mate.domain.goodsChat.entity.GoodsChatRoom; +import com.example.mate.domain.goodsChat.event.GoodsChatEvent; import com.example.mate.domain.goodsChat.repository.GoodsChatMessageRepository; -import com.example.mate.domain.goodsChat.repository.GoodsChatPartRepository; import com.example.mate.domain.goodsChat.repository.GoodsChatRoomRepository; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.MemberRepository; +import java.time.LocalDateTime; import lombok.RequiredArgsConstructor; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; @@ -27,7 +25,6 @@ public class GoodsChatMessageService { private final MemberRepository memberRepository; private final GoodsChatRoomRepository chatRoomRepository; - private final GoodsChatPartRepository chatPartRepository; private final GoodsChatMessageRepository messageRepository; private final SimpMessagingTemplate messagingTemplate; @@ -35,26 +32,23 @@ public class GoodsChatMessageService { private static final String MEMBER_LEAVE_MESSAGE = "님이 대화를 떠났습니다."; public void sendMessage(GoodsChatMessageRequest message) { - Member sender = findMemberById(message.getSenderId()); + Member member = findMemberById(message.getSenderId()); GoodsChatRoom chatRoom = findByChatRoomById(message.getRoomId()); - GoodsChatPart chatPart = findByChatPartById(sender.getId(), chatRoom.getId()); + GoodsChatMessage chatMessage = createChatMessage(chatRoom.getId(), member.getId(), message.getMessage(), message.getType()); - // DB에 메시지 저장 - GoodsChatMessage chatMessage - = messageRepository.save(createChatMessage(message.getMessage(), chatPart, message.getType())); + // 채팅 데이터 저장 & 최신 채팅 내역 업데이트 + GoodsChatMessage savedMessage = messageRepository.save(chatMessage); chatRoom.updateLastChat(chatMessage.getContent(), chatMessage.getSentAt()); - GoodsChatMessageResponse response = GoodsChatMessageResponse.of(chatMessage); + GoodsChatMessageResponse response = GoodsChatMessageResponse.of(savedMessage, member); sendToSubscribers(message.getRoomId(), response); } // 입장 및 퇴장 메시지 전송 public void sendChatEventMessage(GoodsChatEvent event) { Member member = event.member(); - Long roomId = event.chatRoomId(); - - GoodsChatRoom chatRoom = findByChatRoomById(roomId); - GoodsChatPart chatPart = findByChatPartById(member.getId(), roomId); + Long chatRoomId = event.chatRoomId(); + GoodsChatRoom chatRoom = findByChatRoomById(chatRoomId); // 메시지 생성 String message = member.getNickname(); @@ -62,18 +56,21 @@ public void sendChatEventMessage(GoodsChatEvent event) { case ENTER -> message += MEMBER_ENTER_MESSAGE; case LEAVE -> message += MEMBER_LEAVE_MESSAGE; } + GoodsChatMessage chatMessage = createChatMessage(member.getId(), chatRoomId, message, event.type()); - // Message DB에 저장 - GoodsChatMessage chatMessage = messageRepository.save(createChatMessage(message, chatPart, event.type())); + // 채팅 데이터 저장 & 최신 채팅 내역 업데이트 + GoodsChatMessage savedMessage = messageRepository.save(chatMessage); chatRoom.updateLastChat(message, chatMessage.getSentAt()); // 이벤트 메시지 전송 - sendToSubscribers(roomId, GoodsChatMessageResponse.of(chatMessage)); + sendToSubscribers(chatRoomId, GoodsChatMessageResponse.of(savedMessage, member)); } - private GoodsChatMessage createChatMessage(String message, GoodsChatPart chatPart, MessageType type) { + private GoodsChatMessage createChatMessage(Long chatRoomId, Long memberId, String message, MessageType type) { return GoodsChatMessage.builder() - .goodsChatPart(chatPart) + .chatRoomId(chatRoomId) + .memberId(memberId) + .sentAt(LocalDateTime.now()) .content(message) .messageType(type) .build(); @@ -89,12 +86,7 @@ private GoodsChatRoom findByChatRoomById(Long chatRoomId) { .orElseThrow(() -> new CustomException(ErrorCode.GOODS_CHAT_ROOM_NOT_FOUND)); } - private GoodsChatPart findByChatPartById(Long memberId, Long chatRoomId) { - return chatPartRepository.findById(new GoodsChatPartId(memberId, chatRoomId)) - .orElseThrow(() -> new CustomException(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART)); - } - - private void sendToSubscribers(Long roomId, GoodsChatMessageResponse message) { - messagingTemplate.convertAndSend("/sub/chat/goods/" + roomId, message); + private void sendToSubscribers(Long chatRoomId, GoodsChatMessageResponse message) { + messagingTemplate.convertAndSend("/sub/chat/goods/" + chatRoomId, message); } } diff --git a/src/main/java/com/example/mate/domain/goodsChat/service/GoodsChatService.java b/src/main/java/com/example/mate/domain/goodsChat/service/GoodsChatService.java index dce08dfb..30f77c31 100644 --- a/src/main/java/com/example/mate/domain/goodsChat/service/GoodsChatService.java +++ b/src/main/java/com/example/mate/domain/goodsChat/service/GoodsChatService.java @@ -4,14 +4,10 @@ import com.example.mate.common.error.ErrorCode; import com.example.mate.common.response.PageResponse; import com.example.mate.domain.constant.MessageType; -import com.example.mate.domain.goodsPost.entity.GoodsPost; -import com.example.mate.domain.goodsPost.entity.Role; -import com.example.mate.domain.goodsPost.entity.Status; -import com.example.mate.domain.goodsPost.repository.GoodsPostRepository; +import com.example.mate.domain.goodsChat.document.GoodsChatMessage; import com.example.mate.domain.goodsChat.dto.response.GoodsChatMessageResponse; import com.example.mate.domain.goodsChat.dto.response.GoodsChatRoomResponse; import com.example.mate.domain.goodsChat.dto.response.GoodsChatRoomSummaryResponse; -import com.example.mate.domain.goodsChat.entity.GoodsChatMessage; import com.example.mate.domain.goodsChat.entity.GoodsChatPart; import com.example.mate.domain.goodsChat.entity.GoodsChatPartId; import com.example.mate.domain.goodsChat.entity.GoodsChatRoom; @@ -20,6 +16,10 @@ import com.example.mate.domain.goodsChat.repository.GoodsChatMessageRepository; import com.example.mate.domain.goodsChat.repository.GoodsChatPartRepository; import com.example.mate.domain.goodsChat.repository.GoodsChatRoomRepository; +import com.example.mate.domain.goodsPost.entity.GoodsPost; +import com.example.mate.domain.goodsPost.entity.Role; +import com.example.mate.domain.goodsPost.entity.Status; +import com.example.mate.domain.goodsPost.repository.GoodsPostRepository; import com.example.mate.domain.member.dto.response.MemberSummaryResponse; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.MemberRepository; @@ -44,29 +44,36 @@ public class GoodsChatService { private final GoodsChatMessageRepository messageRepository; private final GoodsChatEventPublisher eventPublisher; + // 채팅방 생성 & 기존 채팅방 입장 public GoodsChatRoomResponse getOrCreateGoodsChatRoom(Long buyerId, Long goodsPostId) { + // 구매자, 판매글, 판매자 조회 및 검증 Member buyer = findMemberById(buyerId); GoodsPost goodsPost = findGoodsPostById(goodsPostId); Member seller = goodsPost.getSeller(); - validateCreateChatRoom(goodsPost, buyer, seller); + // 판매글 유효성 검증 + validateChatRoomCreation(goodsPost, buyer, seller); - // 구매자가 채팅방이 존재하면 기존 채팅방을 반환하고, 없다면 새로 생성하여 반환 + // 기존 채팅방이 있으면 반환, 없으면 새 채팅방 생성 return chatRoomRepository.findExistingChatRoom(goodsPostId, buyerId, Role.BUYER) - .map(this::buildChatRoomResponse) + .map(chatRoom -> getChatRoomWithMessages(chatRoom, PageRequest.of(0, 20))) .orElseGet(() -> createChatRoom(goodsPost, buyer, seller)); } - // 기존 채팅방 & 채팅 내역 반환 (최신 20개) - private GoodsChatRoomResponse buildChatRoomResponse(GoodsChatRoom chatRoom) { - Page messages = messageRepository.getChatMessages(chatRoom.getId(), PageRequest.of(0, 20)); + // 채팅방과 채팅 내역 반환 + private GoodsChatRoomResponse getChatRoomWithMessages(GoodsChatRoom chatRoom, Pageable pageable) { + Page messages = messageRepository.getChatMessages(chatRoom.getId(), pageable); List content = messages.getContent().stream() - .map(GoodsChatMessageResponse::of) + .map(message -> { + Long memberId = message.getMemberId(); + Member member = findMemberById(memberId); + return GoodsChatMessageResponse.of(message, member); + }) .toList(); return GoodsChatRoomResponse.of(chatRoom, PageResponse.from(messages, content)); } - // 새로운 채팅방 반환 + // 새 채팅방 생성 private GoodsChatRoomResponse createChatRoom(GoodsPost goodsPost, Member buyer, Member seller) { GoodsChatRoom goodsChatRoom = GoodsChatRoom.builder() .goodsPost(goodsPost) @@ -76,13 +83,14 @@ private GoodsChatRoomResponse createChatRoom(GoodsPost goodsPost, Member buyer, savedChatRoom.addChatParticipant(buyer, Role.BUYER); savedChatRoom.addChatParticipant(seller, Role.SELLER); - // 새로운 채팅방 생성 - 입장 메시지 전송 + // 입장 메시지 이벤트 전송 eventPublisher.publish(GoodsChatEvent.from(goodsChatRoom.getId(), buyer, MessageType.ENTER)); return GoodsChatRoomResponse.of(savedChatRoom, null); } - private void validateCreateChatRoom(GoodsPost goodsPost, Member seller, Member buyer) { + // 채팅방 생성 유효성 검증 + private void validateChatRoomCreation(GoodsPost goodsPost, Member seller, Member buyer) { if (goodsPost.getStatus() == Status.CLOSED) { throw new CustomException(ErrorCode.GOODS_CHAT_CLOSED_POST); } @@ -91,58 +99,62 @@ private void validateCreateChatRoom(GoodsPost goodsPost, Member seller, Member b } } + // 단순 채팅 내역 조회 @Transactional(readOnly = true) - public PageResponse getMessagesForChatRoom(Long chatRoomId, Long memberId, Pageable pageable) { - validateMemberParticipation(memberId, chatRoomId); + public PageResponse getChatRoomMessages(Long chatRoomId, Long memberId, Pageable pageable) { + validateMemberInChatRoom(memberId, chatRoomId); Page chatMessagePage = messageRepository.getChatMessages(chatRoomId, pageable); + List content = chatMessagePage.getContent().stream() - .map(GoodsChatMessageResponse::of) + .map(message -> { + Member member = findMemberById(message.getMemberId()); + return GoodsChatMessageResponse.of(message, member); + }) .toList(); return PageResponse.from(chatMessagePage, content); } - private void validateMemberParticipation(Long memberId, Long chatRoomId) { + private void validateMemberInChatRoom(Long memberId, Long chatRoomId) { if (!partRepository.existsById(new GoodsChatPartId(memberId, chatRoomId))) { throw new CustomException(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART); } } + // 채팅 목록 조회 @Transactional(readOnly = true) public PageResponse getGoodsChatRooms(Long memberId, Pageable pageable) { Member member = findMemberById(memberId); Page chatRoomPage = chatRoomRepository.findChatRoomPageByMemberId(memberId, pageable); - List content = chatRoomPage.getContent().stream() + + List summaries = chatRoomPage.getContent().stream() .map(chatRoom -> GoodsChatRoomSummaryResponse.of(chatRoom, getOpponentMember(chatRoom, member))) .toList(); - return PageResponse.from(chatRoomPage, content); + return PageResponse.from(chatRoomPage, summaries); } - // 채팅 참여 테이블에서 상대방 회원 정보를 찾음 - private Member getOpponentMember(GoodsChatRoom chatRoom, Member member) { + // 상대방 회원 조회 + private Member getOpponentMember(GoodsChatRoom chatRoom, Member currentUser) { return chatRoom.getChatParts().stream() - .filter(part -> part.getMember() != member) - .findAny() .map(GoodsChatPart::getMember) + .filter(member -> !member.equals(currentUser)) + .findFirst() .orElseThrow(() -> new CustomException(ErrorCode.GOODS_CHAT_OPPONENT_NOT_FOUND)); } + // 채팅방 입장 @Transactional(readOnly = true) public GoodsChatRoomResponse getGoodsChatRoomInfo(Long memberId, Long chatRoomId) { - validateMemberParticipation(memberId, chatRoomId); + validateMemberInChatRoom(memberId, chatRoomId); GoodsChatRoom chatRoom = findChatRoomById(chatRoomId); - Page messages = messageRepository.getChatMessages(chatRoom.getId(), PageRequest.of(0, 20)); - List content = messages.getContent().stream() - .map(GoodsChatMessageResponse::of) - .toList(); - - return GoodsChatRoomResponse.of(chatRoom, PageResponse.from(messages, content)); + return getChatRoomWithMessages(chatRoom, PageRequest.of(0, 20)); } + // 채팅방 참여 인원 조회 @Transactional(readOnly = true) - public List getChatRoomMembers(Long memberId, Long chatRoomId) { - validateMemberParticipation(memberId, chatRoomId); + public List getMembersInChatRoom(Long memberId, Long chatRoomId) { + validateMemberInChatRoom(memberId, chatRoomId); List goodsChatParts = partRepository.findAllWithMemberByChatRoomId(chatRoomId); return goodsChatParts.stream() @@ -150,6 +162,7 @@ public List getChatRoomMembers(Long memberId, Long chatRo .collect(Collectors.toList()); } + // 채팅방 나가기 & 채팅 정보 삭제 public void deactivateGoodsChatPart(Long memberId, Long chatRoomId) { Member member = findMemberById(memberId); GoodsChatPart goodsChatPart = partRepository.findById(new GoodsChatPartId(memberId, chatRoomId)) @@ -160,10 +173,16 @@ public void deactivateGoodsChatPart(Long memberId, Long chatRoomId) { eventPublisher.publish(GoodsChatEvent.from(chatRoomId, member, MessageType.LEAVE)); } else { // 모두 나갔다면 채팅방, 채팅 참여, 채팅 삭제 - chatRoomRepository.deleteById(chatRoomId); + deleteChatRoom(chatRoomId); } } + // 채팅방 삭제 + private void deleteChatRoom(Long chatRoomId) { + chatRoomRepository.deleteById(chatRoomId); + messageRepository.deleteAllByChatRoomId(chatRoomId); // 메시지 삭제 + } + private GoodsChatRoom findChatRoomById(Long chatRoomId) { return chatRoomRepository.findByChatRoomId(chatRoomId) .orElseThrow(() -> new CustomException(ErrorCode.GOODS_CHAT_ROOM_NOT_FOUND)); diff --git a/src/test/java/com/example/mate/config/mongoConfig/AcceptanceTestWithMongo.java b/src/test/java/com/example/mate/config/mongoConfig/AcceptanceTestWithMongo.java new file mode 100644 index 00000000..752856c3 --- /dev/null +++ b/src/test/java/com/example/mate/config/mongoConfig/AcceptanceTestWithMongo.java @@ -0,0 +1,20 @@ +package com.example.mate.config.mongoConfig; + +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.data.mongodb.core.MongoTemplate; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@EnableMongoTestServer +public abstract class AcceptanceTestWithMongo { + + @Autowired + MongoTemplate mongoTemplate; + + @BeforeEach + public void setup() { + mongoTemplate.getDb().drop(); + } +} \ No newline at end of file diff --git a/src/test/java/com/example/mate/config/mongoConfig/EnableMongoTestServer.java b/src/test/java/com/example/mate/config/mongoConfig/EnableMongoTestServer.java new file mode 100644 index 00000000..7172204f --- /dev/null +++ b/src/test/java/com/example/mate/config/mongoConfig/EnableMongoTestServer.java @@ -0,0 +1,12 @@ +package com.example.mate.config.mongoConfig; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.springframework.context.annotation.Import; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Import(MongoTestServerConfig.class) +public @interface EnableMongoTestServer {} \ No newline at end of file diff --git a/src/test/java/com/example/mate/config/mongoConfig/MongoTestServerConfig.java b/src/test/java/com/example/mate/config/mongoConfig/MongoTestServerConfig.java new file mode 100644 index 00000000..b4ac869b --- /dev/null +++ b/src/test/java/com/example/mate/config/mongoConfig/MongoTestServerConfig.java @@ -0,0 +1,30 @@ +package com.example.mate.config.mongoConfig; + +import de.bwaldvogel.mongo.MongoServer; +import de.bwaldvogel.mongo.backend.memory.MemoryBackend; +import org.springframework.context.annotation.Bean; +import org.springframework.data.mongodb.MongoDatabaseFactory; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory; + +public class MongoTestServerConfig { + + @Bean + public MongoTemplate mongoTemplate(MongoDatabaseFactory mongoDbFactory) { + return new MongoTemplate(mongoDbFactory); + } + + @Bean + public MongoDatabaseFactory mongoDbFactory(MongoServer mongoServer) { + String connectionString = mongoServer.getConnectionString(); + return new SimpleMongoClientDatabaseFactory(connectionString + "/test"); + } + + @Bean(destroyMethod = "shutdown") + public MongoServer mongoServer() { + MongoServer mongoServer = new MongoServer(new MemoryBackend()); + mongoServer.bind(); + + return mongoServer; + } +} diff --git a/src/test/java/com/example/mate/config/WithAuthMember.java b/src/test/java/com/example/mate/config/securityConfig/WithAuthMember.java similarity index 89% rename from src/test/java/com/example/mate/config/WithAuthMember.java rename to src/test/java/com/example/mate/config/securityConfig/WithAuthMember.java index 00db320f..84e24894 100644 --- a/src/test/java/com/example/mate/config/WithAuthMember.java +++ b/src/test/java/com/example/mate/config/securityConfig/WithAuthMember.java @@ -1,4 +1,4 @@ -package com.example.mate.config; +package com.example.mate.config.securityConfig; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/test/java/com/example/mate/config/WithAuthMemberSecurityContextFactory.java b/src/test/java/com/example/mate/config/securityConfig/WithAuthMemberSecurityContextFactory.java similarity index 96% rename from src/test/java/com/example/mate/config/WithAuthMemberSecurityContextFactory.java rename to src/test/java/com/example/mate/config/securityConfig/WithAuthMemberSecurityContextFactory.java index 8a6deb6d..7037739e 100644 --- a/src/test/java/com/example/mate/config/WithAuthMemberSecurityContextFactory.java +++ b/src/test/java/com/example/mate/config/securityConfig/WithAuthMemberSecurityContextFactory.java @@ -1,4 +1,4 @@ -package com.example.mate.config; +package com.example.mate.config.securityConfig; import com.example.mate.common.security.auth.AuthMember; import java.util.Arrays; diff --git a/src/test/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomControllerTest.java b/src/test/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomControllerTest.java index 366e3034..4ea69b57 100644 --- a/src/test/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomControllerTest.java +++ b/src/test/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomControllerTest.java @@ -14,8 +14,7 @@ import com.example.mate.common.response.PageResponse; import com.example.mate.common.security.util.JwtUtil; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.common.security.util.JwtUtil; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.goodsChat.dto.response.GoodsChatMessageResponse; import com.example.mate.domain.goodsChat.dto.response.GoodsChatRoomResponse; import com.example.mate.domain.goodsChat.dto.response.GoodsChatRoomSummaryResponse; @@ -140,14 +139,14 @@ void getMessagesForChatRoom_should_return_messages() throws Exception { PageRequest pageable = PageRequest.of(0, 10); GoodsChatMessageResponse firstMessage = GoodsChatMessageResponse.builder() - .chatMessageId(1L) + .chatMessageId("1") .message("first message") .senderId(memberId) .sentAt(LocalDateTime.now().minusMinutes(10)) .build(); GoodsChatMessageResponse secondMessage = GoodsChatMessageResponse.builder() - .chatMessageId(2L) + .chatMessageId("2") .message("second message") .senderId(memberId) .sentAt(LocalDateTime.now()) @@ -158,7 +157,7 @@ void getMessagesForChatRoom_should_return_messages() throws Exception { List.of(secondMessage, firstMessage) ); - when(goodsChatService.getMessagesForChatRoom(chatRoomId, memberId, pageable)).thenReturn(pageResponse); + when(goodsChatService.getChatRoomMessages(chatRoomId, memberId, pageable)).thenReturn(pageResponse); // when & then mockMvc.perform(get("/api/goods/chat/{chatRoomId}/message", chatRoomId) @@ -173,7 +172,7 @@ void getMessagesForChatRoom_should_return_messages() throws Exception { .andExpect(jsonPath("$.data.content[1].message").value(firstMessage.getMessage())) .andExpect(jsonPath("$.data.content[1].chatMessageId").value(firstMessage.getChatMessageId())); - verify(goodsChatService).getMessagesForChatRoom(chatRoomId, memberId, pageable); + verify(goodsChatService).getChatRoomMessages(chatRoomId, memberId, pageable); } @Test @@ -185,14 +184,14 @@ void getGoodsChatRoomInfo_should_return_chatroom_info_and_latest_message() throw Long goodsPostId = 1L; GoodsChatMessageResponse firstMessage = GoodsChatMessageResponse.builder() - .chatMessageId(1L) + .chatMessageId("1") .message("first message") .senderId(memberId) .sentAt(LocalDateTime.now().minusMinutes(10)) .build(); GoodsChatMessageResponse secondMessage = GoodsChatMessageResponse.builder() - .chatMessageId(2L) + .chatMessageId("2") .message("second message") .senderId(memberId) .sentAt(LocalDateTime.now()) @@ -277,14 +276,14 @@ void getGoodsChatRoomMessages_should_return_messages() throws Exception { PageRequest pageable = PageRequest.of(0, 20); GoodsChatMessageResponse firstMessage = GoodsChatMessageResponse.builder() - .chatMessageId(1L) + .chatMessageId("1") .message("First message") .senderId(memberId) .sentAt(LocalDateTime.now().minusMinutes(10)) .build(); GoodsChatMessageResponse secondMessage = GoodsChatMessageResponse.builder() - .chatMessageId(2L) + .chatMessageId("2") .message("Second message") .senderId(memberId) .sentAt(LocalDateTime.now()) @@ -295,7 +294,7 @@ void getGoodsChatRoomMessages_should_return_messages() throws Exception { List.of(secondMessage, firstMessage) ); - when(goodsChatService.getMessagesForChatRoom(chatRoomId, memberId, pageable)).thenReturn(pageResponse); + when(goodsChatService.getChatRoomMessages(chatRoomId, memberId, pageable)).thenReturn(pageResponse); // when & then mockMvc.perform(get("/api/goods/chat/{chatRoomId}/message", chatRoomId) @@ -310,7 +309,7 @@ void getGoodsChatRoomMessages_should_return_messages() throws Exception { .andExpect(jsonPath("$.data.content[1].chatMessageId").value(firstMessage.getChatMessageId())) .andExpect(jsonPath("$.data.content[1].message").value(firstMessage.getMessage())); - verify(goodsChatService).getMessagesForChatRoom(chatRoomId, memberId, pageable); + verify(goodsChatService).getChatRoomMessages(chatRoomId, memberId, pageable); } @Test @@ -350,7 +349,7 @@ void getGoodsChatRoomMembers_should_return_list_of_chat_members() throws Excepti List memberList = List.of(member, anotherMember); - when(goodsChatService.getChatRoomMembers(memberId, chatRoomId)).thenReturn(memberList); + when(goodsChatService.getMembersInChatRoom(memberId, chatRoomId)).thenReturn(memberList); // when & then mockMvc.perform(get("/api/goods/chat/{chatRoomId}/members", chatRoomId)) @@ -365,7 +364,7 @@ void getGoodsChatRoomMembers_should_return_list_of_chat_members() throws Excepti .andExpect(jsonPath("$.data[1].nickname").value(anotherMember.getNickname())) .andExpect(jsonPath("$.data[1].imageUrl").value(anotherMember.getImageUrl())); - verify(goodsChatService).getChatRoomMembers(memberId, chatRoomId); + verify(goodsChatService).getMembersInChatRoom(memberId, chatRoomId); } @Test @@ -375,7 +374,7 @@ void getGoodsChatRoomMembers_should_throw_exception_when_user_is_not_a_member() Long memberId = 1L; Long chatRoomId = 2L; - when(goodsChatService.getChatRoomMembers(memberId, chatRoomId)) + when(goodsChatService.getMembersInChatRoom(memberId, chatRoomId)) .thenThrow(new CustomException(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART)); // when & then @@ -385,6 +384,6 @@ void getGoodsChatRoomMembers_should_throw_exception_when_user_is_not_a_member() .andExpect(jsonPath("$.code").value(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART.getStatus().value())) .andExpect(jsonPath("$.message").value(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART.getMessage())); - verify(goodsChatService).getChatRoomMembers(memberId, chatRoomId); + verify(goodsChatService).getMembersInChatRoom(memberId, chatRoomId); } } \ No newline at end of file diff --git a/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java b/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java index 60d34583..7beef9a5 100644 --- a/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/goodsChat/integration/GoodsChatIntegrationTest.java @@ -10,27 +10,27 @@ import com.example.mate.common.response.ApiResponse; import com.example.mate.common.response.PageResponse; -import com.example.mate.common.security.util.JwtUtil; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.mongoConfig.AcceptanceTestWithMongo; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.MessageType; import com.example.mate.domain.file.FileUtils; -import com.example.mate.domain.goodsPost.dto.response.LocationInfo; -import com.example.mate.domain.goodsPost.entity.Category; -import com.example.mate.domain.goodsPost.entity.GoodsPost; -import com.example.mate.domain.goodsPost.entity.GoodsPostImage; -import com.example.mate.domain.goodsPost.entity.Role; -import com.example.mate.domain.goodsPost.entity.Status; -import com.example.mate.domain.goodsPost.repository.GoodsPostRepository; +import com.example.mate.domain.goodsChat.document.GoodsChatMessage; import com.example.mate.domain.goodsChat.dto.response.GoodsChatMessageResponse; import com.example.mate.domain.goodsChat.dto.response.GoodsChatRoomResponse; -import com.example.mate.domain.goodsChat.entity.GoodsChatMessage; import com.example.mate.domain.goodsChat.entity.GoodsChatPart; import com.example.mate.domain.goodsChat.entity.GoodsChatPartId; import com.example.mate.domain.goodsChat.entity.GoodsChatRoom; import com.example.mate.domain.goodsChat.repository.GoodsChatMessageRepository; import com.example.mate.domain.goodsChat.repository.GoodsChatPartRepository; import com.example.mate.domain.goodsChat.repository.GoodsChatRoomRepository; +import com.example.mate.domain.goodsPost.dto.response.LocationInfo; +import com.example.mate.domain.goodsPost.entity.Category; +import com.example.mate.domain.goodsPost.entity.GoodsPost; +import com.example.mate.domain.goodsPost.entity.GoodsPostImage; +import com.example.mate.domain.goodsPost.entity.Role; +import com.example.mate.domain.goodsPost.entity.Status; +import com.example.mate.domain.goodsPost.repository.GoodsPostRepository; import com.example.mate.domain.member.dto.response.MemberSummaryResponse; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.MemberRepository; @@ -46,7 +46,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -58,7 +57,7 @@ @SpringBootTest @AutoConfigureMockMvc(addFilters = false) @Transactional -public class GoodsChatIntegrationTest { +public class GoodsChatIntegrationTest extends AcceptanceTestWithMongo { @Autowired private MockMvc mockMvc; @Autowired private MemberRepository memberRepository; @@ -258,12 +257,10 @@ void getGoodsChatRoomMessages_integration_test() throws Exception { GoodsChatMessage actualMessage = actualMessages.get(i); assertThat(expectedMessage.getChatMessageId()).isEqualTo(actualMessage.getId()); - assertThat(expectedMessage.getRoomId()).isEqualTo(actualMessage.getGoodsChatPart().getGoodsChatRoom().getId()); - assertThat(expectedMessage.getSenderId()).isEqualTo(actualMessage.getGoodsChatPart().getMember().getId()); - assertThat(expectedMessage.getSenderNickname()).isEqualTo(actualMessage.getGoodsChatPart().getMember().getNickname()); + assertThat(expectedMessage.getRoomId()).isEqualTo(actualMessage.getChatRoomId()); + assertThat(expectedMessage.getSenderId()).isEqualTo(actualMessage.getMemberId()); assertThat(expectedMessage.getMessage()).isEqualTo(actualMessage.getContent()); assertThat(expectedMessage.getMessageType()).isEqualTo(actualMessage.getMessageType().getValue()); - assertThat(expectedMessage.getSenderImageUrl()).isEqualTo(FileUtils.getThumbnailImageUrl(actualMessage.getGoodsChatPart().getMember().getImageUrl())); assertThat(expectedMessage.getSentAt()).isEqualToIgnoringNanos(actualMessage.getSentAt()); // 시간 비교, 나노초는 무시 } } @@ -394,7 +391,8 @@ private void createGoodsPostImage(GoodsPost goodsPost) { private GoodsChatMessage createChatMessage(GoodsChatPart goodsChatPart, String content) { return messageRepository.save( GoodsChatMessage.builder() - .goodsChatPart(goodsChatPart) + .chatRoomId(goodsChatPart.getGoodsChatRoom().getId()) + .memberId(goodsChatPart.getMember().getId()) .content(content) .messageType(MessageType.TALK) .sentAt(LocalDateTime.now()) diff --git a/src/test/java/com/example/mate/domain/goodsChat/service/GoodsChatMessageServiceTest.java b/src/test/java/com/example/mate/domain/goodsChat/service/GoodsChatMessageServiceTest.java index eb59a065..b3861940 100644 --- a/src/test/java/com/example/mate/domain/goodsChat/service/GoodsChatMessageServiceTest.java +++ b/src/test/java/com/example/mate/domain/goodsChat/service/GoodsChatMessageServiceTest.java @@ -10,15 +10,13 @@ import com.example.mate.common.error.CustomException; import com.example.mate.common.error.ErrorCode; import com.example.mate.domain.constant.MessageType; +import com.example.mate.domain.goodsChat.document.GoodsChatMessage; import com.example.mate.domain.goodsChat.dto.request.GoodsChatMessageRequest; import com.example.mate.domain.goodsChat.dto.response.GoodsChatMessageResponse; -import com.example.mate.domain.goodsChat.entity.GoodsChatMessage; import com.example.mate.domain.goodsChat.entity.GoodsChatPart; -import com.example.mate.domain.goodsChat.entity.GoodsChatPartId; import com.example.mate.domain.goodsChat.entity.GoodsChatRoom; import com.example.mate.domain.goodsChat.event.GoodsChatEvent; import com.example.mate.domain.goodsChat.repository.GoodsChatMessageRepository; -import com.example.mate.domain.goodsChat.repository.GoodsChatPartRepository; import com.example.mate.domain.goodsChat.repository.GoodsChatRoomRepository; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.MemberRepository; @@ -45,9 +43,6 @@ class GoodsChatMessageServiceTest { @Mock private GoodsChatRoomRepository chatRoomRepository; - @Mock - private GoodsChatPartRepository chatPartRepository; - @Mock private GoodsChatMessageRepository messageRepository; @@ -78,7 +73,8 @@ private GoodsChatPart createGoodsChatPart(Member member, GoodsChatRoom chatRoom) private GoodsChatMessage createGoodsChatMessage(String message, GoodsChatPart chatPart, MessageType type) { return GoodsChatMessage.builder() .content(message) - .goodsChatPart(chatPart) + .chatRoomId(chatPart.getGoodsChatRoom().getId()) + .memberId(chatPart.getMember().getId()) .messageType(type) .sentAt(LocalDateTime.now()) .build(); @@ -103,7 +99,6 @@ void sendMessage_should_save_message_and_send_to_subscribers() { when(memberRepository.findById(memberId)).thenReturn(Optional.of(member)); when(chatRoomRepository.findById(chatRoomId)).thenReturn(Optional.of(chatRoom)); - when(chatPartRepository.findById(new GoodsChatPartId(memberId, chatRoomId))).thenReturn(Optional.of(chatPart)); when(messageRepository.save(any(GoodsChatMessage.class))).thenReturn(chatMessage); // when @@ -112,7 +107,6 @@ void sendMessage_should_save_message_and_send_to_subscribers() { // then verify(memberRepository).findById(memberId); verify(chatRoomRepository).findById(chatRoomId); - verify(chatPartRepository).findById(new GoodsChatPartId(memberId, chatRoomId)); verify(messageRepository).save(any(GoodsChatMessage.class)); verify(messagingTemplate).convertAndSend(eq("/sub/chat/goods/" + chatRoomId), any(GoodsChatMessageResponse.class)); } @@ -135,7 +129,6 @@ void sendMessage_should_throw_custom_exception_for_invalid_member() { // then verify(memberRepository).findById(memberId); verify(chatRoomRepository, never()).findById(chatRoomId); - verify(chatPartRepository, never()).findById(new GoodsChatPartId(memberId, chatRoomId)); verify(messageRepository, never()).save(any(GoodsChatMessage.class)); verify(messagingTemplate, never()).convertAndSend(eq("/sub/chat/goods/" + chatRoomId), any(GoodsChatMessageResponse.class)); } @@ -149,21 +142,18 @@ void sendMessage_should_throw_custom_exception_for_invalid_chatroom() { GoodsChatMessageRequest request = new GoodsChatMessageRequest(chatRoomId, memberId, "Hello World", MessageType.TALK); Member member = createMember(memberId, "Test User", "test_user"); - GoodsChatRoom chatRoom = createGoodsChatRoom(chatRoomId); when(memberRepository.findById(memberId)).thenReturn(Optional.of(member)); - when(chatRoomRepository.findById(chatRoomId)).thenReturn(Optional.of(chatRoom)); - when(chatPartRepository.findById(new GoodsChatPartId(memberId, chatRoomId))).thenReturn(Optional.empty()); + when(chatRoomRepository.findById(chatRoomId)).thenReturn(Optional.empty()); // when assertThatThrownBy(() -> goodsChatMessageService.sendMessage(request)) .isExactlyInstanceOf(CustomException.class) - .hasMessage(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART.getMessage()); + .hasMessage(ErrorCode.GOODS_CHAT_ROOM_NOT_FOUND.getMessage()); // then verify(memberRepository).findById(memberId); verify(chatRoomRepository).findById(chatRoomId); - verify(chatPartRepository).findById(new GoodsChatPartId(memberId, chatRoomId)); verify(messageRepository, never()).save(any(GoodsChatMessage.class)); verify(messagingTemplate, never()).convertAndSend(eq("/sub/chat/goods/" + chatRoomId), any(GoodsChatMessageResponse.class)); } @@ -188,7 +178,6 @@ void sendMessage_should_throw_custom_exception_for_non_participant() { // then verify(memberRepository).findById(memberId); verify(chatRoomRepository).findById(chatRoomId); - verify(chatPartRepository, never()).findById(new GoodsChatPartId(memberId, chatRoomId)); verify(messageRepository, never()).save(any(GoodsChatMessage.class)); verify(messagingTemplate, never()).convertAndSend(eq("/sub/chat/goods/" + chatRoomId), any(GoodsChatMessageResponse.class)); } @@ -215,7 +204,6 @@ void sendChatEventMessage_should_send_enter_message() { = createGoodsChatMessage(member.getNickname() + "님이 대화를 시작했습니다.", chatPart, event.type()); when(chatRoomRepository.findById(chatRoomId)).thenReturn(Optional.of(chatRoom)); - when(chatPartRepository.findById(new GoodsChatPartId(memberId, chatRoomId))).thenReturn(Optional.of(chatPart)); when(messageRepository.save(any(GoodsChatMessage.class))).thenReturn(chatMessage); // when @@ -223,7 +211,6 @@ void sendChatEventMessage_should_send_enter_message() { // then verify(chatRoomRepository).findById(chatRoomId); - verify(chatPartRepository).findById(new GoodsChatPartId(memberId, chatRoomId)); verify(messageRepository).save(any(GoodsChatMessage.class)); verify(messagingTemplate).convertAndSend(eq("/sub/chat/goods/" + chatRoomId), any(GoodsChatMessageResponse.class)); } @@ -245,7 +232,6 @@ void sendChatEventMessage_should_send_leave_message() { = createGoodsChatMessage(member.getNickname() + "님이 대화를 떠났습니다.", chatPart, event.type()); when(chatRoomRepository.findById(chatRoomId)).thenReturn(Optional.of(chatRoom)); - when(chatPartRepository.findById(new GoodsChatPartId(memberId, chatRoomId))).thenReturn(Optional.of(chatPart)); when(messageRepository.save(any(GoodsChatMessage.class))).thenReturn(chatMessage); // when @@ -253,7 +239,6 @@ void sendChatEventMessage_should_send_leave_message() { // then verify(chatRoomRepository).findById(chatRoomId); - verify(chatPartRepository).findById(new GoodsChatPartId(memberId, chatRoomId)); verify(messageRepository).save(any(GoodsChatMessage.class)); verify(messagingTemplate).convertAndSend(eq("/sub/chat/goods/" + chatRoomId), any(GoodsChatMessageResponse.class)); } @@ -277,33 +262,6 @@ void sendChatEventMessage_should_throw_custom_exception_for_invalid_chatroom() { // then verify(chatRoomRepository).findById(chatRoomId); - verify(chatPartRepository, never()).findById(new GoodsChatPartId(memberId, chatRoomId)); - verify(messageRepository, never()).save(any(GoodsChatMessage.class)); - verify(messagingTemplate, never()).convertAndSend(eq("/sub/chat/goods/" + chatRoomId), any(GoodsChatMessageResponse.class)); - } - - @Test - @DisplayName("시스템 메시지 전송 실패 - 해당 채팅방에 참가한 회원이 아닌 경우") - void sendChatEventMessage_should_throw_custom_exception_for_non_participant() { - // given - Long memberId = 1L; - Long chatRoomId = 1L; - - Member member = createMember(memberId, "Test User", "test_user"); - GoodsChatEvent event = new GoodsChatEvent(chatRoomId, member, MessageType.LEAVE); - GoodsChatRoom chatRoom = createGoodsChatRoom(event.chatRoomId()); - - when(chatRoomRepository.findById(chatRoomId)).thenReturn(Optional.of(chatRoom)); - when(chatPartRepository.findById(new GoodsChatPartId(memberId, chatRoomId))).thenReturn(Optional.empty()); - - // when - assertThatThrownBy(() -> goodsChatMessageService.sendChatEventMessage(event)) - .isExactlyInstanceOf(CustomException.class) - .hasMessage(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART.getMessage()); - - // then - verify(chatRoomRepository).findById(chatRoomId); - verify(chatPartRepository).findById(new GoodsChatPartId(memberId, chatRoomId)); verify(messageRepository, never()).save(any(GoodsChatMessage.class)); verify(messagingTemplate, never()).convertAndSend(eq("/sub/chat/goods/" + chatRoomId), any(GoodsChatMessageResponse.class)); } diff --git a/src/test/java/com/example/mate/domain/goodsChat/service/GoodsChatServiceTest.java b/src/test/java/com/example/mate/domain/goodsChat/service/GoodsChatServiceTest.java index fae74915..5143fab7 100644 --- a/src/test/java/com/example/mate/domain/goodsChat/service/GoodsChatServiceTest.java +++ b/src/test/java/com/example/mate/domain/goodsChat/service/GoodsChatServiceTest.java @@ -5,6 +5,7 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.any; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -13,17 +14,10 @@ import com.example.mate.common.response.PageResponse; import com.example.mate.domain.constant.MessageType; import com.example.mate.domain.file.FileUtils; -import com.example.mate.domain.goodsPost.entity.Category; -import com.example.mate.domain.goodsPost.entity.GoodsPost; -import com.example.mate.domain.goodsPost.entity.GoodsPostImage; -import com.example.mate.domain.goodsPost.entity.Location; -import com.example.mate.domain.goodsPost.entity.Role; -import com.example.mate.domain.goodsPost.entity.Status; -import com.example.mate.domain.goodsPost.repository.GoodsPostRepository; +import com.example.mate.domain.goodsChat.document.GoodsChatMessage; import com.example.mate.domain.goodsChat.dto.response.GoodsChatMessageResponse; import com.example.mate.domain.goodsChat.dto.response.GoodsChatRoomResponse; import com.example.mate.domain.goodsChat.dto.response.GoodsChatRoomSummaryResponse; -import com.example.mate.domain.goodsChat.entity.GoodsChatMessage; import com.example.mate.domain.goodsChat.entity.GoodsChatPart; import com.example.mate.domain.goodsChat.entity.GoodsChatPartId; import com.example.mate.domain.goodsChat.entity.GoodsChatRoom; @@ -32,6 +26,13 @@ import com.example.mate.domain.goodsChat.repository.GoodsChatMessageRepository; import com.example.mate.domain.goodsChat.repository.GoodsChatPartRepository; import com.example.mate.domain.goodsChat.repository.GoodsChatRoomRepository; +import com.example.mate.domain.goodsPost.entity.Category; +import com.example.mate.domain.goodsPost.entity.GoodsPost; +import com.example.mate.domain.goodsPost.entity.GoodsPostImage; +import com.example.mate.domain.goodsPost.entity.Location; +import com.example.mate.domain.goodsPost.entity.Role; +import com.example.mate.domain.goodsPost.entity.Status; +import com.example.mate.domain.goodsPost.repository.GoodsPostRepository; import com.example.mate.domain.member.dto.response.MemberSummaryResponse; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.MemberRepository; @@ -69,7 +70,7 @@ class GoodsChatServiceTest { private GoodsChatPartRepository partRepository; @Mock - private GoodsChatMessageRepository messageRepository; + private GoodsChatMessageRepository messageRepository; @Mock private GoodsChatEventPublisher eventPublisher; @@ -119,10 +120,13 @@ private GoodsChatRoom createGoodsChatRoom(Long id, GoodsPost goodsPost) { .build(); } - private GoodsChatMessage createMessage(GoodsChatRoom chatRoom, Long id, int idx, String content, LocalDateTime sentAt) { + private GoodsChatMessage createMessage(GoodsChatRoom chatRoom, String id, int idx, String content, LocalDateTime sentAt) { + GoodsChatPart goodsChatPart = chatRoom.getChatParts().get(idx); + return GoodsChatMessage.builder() .id(id) - .goodsChatPart(chatRoom.getChatParts().get(idx)) + .memberId(goodsChatPart.getMember().getId()) + .chatRoomId(chatRoom.getId()) .content(content) .sentAt(sentAt) .messageType(MessageType.TALK) @@ -149,13 +153,12 @@ void get_Or_Create_GoodsChatRoom_should_return_existing_chatroom() { existingChatRoom.addChatParticipant(buyer, Role.BUYER); existingChatRoom.addChatParticipant(seller, Role.SELLER); - GoodsChatMessage message = createMessage(existingChatRoom, 1L, 0, "test Message", LocalDateTime.now()); + GoodsChatMessage message = createMessage(existingChatRoom, "1", 0, "test Message", LocalDateTime.now()); PageImpl goodsChatMessages = new PageImpl<>(List.of(message)); when(memberRepository.findById(buyerId)).thenReturn(Optional.of(buyer)); when(goodsPostRepository.findById(goodsPostId)).thenReturn(Optional.of(goodsPost)); - when(chatRoomRepository.findExistingChatRoom(goodsPostId, buyerId, Role.BUYER)) - .thenReturn(Optional.of(existingChatRoom)); + when(chatRoomRepository.findExistingChatRoom(goodsPostId, buyerId, Role.BUYER)).thenReturn(Optional.of(existingChatRoom)); when(messageRepository.getChatMessages(existingChatRoom.getId(), PageRequest.of(0, 20))).thenReturn(goodsChatMessages); // when @@ -166,7 +169,7 @@ void get_Or_Create_GoodsChatRoom_should_return_existing_chatroom() { assertThat(result.getGoodsPostId()).isEqualTo(goodsPost.getId()); assertThat(result.getPostStatus()).isEqualTo(goodsPost.getStatus().getValue()); - verify(memberRepository).findById(buyerId); + verify(memberRepository, times(2)).findById(buyerId); verify(goodsPostRepository).findById(goodsPostId); verify(chatRoomRepository).findExistingChatRoom(goodsPostId, buyerId, Role.BUYER); verify(chatRoomRepository, never()).save(any()); @@ -278,16 +281,17 @@ void getMessagesForChatRoom_should_return_messages() { Pageable pageable = PageRequest.of(0, 10); - GoodsChatMessage firstMessage = createMessage(chatRoom, 1L, 0, "first message", LocalDateTime.now().minusMinutes(10)); - GoodsChatMessage secondMessage = createMessage(chatRoom, 2L, 1, "second message", LocalDateTime.now()); + GoodsChatMessage firstMessage = createMessage(chatRoom, "1", 0, "first message", LocalDateTime.now().minusMinutes(10)); + GoodsChatMessage secondMessage = createMessage(chatRoom, "2", 1, "second message", LocalDateTime.now()); Page messagePage = new PageImpl<>(List.of(secondMessage, firstMessage)); when(partRepository.existsById(goodsChatPartId)).thenReturn(true); when(messageRepository.getChatMessages(chatRoomId, pageable)).thenReturn(messagePage); + when(memberRepository.findById(2L)).thenReturn(Optional.of(member)); // when - PageResponse result = goodsChatService.getMessagesForChatRoom(chatRoomId, memberId, pageable); + PageResponse result = goodsChatService.getChatRoomMessages(chatRoomId, memberId, pageable); // then assertThat(result.getContent()).hasSize(2); @@ -313,7 +317,7 @@ void getMessagesForChatRoom_should_throw_exception_for_non_participant() { when(partRepository.existsById(goodsChatPartId)).thenReturn(false); // when - assertThatThrownBy(() -> goodsChatService.getMessagesForChatRoom(chatRoomId, memberId, pageable)) + assertThatThrownBy(() -> goodsChatService.getChatRoomMessages(chatRoomId, memberId, pageable)) .isInstanceOf(CustomException.class) .hasMessage(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART.getMessage()); @@ -343,14 +347,15 @@ void getGoodsChatRoomInfo_should_return_chatroom_info_and_latest_message() { chatRoom.addChatParticipant(member, Role.BUYER); chatRoom.addChatParticipant(member, Role.SELLER); - GoodsChatMessage firstMessage = createMessage(chatRoom, 1L, 0, "first message", LocalDateTime.now().minusMinutes(10)); - GoodsChatMessage secondMessage = createMessage(chatRoom, 2L, 1, "second message", LocalDateTime.now()); + GoodsChatMessage firstMessage = createMessage(chatRoom, "1", 0, "first message", LocalDateTime.now().minusMinutes(10)); + GoodsChatMessage secondMessage = createMessage(chatRoom, "2", 1, "second message", LocalDateTime.now()); Page messages = new PageImpl<>(List.of(secondMessage, firstMessage)); when(partRepository.existsById(goodsChatPartId)).thenReturn(true); when(chatRoomRepository.findByChatRoomId(chatRoomId)).thenReturn(Optional.of(chatRoom)); when(messageRepository.getChatMessages(chatRoomId, PageRequest.of(0, 20))).thenReturn(messages); + when(memberRepository.findById(1L)).thenReturn(Optional.of(member)); // when GoodsChatRoomResponse goodsChatRoomInfo = goodsChatService.getGoodsChatRoomInfo(memberId, chatRoomId); @@ -514,16 +519,18 @@ void getMessagesForChatRoom_should_return_paginated_messages() { Pageable pageable = PageRequest.of(0, 20); GoodsChatPartId goodsChatPartId = new GoodsChatPartId(buyerId, chatRoomId); - GoodsChatMessage firstMessage = createMessage(chatRoom, 1L, 0, "First message", LocalDateTime.now().minusMinutes(10)); - GoodsChatMessage secondMessage = createMessage(chatRoom, 2L, 1, "Second message", LocalDateTime.now()); + GoodsChatMessage firstMessage = createMessage(chatRoom, "1", 0, "First message", LocalDateTime.now().minusMinutes(10)); + GoodsChatMessage secondMessage = createMessage(chatRoom, "2", 1, "Second message", LocalDateTime.now()); Page messagePage = new PageImpl<>(List.of(secondMessage, firstMessage), pageable, 2); when(partRepository.existsById(goodsChatPartId)).thenReturn(true); when(messageRepository.getChatMessages(chatRoomId, pageable)).thenReturn(messagePage); + when(memberRepository.findById(1L)).thenReturn(Optional.of(buyer)); + when(memberRepository.findById(2L)).thenReturn(Optional.of(seller)); // when - PageResponse result = goodsChatService.getMessagesForChatRoom(chatRoomId, buyerId, pageable); + PageResponse result = goodsChatService.getChatRoomMessages(chatRoomId, buyerId, pageable); // then assertThat(result.getContent()).hasSize(2); @@ -557,7 +564,7 @@ void getMessagesForChatRoom_should_throw_exception_when_member_not_participant() when(partRepository.existsById(goodsChatPartId)).thenReturn(false); // when - assertThatThrownBy(() -> goodsChatService.getMessagesForChatRoom(chatRoomId, buyerId, pageable)) + assertThatThrownBy(() -> goodsChatService.getChatRoomMessages(chatRoomId, buyerId, pageable)) .isInstanceOf(CustomException.class) .hasMessage(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART.getMessage()); @@ -699,7 +706,7 @@ void getChatRoomMembers_should_return_list_of_participants() { when(partRepository.findAllWithMemberByChatRoomId(chatRoomId)).thenReturn(goodsChatRoom.getChatParts()); // when - List result = goodsChatService.getChatRoomMembers(memberId, chatRoomId); + List result = goodsChatService.getMembersInChatRoom(memberId, chatRoomId); // then assertThat(result).hasSize(2); @@ -722,7 +729,7 @@ void getChatRoomMembers_should_throw_exception_for_non_participant() { when(partRepository.existsById(new GoodsChatPartId(memberId, chatRoomId))).thenReturn(false); // when & then - assertThatThrownBy(() -> goodsChatService.getChatRoomMembers(memberId, chatRoomId)) + assertThatThrownBy(() -> goodsChatService.getMembersInChatRoom(memberId, chatRoomId)) .isInstanceOf(CustomException.class) .hasMessage(ErrorCode.GOODS_CHAT_NOT_FOUND_CHAT_PART.getMessage()); diff --git a/src/test/java/com/example/mate/domain/goodsPost/controller/GoodsPostControllerTest.java b/src/test/java/com/example/mate/domain/goodsPost/controller/GoodsPostControllerTest.java index 9d3cd9c0..56eb5699 100644 --- a/src/test/java/com/example/mate/domain/goodsPost/controller/GoodsPostControllerTest.java +++ b/src/test/java/com/example/mate/domain/goodsPost/controller/GoodsPostControllerTest.java @@ -16,7 +16,7 @@ import com.example.mate.common.response.PageResponse; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.goodsPost.dto.request.GoodsPostRequest; import com.example.mate.domain.goodsPost.dto.response.GoodsPostResponse; import com.example.mate.domain.goodsPost.dto.response.GoodsPostSummaryResponse; diff --git a/src/test/java/com/example/mate/domain/goodsPost/integration/GoodsPostIntegrationTest.java b/src/test/java/com/example/mate/domain/goodsPost/integration/GoodsPostIntegrationTest.java index 943fe0fe..00e827f2 100644 --- a/src/test/java/com/example/mate/domain/goodsPost/integration/GoodsPostIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/goodsPost/integration/GoodsPostIntegrationTest.java @@ -10,7 +10,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.mate.common.response.ApiResponse; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.TeamInfo; import com.example.mate.domain.file.FileUtils; diff --git a/src/test/java/com/example/mate/domain/goodsReview/controller/GoodsReviewControllerTest.java b/src/test/java/com/example/mate/domain/goodsReview/controller/GoodsReviewControllerTest.java index 113860a0..7f2e1b54 100644 --- a/src/test/java/com/example/mate/domain/goodsReview/controller/GoodsReviewControllerTest.java +++ b/src/test/java/com/example/mate/domain/goodsReview/controller/GoodsReviewControllerTest.java @@ -10,7 +10,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.goodsReview.dto.request.GoodsReviewRequest; import com.example.mate.domain.goodsReview.dto.response.GoodsReviewResponse; diff --git a/src/test/java/com/example/mate/domain/goodsReview/integration/GoodsReviewIntegrationTest.java b/src/test/java/com/example/mate/domain/goodsReview/integration/GoodsReviewIntegrationTest.java index 79d9779e..2b9f0256 100644 --- a/src/test/java/com/example/mate/domain/goodsReview/integration/GoodsReviewIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/goodsReview/integration/GoodsReviewIntegrationTest.java @@ -8,7 +8,7 @@ import com.example.mate.common.response.ApiResponse; import com.example.mate.common.security.util.JwtUtil; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.goodsPost.dto.response.LocationInfo; diff --git a/src/test/java/com/example/mate/domain/mateChat/controller/MateChatControllerTest.java b/src/test/java/com/example/mate/domain/mateChat/controller/MateChatControllerTest.java index 0a3e4ac7..214f781a 100644 --- a/src/test/java/com/example/mate/domain/mateChat/controller/MateChatControllerTest.java +++ b/src/test/java/com/example/mate/domain/mateChat/controller/MateChatControllerTest.java @@ -3,7 +3,7 @@ import com.example.mate.common.response.PageResponse; import com.example.mate.common.security.filter.JwtCheckFilter; import com.example.mate.common.security.util.JwtUtil; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.mateChat.dto.response.MateChatMessageResponse; import com.example.mate.domain.mateChat.dto.response.MateChatRoomListResponse; import com.example.mate.domain.mateChat.dto.response.MateChatRoomResponse; diff --git a/src/test/java/com/example/mate/domain/matePost/controller/MatePostControllerTest.java b/src/test/java/com/example/mate/domain/matePost/controller/MatePostControllerTest.java index aaecb710..394f794e 100644 --- a/src/test/java/com/example/mate/domain/matePost/controller/MatePostControllerTest.java +++ b/src/test/java/com/example/mate/domain/matePost/controller/MatePostControllerTest.java @@ -21,7 +21,7 @@ import com.example.mate.common.error.ErrorCode; import com.example.mate.common.response.PageResponse; import com.example.mate.common.security.util.JwtUtil; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.matePost.dto.request.MatePostCreateRequest; import com.example.mate.domain.matePost.dto.request.MatePostUpdateRequest; diff --git a/src/test/java/com/example/mate/domain/matePost/controller/MateStatusControllerTest.java b/src/test/java/com/example/mate/domain/matePost/controller/MateStatusControllerTest.java index e0078041..1a23f904 100644 --- a/src/test/java/com/example/mate/domain/matePost/controller/MateStatusControllerTest.java +++ b/src/test/java/com/example/mate/domain/matePost/controller/MateStatusControllerTest.java @@ -19,7 +19,7 @@ import com.example.mate.common.error.CustomException; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.matePost.dto.request.MatePostCompleteRequest; import com.example.mate.domain.matePost.dto.request.MatePostStatusRequest; import com.example.mate.domain.matePost.dto.response.MatePostCompleteResponse; diff --git a/src/test/java/com/example/mate/domain/matePost/integration/MatePostIntegrationTest.java b/src/test/java/com/example/mate/domain/matePost/integration/MatePostIntegrationTest.java index 8426a0ed..da9da6b7 100644 --- a/src/test/java/com/example/mate/domain/matePost/integration/MatePostIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/matePost/integration/MatePostIntegrationTest.java @@ -1,6 +1,6 @@ package com.example.mate.domain.matePost.integration; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.file.FileUtils; import com.example.mate.domain.match.entity.Match; diff --git a/src/test/java/com/example/mate/domain/matePost/integration/MatePostStatusIntegrationTest.java b/src/test/java/com/example/mate/domain/matePost/integration/MatePostStatusIntegrationTest.java index 63413295..8286051b 100644 --- a/src/test/java/com/example/mate/domain/matePost/integration/MatePostStatusIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/matePost/integration/MatePostStatusIntegrationTest.java @@ -1,6 +1,6 @@ package com.example.mate.domain.matePost.integration; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.match.entity.Match; import com.example.mate.domain.match.repository.MatchRepository; diff --git a/src/test/java/com/example/mate/domain/mateReview/controller/MateReviewControllerTest.java b/src/test/java/com/example/mate/domain/mateReview/controller/MateReviewControllerTest.java index c520d7d1..b4027b22 100644 --- a/src/test/java/com/example/mate/domain/mateReview/controller/MateReviewControllerTest.java +++ b/src/test/java/com/example/mate/domain/mateReview/controller/MateReviewControllerTest.java @@ -1,7 +1,7 @@ package com.example.mate.domain.mateReview.controller; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.mateReview.dto.request.MateReviewCreateRequest; import com.example.mate.domain.mateReview.dto.response.MateReviewCreateResponse; diff --git a/src/test/java/com/example/mate/domain/mateReview/integration/MateReviewIntegrationTest.java b/src/test/java/com/example/mate/domain/mateReview/integration/MateReviewIntegrationTest.java index 9f7fa558..bf7cb775 100644 --- a/src/test/java/com/example/mate/domain/mateReview/integration/MateReviewIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/mateReview/integration/MateReviewIntegrationTest.java @@ -1,6 +1,6 @@ package com.example.mate.domain.mateReview.integration; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.match.entity.Match; diff --git a/src/test/java/com/example/mate/domain/member/controller/FollowControllerTest.java b/src/test/java/com/example/mate/domain/member/controller/FollowControllerTest.java index e02423bd..aaf1ffbc 100644 --- a/src/test/java/com/example/mate/domain/member/controller/FollowControllerTest.java +++ b/src/test/java/com/example/mate/domain/member/controller/FollowControllerTest.java @@ -19,7 +19,7 @@ import com.example.mate.common.error.ErrorCode; import com.example.mate.common.response.PageResponse; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.member.dto.response.MemberSummaryResponse; import com.example.mate.domain.member.entity.Follow; diff --git a/src/test/java/com/example/mate/domain/member/controller/MemberControllerTest.java b/src/test/java/com/example/mate/domain/member/controller/MemberControllerTest.java index bbc740c1..77e1cd57 100644 --- a/src/test/java/com/example/mate/domain/member/controller/MemberControllerTest.java +++ b/src/test/java/com/example/mate/domain/member/controller/MemberControllerTest.java @@ -3,7 +3,7 @@ import com.example.mate.common.error.CustomException; import com.example.mate.common.error.ErrorCode; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.member.dto.request.JoinRequest; import com.example.mate.domain.member.dto.request.MemberInfoUpdateRequest; import com.example.mate.domain.member.dto.request.MemberLoginRequest; diff --git a/src/test/java/com/example/mate/domain/member/controller/ProfileControllerTest.java b/src/test/java/com/example/mate/domain/member/controller/ProfileControllerTest.java index 246ed3a3..c68496a6 100644 --- a/src/test/java/com/example/mate/domain/member/controller/ProfileControllerTest.java +++ b/src/test/java/com/example/mate/domain/member/controller/ProfileControllerTest.java @@ -4,7 +4,7 @@ import com.example.mate.common.error.ErrorCode; import com.example.mate.common.response.PageResponse; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.goodsPost.dto.response.GoodsPostSummaryResponse; import com.example.mate.domain.matePost.dto.response.MatePostSummaryResponse; diff --git a/src/test/java/com/example/mate/domain/member/integration/FollowIntegrationTest.java b/src/test/java/com/example/mate/domain/member/integration/FollowIntegrationTest.java index 41399f41..15fb0ea1 100644 --- a/src/test/java/com/example/mate/domain/member/integration/FollowIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/member/integration/FollowIntegrationTest.java @@ -8,12 +8,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import com.example.mate.common.config.S3Config; import com.example.mate.common.error.ErrorCode; -import com.example.mate.config.WithAuthMember; -import com.example.mate.common.security.util.JwtUtil; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; -import com.example.mate.domain.file.FileService; import com.example.mate.domain.member.entity.Follow; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.FollowRepository; @@ -26,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.web.servlet.MockMvc; diff --git a/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java b/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java index 90ed4d3c..bfaf8073 100644 --- a/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/member/integration/MemberIntegrationTest.java @@ -2,7 +2,7 @@ import com.example.mate.common.jwt.JwtToken; import com.example.mate.common.security.util.JwtUtil; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.file.FileUtils; diff --git a/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java b/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java index ee5ecb15..7f8c7763 100644 --- a/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/member/integration/ProfileIntegrationTest.java @@ -1,6 +1,6 @@ package com.example.mate.domain.member.integration; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.constant.Rating; import com.example.mate.domain.goodsPost.dto.response.LocationInfo; diff --git a/src/test/java/com/example/mate/domain/notification/controller/NotificationControllerTest.java b/src/test/java/com/example/mate/domain/notification/controller/NotificationControllerTest.java index f2ac6c20..1fc48e86 100644 --- a/src/test/java/com/example/mate/domain/notification/controller/NotificationControllerTest.java +++ b/src/test/java/com/example/mate/domain/notification/controller/NotificationControllerTest.java @@ -7,7 +7,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.example.mate.common.security.filter.JwtCheckFilter; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.notification.service.NotificationService; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/example/mate/domain/notification/integration/NotificationIntegrationTest.java b/src/test/java/com/example/mate/domain/notification/integration/NotificationIntegrationTest.java index 6de6ce35..3008998c 100644 --- a/src/test/java/com/example/mate/domain/notification/integration/NotificationIntegrationTest.java +++ b/src/test/java/com/example/mate/domain/notification/integration/NotificationIntegrationTest.java @@ -5,7 +5,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import com.example.mate.config.WithAuthMember; +import com.example.mate.config.securityConfig.WithAuthMember; import com.example.mate.domain.constant.Gender; import com.example.mate.domain.member.entity.Member; import com.example.mate.domain.member.repository.MemberRepository;