From 2d0f4ef570ff85d4e32fe7ad5574254662f3dd26 Mon Sep 17 00:00:00 2001 From: kmebin Date: Wed, 1 Nov 2023 23:58:28 +0900 Subject: [PATCH 01/24] =?UTF-8?q?refactor:=20ResponseStatus=20+=20DTO=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/moabam/api/presentation/ProductController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/moabam/api/presentation/ProductController.java b/src/main/java/com/moabam/api/presentation/ProductController.java index c2231d5b..7a686810 100644 --- a/src/main/java/com/moabam/api/presentation/ProductController.java +++ b/src/main/java/com/moabam/api/presentation/ProductController.java @@ -1,8 +1,9 @@ package com.moabam.api.presentation; -import org.springframework.http.ResponseEntity; +import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import com.moabam.api.application.ProductService; @@ -18,7 +19,8 @@ public class ProductController { private final ProductService productService; @GetMapping - public ResponseEntity getProducts() { - return ResponseEntity.ok(productService.getProducts()); + @ResponseStatus(HttpStatus.OK) + public ProductsResponse getProducts() { + return productService.getProducts(); } } From 8555fb89867146d02396342caddc385bed0fe9bb Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 17:29:39 +0900 Subject: [PATCH 02/24] =?UTF-8?q?feat:=20=EC=95=84=EC=9D=B4=ED=85=9C,=20?= =?UTF-8?q?=EC=9D=B8=EB=B2=A4=ED=86=A0=EB=A6=AC=20Entity=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moabam/api/domain/entity/Inventory.java | 52 +++++++++++ .../com/moabam/api/domain/entity/Item.java | 90 +++++++++++++++++++ .../api/domain/entity/enums/ItemCategory.java | 6 ++ 3 files changed, 148 insertions(+) create mode 100644 src/main/java/com/moabam/api/domain/entity/Inventory.java create mode 100644 src/main/java/com/moabam/api/domain/entity/Item.java create mode 100644 src/main/java/com/moabam/api/domain/entity/enums/ItemCategory.java diff --git a/src/main/java/com/moabam/api/domain/entity/Inventory.java b/src/main/java/com/moabam/api/domain/entity/Inventory.java new file mode 100644 index 00000000..4921ab7d --- /dev/null +++ b/src/main/java/com/moabam/api/domain/entity/Inventory.java @@ -0,0 +1,52 @@ +package com.moabam.api.domain.entity; + +import static java.util.Objects.*; + +import org.hibernate.annotations.ColumnDefault; + +import com.moabam.global.common.entity.BaseTimeEntity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Index; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Table(name = "inventory", indexes = @Index(name = "idx_member_id", columnList = "member_id")) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Inventory extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @Column(name = "member_id", updatable = false, nullable = false) + private Long memberId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "item_id", updatable = false, nullable = false) + private Item item; + + @Column(name = "is_default", nullable = false) + @ColumnDefault("false") + private boolean isDefault; + + @Builder + private Inventory(Long memberId, Item item, boolean isDefault) { + this.memberId = requireNonNull(memberId); + this.item = requireNonNull(item); + this.isDefault = isDefault; + } +} diff --git a/src/main/java/com/moabam/api/domain/entity/Item.java b/src/main/java/com/moabam/api/domain/entity/Item.java new file mode 100644 index 00000000..44e0038b --- /dev/null +++ b/src/main/java/com/moabam/api/domain/entity/Item.java @@ -0,0 +1,90 @@ +package com.moabam.api.domain.entity; + +import static com.moabam.global.error.model.ErrorMessage.*; +import static java.util.Objects.*; + +import org.hibernate.annotations.ColumnDefault; + +import com.moabam.api.domain.entity.enums.ItemCategory; +import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.global.common.entity.BaseTimeEntity; +import com.moabam.global.error.exception.BadRequestException; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Table(name = "item") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Item extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @Enumerated(value = EnumType.STRING) + @Column(name = "type", nullable = false) + private RoomType type; + + @Enumerated(value = EnumType.STRING) + @Column(name = "category", nullable = false) + private ItemCategory category; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "image", nullable = false) + private String image; + + @Column(name = "bug_price", nullable = false) + @ColumnDefault("0") + private int bugPrice; + + @Column(name = "golden_bug_price", nullable = false) + @ColumnDefault("0") + private int goldenBugPrice; + + @Column(name = "unlock_level", nullable = false) + @ColumnDefault("1") + private int unlockLevel; + + @Builder + private Item(RoomType type, ItemCategory category, String name, String image, int bugPrice, int goldenBugPrice, + Integer unlockLevel) { + this.type = requireNonNull(type); + this.category = requireNonNull(category); + this.name = requireNonNull(name); + this.image = requireNonNull(image); + this.bugPrice = validatePrice(bugPrice); + this.goldenBugPrice = validatePrice(goldenBugPrice); + this.unlockLevel = validateLevel(requireNonNullElse(unlockLevel, 1)); + } + + private int validatePrice(int price) { + if (price < 0) { + throw new BadRequestException(INVALID_PRICE); + } + + return price; + } + + private int validateLevel(int level) { + if (level < 1) { + throw new BadRequestException(INVALID_LEVEL); + } + + return level; + } +} diff --git a/src/main/java/com/moabam/api/domain/entity/enums/ItemCategory.java b/src/main/java/com/moabam/api/domain/entity/enums/ItemCategory.java new file mode 100644 index 00000000..581698c0 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/entity/enums/ItemCategory.java @@ -0,0 +1,6 @@ +package com.moabam.api.domain.entity.enums; + +public enum ItemCategory { + + SKIN; +} From b6703afbf8d86cfcbc0478c44cb92309b51cb5da Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 17:31:06 +0900 Subject: [PATCH 03/24] =?UTF-8?q?feat:=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moabam/api/application/ItemService.java | 31 +++++++++++++ .../repository/InventoryRepository.java | 9 ++++ .../repository/InventorySearchRepository.java | 33 ++++++++++++++ .../api/domain/repository/ItemRepository.java | 9 ++++ .../repository/ItemSearchRepository.java | 43 +++++++++++++++++++ .../java/com/moabam/api/dto/ItemMapper.java | 36 ++++++++++++++++ .../java/com/moabam/api/dto/ItemResponse.java | 17 ++++++++ .../com/moabam/api/dto/ItemsResponse.java | 13 ++++++ .../api/presentation/ItemController.java | 28 ++++++++++++ .../global/error/model/ErrorMessage.java | 1 + 10 files changed, 220 insertions(+) create mode 100644 src/main/java/com/moabam/api/application/ItemService.java create mode 100644 src/main/java/com/moabam/api/domain/repository/InventoryRepository.java create mode 100644 src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java create mode 100644 src/main/java/com/moabam/api/domain/repository/ItemRepository.java create mode 100644 src/main/java/com/moabam/api/domain/repository/ItemSearchRepository.java create mode 100644 src/main/java/com/moabam/api/dto/ItemMapper.java create mode 100644 src/main/java/com/moabam/api/dto/ItemResponse.java create mode 100644 src/main/java/com/moabam/api/dto/ItemsResponse.java create mode 100644 src/main/java/com/moabam/api/presentation/ItemController.java diff --git a/src/main/java/com/moabam/api/application/ItemService.java b/src/main/java/com/moabam/api/application/ItemService.java new file mode 100644 index 00000000..f21e0df0 --- /dev/null +++ b/src/main/java/com/moabam/api/application/ItemService.java @@ -0,0 +1,31 @@ +package com.moabam.api.application; + +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.api.domain.repository.InventorySearchRepository; +import com.moabam.api.domain.repository.ItemSearchRepository; +import com.moabam.api.dto.ItemMapper; +import com.moabam.api.dto.ItemsResponse; + +import lombok.RequiredArgsConstructor; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class ItemService { + + private final ItemSearchRepository itemSearchRepository; + private final InventorySearchRepository inventorySearchRepository; + + public ItemsResponse getItems(Long memberId, RoomType type) { + List purchasedItems = inventorySearchRepository.findItems(memberId, type); + List notPurchasedItems = itemSearchRepository.findNotPurchasedItems(memberId, type); + + return ItemMapper.toItemsResponse(purchasedItems, notPurchasedItems); + } +} diff --git a/src/main/java/com/moabam/api/domain/repository/InventoryRepository.java b/src/main/java/com/moabam/api/domain/repository/InventoryRepository.java new file mode 100644 index 00000000..bac07502 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/repository/InventoryRepository.java @@ -0,0 +1,9 @@ +package com.moabam.api.domain.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.moabam.api.domain.entity.Inventory; + +public interface InventoryRepository extends JpaRepository { + +} diff --git a/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java b/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java new file mode 100644 index 00000000..033c8fa8 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java @@ -0,0 +1,33 @@ +package com.moabam.api.domain.repository; + +import static com.moabam.api.domain.entity.QInventory.*; +import static com.moabam.api.domain.entity.QItem.*; + +import java.util.List; + +import org.springframework.stereotype.Repository; + +import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.global.common.util.DynamicQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class InventorySearchRepository { + + private final JPAQueryFactory jpaQueryFactory; + + public List findItems(Long memberId, RoomType type) { + return jpaQueryFactory.selectFrom(inventory) + .join(inventory.item, item) + .where( + DynamicQuery.generateEq(memberId, inventory.memberId::eq), + DynamicQuery.generateEq(type, inventory.item.type::eq)) + .orderBy(inventory.createdAt.desc()) + .select(item) + .fetch(); + } +} diff --git a/src/main/java/com/moabam/api/domain/repository/ItemRepository.java b/src/main/java/com/moabam/api/domain/repository/ItemRepository.java new file mode 100644 index 00000000..ae5eede0 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/repository/ItemRepository.java @@ -0,0 +1,9 @@ +package com.moabam.api.domain.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.moabam.api.domain.entity.Item; + +public interface ItemRepository extends JpaRepository { + +} diff --git a/src/main/java/com/moabam/api/domain/repository/ItemSearchRepository.java b/src/main/java/com/moabam/api/domain/repository/ItemSearchRepository.java new file mode 100644 index 00000000..4ea7e5b3 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/repository/ItemSearchRepository.java @@ -0,0 +1,43 @@ +package com.moabam.api.domain.repository; + +import static com.moabam.api.domain.entity.QInventory.*; +import static com.moabam.api.domain.entity.QItem.*; + +import java.util.List; + +import org.springframework.stereotype.Repository; + +import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.global.common.util.DynamicQuery; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class ItemSearchRepository { + + private final JPAQueryFactory jpaQueryFactory; + + public List findNotPurchasedItems(Long memberId, RoomType type) { + return jpaQueryFactory.selectFrom(item) + .leftJoin(inventory) + .on(inventory.item.id.eq(item.id)) + .where( + DynamicQuery.generateEq(type, item.type::eq), + DynamicQuery.generateEq(memberId, this::filterByMemberId)) + .orderBy( + item.unlockLevel.asc(), + item.bugPrice.asc(), + item.goldenBugPrice.asc(), + item.name.asc()) + .fetch(); + } + + private BooleanExpression filterByMemberId(Long memberId) { + return inventory.memberId.isNull() + .or(inventory.memberId.ne(memberId)); + } +} diff --git a/src/main/java/com/moabam/api/dto/ItemMapper.java b/src/main/java/com/moabam/api/dto/ItemMapper.java new file mode 100644 index 00000000..8e2505ea --- /dev/null +++ b/src/main/java/com/moabam/api/dto/ItemMapper.java @@ -0,0 +1,36 @@ +package com.moabam.api.dto; + +import java.util.List; + +import com.moabam.api.domain.entity.Item; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public final class ItemMapper { + + public static ItemResponse toItemResponse(Item item) { + return ItemResponse.builder() + .id(item.getId()) + .type(item.getType().name()) + .category(item.getCategory().name()) + .name(item.getName()) + .image(item.getImage()) + .level(item.getUnlockLevel()) + .bugPrice(item.getBugPrice()) + .goldenBugPrice(item.getGoldenBugPrice()) + .build(); + } + + public static ItemsResponse toItemsResponse(List purchasedItems, List notPurchasedItems) { + return ItemsResponse.builder() + .purchasedItems(purchasedItems.stream() + .map(ItemMapper::toItemResponse) + .toList()) + .notPurchasedItems(notPurchasedItems.stream() + .map(ItemMapper::toItemResponse) + .toList()) + .build(); + } +} diff --git a/src/main/java/com/moabam/api/dto/ItemResponse.java b/src/main/java/com/moabam/api/dto/ItemResponse.java new file mode 100644 index 00000000..13c83ace --- /dev/null +++ b/src/main/java/com/moabam/api/dto/ItemResponse.java @@ -0,0 +1,17 @@ +package com.moabam.api.dto; + +import lombok.Builder; + +@Builder +public record ItemResponse( + Long id, + String type, + String category, + String name, + String image, + int level, + int bugPrice, + int goldenBugPrice +) { + +} diff --git a/src/main/java/com/moabam/api/dto/ItemsResponse.java b/src/main/java/com/moabam/api/dto/ItemsResponse.java new file mode 100644 index 00000000..a0d323c8 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/ItemsResponse.java @@ -0,0 +1,13 @@ +package com.moabam.api.dto; + +import java.util.List; + +import lombok.Builder; + +@Builder +public record ItemsResponse( + List purchasedItems, + List notPurchasedItems +) { + +} diff --git a/src/main/java/com/moabam/api/presentation/ItemController.java b/src/main/java/com/moabam/api/presentation/ItemController.java new file mode 100644 index 00000000..0583e3ec --- /dev/null +++ b/src/main/java/com/moabam/api/presentation/ItemController.java @@ -0,0 +1,28 @@ +package com.moabam.api.presentation; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import com.moabam.api.application.ItemService; +import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.api.dto.ItemsResponse; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/items") +@RequiredArgsConstructor +public class ItemController { + + private final ItemService itemService; + + @GetMapping + @ResponseStatus(HttpStatus.OK) + public ItemsResponse getItems(@RequestParam RoomType type) { + return itemService.getItems(1L, type); + } +} diff --git a/src/main/java/com/moabam/global/error/model/ErrorMessage.java b/src/main/java/com/moabam/global/error/model/ErrorMessage.java index 4421ceea..052c8f68 100644 --- a/src/main/java/com/moabam/global/error/model/ErrorMessage.java +++ b/src/main/java/com/moabam/global/error/model/ErrorMessage.java @@ -26,6 +26,7 @@ public enum ErrorMessage { INVALID_BUG_COUNT("벌레 개수는 0 이상이어야 합니다."), INVALID_PRICE("가격은 0 이상이어야 합니다."), INVALID_QUANTITY("수량은 1 이상이어야 합니다."), + INVALID_LEVEL("레벨은 1 이상이어야 합니다."), FCM_INIT_FAILED("파이어베이스 설정을 실패했습니다."), FCM_TOKEN_NOT_FOUND("해당 유저는 접속 중이 아닙니다."), From fbfa92553cffcd3470010a6585ef53cd9b305156 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 17:31:35 +0900 Subject: [PATCH 04/24] =?UTF-8?q?test:=20containsExactly=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/moabam/api/application/ProductServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/moabam/api/application/ProductServiceTest.java b/src/test/java/com/moabam/api/application/ProductServiceTest.java index f3445bd3..6244ed59 100644 --- a/src/test/java/com/moabam/api/application/ProductServiceTest.java +++ b/src/test/java/com/moabam/api/application/ProductServiceTest.java @@ -43,6 +43,6 @@ void get_products_success() { .map(ProductResponse::name) .toList(); assertThat(response.products()).hasSize(2); - assertThat(productNames).containsOnly(BUG_PRODUCT_NAME, BUG_PRODUCT_NAME); + assertThat(productNames).containsExactly(BUG_PRODUCT_NAME, BUG_PRODUCT_NAME); } } From 6f939a581f2203db6458597b010928f2dc6e674d Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 17:32:31 +0900 Subject: [PATCH 05/24] =?UTF-8?q?test:=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20Service=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/application/ItemServiceTest.java | 61 +++++++++++++++++++ .../java/com/moabam/fixture/ItemFixture.java | 40 ++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/test/java/com/moabam/api/application/ItemServiceTest.java create mode 100644 src/test/java/com/moabam/fixture/ItemFixture.java diff --git a/src/test/java/com/moabam/api/application/ItemServiceTest.java b/src/test/java/com/moabam/api/application/ItemServiceTest.java new file mode 100644 index 00000000..cf5aca27 --- /dev/null +++ b/src/test/java/com/moabam/api/application/ItemServiceTest.java @@ -0,0 +1,61 @@ +package com.moabam.api.application; + +import static com.moabam.fixture.ItemFixture.*; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.api.domain.repository.InventorySearchRepository; +import com.moabam.api.domain.repository.ItemSearchRepository; +import com.moabam.api.dto.ItemResponse; +import com.moabam.api.dto.ItemsResponse; + +@ExtendWith(MockitoExtension.class) +class ItemServiceTest { + + @InjectMocks + ItemService itemService; + + @Mock + ItemSearchRepository itemSearchRepository; + + @Mock + InventorySearchRepository inventorySearchRepository; + + @DisplayName("아이템 목록을 조회한다.") + @Test + void get_products_success() { + // given + Long memberId = 1L; + RoomType type = RoomType.MORNING; + Item item1 = morningSantaSkin().build(); + Item item2 = morningKillerSkin().build(); + given(inventorySearchRepository.findItems(memberId, type)).willReturn(List.of(item1, item2)); + given(itemSearchRepository.findNotPurchasedItems(memberId, type)).willReturn(List.of(item1, item2)); + + // when + ItemsResponse response = itemService.getItems(memberId, type); + + // then + List purchasedItemNames = response.purchasedItems().stream() + .map(ItemResponse::name) + .toList(); + List notPurchasedItemNames = response.notPurchasedItems().stream() + .map(ItemResponse::name) + .toList(); + assertThat(response.purchasedItems()).hasSize(2); + assertThat(response.notPurchasedItems()).hasSize(2); + assertThat(purchasedItemNames).containsExactly(MORNING_SANTA_SKIN_NAME, MORNING_KILLER_SKIN_NAME); + assertThat(notPurchasedItemNames).containsExactly(MORNING_SANTA_SKIN_NAME, MORNING_KILLER_SKIN_NAME); + } +} diff --git a/src/test/java/com/moabam/fixture/ItemFixture.java b/src/test/java/com/moabam/fixture/ItemFixture.java new file mode 100644 index 00000000..96e3f821 --- /dev/null +++ b/src/test/java/com/moabam/fixture/ItemFixture.java @@ -0,0 +1,40 @@ +package com.moabam.fixture; + +import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.enums.ItemCategory; +import com.moabam.api.domain.entity.enums.RoomType; + +public class ItemFixture { + + public static final String MORNING_SANTA_SKIN_NAME = "산타 오목눈이"; + public static final String MORNING_SANTA_SKIN_IMAGE = "/item/morning_santa.png"; + public static final String MORNING_KILLER_SKIN_NAME = "킬러 오목눈이"; + public static final String MORNING_KILLER_SKIN_IMAGE = "/item/morning_killer.png"; + public static final String NIGHT_MAGE_SKIN_NAME = "메이지 부엉이"; + public static final String NIGHT_MAGE_SKIN_IMAGE = "/item/night_mage.png"; + + public static Item.ItemBuilder morningSantaSkin() { + return Item.builder() + .type(RoomType.MORNING) + .category(ItemCategory.SKIN) + .name(MORNING_SANTA_SKIN_NAME) + .image(MORNING_SANTA_SKIN_IMAGE); + } + + public static Item.ItemBuilder morningKillerSkin() { + return Item.builder() + .type(RoomType.MORNING) + .category(ItemCategory.SKIN) + .name(MORNING_KILLER_SKIN_NAME) + .image(MORNING_KILLER_SKIN_IMAGE); + } + + public static Item nightMageSkin() { + return Item.builder() + .type(RoomType.NIGHT) + .category(ItemCategory.SKIN) + .name(NIGHT_MAGE_SKIN_NAME) + .image(NIGHT_MAGE_SKIN_IMAGE) + .build(); + } +} From f502897abfb5e57d9db924c6d9ec1a1888358998 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 17:32:53 +0900 Subject: [PATCH 06/24] =?UTF-8?q?test:=20=EC=9D=B8=EB=B2=A4=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=95=84=EC=9D=B4=ED=85=9C=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20Repository=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InventorySearchRepositoryTest.java | 67 +++++++++++++++++++ .../com/moabam/fixture/InventoryFixture.java | 14 ++++ 2 files changed, 81 insertions(+) create mode 100644 src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java create mode 100644 src/test/java/com/moabam/fixture/InventoryFixture.java diff --git a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java new file mode 100644 index 00000000..81614ca9 --- /dev/null +++ b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java @@ -0,0 +1,67 @@ +package com.moabam.api.domain.repository; + +import static com.moabam.fixture.InventoryFixture.*; +import static com.moabam.fixture.ItemFixture.*; +import static org.assertj.core.api.Assertions.*; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.enums.RoomType; + +@SpringBootTest +@Transactional(readOnly = true) +class InventorySearchRepositoryTest { + + @Autowired + ItemRepository itemRepository; + + @Autowired + InventoryRepository inventoryRepository; + + @Autowired + InventorySearchRepository inventorySearchRepository; + + @DisplayName("타입으로 인벤토리에 있는 아이템 목록을 구매일 순으로 조회한다.") + @Test + void find_items_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin()); + inventoryRepository.save(inventory(memberId, morningSantaSkin)); + Item morningKillerSkin = itemRepository.save(morningKillerSkin()); + inventoryRepository.save(inventory(memberId, morningKillerSkin)); + Item nightMageSkin = itemRepository.save(nightMageSkin()); + inventoryRepository.save(inventory(memberId, nightMageSkin)); + + // when + List actual = inventorySearchRepository.findItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(2) + .containsExactly(morningKillerSkin, morningSantaSkin); + } + + @DisplayName("인벤토리에 해당하는 타입의 아이템이 없으면 빈 목록을 조회한다.") + @Test + void find_empty_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin()); + inventoryRepository.save(inventory(memberId, morningSantaSkin)); + Item morningKillerSkin = itemRepository.save(morningKillerSkin()); + inventoryRepository.save(inventory(memberId, morningKillerSkin)); + + // when + List actual = inventorySearchRepository.findItems(memberId, RoomType.NIGHT); + + // then + assertThat(actual).isEmpty(); + } +} diff --git a/src/test/java/com/moabam/fixture/InventoryFixture.java b/src/test/java/com/moabam/fixture/InventoryFixture.java new file mode 100644 index 00000000..357443dc --- /dev/null +++ b/src/test/java/com/moabam/fixture/InventoryFixture.java @@ -0,0 +1,14 @@ +package com.moabam.fixture; + +import com.moabam.api.domain.entity.Inventory; +import com.moabam.api.domain.entity.Item; + +public class InventoryFixture { + + public static Inventory inventory(Long memberId, Item item) { + return Inventory.builder() + .memberId(memberId) + .item(item) + .build(); + } +} From d4f60dc478c8fc6041b710d7926cae3265bf7dc7 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 17:40:48 +0900 Subject: [PATCH 07/24] =?UTF-8?q?feat:=20Stream=20=EC=9C=A0=ED=8B=B8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/moabam/api/dto/ItemMapper.java | 9 +++------ .../java/com/moabam/api/dto/ProductMapper.java | 5 ++--- .../moabam/global/common/util/StreamUtils.java | 17 +++++++++++++++++ .../moabam/api/application/ItemServiceTest.java | 14 +++++--------- .../api/application/ProductServiceTest.java | 5 ++--- 5 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/moabam/global/common/util/StreamUtils.java diff --git a/src/main/java/com/moabam/api/dto/ItemMapper.java b/src/main/java/com/moabam/api/dto/ItemMapper.java index 8e2505ea..d7ccf4b7 100644 --- a/src/main/java/com/moabam/api/dto/ItemMapper.java +++ b/src/main/java/com/moabam/api/dto/ItemMapper.java @@ -3,6 +3,7 @@ import java.util.List; import com.moabam.api.domain.entity.Item; +import com.moabam.global.common.util.StreamUtils; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -25,12 +26,8 @@ public static ItemResponse toItemResponse(Item item) { public static ItemsResponse toItemsResponse(List purchasedItems, List notPurchasedItems) { return ItemsResponse.builder() - .purchasedItems(purchasedItems.stream() - .map(ItemMapper::toItemResponse) - .toList()) - .notPurchasedItems(notPurchasedItems.stream() - .map(ItemMapper::toItemResponse) - .toList()) + .purchasedItems(StreamUtils.map(purchasedItems, ItemMapper::toItemResponse)) + .notPurchasedItems(StreamUtils.map(notPurchasedItems, ItemMapper::toItemResponse)) .build(); } } diff --git a/src/main/java/com/moabam/api/dto/ProductMapper.java b/src/main/java/com/moabam/api/dto/ProductMapper.java index 0851d490..7f4c34c2 100644 --- a/src/main/java/com/moabam/api/dto/ProductMapper.java +++ b/src/main/java/com/moabam/api/dto/ProductMapper.java @@ -3,6 +3,7 @@ import java.util.List; import com.moabam.api.domain.entity.Product; +import com.moabam.global.common.util.StreamUtils; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -22,9 +23,7 @@ public static ProductResponse toProductResponse(Product product) { public static ProductsResponse toProductsResponse(List products) { return ProductsResponse.builder() - .products(products.stream() - .map(ProductMapper::toProductResponse) - .toList()) + .products(StreamUtils.map(products, ProductMapper::toProductResponse)) .build(); } } diff --git a/src/main/java/com/moabam/global/common/util/StreamUtils.java b/src/main/java/com/moabam/global/common/util/StreamUtils.java new file mode 100644 index 00000000..2820d908 --- /dev/null +++ b/src/main/java/com/moabam/global/common/util/StreamUtils.java @@ -0,0 +1,17 @@ +package com.moabam.global.common.util; + +import java.util.List; +import java.util.function.Function; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class StreamUtils { + + public static List map(List list, Function mapper) { + return list.stream() + .map(mapper) + .toList(); + } +} diff --git a/src/test/java/com/moabam/api/application/ItemServiceTest.java b/src/test/java/com/moabam/api/application/ItemServiceTest.java index cf5aca27..6b050d55 100644 --- a/src/test/java/com/moabam/api/application/ItemServiceTest.java +++ b/src/test/java/com/moabam/api/application/ItemServiceTest.java @@ -1,6 +1,7 @@ package com.moabam.api.application; import static com.moabam.fixture.ItemFixture.*; +import static java.util.Collections.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; @@ -19,6 +20,7 @@ import com.moabam.api.domain.repository.ItemSearchRepository; import com.moabam.api.dto.ItemResponse; import com.moabam.api.dto.ItemsResponse; +import com.moabam.global.common.util.StreamUtils; @ExtendWith(MockitoExtension.class) class ItemServiceTest { @@ -41,21 +43,15 @@ void get_products_success() { Item item1 = morningSantaSkin().build(); Item item2 = morningKillerSkin().build(); given(inventorySearchRepository.findItems(memberId, type)).willReturn(List.of(item1, item2)); - given(itemSearchRepository.findNotPurchasedItems(memberId, type)).willReturn(List.of(item1, item2)); + given(itemSearchRepository.findNotPurchasedItems(memberId, type)).willReturn(emptyList()); // when ItemsResponse response = itemService.getItems(memberId, type); // then - List purchasedItemNames = response.purchasedItems().stream() - .map(ItemResponse::name) - .toList(); - List notPurchasedItemNames = response.notPurchasedItems().stream() - .map(ItemResponse::name) - .toList(); + List purchasedItemNames = StreamUtils.map(response.purchasedItems(), ItemResponse::name); assertThat(response.purchasedItems()).hasSize(2); - assertThat(response.notPurchasedItems()).hasSize(2); assertThat(purchasedItemNames).containsExactly(MORNING_SANTA_SKIN_NAME, MORNING_KILLER_SKIN_NAME); - assertThat(notPurchasedItemNames).containsExactly(MORNING_SANTA_SKIN_NAME, MORNING_KILLER_SKIN_NAME); + assertThat(response.notPurchasedItems()).isEmpty(); } } diff --git a/src/test/java/com/moabam/api/application/ProductServiceTest.java b/src/test/java/com/moabam/api/application/ProductServiceTest.java index 6244ed59..bb63597f 100644 --- a/src/test/java/com/moabam/api/application/ProductServiceTest.java +++ b/src/test/java/com/moabam/api/application/ProductServiceTest.java @@ -17,6 +17,7 @@ import com.moabam.api.domain.repository.ProductRepository; import com.moabam.api.dto.ProductResponse; import com.moabam.api.dto.ProductsResponse; +import com.moabam.global.common.util.StreamUtils; @ExtendWith(MockitoExtension.class) class ProductServiceTest { @@ -39,9 +40,7 @@ void get_products_success() { ProductsResponse response = productService.getProducts(); // then - List productNames = response.products().stream() - .map(ProductResponse::name) - .toList(); + List productNames = StreamUtils.map(response.products(), ProductResponse::name); assertThat(response.products()).hasSize(2); assertThat(productNames).containsExactly(BUG_PRODUCT_NAME, BUG_PRODUCT_NAME); } From e77c28486ae18d3d3a44f07f1fb166b62c799186 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 17:41:37 +0900 Subject: [PATCH 08/24] =?UTF-8?q?fix:=20ItemFixture=EB=A5=BC=20=ED=86=B5?= =?UTF-8?q?=ED=95=9C=20=EC=95=84=EC=9D=B4=ED=85=9C=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=8B=9C=20build()=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/InventorySearchRepositoryTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java index 81614ca9..d4dde127 100644 --- a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java @@ -33,9 +33,9 @@ class InventorySearchRepositoryTest { void find_items_success() { // given Long memberId = 1L; - Item morningSantaSkin = itemRepository.save(morningSantaSkin()); + Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); inventoryRepository.save(inventory(memberId, morningSantaSkin)); - Item morningKillerSkin = itemRepository.save(morningKillerSkin()); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); inventoryRepository.save(inventory(memberId, morningKillerSkin)); Item nightMageSkin = itemRepository.save(nightMageSkin()); inventoryRepository.save(inventory(memberId, nightMageSkin)); @@ -53,9 +53,9 @@ void find_items_success() { void find_empty_success() { // given Long memberId = 1L; - Item morningSantaSkin = itemRepository.save(morningSantaSkin()); + Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); inventoryRepository.save(inventory(memberId, morningSantaSkin)); - Item morningKillerSkin = itemRepository.save(morningKillerSkin()); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); inventoryRepository.save(inventory(memberId, morningKillerSkin)); // when From a0a7c3ea84c0d8f562e7da634d6de81060fbff3a Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 17:53:04 +0900 Subject: [PATCH 09/24] =?UTF-8?q?test:=20=EA=B5=AC=EB=A7=A4=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20Repository=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ItemSearchRepositoryTest.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java diff --git a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java new file mode 100644 index 00000000..6bdc06a5 --- /dev/null +++ b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java @@ -0,0 +1,96 @@ +package com.moabam.api.domain.repository; + +import static com.moabam.fixture.InventoryFixture.*; +import static com.moabam.fixture.ItemFixture.*; +import static org.assertj.core.api.Assertions.*; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.enums.RoomType; + +@SpringBootTest +@Transactional(readOnly = true) +class ItemSearchRepositoryTest { + + @Autowired + ItemRepository itemRepository; + + @Autowired + InventoryRepository inventoryRepository; + + @Autowired + ItemSearchRepository itemSearchRepository; + + @DisplayName("타입으로 구매하지 않은 아이템 목록을 조회한다.") + @Test + void find_not_purchased_items_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); + inventoryRepository.save(inventory(memberId, morningSantaSkin)); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); + itemRepository.save(nightMageSkin()); + + // when + List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(1) + .containsExactly(morningKillerSkin); + } + + @DisplayName("구매하지 않은 아이템 목록은 레벨 순으로 정렬된다.") + @Test + void find_not_purchased_items_sorted_by_level_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().unlockLevel(5).build()); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().unlockLevel(1).build()); + + // when + List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(2) + .containsExactly(morningKillerSkin, morningSantaSkin); + } + + @DisplayName("레벨이 같으면 가격 순으로 정렬된다.") + @Test + void find_not_purchased_items_sorted_by_price_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().bugPrice(10).build()); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().bugPrice(20).build()); + + // when + List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(2) + .containsExactly(morningSantaSkin, morningKillerSkin); + } + + @DisplayName("레벨과 가격이 같으면 이름 순으로 정렬된다.") + @Test + void find_not_purchased_items_sorted_by_name_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); + + // when + List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(2) + .containsExactly(morningSantaSkin, morningKillerSkin); + } +} From 2b88546efbeb7038fb97993930608eb47f975d3a Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 18:19:34 +0900 Subject: [PATCH 10/24] =?UTF-8?q?feat:=20MethodArgumentTypeMismatchExcepti?= =?UTF-8?q?on=20handler=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../error/handler/GlobalExceptionHandler.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/moabam/global/error/handler/GlobalExceptionHandler.java b/src/main/java/com/moabam/global/error/handler/GlobalExceptionHandler.java index 2dc1f65d..0adac8f0 100644 --- a/src/main/java/com/moabam/global/error/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/moabam/global/error/handler/GlobalExceptionHandler.java @@ -3,6 +3,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import org.springframework.http.HttpStatus; import org.springframework.validation.FieldError; @@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import com.moabam.global.error.exception.BadRequestException; import com.moabam.global.error.exception.ConflictException; @@ -78,4 +80,15 @@ protected ErrorResponse handleMethodArgumentNotValidException(MethodArgumentNotV return new ErrorResponse(ErrorMessage.INVALID_REQUEST_FIELD.getMessage(), validation); } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public ErrorResponse handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException exception) { + String typeName = Optional.ofNullable(exception.getRequiredType()) + .map(Class::getSimpleName) + .orElse(""); + String message = String.format("'%s' 값은 유효한 %s 값이 아닙니다.", exception.getValue(), typeName); + + return new ErrorResponse(message, null); + } } From 9e50a2b33d4b156c21cc6bef127d9bc025842cd9 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sat, 4 Nov 2023 18:27:37 +0900 Subject: [PATCH 11/24] =?UTF-8?q?test:=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20Controller=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/presentation/ItemControllerTest.java | 64 +++++++++++++++++++ .../presentation/ProductControllerTest.java | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/moabam/api/presentation/ItemControllerTest.java diff --git a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java new file mode 100644 index 00000000..cfa18a0c --- /dev/null +++ b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java @@ -0,0 +1,64 @@ +package com.moabam.api.presentation; + +import static java.nio.charset.StandardCharsets.*; +import static java.util.Collections.*; +import static org.mockito.BDDMockito.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +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.test.web.servlet.MockMvc; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.moabam.api.application.ItemService; +import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.api.dto.ItemMapper; +import com.moabam.api.dto.ItemsResponse; +import com.moabam.fixture.ItemFixture; + +@SpringBootTest +@AutoConfigureMockMvc +class ItemControllerTest { + + @Autowired + MockMvc mockMvc; + + @Autowired + ObjectMapper objectMapper; + + @MockBean + ItemService itemService; + + @DisplayName("아이템 목록을 조회한다.") + @Test + void get_items_success() throws Exception { + // given + Long memberId = 1L; + RoomType type = RoomType.MORNING; + Item item1 = ItemFixture.morningSantaSkin().build(); + Item item2 = ItemFixture.morningKillerSkin().build(); + ItemsResponse expected = ItemMapper.toItemsResponse(List.of(item1, item2), emptyList()); + given(itemService.getItems(memberId, type)).willReturn(expected); + + // expected + String content = mockMvc.perform(get("/items") + .param("type", RoomType.MORNING.name())) + .andDo(print()) + .andExpect(status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(UTF_8); + ItemsResponse actual = objectMapper.readValue(content, ItemsResponse.class); + Assertions.assertThat(actual).isEqualTo(expected); + } +} diff --git a/src/test/java/com/moabam/api/presentation/ProductControllerTest.java b/src/test/java/com/moabam/api/presentation/ProductControllerTest.java index f18b3236..a14c21c8 100644 --- a/src/test/java/com/moabam/api/presentation/ProductControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/ProductControllerTest.java @@ -46,7 +46,7 @@ void get_products_success() throws Exception { ProductsResponse expected = ProductMapper.toProductsResponse(List.of(product1, product2)); given(productService.getProducts()).willReturn(expected); - // when & then + // expected String content = mockMvc.perform(get("/products")) .andDo(print()) .andExpect(status().isOk()) From c5000ad22121f3cc86c931398dce7d214dde530d Mon Sep 17 00:00:00 2001 From: kmebin Date: Sun, 5 Nov 2023 16:22:06 +0900 Subject: [PATCH 12/24] =?UTF-8?q?feat:=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moabam/api/application/ItemService.java | 17 ++++++++++++++ .../moabam/api/domain/entity/Inventory.java | 8 +++++++ .../repository/InventorySearchRepository.java | 22 +++++++++++++++++++ .../api/presentation/ItemController.java | 8 +++++++ .../global/error/model/ErrorMessage.java | 2 ++ 5 files changed, 57 insertions(+) diff --git a/src/main/java/com/moabam/api/application/ItemService.java b/src/main/java/com/moabam/api/application/ItemService.java index f21e0df0..c9ee541e 100644 --- a/src/main/java/com/moabam/api/application/ItemService.java +++ b/src/main/java/com/moabam/api/application/ItemService.java @@ -1,16 +1,20 @@ package com.moabam.api.application; +import static com.moabam.global.error.model.ErrorMessage.*; + import java.util.List; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.moabam.api.domain.entity.Inventory; import com.moabam.api.domain.entity.Item; import com.moabam.api.domain.entity.enums.RoomType; import com.moabam.api.domain.repository.InventorySearchRepository; import com.moabam.api.domain.repository.ItemSearchRepository; import com.moabam.api.dto.ItemMapper; import com.moabam.api.dto.ItemsResponse; +import com.moabam.global.error.exception.NotFoundException; import lombok.RequiredArgsConstructor; @@ -28,4 +32,17 @@ public ItemsResponse getItems(Long memberId, RoomType type) { return ItemMapper.toItemsResponse(purchasedItems, notPurchasedItems); } + + public void selectItem(Long memberId, Long itemId) { + Inventory inventory = getInventory(memberId, itemId); + + inventorySearchRepository.findDefault(memberId) + .ifPresent(Inventory::unsetDefault); + inventory.setDefault(); + } + + private Inventory getInventory(Long memberId, Long itemId) { + return inventorySearchRepository.findOne(memberId, itemId) + .orElseThrow(() -> new NotFoundException(INVENTORY_NOT_FOUND)); + } } diff --git a/src/main/java/com/moabam/api/domain/entity/Inventory.java b/src/main/java/com/moabam/api/domain/entity/Inventory.java index 4921ab7d..724c8afd 100644 --- a/src/main/java/com/moabam/api/domain/entity/Inventory.java +++ b/src/main/java/com/moabam/api/domain/entity/Inventory.java @@ -49,4 +49,12 @@ private Inventory(Long memberId, Item item, boolean isDefault) { this.item = requireNonNull(item); this.isDefault = isDefault; } + + public void setDefault() { + this.isDefault = true; + } + + public void unsetDefault() { + this.isDefault = false; + } } diff --git a/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java b/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java index 033c8fa8..8ba35fee 100644 --- a/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java +++ b/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java @@ -4,9 +4,11 @@ import static com.moabam.api.domain.entity.QItem.*; import java.util.List; +import java.util.Optional; import org.springframework.stereotype.Repository; +import com.moabam.api.domain.entity.Inventory; import com.moabam.api.domain.entity.Item; import com.moabam.api.domain.entity.enums.RoomType; import com.moabam.global.common.util.DynamicQuery; @@ -20,6 +22,26 @@ public class InventorySearchRepository { private final JPAQueryFactory jpaQueryFactory; + public Optional findOne(Long memberId, Long itemId) { + return Optional.ofNullable( + jpaQueryFactory.selectFrom(inventory) + .where( + DynamicQuery.generateEq(memberId, inventory.memberId::eq), + DynamicQuery.generateEq(itemId, inventory.item.id::eq)) + .fetchOne() + ); + } + + public Optional findDefault(Long memberId) { + return Optional.ofNullable( + jpaQueryFactory.selectFrom(inventory) + .where( + DynamicQuery.generateEq(memberId, inventory.memberId::eq), + inventory.isDefault.isTrue()) + .fetchOne() + ); + } + public List findItems(Long memberId, RoomType type) { return jpaQueryFactory.selectFrom(inventory) .join(inventory.item, item) diff --git a/src/main/java/com/moabam/api/presentation/ItemController.java b/src/main/java/com/moabam/api/presentation/ItemController.java index 0583e3ec..a2e9678e 100644 --- a/src/main/java/com/moabam/api/presentation/ItemController.java +++ b/src/main/java/com/moabam/api/presentation/ItemController.java @@ -2,6 +2,8 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; @@ -25,4 +27,10 @@ public class ItemController { public ItemsResponse getItems(@RequestParam RoomType type) { return itemService.getItems(1L, type); } + + @PostMapping("/{itemId}/select") + @ResponseStatus(HttpStatus.OK) + public void selectItem(@PathVariable Long itemId) { + itemService.selectItem(1L, itemId); + } } diff --git a/src/main/java/com/moabam/global/error/model/ErrorMessage.java b/src/main/java/com/moabam/global/error/model/ErrorMessage.java index 052c8f68..a1f95065 100644 --- a/src/main/java/com/moabam/global/error/model/ErrorMessage.java +++ b/src/main/java/com/moabam/global/error/model/ErrorMessage.java @@ -23,6 +23,8 @@ public enum ErrorMessage { MEMBER_NOT_FOUND("존재하지 않는 회원입니다."), MEMBER_ROOM_EXCEED("참여할 수 있는 방의 개수가 모두 찼습니다."), + INVENTORY_NOT_FOUND("구매하지 않은 아이템은 적용할 수 없습니다."), + INVALID_BUG_COUNT("벌레 개수는 0 이상이어야 합니다."), INVALID_PRICE("가격은 0 이상이어야 합니다."), INVALID_QUANTITY("수량은 1 이상이어야 합니다."), From e1cd9fd7e4b703db8d7baa1e7e2dcf779f4d7ad5 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sun, 5 Nov 2023 16:22:30 +0900 Subject: [PATCH 13/24] =?UTF-8?q?test:=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20Service=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/application/ItemServiceTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/test/java/com/moabam/api/application/ItemServiceTest.java b/src/test/java/com/moabam/api/application/ItemServiceTest.java index 6b050d55..48e4b32c 100644 --- a/src/test/java/com/moabam/api/application/ItemServiceTest.java +++ b/src/test/java/com/moabam/api/application/ItemServiceTest.java @@ -3,24 +3,30 @@ import static com.moabam.fixture.ItemFixture.*; import static java.util.Collections.*; import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.BDDMockito.*; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import com.moabam.api.domain.entity.Inventory; import com.moabam.api.domain.entity.Item; import com.moabam.api.domain.entity.enums.RoomType; import com.moabam.api.domain.repository.InventorySearchRepository; import com.moabam.api.domain.repository.ItemSearchRepository; import com.moabam.api.dto.ItemResponse; import com.moabam.api.dto.ItemsResponse; +import com.moabam.fixture.InventoryFixture; import com.moabam.global.common.util.StreamUtils; +import com.moabam.global.error.exception.NotFoundException; @ExtendWith(MockitoExtension.class) class ItemServiceTest { @@ -54,4 +60,44 @@ void get_products_success() { assertThat(purchasedItemNames).containsExactly(MORNING_SANTA_SKIN_NAME, MORNING_KILLER_SKIN_NAME); assertThat(response.notPurchasedItems()).isEmpty(); } + + @DisplayName("아이템을 적용한다.") + @Nested + class select_item { + + @DisplayName("성공한다.") + @Test + void success() { + // given + Long memberId = 1L; + Long itemId = 1L; + Inventory inventory = InventoryFixture.inventory(memberId, nightMageSkin()); + Inventory defaultInventory = InventoryFixture.inventory(memberId, nightMageSkin()); + when(inventorySearchRepository.findOne(memberId, itemId)).thenReturn(Optional.of(inventory)); + when(inventorySearchRepository.findDefault(memberId)).thenReturn(Optional.of(defaultInventory)); + + // when + itemService.selectItem(memberId, itemId); + + // then + verify(inventorySearchRepository).findOne(memberId, itemId); + verify(inventorySearchRepository).findDefault(memberId); + assertFalse(defaultInventory.isDefault()); + assertTrue(inventory.isDefault()); + } + + @DisplayName("인벤토리 아이템이 아니면 예외가 발생한다.") + @Test + void exception() { + // given + Long memberId = 1L; + Long itemId = 1L; + when(inventorySearchRepository.findOne(memberId, itemId)).thenReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> itemService.selectItem(memberId, itemId)) + .isInstanceOf(NotFoundException.class) + .hasMessage("구매하지 않은 아이템은 적용할 수 없습니다."); + } + } } From 344d99ef99e546e339bc33087adc7984ca66a3ba Mon Sep 17 00:00:00 2001 From: kmebin Date: Sun, 5 Nov 2023 16:56:05 +0900 Subject: [PATCH 14/24] =?UTF-8?q?test:=20Controller=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20@WebMvcTest=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/presentation/BugControllerTest.java | 20 ++++++++--------- .../presentation/ProductControllerTest.java | 22 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/test/java/com/moabam/api/presentation/BugControllerTest.java b/src/test/java/com/moabam/api/presentation/BugControllerTest.java index 4bfedb04..ac187642 100644 --- a/src/test/java/com/moabam/api/presentation/BugControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/BugControllerTest.java @@ -1,17 +1,18 @@ package com.moabam.api.presentation; +import static com.moabam.fixture.BugFixture.*; import static java.nio.charset.StandardCharsets.*; +import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; +import static org.springframework.http.MediaType.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; 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.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.web.servlet.MockMvc; @@ -19,10 +20,8 @@ import com.moabam.api.application.BugService; import com.moabam.api.dto.BugMapper; import com.moabam.api.dto.BugResponse; -import com.moabam.fixture.BugFixture; -@SpringBootTest -@AutoConfigureMockMvc +@WebMvcTest(BugController.class) class BugControllerTest { @Autowired @@ -39,17 +38,18 @@ class BugControllerTest { void get_bug_success() throws Exception { // given Long memberId = 1L; - BugResponse expected = BugMapper.toBugResponse(BugFixture.bug()); + BugResponse expected = BugMapper.toBugResponse(bug()); given(bugService.getBug(memberId)).willReturn(expected); - // expected - String content = mockMvc.perform(get("/bugs")) + // when, then + String content = mockMvc.perform(get("/bugs") + .contentType(APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) .andReturn() .getResponse() .getContentAsString(UTF_8); BugResponse actual = objectMapper.readValue(content, BugResponse.class); - Assertions.assertThat(actual).isEqualTo(expected); + assertThat(actual).isEqualTo(expected); } } diff --git a/src/test/java/com/moabam/api/presentation/ProductControllerTest.java b/src/test/java/com/moabam/api/presentation/ProductControllerTest.java index a14c21c8..82f04f8d 100644 --- a/src/test/java/com/moabam/api/presentation/ProductControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/ProductControllerTest.java @@ -1,19 +1,20 @@ package com.moabam.api.presentation; +import static com.moabam.fixture.ProductFixture.*; import static java.nio.charset.StandardCharsets.*; +import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; +import static org.springframework.http.MediaType.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import java.util.List; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; 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.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.web.servlet.MockMvc; @@ -22,10 +23,8 @@ import com.moabam.api.domain.entity.Product; import com.moabam.api.dto.ProductMapper; import com.moabam.api.dto.ProductsResponse; -import com.moabam.fixture.ProductFixture; -@SpringBootTest -@AutoConfigureMockMvc +@WebMvcTest(ProductController.class) class ProductControllerTest { @Autowired @@ -41,19 +40,20 @@ class ProductControllerTest { @Test void get_products_success() throws Exception { // given - Product product1 = ProductFixture.bugProduct(); - Product product2 = ProductFixture.bugProduct(); + Product product1 = bugProduct(); + Product product2 = bugProduct(); ProductsResponse expected = ProductMapper.toProductsResponse(List.of(product1, product2)); given(productService.getProducts()).willReturn(expected); - // expected - String content = mockMvc.perform(get("/products")) + // when, then + String content = mockMvc.perform(get("/products") + .contentType(APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) .andReturn() .getResponse() .getContentAsString(UTF_8); ProductsResponse actual = objectMapper.readValue(content, ProductsResponse.class); - Assertions.assertThat(actual).isEqualTo(expected); + assertThat(actual).isEqualTo(expected); } } From b1524f5dc17213d0d34a202b7a8fbc5853cd18a6 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sun, 5 Nov 2023 17:12:42 +0900 Subject: [PATCH 15/24] =?UTF-8?q?test:=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20Controller=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/presentation/ItemControllerTest.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java index cfa18a0c..6feb8bf4 100644 --- a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java @@ -1,20 +1,21 @@ package com.moabam.api.presentation; +import static com.moabam.fixture.ItemFixture.*; import static java.nio.charset.StandardCharsets.*; import static java.util.Collections.*; +import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; +import static org.springframework.http.MediaType.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import java.util.List; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; 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.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.web.servlet.MockMvc; @@ -24,10 +25,8 @@ import com.moabam.api.domain.entity.enums.RoomType; import com.moabam.api.dto.ItemMapper; import com.moabam.api.dto.ItemsResponse; -import com.moabam.fixture.ItemFixture; -@SpringBootTest -@AutoConfigureMockMvc +@WebMvcTest(ItemController.class) class ItemControllerTest { @Autowired @@ -45,20 +44,36 @@ void get_items_success() throws Exception { // given Long memberId = 1L; RoomType type = RoomType.MORNING; - Item item1 = ItemFixture.morningSantaSkin().build(); - Item item2 = ItemFixture.morningKillerSkin().build(); + Item item1 = morningSantaSkin().build(); + Item item2 = morningKillerSkin().build(); ItemsResponse expected = ItemMapper.toItemsResponse(List.of(item1, item2), emptyList()); given(itemService.getItems(memberId, type)).willReturn(expected); - // expected + // when, then String content = mockMvc.perform(get("/items") - .param("type", RoomType.MORNING.name())) + .param("type", RoomType.MORNING.name()) + .contentType(APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) .andReturn() .getResponse() .getContentAsString(UTF_8); ItemsResponse actual = objectMapper.readValue(content, ItemsResponse.class); - Assertions.assertThat(actual).isEqualTo(expected); + assertThat(actual).isEqualTo(expected); + } + + @DisplayName("아이템을 적용한다.") + @Test + void select_item_success() throws Exception { + // given + Long memberId = 1L; + Long itemId = 1L; + + // when, then + mockMvc.perform(post("/items/{itemId}/select", itemId) + .contentType(APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()); + verify(itemService).selectItem(memberId, itemId); } } From 73bc05f993eae427632bb1c65b1bb130e03b38ad Mon Sep 17 00:00:00 2001 From: kmebin Date: Sun, 5 Nov 2023 17:31:46 +0900 Subject: [PATCH 16/24] =?UTF-8?q?style:=20support=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/moabam/api/application/AuthenticationServiceTest.java | 2 +- src/test/java/com/moabam/api/application/BugServiceTest.java | 2 +- src/test/java/com/moabam/api/application/ItemServiceTest.java | 4 ++-- .../java/com/moabam/api/application/ProductServiceTest.java | 2 +- src/test/java/com/moabam/api/domain/entity/MemberTest.java | 2 +- .../api/domain/repository/InventorySearchRepositoryTest.java | 4 ++-- .../api/domain/repository/ItemSearchRepositoryTest.java | 4 ++-- .../java/com/moabam/api/presentation/BugControllerTest.java | 2 +- .../java/com/moabam/api/presentation/ItemControllerTest.java | 2 +- .../com/moabam/api/presentation/MemberControllerTest.java | 3 ++- .../com/moabam/api/presentation/ProductControllerTest.java | 2 +- .../java/com/moabam/api/presentation/RoomControllerTest.java | 4 ++-- .../fixture/AuthorizationTokenResponseFixture.java | 2 +- .../java/com/moabam/{ => support}/fixture/BugFixture.java | 2 +- .../com/moabam/{ => support}/fixture/InventoryFixture.java | 2 +- .../java/com/moabam/{ => support}/fixture/ItemFixture.java | 2 +- .../java/com/moabam/{ => support}/fixture/MemberFixture.java | 2 +- .../java/com/moabam/{ => support}/fixture/ProductFixture.java | 2 +- 18 files changed, 23 insertions(+), 22 deletions(-) rename src/test/java/com/moabam/{ => support}/fixture/AuthorizationTokenResponseFixture.java (94%) rename src/test/java/com/moabam/{ => support}/fixture/BugFixture.java (90%) rename src/test/java/com/moabam/{ => support}/fixture/InventoryFixture.java (88%) rename src/test/java/com/moabam/{ => support}/fixture/ItemFixture.java (97%) rename src/test/java/com/moabam/{ => support}/fixture/MemberFixture.java (92%) rename src/test/java/com/moabam/{ => support}/fixture/ProductFixture.java (93%) diff --git a/src/test/java/com/moabam/api/application/AuthenticationServiceTest.java b/src/test/java/com/moabam/api/application/AuthenticationServiceTest.java index 744b466f..f315f9a3 100644 --- a/src/test/java/com/moabam/api/application/AuthenticationServiceTest.java +++ b/src/test/java/com/moabam/api/application/AuthenticationServiceTest.java @@ -25,10 +25,10 @@ import com.moabam.api.dto.AuthorizationTokenRequest; import com.moabam.api.dto.AuthorizationTokenResponse; import com.moabam.api.dto.OAuthMapper; -import com.moabam.fixture.AuthorizationTokenResponseFixture; import com.moabam.global.config.OAuthConfig; import com.moabam.global.error.exception.BadRequestException; import com.moabam.global.error.model.ErrorMessage; +import com.moabam.support.fixture.AuthorizationTokenResponseFixture; @ExtendWith(MockitoExtension.class) class AuthenticationServiceTest { diff --git a/src/test/java/com/moabam/api/application/BugServiceTest.java b/src/test/java/com/moabam/api/application/BugServiceTest.java index 416ba5fb..a06fd729 100644 --- a/src/test/java/com/moabam/api/application/BugServiceTest.java +++ b/src/test/java/com/moabam/api/application/BugServiceTest.java @@ -13,7 +13,7 @@ import com.moabam.api.domain.entity.Bug; import com.moabam.api.domain.entity.Member; import com.moabam.api.dto.BugResponse; -import com.moabam.fixture.MemberFixture; +import com.moabam.support.fixture.MemberFixture; @ExtendWith(MockitoExtension.class) class BugServiceTest { diff --git a/src/test/java/com/moabam/api/application/ItemServiceTest.java b/src/test/java/com/moabam/api/application/ItemServiceTest.java index 48e4b32c..97c6e1ac 100644 --- a/src/test/java/com/moabam/api/application/ItemServiceTest.java +++ b/src/test/java/com/moabam/api/application/ItemServiceTest.java @@ -1,6 +1,6 @@ package com.moabam.api.application; -import static com.moabam.fixture.ItemFixture.*; +import static com.moabam.support.fixture.ItemFixture.*; import static java.util.Collections.*; import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; @@ -24,9 +24,9 @@ import com.moabam.api.domain.repository.ItemSearchRepository; import com.moabam.api.dto.ItemResponse; import com.moabam.api.dto.ItemsResponse; -import com.moabam.fixture.InventoryFixture; import com.moabam.global.common.util.StreamUtils; import com.moabam.global.error.exception.NotFoundException; +import com.moabam.support.fixture.InventoryFixture; @ExtendWith(MockitoExtension.class) class ItemServiceTest { diff --git a/src/test/java/com/moabam/api/application/ProductServiceTest.java b/src/test/java/com/moabam/api/application/ProductServiceTest.java index bb63597f..c4555b94 100644 --- a/src/test/java/com/moabam/api/application/ProductServiceTest.java +++ b/src/test/java/com/moabam/api/application/ProductServiceTest.java @@ -1,6 +1,6 @@ package com.moabam.api.application; -import static com.moabam.fixture.ProductFixture.*; +import static com.moabam.support.fixture.ProductFixture.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; diff --git a/src/test/java/com/moabam/api/domain/entity/MemberTest.java b/src/test/java/com/moabam/api/domain/entity/MemberTest.java index 1a947ac8..ab0df828 100644 --- a/src/test/java/com/moabam/api/domain/entity/MemberTest.java +++ b/src/test/java/com/moabam/api/domain/entity/MemberTest.java @@ -8,8 +8,8 @@ import org.junit.jupiter.api.Test; import com.moabam.api.domain.entity.enums.Role; -import com.moabam.fixture.MemberFixture; import com.moabam.global.common.util.BaseImageUrl; +import com.moabam.support.fixture.MemberFixture; class MemberTest { diff --git a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java index d4dde127..b5fb581c 100644 --- a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java @@ -1,7 +1,7 @@ package com.moabam.api.domain.repository; -import static com.moabam.fixture.InventoryFixture.*; -import static com.moabam.fixture.ItemFixture.*; +import static com.moabam.support.fixture.InventoryFixture.*; +import static com.moabam.support.fixture.ItemFixture.*; import static org.assertj.core.api.Assertions.*; import java.util.List; diff --git a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java index 6bdc06a5..5ba2c245 100644 --- a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java @@ -1,7 +1,7 @@ package com.moabam.api.domain.repository; -import static com.moabam.fixture.InventoryFixture.*; -import static com.moabam.fixture.ItemFixture.*; +import static com.moabam.support.fixture.InventoryFixture.*; +import static com.moabam.support.fixture.ItemFixture.*; import static org.assertj.core.api.Assertions.*; import java.util.List; diff --git a/src/test/java/com/moabam/api/presentation/BugControllerTest.java b/src/test/java/com/moabam/api/presentation/BugControllerTest.java index ac187642..4a78621a 100644 --- a/src/test/java/com/moabam/api/presentation/BugControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/BugControllerTest.java @@ -1,6 +1,6 @@ package com.moabam.api.presentation; -import static com.moabam.fixture.BugFixture.*; +import static com.moabam.support.fixture.BugFixture.*; import static java.nio.charset.StandardCharsets.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; diff --git a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java index 6feb8bf4..42794875 100644 --- a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java @@ -1,6 +1,6 @@ package com.moabam.api.presentation; -import static com.moabam.fixture.ItemFixture.*; +import static com.moabam.support.fixture.ItemFixture.*; import static java.nio.charset.StandardCharsets.*; import static java.util.Collections.*; import static org.assertj.core.api.Assertions.*; diff --git a/src/test/java/com/moabam/api/presentation/MemberControllerTest.java b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java index 114d5ba8..685d2434 100644 --- a/src/test/java/com/moabam/api/presentation/MemberControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java @@ -4,6 +4,7 @@ import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; import static org.springframework.test.web.client.response.MockRestResponseCreators.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import org.junit.jupiter.api.BeforeAll; @@ -29,9 +30,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.moabam.api.application.OAuth2AuthorizationServerRequestService; import com.moabam.api.dto.AuthorizationCodeResponse; -import com.moabam.fixture.AuthorizationTokenResponseFixture; import com.moabam.global.common.util.GlobalConstant; import com.moabam.global.config.OAuthConfig; +import com.moabam.support.fixture.AuthorizationTokenResponseFixture; @SpringBootTest @AutoConfigureMockMvc diff --git a/src/test/java/com/moabam/api/presentation/ProductControllerTest.java b/src/test/java/com/moabam/api/presentation/ProductControllerTest.java index 82f04f8d..554b9b6b 100644 --- a/src/test/java/com/moabam/api/presentation/ProductControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/ProductControllerTest.java @@ -1,6 +1,6 @@ package com.moabam.api.presentation; -import static com.moabam.fixture.ProductFixture.*; +import static com.moabam.support.fixture.ProductFixture.*; import static java.nio.charset.StandardCharsets.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; diff --git a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java index 31ce6517..cb9986b1 100644 --- a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java @@ -34,8 +34,8 @@ import com.moabam.api.dto.CreateRoomRequest; import com.moabam.api.dto.EnterRoomRequest; import com.moabam.api.dto.ModifyRoomRequest; -import com.moabam.fixture.BugFixture; -import com.moabam.fixture.MemberFixture; +import com.moabam.support.fixture.BugFixture; +import com.moabam.support.fixture.MemberFixture; @Transactional @SpringBootTest diff --git a/src/test/java/com/moabam/fixture/AuthorizationTokenResponseFixture.java b/src/test/java/com/moabam/support/fixture/AuthorizationTokenResponseFixture.java similarity index 94% rename from src/test/java/com/moabam/fixture/AuthorizationTokenResponseFixture.java rename to src/test/java/com/moabam/support/fixture/AuthorizationTokenResponseFixture.java index ecfa1506..62469489 100644 --- a/src/test/java/com/moabam/fixture/AuthorizationTokenResponseFixture.java +++ b/src/test/java/com/moabam/support/fixture/AuthorizationTokenResponseFixture.java @@ -1,4 +1,4 @@ -package com.moabam.fixture; +package com.moabam.support.fixture; import com.moabam.api.dto.AuthorizationTokenResponse; diff --git a/src/test/java/com/moabam/fixture/BugFixture.java b/src/test/java/com/moabam/support/fixture/BugFixture.java similarity index 90% rename from src/test/java/com/moabam/fixture/BugFixture.java rename to src/test/java/com/moabam/support/fixture/BugFixture.java index 8d2b8703..91eb772e 100644 --- a/src/test/java/com/moabam/fixture/BugFixture.java +++ b/src/test/java/com/moabam/support/fixture/BugFixture.java @@ -1,4 +1,4 @@ -package com.moabam.fixture; +package com.moabam.support.fixture; import com.moabam.api.domain.entity.Bug; diff --git a/src/test/java/com/moabam/fixture/InventoryFixture.java b/src/test/java/com/moabam/support/fixture/InventoryFixture.java similarity index 88% rename from src/test/java/com/moabam/fixture/InventoryFixture.java rename to src/test/java/com/moabam/support/fixture/InventoryFixture.java index 357443dc..9c060c20 100644 --- a/src/test/java/com/moabam/fixture/InventoryFixture.java +++ b/src/test/java/com/moabam/support/fixture/InventoryFixture.java @@ -1,4 +1,4 @@ -package com.moabam.fixture; +package com.moabam.support.fixture; import com.moabam.api.domain.entity.Inventory; import com.moabam.api.domain.entity.Item; diff --git a/src/test/java/com/moabam/fixture/ItemFixture.java b/src/test/java/com/moabam/support/fixture/ItemFixture.java similarity index 97% rename from src/test/java/com/moabam/fixture/ItemFixture.java rename to src/test/java/com/moabam/support/fixture/ItemFixture.java index 96e3f821..24cf29c4 100644 --- a/src/test/java/com/moabam/fixture/ItemFixture.java +++ b/src/test/java/com/moabam/support/fixture/ItemFixture.java @@ -1,4 +1,4 @@ -package com.moabam.fixture; +package com.moabam.support.fixture; import com.moabam.api.domain.entity.Item; import com.moabam.api.domain.entity.enums.ItemCategory; diff --git a/src/test/java/com/moabam/fixture/MemberFixture.java b/src/test/java/com/moabam/support/fixture/MemberFixture.java similarity index 92% rename from src/test/java/com/moabam/fixture/MemberFixture.java rename to src/test/java/com/moabam/support/fixture/MemberFixture.java index 02c5d84a..b074be4f 100644 --- a/src/test/java/com/moabam/fixture/MemberFixture.java +++ b/src/test/java/com/moabam/support/fixture/MemberFixture.java @@ -1,4 +1,4 @@ -package com.moabam.fixture; +package com.moabam.support.fixture; import com.moabam.api.domain.entity.Member; diff --git a/src/test/java/com/moabam/fixture/ProductFixture.java b/src/test/java/com/moabam/support/fixture/ProductFixture.java similarity index 93% rename from src/test/java/com/moabam/fixture/ProductFixture.java rename to src/test/java/com/moabam/support/fixture/ProductFixture.java index 91170206..e8b2b3fd 100644 --- a/src/test/java/com/moabam/fixture/ProductFixture.java +++ b/src/test/java/com/moabam/support/fixture/ProductFixture.java @@ -1,4 +1,4 @@ -package com.moabam.fixture; +package com.moabam.support.fixture; import com.moabam.api.domain.entity.Product; import com.moabam.api.domain.entity.enums.ProductType; From 2ba7aaf1bd56eba0f585b2e4d27aba4783687805 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sun, 5 Nov 2023 18:07:08 +0900 Subject: [PATCH 17/24] =?UTF-8?q?test:=20RepositoryTest=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EB=B0=8F=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InventorySearchRepositoryTest.java | 12 +++---- .../repository/ItemSearchRepositoryTest.java | 12 +++---- .../support/annotation/RepositoryTest.java | 19 ++++++++++ .../support/config/TestQueryDslConfig.java | 35 +++++++++++++++++++ 4 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 src/test/java/com/moabam/support/annotation/RepositoryTest.java create mode 100644 src/test/java/com/moabam/support/config/TestQueryDslConfig.java diff --git a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java index b5fb581c..70f2b0c3 100644 --- a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java @@ -9,24 +9,22 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; import com.moabam.api.domain.entity.Item; import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.support.annotation.RepositoryTest; -@SpringBootTest -@Transactional(readOnly = true) +@RepositoryTest class InventorySearchRepositoryTest { @Autowired - ItemRepository itemRepository; + InventorySearchRepository inventorySearchRepository; @Autowired - InventoryRepository inventoryRepository; + ItemRepository itemRepository; @Autowired - InventorySearchRepository inventorySearchRepository; + InventoryRepository inventoryRepository; @DisplayName("타입으로 인벤토리에 있는 아이템 목록을 구매일 순으로 조회한다.") @Test diff --git a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java index 5ba2c245..345f10eb 100644 --- a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java @@ -9,24 +9,22 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; import com.moabam.api.domain.entity.Item; import com.moabam.api.domain.entity.enums.RoomType; +import com.moabam.support.annotation.RepositoryTest; -@SpringBootTest -@Transactional(readOnly = true) +@RepositoryTest class ItemSearchRepositoryTest { @Autowired - ItemRepository itemRepository; + ItemSearchRepository itemSearchRepository; @Autowired - InventoryRepository inventoryRepository; + ItemRepository itemRepository; @Autowired - ItemSearchRepository itemSearchRepository; + InventoryRepository inventoryRepository; @DisplayName("타입으로 구매하지 않은 아이템 목록을 조회한다.") @Test diff --git a/src/test/java/com/moabam/support/annotation/RepositoryTest.java b/src/test/java/com/moabam/support/annotation/RepositoryTest.java new file mode 100644 index 00000000..82a5288a --- /dev/null +++ b/src/test/java/com/moabam/support/annotation/RepositoryTest.java @@ -0,0 +1,19 @@ +package com.moabam.support.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +import com.moabam.support.config.TestQueryDslConfig; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Import(TestQueryDslConfig.class) +@DataJpaTest +public @interface RepositoryTest { + +} diff --git a/src/test/java/com/moabam/support/config/TestQueryDslConfig.java b/src/test/java/com/moabam/support/config/TestQueryDslConfig.java new file mode 100644 index 00000000..6510bb8e --- /dev/null +++ b/src/test/java/com/moabam/support/config/TestQueryDslConfig.java @@ -0,0 +1,35 @@ +package com.moabam.support.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +import com.moabam.api.domain.repository.InventorySearchRepository; +import com.moabam.api.domain.repository.ItemSearchRepository; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + +@EnableJpaAuditing +@TestConfiguration +public class TestQueryDslConfig { + + @PersistenceContext + private EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } + + @Bean + public ItemSearchRepository itemSearchRepository() { + return new ItemSearchRepository(jpaQueryFactory()); + } + + @Bean + public InventorySearchRepository inventorySearchRepository() { + return new InventorySearchRepository(jpaQueryFactory()); + } +} From 2d008d8e2543c8e2006d03c6c309e7833b6c1144 Mon Sep 17 00:00:00 2001 From: kmebin Date: Sun, 5 Nov 2023 18:24:04 +0900 Subject: [PATCH 18/24] =?UTF-8?q?test:=20=EB=8F=99=EC=9D=BC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20Nested?= =?UTF-8?q?=EB=A1=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/application/BugServiceTest.java | 4 +- .../InventorySearchRepositoryTest.java | 66 +++++---- .../repository/ItemSearchRepositoryTest.java | 134 +++++++++--------- 3 files changed, 108 insertions(+), 96 deletions(-) diff --git a/src/test/java/com/moabam/api/application/BugServiceTest.java b/src/test/java/com/moabam/api/application/BugServiceTest.java index a06fd729..72c06ae6 100644 --- a/src/test/java/com/moabam/api/application/BugServiceTest.java +++ b/src/test/java/com/moabam/api/application/BugServiceTest.java @@ -1,5 +1,6 @@ package com.moabam.api.application; +import static com.moabam.support.fixture.MemberFixture.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; @@ -13,7 +14,6 @@ import com.moabam.api.domain.entity.Bug; import com.moabam.api.domain.entity.Member; import com.moabam.api.dto.BugResponse; -import com.moabam.support.fixture.MemberFixture; @ExtendWith(MockitoExtension.class) class BugServiceTest { @@ -29,7 +29,7 @@ class BugServiceTest { void get_bug_success() { // given Long memberId = 1L; - Member member = MemberFixture.member(); + Member member = member(); given(memberService.getById(memberId)).willReturn(member); // when diff --git a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java index 70f2b0c3..5546fe0b 100644 --- a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java @@ -7,6 +7,7 @@ import java.util.List; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -26,40 +27,45 @@ class InventorySearchRepositoryTest { @Autowired InventoryRepository inventoryRepository; - @DisplayName("타입으로 인벤토리에 있는 아이템 목록을 구매일 순으로 조회한다.") - @Test - void find_items_success() { - // given - Long memberId = 1L; - Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); - inventoryRepository.save(inventory(memberId, morningSantaSkin)); - Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); - inventoryRepository.save(inventory(memberId, morningKillerSkin)); - Item nightMageSkin = itemRepository.save(nightMageSkin()); - inventoryRepository.save(inventory(memberId, nightMageSkin)); + @DisplayName("인벤토리 아이템 목록을 조회한다.") + @Nested + class find_items { - // when - List actual = inventorySearchRepository.findItems(memberId, RoomType.MORNING); + @DisplayName("해당 타입의 아이템 목록을 구매일 순으로 정렬한다.") + @Test + void sorted_by_created_at_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); + inventoryRepository.save(inventory(memberId, morningSantaSkin)); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); + inventoryRepository.save(inventory(memberId, morningKillerSkin)); + Item nightMageSkin = itemRepository.save(nightMageSkin()); + inventoryRepository.save(inventory(memberId, nightMageSkin)); - // then - assertThat(actual).hasSize(2) - .containsExactly(morningKillerSkin, morningSantaSkin); - } + // when + List actual = inventorySearchRepository.findItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(2) + .containsExactly(morningKillerSkin, morningSantaSkin); + } - @DisplayName("인벤토리에 해당하는 타입의 아이템이 없으면 빈 목록을 조회한다.") - @Test - void find_empty_success() { - // given - Long memberId = 1L; - Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); - inventoryRepository.save(inventory(memberId, morningSantaSkin)); - Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); - inventoryRepository.save(inventory(memberId, morningKillerSkin)); + @DisplayName("해당 타입의 아이템이 없으면 빈 목록을 조회한다.") + @Test + void empty_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); + inventoryRepository.save(inventory(memberId, morningSantaSkin)); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); + inventoryRepository.save(inventory(memberId, morningKillerSkin)); - // when - List actual = inventorySearchRepository.findItems(memberId, RoomType.NIGHT); + // when + List actual = inventorySearchRepository.findItems(memberId, RoomType.NIGHT); - // then - assertThat(actual).isEmpty(); + // then + assertThat(actual).isEmpty(); + } } } diff --git a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java index 345f10eb..52c3bdfa 100644 --- a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java @@ -7,6 +7,7 @@ import java.util.List; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -26,69 +27,74 @@ class ItemSearchRepositoryTest { @Autowired InventoryRepository inventoryRepository; - @DisplayName("타입으로 구매하지 않은 아이템 목록을 조회한다.") - @Test - void find_not_purchased_items_success() { - // given - Long memberId = 1L; - Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); - inventoryRepository.save(inventory(memberId, morningSantaSkin)); - Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); - itemRepository.save(nightMageSkin()); - - // when - List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); - - // then - assertThat(actual).hasSize(1) - .containsExactly(morningKillerSkin); - } - - @DisplayName("구매하지 않은 아이템 목록은 레벨 순으로 정렬된다.") - @Test - void find_not_purchased_items_sorted_by_level_success() { - // given - Long memberId = 1L; - Item morningSantaSkin = itemRepository.save(morningSantaSkin().unlockLevel(5).build()); - Item morningKillerSkin = itemRepository.save(morningKillerSkin().unlockLevel(1).build()); - - // when - List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); - - // then - assertThat(actual).hasSize(2) - .containsExactly(morningKillerSkin, morningSantaSkin); - } - - @DisplayName("레벨이 같으면 가격 순으로 정렬된다.") - @Test - void find_not_purchased_items_sorted_by_price_success() { - // given - Long memberId = 1L; - Item morningSantaSkin = itemRepository.save(morningSantaSkin().bugPrice(10).build()); - Item morningKillerSkin = itemRepository.save(morningKillerSkin().bugPrice(20).build()); - - // when - List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); - - // then - assertThat(actual).hasSize(2) - .containsExactly(morningSantaSkin, morningKillerSkin); - } - - @DisplayName("레벨과 가격이 같으면 이름 순으로 정렬된다.") - @Test - void find_not_purchased_items_sorted_by_name_success() { - // given - Long memberId = 1L; - Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); - Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); - - // when - List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); - - // then - assertThat(actual).hasSize(2) - .containsExactly(morningSantaSkin, morningKillerSkin); + @DisplayName("구매하지 않은 아이템 목록을 조회한다.") + @Nested + class find_not_purchased_items { + + @DisplayName("해당 타입의 구매하지 않은 아이템 목록을 조회한다.") + @Test + void success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); + inventoryRepository.save(inventory(memberId, morningSantaSkin)); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); + itemRepository.save(nightMageSkin()); + + // when + List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(1) + .containsExactly(morningKillerSkin); + } + + @DisplayName("구매하지 않은 아이템 목록은 레벨 순으로 정렬된다.") + @Test + void sorted_by_level_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().unlockLevel(5).build()); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().unlockLevel(1).build()); + + // when + List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(2) + .containsExactly(morningKillerSkin, morningSantaSkin); + } + + @DisplayName("레벨이 같으면 가격 순으로 정렬된다.") + @Test + void sorted_by_price_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().bugPrice(10).build()); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().bugPrice(20).build()); + + // when + List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(2) + .containsExactly(morningSantaSkin, morningKillerSkin); + } + + @DisplayName("레벨과 가격이 같으면 이름 순으로 정렬된다.") + @Test + void sorted_by_name_success() { + // given + Long memberId = 1L; + Item morningSantaSkin = itemRepository.save(morningSantaSkin().build()); + Item morningKillerSkin = itemRepository.save(morningKillerSkin().build()); + + // when + List actual = itemSearchRepository.findNotPurchasedItems(memberId, RoomType.MORNING); + + // then + assertThat(actual).hasSize(2) + .containsExactly(morningSantaSkin, morningKillerSkin); + } } } From 42c13bb060576ca26ab0ffaf99bcd6dc6f416272 Mon Sep 17 00:00:00 2001 From: kmebin Date: Mon, 6 Nov 2023 12:14:56 +0900 Subject: [PATCH 19/24] =?UTF-8?q?feat:=20=ED=98=84=EC=9E=AC=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=EB=90=9C=20=EC=9D=B8=EB=B2=A4=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/moabam/api/application/ItemService.java | 3 ++- src/main/java/com/moabam/api/domain/entity/Inventory.java | 5 +++++ .../api/domain/repository/InventorySearchRepository.java | 3 ++- .../java/com/moabam/api/application/ItemServiceTest.java | 7 ++++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/moabam/api/application/ItemService.java b/src/main/java/com/moabam/api/application/ItemService.java index c9ee541e..493aed65 100644 --- a/src/main/java/com/moabam/api/application/ItemService.java +++ b/src/main/java/com/moabam/api/application/ItemService.java @@ -33,10 +33,11 @@ public ItemsResponse getItems(Long memberId, RoomType type) { return ItemMapper.toItemsResponse(purchasedItems, notPurchasedItems); } + @Transactional public void selectItem(Long memberId, Long itemId) { Inventory inventory = getInventory(memberId, itemId); - inventorySearchRepository.findDefault(memberId) + inventorySearchRepository.findDefault(memberId, inventory.getItemType()) .ifPresent(Inventory::unsetDefault); inventory.setDefault(); } diff --git a/src/main/java/com/moabam/api/domain/entity/Inventory.java b/src/main/java/com/moabam/api/domain/entity/Inventory.java index 724c8afd..a6f7fbd3 100644 --- a/src/main/java/com/moabam/api/domain/entity/Inventory.java +++ b/src/main/java/com/moabam/api/domain/entity/Inventory.java @@ -4,6 +4,7 @@ import org.hibernate.annotations.ColumnDefault; +import com.moabam.api.domain.entity.enums.RoomType; import com.moabam.global.common.entity.BaseTimeEntity; import jakarta.persistence.Column; @@ -50,6 +51,10 @@ private Inventory(Long memberId, Item item, boolean isDefault) { this.isDefault = isDefault; } + public RoomType getItemType() { + return this.item.getType(); + } + public void setDefault() { this.isDefault = true; } diff --git a/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java b/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java index 8ba35fee..555d3286 100644 --- a/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java +++ b/src/main/java/com/moabam/api/domain/repository/InventorySearchRepository.java @@ -32,11 +32,12 @@ public Optional findOne(Long memberId, Long itemId) { ); } - public Optional findDefault(Long memberId) { + public Optional findDefault(Long memberId, RoomType type) { return Optional.ofNullable( jpaQueryFactory.selectFrom(inventory) .where( DynamicQuery.generateEq(memberId, inventory.memberId::eq), + DynamicQuery.generateEq(type, inventory.item.type::eq), inventory.isDefault.isTrue()) .fetchOne() ); diff --git a/src/test/java/com/moabam/api/application/ItemServiceTest.java b/src/test/java/com/moabam/api/application/ItemServiceTest.java index 97c6e1ac..94e4b165 100644 --- a/src/test/java/com/moabam/api/application/ItemServiceTest.java +++ b/src/test/java/com/moabam/api/application/ItemServiceTest.java @@ -63,7 +63,7 @@ void get_products_success() { @DisplayName("아이템을 적용한다.") @Nested - class select_item { + class SelectItem { @DisplayName("성공한다.") @Test @@ -73,15 +73,16 @@ void success() { Long itemId = 1L; Inventory inventory = InventoryFixture.inventory(memberId, nightMageSkin()); Inventory defaultInventory = InventoryFixture.inventory(memberId, nightMageSkin()); + RoomType itemType = inventory.getItemType(); when(inventorySearchRepository.findOne(memberId, itemId)).thenReturn(Optional.of(inventory)); - when(inventorySearchRepository.findDefault(memberId)).thenReturn(Optional.of(defaultInventory)); + when(inventorySearchRepository.findDefault(memberId, itemType)).thenReturn(Optional.of(defaultInventory)); // when itemService.selectItem(memberId, itemId); // then verify(inventorySearchRepository).findOne(memberId, itemId); - verify(inventorySearchRepository).findDefault(memberId); + verify(inventorySearchRepository).findDefault(memberId, itemType); assertFalse(defaultInventory.isDefault()); assertTrue(inventory.isDefault()); } From d4d5e71043c83d6d7b24e4ebfe613c04731299ac Mon Sep 17 00:00:00 2001 From: kmebin Date: Mon, 6 Nov 2023 12:15:25 +0900 Subject: [PATCH 20/24] =?UTF-8?q?test:=20=EC=9D=B8=EB=B2=A4=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20Repository=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InventorySearchRepositoryTest.java | 40 ++++++++++++++++++- .../repository/ItemSearchRepositoryTest.java | 2 +- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java index 5546fe0b..2efbd41e 100644 --- a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java @@ -2,16 +2,20 @@ import static com.moabam.support.fixture.InventoryFixture.*; import static com.moabam.support.fixture.ItemFixture.*; +import static com.moabam.support.fixture.MemberFixture.*; import static org.assertj.core.api.Assertions.*; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import com.moabam.api.domain.entity.Inventory; import com.moabam.api.domain.entity.Item; +import com.moabam.api.domain.entity.Member; import com.moabam.api.domain.entity.enums.RoomType; import com.moabam.support.annotation.RepositoryTest; @@ -21,6 +25,9 @@ class InventorySearchRepositoryTest { @Autowired InventorySearchRepository inventorySearchRepository; + @Autowired + MemberRepository memberRepository; + @Autowired ItemRepository itemRepository; @@ -29,7 +36,7 @@ class InventorySearchRepositoryTest { @DisplayName("인벤토리 아이템 목록을 조회한다.") @Nested - class find_items { + class FindItems { @DisplayName("해당 타입의 아이템 목록을 구매일 순으로 정렬한다.") @Test @@ -68,4 +75,35 @@ void empty_success() { assertThat(actual).isEmpty(); } } + + @DisplayName("인벤토리를 조회한다.") + @Test + void find_one_success() { + // given + Member member = memberRepository.save(member()); + Item item = itemRepository.save(nightMageSkin()); + Inventory inventory = inventoryRepository.save(inventory(member.getId(), item)); + + // when + Optional actual = inventorySearchRepository.findOne(member.getId(), item.getId()); + + // then + assertThat(actual).isPresent().contains(inventory); + } + + @DisplayName("현재 적용된 인벤토리를 조회한다.") + @Test + void find_default_success() { + // given + Member member = memberRepository.save(member()); + Item item = itemRepository.save(nightMageSkin()); + Inventory inventory = inventoryRepository.save(inventory(member.getId(), item)); + inventory.setDefault(); + + // when + Optional actual = inventorySearchRepository.findDefault(member.getId(), inventory.getItemType()); + + // then + assertThat(actual).isPresent().contains(inventory); + } } diff --git a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java index 52c3bdfa..74f5412f 100644 --- a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java @@ -29,7 +29,7 @@ class ItemSearchRepositoryTest { @DisplayName("구매하지 않은 아이템 목록을 조회한다.") @Nested - class find_not_purchased_items { + class FindNotPurchasedItems { @DisplayName("해당 타입의 구매하지 않은 아이템 목록을 조회한다.") @Test From dcd87fd2fc5b09517b24187478da2011a697e5bb Mon Sep 17 00:00:00 2001 From: kmebin Date: Mon, 6 Nov 2023 22:30:46 +0900 Subject: [PATCH 21/24] =?UTF-8?q?fix:=20merge=20conflict=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/error/handler/GlobalExceptionHandler.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/com/moabam/global/error/handler/GlobalExceptionHandler.java b/src/main/java/com/moabam/global/error/handler/GlobalExceptionHandler.java index 02ef6b22..b641f69b 100644 --- a/src/main/java/com/moabam/global/error/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/moabam/global/error/handler/GlobalExceptionHandler.java @@ -92,15 +92,4 @@ public ErrorResponse handleMethodArgumentTypeMismatchException(MethodArgumentTyp return new ErrorResponse(message, null); } - - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(MethodArgumentTypeMismatchException.class) - public ErrorResponse handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException exception) { - String typeName = Optional.ofNullable(exception.getRequiredType()) - .map(Class::getSimpleName) - .orElse(""); - String message = String.format("'%s' 값은 유효한 %s 값이 아닙니다.", exception.getValue(), typeName); - - return new ErrorResponse(message, null); - } } From 1f1f5b53396ec22ada0b89fbea50b86b963642b3 Mon Sep 17 00:00:00 2001 From: kmebin Date: Tue, 7 Nov 2023 15:28:50 +0900 Subject: [PATCH 22/24] =?UTF-8?q?test:=20given-willReturn=20=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/moabam/api/application/ItemServiceTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/moabam/api/application/ItemServiceTest.java b/src/test/java/com/moabam/api/application/ItemServiceTest.java index 2feee52e..b07741a8 100644 --- a/src/test/java/com/moabam/api/application/ItemServiceTest.java +++ b/src/test/java/com/moabam/api/application/ItemServiceTest.java @@ -74,8 +74,8 @@ void success() { Inventory inventory = InventoryFixture.inventory(memberId, nightMageSkin()); Inventory defaultInventory = InventoryFixture.inventory(memberId, nightMageSkin()); ItemType itemType = inventory.getItemType(); - when(inventorySearchRepository.findOne(memberId, itemId)).thenReturn(Optional.of(inventory)); - when(inventorySearchRepository.findDefault(memberId, itemType)).thenReturn(Optional.of(defaultInventory)); + given(inventorySearchRepository.findOne(memberId, itemId)).willReturn(Optional.of(inventory)); + given(inventorySearchRepository.findDefault(memberId, itemType)).willReturn(Optional.of(defaultInventory)); // when itemService.selectItem(memberId, itemId); @@ -93,7 +93,7 @@ void exception() { // given Long memberId = 1L; Long itemId = 1L; - when(inventorySearchRepository.findOne(memberId, itemId)).thenReturn(Optional.empty()); + given(inventorySearchRepository.findOne(memberId, itemId)).willReturn(Optional.empty()); // when, then assertThatThrownBy(() -> itemService.selectItem(memberId, itemId)) From a1362d701261bb660bf79fc580abb7e9d979b5f5 Mon Sep 17 00:00:00 2001 From: kmebin Date: Tue, 7 Nov 2023 16:11:45 +0900 Subject: [PATCH 23/24] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/moabam/api/application/ItemService.java | 4 ++-- src/main/java/com/moabam/api/domain/entity/Inventory.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/moabam/api/application/ItemService.java b/src/main/java/com/moabam/api/application/ItemService.java index 272ab47f..4ba1203e 100644 --- a/src/main/java/com/moabam/api/application/ItemService.java +++ b/src/main/java/com/moabam/api/application/ItemService.java @@ -38,8 +38,8 @@ public void selectItem(Long memberId, Long itemId) { Inventory inventory = getInventory(memberId, itemId); inventorySearchRepository.findDefault(memberId, inventory.getItemType()) - .ifPresent(Inventory::unsetDefault); - inventory.setDefault(); + .ifPresent(Inventory::deselect); + inventory.select(); } private Inventory getInventory(Long memberId, Long itemId) { diff --git a/src/main/java/com/moabam/api/domain/entity/Inventory.java b/src/main/java/com/moabam/api/domain/entity/Inventory.java index 91fe9c61..dd493564 100644 --- a/src/main/java/com/moabam/api/domain/entity/Inventory.java +++ b/src/main/java/com/moabam/api/domain/entity/Inventory.java @@ -55,11 +55,11 @@ public ItemType getItemType() { return this.item.getType(); } - public void setDefault() { + public void select() { this.isDefault = true; } - public void unsetDefault() { + public void deselect() { this.isDefault = false; } } From 051f695b1f2275bd9391ac1557a774d28b773088 Mon Sep 17 00:00:00 2001 From: kmebin Date: Tue, 7 Nov 2023 16:13:49 +0900 Subject: [PATCH 24/24] =?UTF-8?q?refactor:=20=EC=96=B4=EB=85=B8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/InventorySearchRepositoryTest.java | 6 +++--- .../api/domain/repository/ItemSearchRepositoryTest.java | 4 ++-- .../{RepositoryTest.java => QuerydslRepositoryTest.java} | 6 +++--- .../{TestQueryDslConfig.java => TestQuerydslConfig.java} | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) rename src/test/java/com/moabam/support/annotation/{RepositoryTest.java => QuerydslRepositoryTest.java} (75%) rename src/test/java/com/moabam/support/config/{TestQueryDslConfig.java => TestQuerydslConfig.java} (96%) diff --git a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java index 502eea71..c8e78153 100644 --- a/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/InventorySearchRepositoryTest.java @@ -17,9 +17,9 @@ import com.moabam.api.domain.entity.Item; import com.moabam.api.domain.entity.Member; import com.moabam.api.domain.entity.enums.ItemType; -import com.moabam.support.annotation.RepositoryTest; +import com.moabam.support.annotation.QuerydslRepositoryTest; -@RepositoryTest +@QuerydslRepositoryTest class InventorySearchRepositoryTest { @Autowired @@ -98,7 +98,7 @@ void find_default_success() { Member member = memberRepository.save(member()); Item item = itemRepository.save(nightMageSkin()); Inventory inventory = inventoryRepository.save(inventory(member.getId(), item)); - inventory.setDefault(); + inventory.select(); // when Optional actual = inventorySearchRepository.findDefault(member.getId(), inventory.getItemType()); diff --git a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java index 3ff04ec5..a1bc7751 100644 --- a/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/repository/ItemSearchRepositoryTest.java @@ -13,9 +13,9 @@ import com.moabam.api.domain.entity.Item; import com.moabam.api.domain.entity.enums.ItemType; -import com.moabam.support.annotation.RepositoryTest; +import com.moabam.support.annotation.QuerydslRepositoryTest; -@RepositoryTest +@QuerydslRepositoryTest class ItemSearchRepositoryTest { @Autowired diff --git a/src/test/java/com/moabam/support/annotation/RepositoryTest.java b/src/test/java/com/moabam/support/annotation/QuerydslRepositoryTest.java similarity index 75% rename from src/test/java/com/moabam/support/annotation/RepositoryTest.java rename to src/test/java/com/moabam/support/annotation/QuerydslRepositoryTest.java index 82a5288a..254439c4 100644 --- a/src/test/java/com/moabam/support/annotation/RepositoryTest.java +++ b/src/test/java/com/moabam/support/annotation/QuerydslRepositoryTest.java @@ -8,12 +8,12 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import com.moabam.support.config.TestQueryDslConfig; +import com.moabam.support.config.TestQuerydslConfig; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -@Import(TestQueryDslConfig.class) +@Import(TestQuerydslConfig.class) @DataJpaTest -public @interface RepositoryTest { +public @interface QuerydslRepositoryTest { } diff --git a/src/test/java/com/moabam/support/config/TestQueryDslConfig.java b/src/test/java/com/moabam/support/config/TestQuerydslConfig.java similarity index 96% rename from src/test/java/com/moabam/support/config/TestQueryDslConfig.java rename to src/test/java/com/moabam/support/config/TestQuerydslConfig.java index 6510bb8e..fb7d6d8f 100644 --- a/src/test/java/com/moabam/support/config/TestQueryDslConfig.java +++ b/src/test/java/com/moabam/support/config/TestQuerydslConfig.java @@ -13,7 +13,7 @@ @EnableJpaAuditing @TestConfiguration -public class TestQueryDslConfig { +public class TestQuerydslConfig { @PersistenceContext private EntityManager entityManager;