From 75071162053e5577c522be3c7c6cbc7ef75a38cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=8A=B9=EC=9B=90=20Merry?= Date: Mon, 16 Oct 2023 01:12:46 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20#690=20Device=20=EC=9D=B8=ED=94=84?= =?UTF-8?q?=EB=9D=BC=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20=20(#696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 도메인 영역 기기토큰 레포지토리 추가 * feat: 도메인 기기토큰 레포지토리의 구현체 추가 * feat: 기기토큰 레포지토리 메서드 중 누락된 메서드 추가 * refactor: 서비스 레이어에서 도메인 영역 기기토큰 레포지토리 사용하도록 변경 * refactor: 누락된 final 추가 * test: 테스트에서 도메인 영역의 기기토큰 레포지토리 사용하도록 변경 * refactor: 레포지토리명에 맞춰 변수명 변경 * refactor: 테스트 픽스처에서 도메인 영역의 사용자 레포지토리 사용하도록 변경 * test: 기기토큰 레포지토리 구현체 테스트 추가 * chore: 질문에 대한 todo 주석 추가 * style: 개행 추가 * refactor: jpaQueryFactory 파라미터명 통일 * refactor: 필드 순서 변경 * refactor: given절 추가 * refactor: jpa 레포지토리 저장 테스트 메서드에서 엔티티 매니저 사용하는 코드 삭제 * refactor: 불필요한 필드 삭제 * refactor: 테스트에서 도메인 레포지토리 사용하도록 변경 * refactor: 불필요한 todo 삭제 --- .../application/AuthenticationService.java | 15 +++-- .../application/DeviceTokenService.java | 4 +- .../repository/DeviceTokenRepository.java | 14 ++++ .../DeviceTokenRepositoryImpl.java | 30 +++++++++ .../persistence/JpaDeviceTokenRepository.java | 2 +- .../application/FcmNotificationService.java | 4 +- .../AuctionRepositoryImplTest.java | 14 ++-- .../persistence/JpaAuctionRepositoryTest.java | 1 + ...QuerydslAuctionAndImageRepositoryTest.java | 4 +- .../fixture/AuctionRepositoryImplFixture.java | 6 +- ...rydslAuctionAndImageRepositoryFixture.java | 34 +++++----- .../AuthenticationServiceTest.java | 22 ++++--- .../fixture/AuthenticationServiceFixture.java | 9 ++- .../persistence/JpaBidRepositoryTest.java | 6 -- .../fixture/BidRepositoryImplFixture.java | 4 +- .../JpaChatRoomRepositoryTest.java | 18 ++---- .../persistence/JpaMessageRepositoryTest.java | 6 -- .../QuerydslMessageRepositoryTest.java | 4 +- ...ChatRoomAndImageRepositoryImplFixture.java | 4 +- .../ChatRoomRepositoryImplFixture.java | 4 +- .../application/DeviceTokenServiceTest.java | 4 +- .../fixture/DeviceTokenServiceFixture.java | 5 +- .../DeviceTokenRepositoryImplTest.java | 63 ++++++++++++++++++ .../JpaDeviceTokenRepositoryTest.java | 4 +- .../DeviceTokenRepositoryImplFixture.java | 64 +++++++++++++++++++ .../JpaDeviceTokenRepositoryFixture.java | 23 ++++--- .../FcmNotificationServiceFixture.java | 4 +- .../fixture/AnswerRepositoryImplFixture.java | 4 +- .../ChatRoomReportRepositoryImplTest.java | 1 + .../JpaChatRoomReportRepositoryTest.java | 1 + ... => QuestionReportRepositoryImplTest.java} | 0 .../AuctionReportRepositoryImplFixture.java | 4 +- ...paQuestionReportRepositoryImplFixture.java | 12 ++-- .../QuestionReportRepositoryImplFixture.java | 4 +- .../persistence/JpaReviewRepositoryTest.java | 22 +++---- .../fixture/JpaReviewRepositoryFixture.java | 1 - 36 files changed, 293 insertions(+), 128 deletions(-) create mode 100644 backend/ddang/src/main/java/com/ddang/ddang/device/domain/repository/DeviceTokenRepository.java create mode 100644 backend/ddang/src/main/java/com/ddang/ddang/device/infrastructure/persistence/DeviceTokenRepositoryImpl.java create mode 100644 backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/DeviceTokenRepositoryImplTest.java create mode 100644 backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/fixture/DeviceTokenRepositoryImplFixture.java rename backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/{QuestionReportRepositoryImplImplTest.java => QuestionReportRepositoryImplTest.java} (100%) diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/AuthenticationService.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/AuthenticationService.java index c3a2d41b7..47df37458 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/AuthenticationService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/AuthenticationService.java @@ -1,7 +1,5 @@ package com.ddang.ddang.authentication.application; -import static com.ddang.ddang.image.domain.ProfileImage.DEFAULT_PROFILE_IMAGE_STORE_NAME; - import com.ddang.ddang.authentication.application.dto.LoginInformationDto; import com.ddang.ddang.authentication.application.dto.LoginUserInformationDto; import com.ddang.ddang.authentication.application.dto.TokenDto; @@ -18,20 +16,23 @@ import com.ddang.ddang.authentication.infrastructure.oauth2.Oauth2Type; import com.ddang.ddang.device.application.DeviceTokenService; import com.ddang.ddang.device.application.dto.PersistDeviceTokenDto; -import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; import com.ddang.ddang.image.application.exception.ImageNotFoundException; import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.domain.repository.ProfileImageRepository; import com.ddang.ddang.user.domain.Reliability; import com.ddang.ddang.user.domain.User; import com.ddang.ddang.user.domain.repository.UserRepository; -import java.time.LocalDateTime; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.ddang.ddang.image.domain.ProfileImage.DEFAULT_PROFILE_IMAGE_STORE_NAME; + @Service @Transactional(readOnly = true) @RequiredArgsConstructor @@ -47,7 +48,7 @@ public class AuthenticationService { private final TokenEncoder tokenEncoder; private final TokenDecoder tokenDecoder; private final BlackListTokenService blackListTokenService; - private final JpaDeviceTokenRepository deviceTokenRepository; + private final DeviceTokenRepository deviceTokenRepository; @Transactional public LoginInformationDto login( diff --git a/backend/ddang/src/main/java/com/ddang/ddang/device/application/DeviceTokenService.java b/backend/ddang/src/main/java/com/ddang/ddang/device/application/DeviceTokenService.java index 0733c5731..3377accda 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/device/application/DeviceTokenService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/device/application/DeviceTokenService.java @@ -2,7 +2,7 @@ import com.ddang.ddang.device.application.dto.PersistDeviceTokenDto; import com.ddang.ddang.device.domain.DeviceToken; -import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; import com.ddang.ddang.user.application.exception.UserNotFoundException; import com.ddang.ddang.user.domain.User; import com.ddang.ddang.user.domain.repository.UserRepository; @@ -15,7 +15,7 @@ @RequiredArgsConstructor public class DeviceTokenService { - private final JpaDeviceTokenRepository deviceTokenRepository; + private final DeviceTokenRepository deviceTokenRepository; private final UserRepository userRepository; @Transactional diff --git a/backend/ddang/src/main/java/com/ddang/ddang/device/domain/repository/DeviceTokenRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/device/domain/repository/DeviceTokenRepository.java new file mode 100644 index 000000000..02ce0b505 --- /dev/null +++ b/backend/ddang/src/main/java/com/ddang/ddang/device/domain/repository/DeviceTokenRepository.java @@ -0,0 +1,14 @@ +package com.ddang.ddang.device.domain.repository; + +import com.ddang.ddang.device.domain.DeviceToken; + +import java.util.Optional; + +public interface DeviceTokenRepository { + + DeviceToken save(final DeviceToken deviceToken); + + Optional findByUserId(final Long userId); + + void deleteByUserId(final Long id); +} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/device/infrastructure/persistence/DeviceTokenRepositoryImpl.java b/backend/ddang/src/main/java/com/ddang/ddang/device/infrastructure/persistence/DeviceTokenRepositoryImpl.java new file mode 100644 index 000000000..c9e5248d5 --- /dev/null +++ b/backend/ddang/src/main/java/com/ddang/ddang/device/infrastructure/persistence/DeviceTokenRepositoryImpl.java @@ -0,0 +1,30 @@ +package com.ddang.ddang.device.infrastructure.persistence; + +import com.ddang.ddang.device.domain.DeviceToken; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +@RequiredArgsConstructor +public class DeviceTokenRepositoryImpl implements DeviceTokenRepository { + + private final JpaDeviceTokenRepository jpaDeviceTokenRepository; + + @Override + public DeviceToken save(final DeviceToken deviceToken) { + return jpaDeviceTokenRepository.save(deviceToken); + } + + @Override + public Optional findByUserId(final Long userId) { + return jpaDeviceTokenRepository.findByUserId(userId); + } + + @Override + public void deleteByUserId(final Long id) { + jpaDeviceTokenRepository.deleteByUserId(id); + } +} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/device/infrastructure/persistence/JpaDeviceTokenRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/device/infrastructure/persistence/JpaDeviceTokenRepository.java index 13fc6f49b..f58182fde 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/device/infrastructure/persistence/JpaDeviceTokenRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/device/infrastructure/persistence/JpaDeviceTokenRepository.java @@ -9,5 +9,5 @@ public interface JpaDeviceTokenRepository extends JpaRepository findByUserId(final Long userId); - void deleteByUserId(Long id); + void deleteByUserId(final Long id); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/notification/application/FcmNotificationService.java b/backend/ddang/src/main/java/com/ddang/ddang/notification/application/FcmNotificationService.java index 8eeb9b6ef..78c8068c4 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/notification/application/FcmNotificationService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/notification/application/FcmNotificationService.java @@ -2,7 +2,7 @@ import com.ddang.ddang.device.application.exception.DeviceTokenNotFoundException; import com.ddang.ddang.device.domain.DeviceToken; -import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; import com.ddang.ddang.notification.application.dto.CreateNotificationDto; import com.ddang.ddang.notification.domain.NotificationStatus; import com.google.firebase.messaging.AndroidConfig; @@ -27,7 +27,7 @@ public class FcmNotificationService implements NotificationService { private final FirebaseMessaging firebaseMessaging; - private final JpaDeviceTokenRepository deviceTokenRepository; + private final DeviceTokenRepository deviceTokenRepository; @Override public NotificationStatus send(final CreateNotificationDto createNotificationDto) throws FirebaseMessagingException { diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/AuctionRepositoryImplTest.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/AuctionRepositoryImplTest.java index 0486386bd..5275f26b6 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/AuctionRepositoryImplTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/AuctionRepositoryImplTest.java @@ -1,14 +1,11 @@ package com.ddang.ddang.auction.infrastructure.persistence; -import static org.assertj.core.api.Assertions.assertThat; - import com.ddang.ddang.auction.domain.Auction; import com.ddang.ddang.auction.domain.repository.AuctionRepository; import com.ddang.ddang.auction.infrastructure.persistence.fixture.AuctionRepositoryImplFixture; import com.ddang.ddang.configuration.JpaConfiguration; import com.ddang.ddang.configuration.QuerydslConfiguration; import com.querydsl.jpa.impl.JPAQueryFactory; -import java.util.Optional; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; @@ -20,6 +17,10 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + @DataJpaTest @Import({JpaConfiguration.class, QuerydslConfiguration.class}) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -29,16 +30,13 @@ class AuctionRepositoryImplTest extends AuctionRepositoryImplFixture { @Autowired JpaAuctionRepository jpaAuctionRepository; - @Autowired - JPAQueryFactory queryFactory; - AuctionRepository auctionRepository; @BeforeEach - void setUp() { + void setUp(@Autowired final JPAQueryFactory jpaQueryFactory) { auctionRepository = new AuctionRepositoryImpl( jpaAuctionRepository, - new QuerydslAuctionRepository(queryFactory) + new QuerydslAuctionRepository(jpaQueryFactory) ); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/JpaAuctionRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/JpaAuctionRepositoryTest.java index d8b992ae6..915dc19f7 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/JpaAuctionRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/JpaAuctionRepositoryTest.java @@ -29,6 +29,7 @@ class JpaAuctionRepositoryTest extends JpaAuctionRepositoryFixture { // when final Auction actual = auctionRepository.save(저장하기_전_경매_엔티티); + // then assertThat(actual.getId()).isPositive(); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionAndImageRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionAndImageRepositoryTest.java index 2adf85696..eb4847e87 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionAndImageRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionAndImageRepositoryTest.java @@ -24,8 +24,8 @@ class QuerydslAuctionAndImageRepositoryTest extends QuerydslAuctionAndImageRepos QuerydslAuctionAndImageRepository querydslAuctionAndImageRepository; @BeforeEach - void setUp(@Autowired final JPAQueryFactory queryFactory) { - querydslAuctionAndImageRepository = new QuerydslAuctionAndImageRepository(queryFactory); + void setUp(@Autowired final JPAQueryFactory jpaQueryFactory) { + querydslAuctionAndImageRepository = new QuerydslAuctionAndImageRepository(jpaQueryFactory); } @Test diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/fixture/AuctionRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/fixture/AuctionRepositoryImplFixture.java index f6e039530..dac3a5df0 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/fixture/AuctionRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/fixture/AuctionRepositoryImplFixture.java @@ -38,15 +38,15 @@ @SuppressWarnings("NonAsciiCharacters") public class AuctionRepositoryImplFixture { + @Autowired + private JpaCategoryRepository categoryRepository; + private AuctionRepository auctionRepository; private UserRepository userRepository; private RegionRepository regionRepository; - @Autowired - private JpaCategoryRepository categoryRepository; - private BidRepository bidRepository; private Instant 시간 = Instant.parse("2023-07-08T22:21:20Z"); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/fixture/QuerydslAuctionAndImageRepositoryFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/fixture/QuerydslAuctionAndImageRepositoryFixture.java index 170011312..949634098 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/fixture/QuerydslAuctionAndImageRepositoryFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/fixture/QuerydslAuctionAndImageRepositoryFixture.java @@ -12,39 +12,47 @@ import com.ddang.ddang.image.infrastructure.persistence.JpaAuctionImageRepository; import com.ddang.ddang.user.domain.Reliability; import com.ddang.ddang.user.domain.User; +import com.ddang.ddang.user.domain.repository.UserRepository; import com.ddang.ddang.user.infrastructure.persistence.JpaUserRepository; +import com.ddang.ddang.user.infrastructure.persistence.UserRepositoryImpl; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; -import java.time.LocalDateTime; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; +import java.time.LocalDateTime; +import java.util.List; + @SuppressWarnings("NonAsciiCharacters") public class QuerydslAuctionAndImageRepositoryFixture { @PersistenceContext private EntityManager em; - @Autowired - private JPAQueryFactory queryFactory; - - @Autowired - private JpaAuctionRepository jpaAuctionRepository; - @Autowired private JpaAuctionImageRepository auctionImageRepository; + + private UserRepository userRepository; - @Autowired - private JpaUserRepository userRepository; + private AuctionRepository auctionRepository; private User 사용자; protected Auction 경매; protected AuctionImage 경매_이미지; @BeforeEach - void setUp() { + void fixtureSetUp( + @Autowired JPAQueryFactory jpaQueryFactory, + @Autowired JpaAuctionRepository jpaAuctionRepository, + @Autowired JpaUserRepository jpaUserRepository + ) { + auctionRepository = new AuctionRepositoryImpl( + jpaAuctionRepository, + new QuerydslAuctionRepository(jpaQueryFactory) + ); + userRepository = new UserRepositoryImpl(jpaUserRepository); + 경매 = Auction.builder() .title("경매 상품 1") .description("이것은 경매 상품 1 입니다.") @@ -63,10 +71,6 @@ void setUp() { .oauthId("12345") .build(); - final AuctionRepository auctionRepository = new AuctionRepositoryImpl( - jpaAuctionRepository, - new QuerydslAuctionRepository(queryFactory) - ); auctionRepository.save(경매); userRepository.save(사용자); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/AuthenticationServiceTest.java b/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/AuthenticationServiceTest.java index cc952942b..5ad2d9bf6 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/AuthenticationServiceTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/AuthenticationServiceTest.java @@ -1,10 +1,5 @@ package com.ddang.ddang.authentication.application; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.given; - import com.ddang.ddang.authentication.application.dto.LoginInformationDto; import com.ddang.ddang.authentication.application.dto.TokenDto; import com.ddang.ddang.authentication.application.exception.InvalidWithdrawalException; @@ -17,6 +12,8 @@ import com.ddang.ddang.authentication.infrastructure.oauth2.OAuth2UserInformationProvider; import com.ddang.ddang.configuration.IsolateDatabase; import com.ddang.ddang.device.application.DeviceTokenService; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; +import com.ddang.ddang.device.infrastructure.persistence.DeviceTokenRepositoryImpl; import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; import com.ddang.ddang.image.application.exception.ImageNotFoundException; import com.ddang.ddang.image.domain.repository.ProfileImageRepository; @@ -32,6 +29,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; + @IsolateDatabase @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") @@ -63,15 +65,19 @@ class AuthenticationServiceTest extends AuthenticationServiceFixture { @Autowired BlackListTokenService blackListTokenService; - @Autowired - JpaDeviceTokenRepository deviceTokenRepository; + DeviceTokenRepository deviceTokenRepository; AuthenticationService authenticationService; + AuthenticationService profileImageNotFoundAuthenticationService; @BeforeEach - void fixtureSetUp(@Autowired final JpaProfileImageRepository jpaProfileImageRepository) { + void fixtureSetUp( + @Autowired final JpaProfileImageRepository jpaProfileImageRepository, + @Autowired final JpaDeviceTokenRepository jpaDeviceTokenRepository + ) { profileImageRepository = new ProfileImageRepositoryImpl(jpaProfileImageRepository); + deviceTokenRepository = new DeviceTokenRepositoryImpl(jpaDeviceTokenRepository); authenticationService = new AuthenticationService( deviceTokenService, diff --git a/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/fixture/AuthenticationServiceFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/fixture/AuthenticationServiceFixture.java index d5e7457b1..743f83d72 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/fixture/AuthenticationServiceFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/fixture/AuthenticationServiceFixture.java @@ -6,6 +6,8 @@ import com.ddang.ddang.authentication.infrastructure.jwt.PrivateClaims; import com.ddang.ddang.authentication.infrastructure.oauth2.Oauth2Type; import com.ddang.ddang.device.domain.DeviceToken; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; +import com.ddang.ddang.device.infrastructure.persistence.DeviceTokenRepositoryImpl; import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.infrastructure.persistence.JpaProfileImageRepository; @@ -58,11 +60,12 @@ public class AuthenticationServiceFixture { @Autowired private TokenEncoder tokenEncoder; - @Autowired - private JpaDeviceTokenRepository deviceTokenRepository; + private DeviceTokenRepository deviceTokenRepository; @BeforeEach - void fixtureSetUp() { + void fixtureSetUp(@Autowired final JpaDeviceTokenRepository jpaDeviceTokenRepository) { + deviceTokenRepository = new DeviceTokenRepositoryImpl(jpaDeviceTokenRepository); + profileImageRepository.save(new ProfileImage("default_profile_image.png", "default_profile_image.png")); 사용자 = User.builder() diff --git a/backend/ddang/src/test/java/com/ddang/ddang/bid/infrastructure/persistence/JpaBidRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/bid/infrastructure/persistence/JpaBidRepositoryTest.java index 90af22d4c..5aafd4ece 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/bid/infrastructure/persistence/JpaBidRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/bid/infrastructure/persistence/JpaBidRepositoryTest.java @@ -25,9 +25,6 @@ @SuppressWarnings("NonAsciiCharacters") class JpaBidRepositoryTest extends JpaBidRepositoryFixture { - @PersistenceContext - EntityManager em; - @Autowired JpaBidRepository bidRepository; @@ -40,9 +37,6 @@ class JpaBidRepositoryTest extends JpaBidRepositoryFixture { final Bid actual = bidRepository.save(bid); // then - em.flush(); - em.clear(); - assertThat(actual.getId()).isPositive(); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/bid/infrastructure/persistence/fixture/BidRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/bid/infrastructure/persistence/fixture/BidRepositoryImplFixture.java index cb36da38a..fbab9a1b0 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/bid/infrastructure/persistence/fixture/BidRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/bid/infrastructure/persistence/fixture/BidRepositoryImplFixture.java @@ -50,13 +50,13 @@ public class BidRepositoryImplFixture { @BeforeEach void fixtureSetUp( + @Autowired final JPAQueryFactory jpaQueryFactory, @Autowired final JpaUserRepository jpaUserRepository, @Autowired final JpaAuctionRepository jpaAuctionRepository, - @Autowired final JPAQueryFactory queryFactory, @Autowired final JpaBidRepository jpaBidRepository ) { userRepository = new UserRepositoryImpl(jpaUserRepository); - auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(queryFactory)); + auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(jpaQueryFactory)); bidRepository = new BidRepositoryImpl(jpaBidRepository); final ProfileImage 프로필_이미지 = new ProfileImage("프로필.jpg", "프로필.jpg"); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/JpaChatRoomRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/JpaChatRoomRepositoryTest.java index 5e5d0da01..18e656f27 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/JpaChatRoomRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/JpaChatRoomRepositoryTest.java @@ -23,11 +23,8 @@ @SuppressWarnings("NonAsciiCharacters") class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture { - @PersistenceContext - EntityManager em; - @Autowired - JpaChatRoomRepository chatRoomRepository; + JpaChatRoomRepository jpaChatRoomRepository; @Test void 채팅방을_저장한다() { @@ -35,19 +32,16 @@ class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture { final ChatRoom chatRoom = new ChatRoom(경매, 구매자); // when - chatRoomRepository.save(chatRoom); + jpaChatRoomRepository.save(chatRoom); // then - em.flush(); - em.clear(); - assertThat(chatRoom.getId()).isPositive(); } @Test void 지정한_아이디에_대한_채팅방을_조회한다() { // when - final Optional actual = chatRoomRepository.findById(채팅방.getId()); + final Optional actual = jpaChatRoomRepository.findById(채팅방.getId()); // then assertThat(actual).contains(채팅방); @@ -56,7 +50,7 @@ class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture { @Test void 지정한_경매_아이디가_포함된_채팅방의_아이디를_조회한다() { // when - final Optional actual = chatRoomRepository.findChatRoomIdByAuctionId(경매.getId()); + final Optional actual = jpaChatRoomRepository.findChatRoomIdByAuctionId(경매.getId()); // then assertThat(actual).contains(채팅방.getId()); @@ -65,7 +59,7 @@ class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture { @Test void 지정한_경매_아이디가_포함된_채팅방이_존재한다면_참을_반환한다() { // when - final boolean actual = chatRoomRepository.existsByAuctionId(경매.getId()); + final boolean actual = jpaChatRoomRepository.existsByAuctionId(경매.getId()); // then assertThat(actual).isTrue(); @@ -74,7 +68,7 @@ class JpaChatRoomRepositoryTest extends JpaChatRoomRepositoryFixture { @Test void 지정한_경매_아이디가_포함된_채팅방이_존재하지_않는다면_거짓을_반환한다() { // when - final boolean actual = chatRoomRepository.existsByAuctionId(존재하지_않는_채팅방_아이디); + final boolean actual = jpaChatRoomRepository.existsByAuctionId(존재하지_않는_채팅방_아이디); // then assertThat(actual).isFalse(); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/JpaMessageRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/JpaMessageRepositoryTest.java index c6e8cb278..0cb97b3e3 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/JpaMessageRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/JpaMessageRepositoryTest.java @@ -21,9 +21,6 @@ @SuppressWarnings("NonAsciiCharacters") class JpaMessageRepositoryTest extends JpaMessageRepositoryFixture { - @PersistenceContext - EntityManager em; - @Autowired JpaMessageRepository messageRepository; @@ -32,9 +29,6 @@ class JpaMessageRepositoryTest extends JpaMessageRepositoryFixture { // when final Message actual = messageRepository.save(메시지); - em.flush(); - em.clear(); - // then assertThat(actual.getId()).isPositive(); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslMessageRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslMessageRepositoryTest.java index 282385a11..2c29b2691 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslMessageRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslMessageRepositoryTest.java @@ -27,8 +27,8 @@ class QuerydslMessageRepositoryTest extends QuerydslMessageRepositoryFixture { QuerydslMessageRepository querydslMessageRepository; @BeforeEach - void setUp(@Autowired final JPAQueryFactory queryFactory) { - querydslMessageRepository = new QuerydslMessageRepository(queryFactory); + void setUp(@Autowired final JPAQueryFactory jpaQueryFactory) { + querydslMessageRepository = new QuerydslMessageRepository(jpaQueryFactory); } @Test diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ChatRoomAndImageRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ChatRoomAndImageRepositoryImplFixture.java index 9ffbf0839..651a16e8d 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ChatRoomAndImageRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ChatRoomAndImageRepositoryImplFixture.java @@ -35,11 +35,11 @@ @SuppressWarnings("NonAsciiCharacters") public class ChatRoomAndImageRepositoryImplFixture { - private AuctionRepository auctionRepository; - @Autowired private JpaCategoryRepository categoryRepository; + private AuctionRepository auctionRepository; + private UserRepository userRepository; private BidRepository bidRepository; diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ChatRoomRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ChatRoomRepositoryImplFixture.java index 9eb5becd0..826573910 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ChatRoomRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/infrastructure/persistence/fixture/ChatRoomRepositoryImplFixture.java @@ -55,13 +55,13 @@ public class ChatRoomRepositoryImplFixture { @BeforeEach void fixtureSetUp( - @Autowired final JPAQueryFactory queryFactory, + @Autowired final JPAQueryFactory jpaQueryFactory, @Autowired final JpaAuctionRepository jpaAuctionRepository, @Autowired final JpaUserRepository jpaUserRepository, @Autowired final JpaChatRoomRepository jpaChatRoomRepository, @Autowired final JpaBidRepository jpaBidRepository ) { - auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(queryFactory)); + auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(jpaQueryFactory)); userRepository = new UserRepositoryImpl(jpaUserRepository); chatRoomRepository = new ChatRoomRepositoryImpl(jpaChatRoomRepository); bidRepository = new BidRepositoryImpl(jpaBidRepository); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/device/application/DeviceTokenServiceTest.java b/backend/ddang/src/test/java/com/ddang/ddang/device/application/DeviceTokenServiceTest.java index 8d3b0e484..15187cd40 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/device/application/DeviceTokenServiceTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/device/application/DeviceTokenServiceTest.java @@ -3,7 +3,7 @@ import com.ddang.ddang.configuration.IsolateDatabase; import com.ddang.ddang.device.application.fixture.DeviceTokenServiceFixture; import com.ddang.ddang.device.domain.DeviceToken; -import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; import com.ddang.ddang.user.application.exception.UserNotFoundException; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -25,7 +25,7 @@ class DeviceTokenServiceTest extends DeviceTokenServiceFixture { DeviceTokenService deviceTokenService; @Autowired - JpaDeviceTokenRepository deviceTokenRepository; + DeviceTokenRepository deviceTokenRepository; @Test void 사용자의_디바이스_토큰이_존재하지_않는다면_저장한다() { diff --git a/backend/ddang/src/test/java/com/ddang/ddang/device/application/fixture/DeviceTokenServiceFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/device/application/fixture/DeviceTokenServiceFixture.java index 243208fc7..e7f5a01eb 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/device/application/fixture/DeviceTokenServiceFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/device/application/fixture/DeviceTokenServiceFixture.java @@ -2,7 +2,7 @@ import com.ddang.ddang.device.application.dto.PersistDeviceTokenDto; import com.ddang.ddang.device.domain.DeviceToken; -import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.user.domain.Reliability; import com.ddang.ddang.user.domain.User; @@ -14,10 +14,11 @@ public class DeviceTokenServiceFixture { @Autowired - private JpaDeviceTokenRepository deviceTokenRepository; + private DeviceTokenRepository deviceTokenRepository; @Autowired private UserRepository userRepository; + private String 초기_디바이스_토큰_값 = "initialDeviceToken"; private DeviceToken 사용자의_디바이스_토큰; diff --git a/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/DeviceTokenRepositoryImplTest.java b/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/DeviceTokenRepositoryImplTest.java new file mode 100644 index 000000000..89b3f23de --- /dev/null +++ b/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/DeviceTokenRepositoryImplTest.java @@ -0,0 +1,63 @@ +package com.ddang.ddang.device.infrastructure.persistence; + +import com.ddang.ddang.configuration.JpaConfiguration; +import com.ddang.ddang.configuration.QuerydslConfiguration; +import com.ddang.ddang.device.domain.DeviceToken; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; +import com.ddang.ddang.device.infrastructure.persistence.fixture.DeviceTokenRepositoryImplFixture; +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +@DataJpaTest +@Import({JpaConfiguration.class, QuerydslConfiguration.class}) +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@SuppressWarnings("NonAsciiCharacters") +public class DeviceTokenRepositoryImplTest extends DeviceTokenRepositoryImplFixture { + + DeviceTokenRepository deviceTokenRepository; + + @BeforeEach + void setUp(@Autowired final JpaDeviceTokenRepository jpaDeviceTokenRepository) { + deviceTokenRepository = new DeviceTokenRepositoryImpl(jpaDeviceTokenRepository); + } + + @Test + void 기기토큰을_저장한다() { + // when + deviceTokenRepository.save(아이디가_없는_기기토큰); + + // then + assertThat(아이디가_없는_기기토큰.getId()).isPositive(); + } + + @Test + void 사용자_아이디에_해당하는_기기토큰을_조회한다() { + // when + final Optional actual = deviceTokenRepository.findByUserId(아이디가_있는_기기토큰_사용자.getId()); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actual).isPresent(); + softAssertions.assertThat(actual.get()).isEqualTo(아이디가_있는_기기토큰); + }); + } + + @Test + void 사용자_아이디에_해당하는_기기토큰을_삭제한다() { + // when + deviceTokenRepository.deleteByUserId(삭제할_기기토큰_사용자.getId()); + + // then + assertThat(deviceTokenRepository.findByUserId(삭제할_기기토큰_사용자.getId())).isEmpty(); + } +} diff --git a/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/JpaDeviceTokenRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/JpaDeviceTokenRepositoryTest.java index 06dbc3a7a..44df2f70f 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/JpaDeviceTokenRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/JpaDeviceTokenRepositoryTest.java @@ -22,12 +22,12 @@ class JpaDeviceTokenRepositoryTest extends JpaDeviceTokenRepositoryFixture { @Autowired - JpaDeviceTokenRepository userDeviceTokenRepository; + JpaDeviceTokenRepository jpaDeviceTokenRepository; @Test void 주어진_사용자_아이디에_해당하는_기기토큰을_조회한다() { // when - final Optional actual = userDeviceTokenRepository.findByUserId(사용자.getId()); + final Optional actual = jpaDeviceTokenRepository.findByUserId(사용자.getId()); // then assertThat(actual).contains(사용자의_디바이스_토큰); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/fixture/DeviceTokenRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/fixture/DeviceTokenRepositoryImplFixture.java new file mode 100644 index 000000000..d4e4e5728 --- /dev/null +++ b/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/fixture/DeviceTokenRepositoryImplFixture.java @@ -0,0 +1,64 @@ +package com.ddang.ddang.device.infrastructure.persistence.fixture; + +import com.ddang.ddang.device.domain.DeviceToken; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; +import com.ddang.ddang.device.infrastructure.persistence.DeviceTokenRepositoryImpl; +import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; +import com.ddang.ddang.image.domain.ProfileImage; +import com.ddang.ddang.user.domain.Reliability; +import com.ddang.ddang.user.domain.User; +import com.ddang.ddang.user.domain.repository.UserRepository; +import com.ddang.ddang.user.infrastructure.persistence.JpaUserRepository; +import com.ddang.ddang.user.infrastructure.persistence.UserRepositoryImpl; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; + +@SuppressWarnings("NonAsciiCharacters") +public class DeviceTokenRepositoryImplFixture { + + private UserRepository userRepository; + private DeviceTokenRepository deviceTokenRepository; + + protected DeviceToken 아이디가_없는_기기토큰; + protected DeviceToken 아이디가_있는_기기토큰; + protected DeviceToken 삭제할_기기토큰; + protected User 아이디가_있는_기기토큰_사용자; + protected User 삭제할_기기토큰_사용자; + + @BeforeEach + void fixtureSetUp( + @Autowired final JpaUserRepository jpaUserRepository, + @Autowired final JpaDeviceTokenRepository jpaDeviceTokenRepository + ) { + userRepository = new UserRepositoryImpl(jpaUserRepository); + deviceTokenRepository = new DeviceTokenRepositoryImpl(jpaDeviceTokenRepository); + + final User 아이디가_없는_기기토큰_사용자 = User.builder() + .name("저장하지 않은 기기토큰 사용자") + .profileImage(new ProfileImage("upload.png", "store.png")) + .reliability(new Reliability(4.7d)) + .oauthId("98765") + .build(); + 아이디가_있는_기기토큰_사용자 = User.builder() + .name("기기토큰_사용자") + .profileImage(new ProfileImage("upload.png", "store.png")) + .reliability(new Reliability(4.7d)) + .oauthId("12345") + .build(); + 삭제할_기기토큰_사용자 = User.builder() + .name("삭제할 기기토큰_사용자") + .profileImage(new ProfileImage("upload.png", "store.png")) + .reliability(new Reliability(4.7d)) + .oauthId("14392") + .build(); + userRepository.save(아이디가_없는_기기토큰_사용자); + userRepository.save(아이디가_있는_기기토큰_사용자); + userRepository.save(삭제할_기기토큰_사용자); + + 아이디가_없는_기기토큰 = new DeviceToken(아이디가_없는_기기토큰_사용자, "아이디가 없는 기기토큰"); + 아이디가_있는_기기토큰 = new DeviceToken(아이디가_있는_기기토큰_사용자, "아이디가_있는_기기토큰"); + 삭제할_기기토큰 = new DeviceToken(삭제할_기기토큰_사용자, "삭제할_기기토큰"); + deviceTokenRepository.save(아이디가_있는_기기토큰); + deviceTokenRepository.save(삭제할_기기토큰); + } +} diff --git a/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/fixture/JpaDeviceTokenRepositoryFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/fixture/JpaDeviceTokenRepositoryFixture.java index 128847999..1c578b432 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/fixture/JpaDeviceTokenRepositoryFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/device/infrastructure/persistence/fixture/JpaDeviceTokenRepositoryFixture.java @@ -5,7 +5,9 @@ import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.user.domain.Reliability; import com.ddang.ddang.user.domain.User; +import com.ddang.ddang.user.domain.repository.UserRepository; import com.ddang.ddang.user.infrastructure.persistence.JpaUserRepository; +import com.ddang.ddang.user.infrastructure.persistence.UserRepositoryImpl; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import org.junit.jupiter.api.BeforeEach; @@ -17,28 +19,29 @@ public class JpaDeviceTokenRepositoryFixture { @PersistenceContext private EntityManager em; - @Autowired - private JpaUserRepository userRepository; + private UserRepository userRepository; @Autowired - private JpaDeviceTokenRepository deviceTokenRepository; + private JpaDeviceTokenRepository jpaDeviceTokenRepository; protected User 사용자; protected DeviceToken 사용자의_디바이스_토큰; @BeforeEach - void setUp() { + void setUp(@Autowired final JpaUserRepository jpaUserRepository) { + userRepository = new UserRepositoryImpl(jpaUserRepository); + 사용자 = User.builder() - .name("사용자") - .profileImage(new ProfileImage("upload.png", "store.png")) - .reliability(new Reliability(4.7d)) - .oauthId("12345") - .build(); + .name("사용자") + .profileImage(new ProfileImage("upload.png", "store.png")) + .reliability(new Reliability(4.7d)) + .oauthId("12345") + .build(); 사용자의_디바이스_토큰 = new DeviceToken(사용자, "deviceToken"); userRepository.save(사용자); - deviceTokenRepository.save(사용자의_디바이스_토큰); + jpaDeviceTokenRepository.save(사용자의_디바이스_토큰); em.flush(); em.clear(); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/notification/application/fixture/FcmNotificationServiceFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/notification/application/fixture/FcmNotificationServiceFixture.java index 686c9b2a4..5d3a217b8 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/notification/application/fixture/FcmNotificationServiceFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/notification/application/fixture/FcmNotificationServiceFixture.java @@ -12,7 +12,7 @@ import com.ddang.ddang.chat.domain.repository.ChatRoomRepository; import com.ddang.ddang.chat.domain.repository.MessageRepository; import com.ddang.ddang.device.domain.DeviceToken; -import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository; +import com.ddang.ddang.device.domain.repository.DeviceTokenRepository; import com.ddang.ddang.image.domain.AuctionImage; import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.infrastructure.persistence.JpaAuctionImageRepository; @@ -40,7 +40,7 @@ public class FcmNotificationServiceFixture { private ChatRoomRepository chatRoomRepository; @Autowired - private JpaDeviceTokenRepository deviceTokenRepository; + private DeviceTokenRepository deviceTokenRepository; @Autowired private AuctionRepository auctionRepository; diff --git a/backend/ddang/src/test/java/com/ddang/ddang/qna/infrastructure/fixture/AnswerRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/qna/infrastructure/fixture/AnswerRepositoryImplFixture.java index 44cac6457..8ad80f28d 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/qna/infrastructure/fixture/AnswerRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/qna/infrastructure/fixture/AnswerRepositoryImplFixture.java @@ -47,14 +47,14 @@ public class AnswerRepositoryImplFixture { @BeforeEach void setUpFixture( + @Autowired final JPAQueryFactory jpaQueryFactory, @Autowired final JpaUserRepository jpaUserRepository, @Autowired final JpaAuctionRepository jpaAuctionRepository, - @Autowired final JPAQueryFactory queryFactory, @Autowired final JpaQuestionRepository jpaQuestionRepository, @Autowired final JpaAnswerRepository jpaAnswerRepository ) { userRepository = new UserRepositoryImpl(jpaUserRepository); - auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(queryFactory)); + auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(jpaQueryFactory)); questionRepository = new QuestionRepositoryImpl(jpaQuestionRepository); answerRepository = new AnswerRepositoryImpl(jpaAnswerRepository); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/ChatRoomReportRepositoryImplTest.java b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/ChatRoomReportRepositoryImplTest.java index 01b72d001..8b76d3c3d 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/ChatRoomReportRepositoryImplTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/ChatRoomReportRepositoryImplTest.java @@ -33,6 +33,7 @@ void setUp(@Autowired final JpaChatRoomReportRepository jpaChatRoomReportReposit @Test void 채팅방_신고를_저장한다() { + // given final ChatRoomReport chatRoomReport = new ChatRoomReport(구매자1, 채팅방1, "신고합니다."); // when diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/JpaChatRoomReportRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/JpaChatRoomReportRepositoryTest.java index 89ab87322..8030b4a76 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/JpaChatRoomReportRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/JpaChatRoomReportRepositoryTest.java @@ -27,6 +27,7 @@ class JpaChatRoomReportRepositoryTest extends JpaChatRoomReportRepositoryFixture @Test void 채팅방_신고를_저장한다() { + // given final ChatRoomReport chatRoomReport = new ChatRoomReport(구매자1, 채팅방1, "신고합니다."); // when diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/QuestionReportRepositoryImplImplTest.java b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/QuestionReportRepositoryImplTest.java similarity index 100% rename from backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/QuestionReportRepositoryImplImplTest.java rename to backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/QuestionReportRepositoryImplTest.java diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/AuctionReportRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/AuctionReportRepositoryImplFixture.java index ff317c0a3..89b9153b6 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/AuctionReportRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/AuctionReportRepositoryImplFixture.java @@ -58,13 +58,13 @@ public class AuctionReportRepositoryImplFixture { @BeforeEach void setUpFixture( + @Autowired final JPAQueryFactory jpaQueryFactory, @Autowired final JpaUserRepository jpaUserRepository, @Autowired final JpaAuctionRepository jpaAuctionRepository, - @Autowired final JPAQueryFactory queryFactory, @Autowired final JpaAuctionReportRepository jpaAuctionReportRepository ) { userRepository = new UserRepositoryImpl(jpaUserRepository); - auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(queryFactory)); + auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(jpaQueryFactory)); auctionReportRepository = new AuctionReportRepositoryImpl(jpaAuctionReportRepository); final ProfileImage 프로필_이미지 = new ProfileImage("프로필.jpg", "프로필.jpg"); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/JpaQuestionReportRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/JpaQuestionReportRepositoryImplFixture.java index 1c975e1d0..06f52d338 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/JpaQuestionReportRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/JpaQuestionReportRepositoryImplFixture.java @@ -37,16 +37,16 @@ public class JpaQuestionReportRepositoryImplFixture { @PersistenceContext private EntityManager em; - private UserRepository userRepository; - @Autowired private JpaCategoryRepository categoryRepository; - private AuctionRepository auctionRepository; - @Autowired private JpaQuestionRepository questionRepository; + private UserRepository userRepository; + + private AuctionRepository auctionRepository; + private QuestionReportRepository questionReportRepository; protected User 신고자; @@ -60,13 +60,13 @@ public class JpaQuestionReportRepositoryImplFixture { @BeforeEach void setUpFixture( + @Autowired final JPAQueryFactory jpaQueryFactory, @Autowired final JpaUserRepository jpaUserRepository, @Autowired final JpaAuctionRepository jpaAuctionRepository, - @Autowired final JPAQueryFactory queryFactory, @Autowired final JpaQuestionReportRepository jpaQuestionReportRepository ) { userRepository = new UserRepositoryImpl(jpaUserRepository); - auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(queryFactory)); + auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(jpaQueryFactory)); questionReportRepository = new QuestionReportRepositoryImpl(jpaQuestionReportRepository); final ProfileImage 프로필_이미지 = new ProfileImage("프로필.jpg", "프로필.jpg"); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/QuestionReportRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/QuestionReportRepositoryImplFixture.java index 1e820ddcc..458fe7f2e 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/QuestionReportRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/report/infrastructure/persistence/fixture/QuestionReportRepositoryImplFixture.java @@ -55,13 +55,13 @@ public class QuestionReportRepositoryImplFixture { @BeforeEach void setUpFixture( + @Autowired final JPAQueryFactory jpaQueryFactory, @Autowired final JpaUserRepository jpaUserRepository, @Autowired final JpaAuctionRepository jpaAuctionRepository, - @Autowired final JPAQueryFactory queryFactory, @Autowired final JpaQuestionReportRepository jpaQuestionReportRepository ) { userRepository = new UserRepositoryImpl(jpaUserRepository); - auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(queryFactory)); + auctionRepository = new AuctionRepositoryImpl(jpaAuctionRepository, new QuerydslAuctionRepository(jpaQueryFactory)); questionReportRepository = new QuestionReportRepositoryImpl(jpaQuestionReportRepository); final ProfileImage 프로필_이미지 = new ProfileImage("프로필.jpg", "프로필.jpg"); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/review/infrastructure/persistence/JpaReviewRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/review/infrastructure/persistence/JpaReviewRepositoryTest.java index d48cd257d..a4f86c7d3 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/review/infrastructure/persistence/JpaReviewRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/review/infrastructure/persistence/JpaReviewRepositoryTest.java @@ -25,28 +25,22 @@ @SuppressWarnings("NonAsciiCharacters") class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture { - @PersistenceContext - EntityManager em; - @Autowired - JpaReviewRepository reviewRepository; + JpaReviewRepository jpaReviewRepository; @Test void 평가를_저장한다() { // when - reviewRepository.save(저장하려는_평가); + jpaReviewRepository.save(저장하려는_평가); // then - em.flush(); - em.clear(); - assertThat(저장하려는_평가.getId()).isPositive(); } @Test void 지정한_경매_아이디와_작성자_아이디를_포함하는_평가가_존재하면_참을_반환한다() { // when - final boolean actual = reviewRepository.existsByAuctionIdAndWriterId(판매자1이_평가한_경매.getId(), 판매자1.getId()); + final boolean actual = jpaReviewRepository.existsByAuctionIdAndWriterId(판매자1이_평가한_경매.getId(), 판매자1.getId()); // then assertThat(actual).isTrue(); @@ -55,7 +49,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture { @Test void 지정한_채팅방_아이디를_포함하는_평가가_존재하지_않는다면_거짓을_반환한다() { // when - final boolean actual = reviewRepository.existsByAuctionIdAndWriterId(평가_안한_경매.getId(), 평가_안한_경매_판매자.getId()); + final boolean actual = jpaReviewRepository.existsByAuctionIdAndWriterId(평가_안한_경매.getId(), 평가_안한_경매_판매자.getId()); // then assertThat(actual).isFalse(); @@ -64,7 +58,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture { @Test void 지정한_아이디가_평가_대상_아이디에_해당하는_평가_목록을_최신순으로_조회한다() { // when - final List actual = reviewRepository.findAllByTargetId(구매자.getId()); + final List actual = jpaReviewRepository.findAllByTargetId(구매자.getId()); // then SoftAssertions.assertSoftly(softAssertions -> { @@ -78,7 +72,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture { void 지정한_경매_아이디와_작성자_아이디가_해당하는_평가가_존재한다면_optional에_넣어_반환한다() { // when final Optional actual = - reviewRepository.findByAuctionIdAndWriterId(판매자1이_평가한_경매.getId(), 판매자1.getId()); + jpaReviewRepository.findByAuctionIdAndWriterId(판매자1이_평가한_경매.getId(), 판매자1.getId()); // then assertThat(actual).contains(구매자가_판매자1에게_받은_평가); @@ -88,7 +82,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture { void 지정한_경매_아이디와_작성자_아이디가_해당하는_평가가_존재하지_않는다면_빈_optional을_반환한다() { // when final Optional actual = - reviewRepository.findByAuctionIdAndWriterId(평가_안한_경매.getId(), 평가_안한_경매_판매자.getId()); + jpaReviewRepository.findByAuctionIdAndWriterId(평가_안한_경매.getId(), 평가_안한_경매_판매자.getId()); // then assertThat(actual).isEmpty(); @@ -97,7 +91,7 @@ class JpaReviewRepositoryTest extends JpaReviewRepositoryFixture { @Test void 지정한_평가_아이디보다_아이디가_큰_평가_목록을_조회한다() { // when - final List actual = reviewRepository.findAllByIdGreaterThan(구매자가_판매자1에게_받은_평가.getId()); + final List actual = jpaReviewRepository.findAllByIdGreaterThan(구매자가_판매자1에게_받은_평가.getId()); // then SoftAssertions.assertSoftly(softAssertions -> { diff --git a/backend/ddang/src/test/java/com/ddang/ddang/review/infrastructure/persistence/fixture/JpaReviewRepositoryFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/review/infrastructure/persistence/fixture/JpaReviewRepositoryFixture.java index fae340ff0..214a2ac84 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/review/infrastructure/persistence/fixture/JpaReviewRepositoryFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/review/infrastructure/persistence/fixture/JpaReviewRepositoryFixture.java @@ -40,7 +40,6 @@ public class JpaReviewRepositoryFixture { @Autowired private JpaReviewRepository reviewRepository; - protected User 판매자1; protected User 판매자2; protected User 평가_안한_경매_판매자;