diff --git a/samples/web-csr/dressca-backend/.vscode/settings.json b/samples/web-csr/dressca-backend/.vscode/settings.json index 36a9dbdb5..dfe9d9c5f 100644 --- a/samples/web-csr/dressca-backend/.vscode/settings.json +++ b/samples/web-csr/dressca-backend/.vscode/settings.json @@ -2,15 +2,28 @@ "java.dependency.packagePresentation": "hierarchical", "java.configuration.updateBuildConfiguration": "automatic", "java.checkstyle.configuration": "${workspaceFolder}\\config\\checkstyle\\checkstyle.xml", + "java.format.settings.url": "${workspaceFolder}\\config\\formatter\\eclipse-formatter.xml", "cSpell.words": [ + "Appender", "applicationcore", + "assertj", "Batis", "controlleradvice", "Dressca", + "Incrementer", + "jdbc", "Mybatis", "Servlet", "shikuchoson", + "skiprows", + "springframework", "systemcommon", - "todofuken" - ] + "tasklet", + "todofuken", + ], + "[java]" : { + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.formatOnType": true + } } \ No newline at end of file diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/accounting/Account.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/accounting/Account.java index 2bee87a0b..bfbe661e4 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/accounting/Account.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/accounting/Account.java @@ -3,7 +3,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; - import lombok.Value; /** @@ -25,8 +24,8 @@ public BigDecimal getItemTotalPrice() { } /** - * 税抜きの送料を取得します。 送料は会計アイテムの合計金額が 5,000 円以上で無料になります。 それ以外の場合 500 円です。 ただし、会計アイテムが登録されていない場合は 0 - * 円を返します。 + * 税抜きの送料を取得します。 送料は会計アイテムの合計金額が 5,000 円以上で無料になります。 それ以外の場合 500 円です。 + * ただし、会計アイテムが登録されていない場合は 0 円を返します。 * * @return 送料 */ diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/accounting/AccountItem.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/accounting/AccountItem.java index 8f85db43f..4833a15f0 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/accounting/AccountItem.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/accounting/AccountItem.java @@ -1,10 +1,12 @@ package com.dressca.applicationcore.accounting; import java.math.BigDecimal; - import lombok.AllArgsConstructor; import lombok.Data; +/** + * 会計情報のドメインモデルです。 + */ @Data @AllArgsConstructor public class AccountItem { diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetApplicationService.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetApplicationService.java index 084961107..04c3edc59 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetApplicationService.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetApplicationService.java @@ -3,7 +3,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.stereotype.Service; - import lombok.AllArgsConstructor; /** @@ -12,7 +11,7 @@ @Service @AllArgsConstructor public class AssetApplicationService { - + @Autowired private AssetRepository repository; @Autowired @@ -30,7 +29,7 @@ public AssetResourceInfo getAssetResourceInfo(String assetCode) throws AssetNotF .orElseThrow(() -> new AssetNotFoundException(assetCode)); Resource resource = this.store.getResource(asset) .orElseThrow(() -> new AssetNotFoundException(assetCode)); - + return new AssetResourceInfo(asset, resource); } } diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetNotFoundException.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetNotFoundException.java index ded45c2e3..58916709a 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetNotFoundException.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetNotFoundException.java @@ -14,7 +14,7 @@ public class AssetNotFoundException extends LogicException { * @param assetCode 見つからなかった買い物かご Id */ public AssetNotFoundException(String assetCode) { - super(null, ExceptionIdConstant.E_ASSET0001, new String[] {assetCode}, - new String[] {assetCode}); + super(null, ExceptionIdConstant.E_ASSET0001, new String[] { assetCode }, + new String[] { assetCode }); } } diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetRepository.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetRepository.java index e6922f761..6e3a6bc6d 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetRepository.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetRepository.java @@ -6,7 +6,7 @@ * アセットリポジトリ。 */ public interface AssetRepository { - + /** * 指定したアセットコードの情報を取得します。 * 存在しない場合は 空のOptional を返します。 diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetResourceInfo.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetResourceInfo.java index 26428773b..01f195e86 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetResourceInfo.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetResourceInfo.java @@ -1,7 +1,6 @@ package com.dressca.applicationcore.assets; import org.springframework.core.io.Resource; - import lombok.Data; import lombok.NonNull; diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetStore.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetStore.java index feac08c36..e9789141a 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetStore.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetStore.java @@ -1,7 +1,6 @@ package com.dressca.applicationcore.assets; import java.util.Optional; - import org.springframework.core.io.Resource; /** diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetTypes.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetTypes.java index f4e617860..33918f50e 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetTypes.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/assets/AssetTypes.java @@ -1,7 +1,6 @@ package com.dressca.applicationcore.assets; import java.util.Set; - import org.apache.commons.lang3.StringUtils; /** diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/Basket.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/Basket.java index 88376858c..e9343cd20 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/Basket.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/Basket.java @@ -5,14 +5,15 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; - import com.dressca.applicationcore.accounting.Account; import com.dressca.applicationcore.accounting.AccountItem; - import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; +/** + * 買い物かごの情報を表現するドメインモデルです。 + */ @Data @NoArgsConstructor public class Basket { @@ -24,7 +25,7 @@ public class Basket { public Basket(@NonNull String buyerId) { this.buyerId = buyerId; } - + public Basket(long id, @NonNull String buyerId) { this.id = id; this.buyerId = buyerId; @@ -34,12 +35,12 @@ public Basket(long id, @NonNull String buyerId) { * 商品を追加します。 * * @param catalogItemId カタログアイテムID - * @param unitPrice 単価 - * @param quantity 数量 + * @param unitPrice 単価 + * @param quantity 数量 */ public void addItem(long catalogItemId, BigDecimal unitPrice, int quantity) { - Optional existingItem = - this.items.stream().filter(item -> item.getCatalogItemId() == catalogItemId).findFirst(); + Optional existingItem = this.items.stream().filter(item -> item.getCatalogItemId() == catalogItemId) + .findFirst(); existingItem.ifPresentOrElse(item -> item.addQuantity(quantity), () -> this.items.add(new BasketItem(0, id, catalogItemId, unitPrice, quantity))); diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketApplicationService.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketApplicationService.java index 08c5356ba..1298f94d9 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketApplicationService.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketApplicationService.java @@ -2,11 +2,13 @@ import java.math.BigDecimal; import java.util.Map; - import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import lombok.AllArgsConstructor; +/** + * 買い物かご情報に関するビジネスユースケースを実現するサービスです。 + */ @Service @AllArgsConstructor public class BasketApplicationService { @@ -15,10 +17,10 @@ public class BasketApplicationService { /** * 買い物かごに商品を追加します。 * - * @param basketId 買い物かごID + * @param basketId 買い物かごID * @param catalogItemId カタログ商品ID - * @param price 単価 - * @param quantity 数量 + * @param price 単価 + * @param quantity 数量 * @throws BasketNotFoundException 買い物かごが見つからなかった場合 */ public void addItemToBasket(long basketId, long catalogItemId, BigDecimal price, int quantity) @@ -47,7 +49,7 @@ public void deleteBasket(long basketId) throws BasketNotFoundException { /** * 買い物かご内の商品の数量を設定します。 * - * @param basketId 買い物かごID + * @param basketId 買い物かごID * @param quantities キーにカタログ商品ID、値に数量を設定したMap * @throws BasketNotFoundException 買い物かごが見つからなかった場合 */ diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketItem.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketItem.java index 4a002e7d6..9c3f813cb 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketItem.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketItem.java @@ -1,12 +1,14 @@ package com.dressca.applicationcore.baskets; import java.math.BigDecimal; - import com.dressca.applicationcore.accounting.AccountItem; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +/** + * 買い物かごアイテムのドメインモデルです。 + */ @Data @NoArgsConstructor @AllArgsConstructor diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketNotFoundException.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketNotFoundException.java index 82fcd7cf9..5412e079a 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketNotFoundException.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketNotFoundException.java @@ -3,9 +3,12 @@ import com.dressca.systemcommon.constant.ExceptionIdConstant; import com.dressca.systemcommon.exception.LogicException; +/** + * 買い物かごが存在しないことを表す例外クラスです。 + */ public class BasketNotFoundException extends LogicException { public BasketNotFoundException(long basketId) { - super(null, ExceptionIdConstant.E_BASKET0001, new String[] {String.valueOf(basketId)}, - new String[] {String.valueOf(basketId)}); + super(null, ExceptionIdConstant.E_BASKET0001, new String[] { String.valueOf(basketId) }, + new String[] { String.valueOf(basketId) }); } } diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketRepository.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketRepository.java index 61379d303..0857b9477 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketRepository.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/baskets/BasketRepository.java @@ -2,6 +2,9 @@ import java.util.Optional; +/** + * 買い物かごリポジトリ。 + */ public interface BasketRepository { Optional findById(long id); diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogApplicationService.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogApplicationService.java index 9d2c8ccd9..91169cba0 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogApplicationService.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogApplicationService.java @@ -1,11 +1,12 @@ package com.dressca.applicationcore.catalog; import java.util.List; - import org.springframework.stereotype.Service; - import lombok.AllArgsConstructor; +/** + * カタログ情報に関するビジネスユースケースを実現するサービスです。 + */ @Service @AllArgsConstructor public class CatalogApplicationService { @@ -16,10 +17,10 @@ public class CatalogApplicationService { /** * 条件に一致するカタログ情報を取得します。 * - * @param brandId ブランドID + * @param brandId ブランドID * @param categoryId カテゴリID - * @param page ページ - * @param pageSize ページサイズ + * @param page ページ + * @param pageSize ページサイズ * @return 条件に一致するカタログ情報のリスト。存在しない場合は空のリスト。 */ public List getCatalogItems(long brandId, long categoryId, int page, int pageSize) { @@ -29,7 +30,7 @@ public List getCatalogItems(long brandId, long categoryId, int page /** * 条件に一致するカテゴリの件数を取得します。 * - * @param brandId ブランドID + * @param brandId ブランドID * @param categoryId カテゴリID * @return 条件に一致するカタログ情報の件数。 */ diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogBrand.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogBrand.java index ac5f7658e..6bcc4d96a 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogBrand.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogBrand.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; - import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogBrandRepository.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogBrandRepository.java index 9cdd0f8bf..7bfcc02f4 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogBrandRepository.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogBrandRepository.java @@ -8,6 +8,7 @@ public interface CatalogBrandRepository { /** * すべてのカタログブランドを取得します。 + * * @return カタログブランドのリスト */ List getAll(); diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogCategory.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogCategory.java index f1663d091..08299de7f 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogCategory.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogCategory.java @@ -1,7 +1,6 @@ package com.dressca.applicationcore.catalog; import java.util.List; - import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -16,7 +15,7 @@ public class CatalogCategory { @NonNull private String name; private List items = List.of(); - + public CatalogCategory(@NonNull String name) { this.name = name; } diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogCategoryRepository.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogCategoryRepository.java index af1d314a5..7b15bc679 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogCategoryRepository.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogCategoryRepository.java @@ -8,6 +8,7 @@ public interface CatalogCategoryRepository { /** * すべてのカタログカテゴリを取得します。 + * * @return カタログカテゴリのリスト */ List getAll(); diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogDomainService.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogDomainService.java index 1ce3c8a28..9307a9c29 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogDomainService.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogDomainService.java @@ -2,9 +2,7 @@ import java.util.List; import java.util.stream.Collectors; - import org.springframework.stereotype.Service; - import lombok.AllArgsConstructor; /** @@ -17,7 +15,8 @@ public class CatalogDomainService { /** * 指定したカタログアイテム Id のうち、存在するカタログアイテムの一覧を返却します。 - * @param catalogItemIds カタログアイテム Id のリスト + * + * @param catalogItemIds カタログアイテム Id のリスト * @return 存在するカタログアイテムの一覧 */ public List getExistCatalogItems(List catalogItemIds) { @@ -26,6 +25,7 @@ public List getExistCatalogItems(List catalogItemIds) { /** * 指定したカタログアイテム Id がリポジトリ内にすべて存在するかを取得します。 + * * @param catalogItemIds カタログアイテム Id のリスト * @return すべて存在する場合は true、一部でも不在の場合は false。 */ @@ -34,7 +34,7 @@ public boolean existAll(List catalogItemIds) { List notExistCatalogItemIds = catalogItemIds.stream() .filter(catalogItemId -> !this.existCatalogItemIdInItems(items, catalogItemId)) .collect(Collectors.toList()); - + return notExistCatalogItemIds.isEmpty(); } diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogItem.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogItem.java index 11be24a06..706a2a73d 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogItem.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogItem.java @@ -3,7 +3,6 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; - import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -28,17 +27,17 @@ public class CatalogItem { private String productCode; private long catalogCategoryId; private long catalogBrandId; - + /** * コンストラクタ。 * - * @param id ID - * @param name 商品名 - * @param description 商品紹介 - * @param price 単価 - * @param productCode プロダクトコード + * @param id ID + * @param name 商品名 + * @param description 商品紹介 + * @param price 単価 + * @param productCode プロダクトコード * @param catalogCategoryId カタログ商品ID - * @param catalogBrandId カタログブランドID + * @param catalogBrandId カタログブランドID */ public CatalogItem(long id, @NonNull String name, @NonNull String description, @NonNull BigDecimal price, @NonNull String productCode, long catalogCategoryId, diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogItemAsset.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogItemAsset.java index 7a1a23190..2338c0582 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogItemAsset.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/catalog/CatalogItemAsset.java @@ -11,7 +11,7 @@ public class CatalogItemAsset { private long id; private long catalogItemId; private String assetCode; - + public CatalogItemAsset() { } @@ -23,9 +23,9 @@ public CatalogItemAsset(long catalogItemId, @NonNull String assetCode) { /** * コンストラクタ。 * - * @param id ID + * @param id ID * @param catalogItemId カタログ商品ID - * @param assetCode アセットコード + * @param assetCode アセットコード */ public CatalogItemAsset(long id, long catalogItemId, @NonNull String assetCode) { this.id = id; diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/CatalogItemOrdered.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/CatalogItemOrdered.java index eb7efd127..766e9024a 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/CatalogItemOrdered.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/CatalogItemOrdered.java @@ -6,7 +6,8 @@ /** * 注文されたカタログアイテムを管理する値オブジェクトです。 *

- * この値オブジェクトは、注文時点でのカタログアイテムエンティティのスナップショットです. これは、注文確定後にカタログ情報が変更されたとしても、注文情報は変更されるべきではないためです. + * この値オブジェクトは、注文時点でのカタログアイテムエンティティのスナップショットです. + * これは、注文確定後にカタログ情報が変更されたとしても、注文情報は変更されるべきではないためです. *

*/ @Value diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/Order.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/Order.java index e7cc4ee1a..3656d2835 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/Order.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/Order.java @@ -33,9 +33,9 @@ public class Order { /** * コンストラクタ。 * - * @param buyerId 顧客ID + * @param buyerId 顧客ID * @param shipToAddress 宛先住所 - * @param orderItems 商品リスト + * @param orderItems 商品リスト */ public Order(String buyerId, ShipTo shipToAddress, List orderItems) { this.buyerId = buyerId; @@ -54,19 +54,19 @@ public Order(String buyerId, ShipTo shipToAddress, List orderItems) { /** * コンストラクタ。 * - * @param id ID - * @param buyerId 顧客ID - * @param orderDate 注文日付 - * @param shipToAddress 宛先住所 + * @param id ID + * @param buyerId 顧客ID + * @param orderDate 注文日付 + * @param shipToAddress 宛先住所 * @param consumptionTaxRate 消費税率 - * @param totalItemsPrice 商品価格合計 - * @param deliveryCharge 送料 - * @param consumptionTax 消費税額 - * @param totalPrice 合計料金 - * @param orderItems 商品リスト + * @param totalItemsPrice 商品価格合計 + * @param deliveryCharge 送料 + * @param consumptionTax 消費税額 + * @param totalPrice 合計料金 + * @param orderItems 商品リスト */ public Order(long id, String buyerId, LocalDateTime orderDate, ShipTo shipToAddress, - BigDecimal consumptionTaxRate, BigDecimal totalItemsPrice, BigDecimal deliveryCharge, + BigDecimal consumptionTaxRate, BigDecimal totalItemsPrice, BigDecimal deliveryCharge, BigDecimal consumptionTax, BigDecimal totalPrice, List orderItems) { this.id = id; this.buyerId = buyerId; diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderApplicationService.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderApplicationService.java index 81b2d4238..4ff459421 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderApplicationService.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderApplicationService.java @@ -26,10 +26,10 @@ public class OrderApplicationService { /** * 注文を作成します。 * - * @param basketId 買い物かご Id. + * @param basketId 買い物かご Id. * @param shipToAddress お届け先. * @return 作成した注文情報. - * @throws BasketNotFoundException basketId に該当する買い物かごが存在しない場合. + * @throws BasketNotFoundException basketId に該当する買い物かごが存在しない場合. * @throws EmptyBasketOnCheckoutException basketId に該当する買い物かごが空の場合. */ public Order createOrder(long basketId, ShipTo shipToAddress) @@ -40,14 +40,14 @@ public Order createOrder(long basketId, ShipTo shipToAddress) throw new EmptyBasketOnCheckoutException(null); } - List catalogItemIds = - basket.getItems().stream().map(BasketItem::getCatalogItemId).collect(Collectors.toList()); + List catalogItemIds = basket.getItems().stream().map(BasketItem::getCatalogItemId) + .collect(Collectors.toList()); List catalogItems = this.catalogRepository.findByCatalogItemIdIn(catalogItemIds); List orderItems = basket.getItems().stream() .map(basketItems -> this.mapToOrderItem(basketItems, catalogItems)) .collect(Collectors.toList()); Order order = new Order(basket.getBuyerId(), shipToAddress, orderItems); - + return this.orderRepository.add(order); } @@ -75,8 +75,7 @@ private OrderItem mapToOrderItem(BasketItem basketItem, List catalo .orElseThrow(() -> new SystemException(null, ExceptionIdConstant.E_SHARE0000, null, null)); CatalogItemOrdered itemOrdered = new CatalogItemOrdered(catalogItem.getId(), catalogItem.getName(), catalogItem.getProductCode()); - OrderItem orderItem = - new OrderItem(itemOrdered, basketItem.getUnitPrice(), basketItem.getQuantity()); + OrderItem orderItem = new OrderItem(itemOrdered, basketItem.getUnitPrice(), basketItem.getQuantity()); List orderItemAssets = catalogItem.getAssets().stream() .map(asset -> new OrderItemAsset(asset.getAssetCode(), orderItem.getId())) .collect(Collectors.toList()); diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderItem.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderItem.java index 0f7c5091e..65b72109f 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderItem.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderItem.java @@ -28,8 +28,8 @@ public class OrderItem { * コンストラクタ。 * * @param itemOrdered 注文されたカタログアイテム - * @param bigDecimal 単価 - * @param quantity 数量 + * @param bigDecimal 単価 + * @param quantity 数量 */ public OrderItem(CatalogItemOrdered itemOrdered, BigDecimal bigDecimal, int quantity) { this.itemOrdered = itemOrdered; diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderItemAsset.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderItemAsset.java index 371530a71..9452c0792 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderItemAsset.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderItemAsset.java @@ -19,7 +19,7 @@ public class OrderItemAsset { /** * コンストラクタ。 * - * @param assetCode アセットコード. + * @param assetCode アセットコード. * @param orderItemId 注文アイテムId. */ public OrderItemAsset(String assetCode, long orderItemId) { diff --git a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderNotFoundException.java b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderNotFoundException.java index 3fc491d49..db1183b7c 100644 --- a/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderNotFoundException.java +++ b/samples/web-csr/dressca-backend/application-core/src/main/java/com/dressca/applicationcore/order/OrderNotFoundException.java @@ -9,15 +9,16 @@ public class OrderNotFoundException extends LogicException { /** - * 見つからなかった注文 Id と購入者 Id を指定して {@link OrderNotFoundException} クラスの新しいインスタンスを初期化します。 + * 見つからなかった注文 Id と購入者 Id を指定して {@link OrderNotFoundException} + * クラスの新しいインスタンスを初期化します。 * - * @param cause 原因例外 + * @param cause 原因例外 * @param orderId 見つからなかった注文 Id. * @param buyerId 見つからなかった購入者 Id. */ public OrderNotFoundException(Throwable cause, long orderId, String buyerId) { - super(cause, ExceptionIdConstant.E_ORDER0002, new String[] {String.valueOf(orderId), buyerId}, - new String[] {String.valueOf(orderId), buyerId}); + super(cause, ExceptionIdConstant.E_ORDER0002, new String[] { String.valueOf(orderId), buyerId }, + new String[] { String.valueOf(orderId), buyerId }); } } diff --git a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/assets/AssetApplicationServiceTest.java b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/assets/AssetApplicationServiceTest.java index 66b7ee77f..8b6d8f45b 100644 --- a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/assets/AssetApplicationServiceTest.java +++ b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/assets/AssetApplicationServiceTest.java @@ -7,7 +7,6 @@ import static org.mockito.Mockito.when; import java.util.Optional; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -17,9 +16,12 @@ import org.springframework.core.io.Resource; import org.springframework.test.context.junit.jupiter.SpringExtension; +/** + * {@link AssetApplicationService}の動作をテストするクラスです。 + */ @ExtendWith(SpringExtension.class) public class AssetApplicationServiceTest { - + @Mock private AssetRepository repository; @Mock @@ -57,7 +59,7 @@ public class AssetApplicationServiceTest { // モックの設定 when(this.repository.findByAssetCode(assetCode)).thenReturn(Optional.empty()); - + try { // 戻り値の検証 service.getAssetResourceInfo(assetCode); @@ -76,11 +78,11 @@ public class AssetApplicationServiceTest { // 期待する戻り値 Asset asset = new Asset(assetCode, "png"); - + // モックの設定 when(this.repository.findByAssetCode(assetCode)).thenReturn(Optional.of(asset)); when(this.store.getResource(asset)).thenReturn(Optional.empty()); - + try { // 戻り値の検証 service.getAssetResourceInfo(assetCode); diff --git a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/baskets/BasketApplicationServiceTest.java b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/baskets/BasketApplicationServiceTest.java index 5d5a9e6e4..9be47eeb2 100644 --- a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/baskets/BasketApplicationServiceTest.java +++ b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/baskets/BasketApplicationServiceTest.java @@ -20,6 +20,9 @@ import org.mockito.Mock; import org.springframework.test.context.junit.jupiter.SpringExtension; +/** + * {@link BasketApplicationService}の動作をテストするクラスです。 + */ @ExtendWith(SpringExtension.class) public class BasketApplicationServiceTest { @Mock @@ -256,13 +259,13 @@ public class BasketApplicationServiceTest { @ParameterizedTest @MethodSource("blankStringSource") - void testGetOrCreateBasketForUser_異常系_購入者Idがnullまたは空白なら例外が発生する(String buyerId) throws IllegalArgumentException{ + void testGetOrCreateBasketForUser_異常系_購入者Idがnullまたは空白なら例外が発生する(String buyerId) throws IllegalArgumentException { // テストメソッドの実行 try { service.getOrCreateBasketForUser(buyerId); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).startsWith("buyerIdがnullまたは空文字"); - } + } // モックが想定通り呼び出されていることの確認 verify(this.repository, times(0)).findByBuyerId(any()); verify(this.repository, times(0)).add(any()); diff --git a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/catalog/CatalogApplicationServiceTest.java b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/catalog/CatalogApplicationServiceTest.java index e60e06dd0..59e2c220c 100644 --- a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/catalog/CatalogApplicationServiceTest.java +++ b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/catalog/CatalogApplicationServiceTest.java @@ -15,6 +15,9 @@ import org.mockito.Mock; import org.springframework.test.context.junit.jupiter.SpringExtension; +/** + * {@link CatalogApplicationService}の動作をテストするクラスです。 + */ @ExtendWith(SpringExtension.class) public class CatalogApplicationServiceTest { @Mock @@ -30,9 +33,8 @@ public class CatalogApplicationServiceTest { void testGetCatalogItems_正常系_リポジトリのfindByBrandIdAndCategoryIdを1回呼出す() { // Arrange List catalogItems = List.of(createCatalogItem(1L)); - when( - this.catalogRepository.findByBrandIdAndCategoryId(anyLong(), anyLong(), anyInt(), anyInt())) - .thenReturn(catalogItems); + when(this.catalogRepository.findByBrandIdAndCategoryId(anyLong(), anyLong(), anyInt(), anyInt())) + .thenReturn(catalogItems); // Act service.getCatalogItems(1L, 1L, 1, 10); diff --git a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/catalog/CatalogDomainServiceTest.java b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/catalog/CatalogDomainServiceTest.java index 529c7d6f2..2883ec37a 100644 --- a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/catalog/CatalogDomainServiceTest.java +++ b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/catalog/CatalogDomainServiceTest.java @@ -6,15 +6,21 @@ import static org.mockito.Mockito.when; import java.math.BigDecimal; +import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.stream.Collectors; + +import org.apache.commons.lang3.ArrayUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.springframework.test.context.junit.jupiter.SpringExtension; +/** + * {@link CatalogDomainService}の動作をテストするクラスです。 + */ @ExtendWith(SpringExtension.class) public class CatalogDomainServiceTest { @Mock @@ -25,24 +31,25 @@ public class CatalogDomainServiceTest { @Test void testGetExistCatalogItems_正常系_リポジトリのfindByCategoryIdInを1度だけ呼出す() { // Arrange - List catalogItemIds = List.of(1L, 2L); - List catalogItems = - catalogItemIds.stream().map(this::createCatalogItem).collect(Collectors.toList()); - when(this.repository.findByCatalogItemIdIn(catalogItemIds)).thenReturn(catalogItems); + long[] catalogItemIds = { 1L, 2L }; + List catalogItemIdsList = Arrays.asList(ArrayUtils.toObject(catalogItemIds)); + List catalogItems = Arrays.stream(catalogItemIds).mapToObj(this::createCatalogItem) + .collect(Collectors.toList()); + when(this.repository.findByCatalogItemIdIn(catalogItemIdsList)).thenReturn(catalogItems); // Act - service.getExistCatalogItems(catalogItemIds); + service.getExistCatalogItems(catalogItemIdsList); // Assert - verify(this.repository, times(1)).findByCatalogItemIdIn(catalogItemIds); + verify(this.repository, times(1)).findByCatalogItemIdIn(catalogItemIdsList); } @Test void testExistAll_正常系_リポジトリ内に存在するアイテムのリストを返す() { // Arrange - List catalogItemIds = List.of(2L); - List catalogItems = - catalogItemIds.stream().map(this::createCatalogItem).collect(Collectors.toList()); + long[] catalogItemIds = { 2L }; + List catalogItems = Arrays.stream(catalogItemIds).mapToObj(this::createCatalogItem) + .collect(Collectors.toList()); when(this.repository.findByCatalogItemIdIn(List.of(1L, 2L))).thenReturn(catalogItems); // Act @@ -56,25 +63,27 @@ public class CatalogDomainServiceTest { @Test void testExistAll_正常系_リポジトリのfindByCategoryIdInを1度だけ呼出す() { // Arrange - List catalogItemIds = List.of(1L, 2L); - List catalogItems = - catalogItemIds.stream().map(this::createCatalogItem).collect(Collectors.toList()); - when(this.repository.findByCatalogItemIdIn(catalogItemIds)).thenReturn(catalogItems); + long[] catalogItemIds = { 1L, 2L }; + List catalogItemIdsList = Arrays.asList(ArrayUtils.toObject(catalogItemIds)); + List catalogItems = Arrays.stream(catalogItemIds).mapToObj(this::createCatalogItem) + .collect(Collectors.toList()); + when(this.repository.findByCatalogItemIdIn(catalogItemIdsList)).thenReturn(catalogItems); // Act - service.existAll(catalogItemIds); + service.existAll(catalogItemIdsList); // Assert - verify(this.repository, times(1)).findByCatalogItemIdIn(catalogItemIds); + verify(this.repository, times(1)).findByCatalogItemIdIn(catalogItemIdsList); } @Test void testExistAll_正常系_カタログアイテムIdがすべて存在する場合trueを返す() { // Arrange - List catalogItemIds = List.of(1L, 2L); - List catalogItems = - catalogItemIds.stream().map(this::createCatalogItem).collect(Collectors.toList()); - when(this.repository.findByCatalogItemIdIn(catalogItemIds)).thenReturn(catalogItems); + long[] catalogItemIds = { 1L, 2L }; + List catalogItemIdsList = Arrays.asList(ArrayUtils.toObject(catalogItemIds)); + List catalogItems = Arrays.stream(catalogItemIds).mapToObj(this::createCatalogItem) + .collect(Collectors.toList()); + when(this.repository.findByCatalogItemIdIn(catalogItemIdsList)).thenReturn(catalogItems); // Act boolean existAll = service.existAll(List.of(1L, 2L)); @@ -86,9 +95,9 @@ public class CatalogDomainServiceTest { @Test void testExistAll_正常系_カタログアイテムIdが一部だけ存在する場合falseを返す() { // Arrange - List catalogItemIds = List.of(2L); - List catalogItems = - catalogItemIds.stream().map(this::createCatalogItem).collect(Collectors.toList()); + long[] catalogItemIds = { 2L }; + List catalogItems = Arrays.stream(catalogItemIds).mapToObj(this::createCatalogItem) + .collect(Collectors.toList()); when(this.repository.findByCatalogItemIdIn(List.of(1L, 2L))).thenReturn(catalogItems); // Act @@ -101,9 +110,9 @@ public class CatalogDomainServiceTest { @Test void testExistAll_正常系_カタログアイテムIdが1件も存在しない場合falseを返す() { // Arrange - List catalogItemIds = List.of(); - List catalogItems = - catalogItemIds.stream().map(this::createCatalogItem).collect(Collectors.toList()); + long[] catalogItemIds = {}; + List catalogItems = Arrays.stream(catalogItemIds).mapToObj(this::createCatalogItem) + .collect(Collectors.toList()); when(this.repository.findByCatalogItemIdIn(List.of(1L, 2L))).thenReturn(catalogItems); // Act diff --git a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/order/OrderApplicationServiceTest.java b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/order/OrderApplicationServiceTest.java index fc68b5673..badd4bd20 100644 --- a/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/order/OrderApplicationServiceTest.java +++ b/samples/web-csr/dressca-backend/application-core/src/test/java/com/dressca/applicationcore/order/OrderApplicationServiceTest.java @@ -24,6 +24,9 @@ import org.mockito.Mock; import org.springframework.test.context.junit.jupiter.SpringExtension; +/** + * {@link OrderApplicationService}の動作をテストするクラスです。 + */ @ExtendWith(SpringExtension.class) public class OrderApplicationServiceTest { @Mock @@ -156,9 +159,8 @@ private List createDefaultOrderItems() { String productName = "ダミー商品1"; String productCode = "C000000001"; - List items = - List.of(new OrderItem(new CatalogItemOrdered(1L, productName, productCode), - BigDecimal.valueOf(100_000_000L), 1)); + List items = List.of(new OrderItem(new CatalogItemOrdered(1L, productName, productCode), + BigDecimal.valueOf(100_000_000L), 1)); return items; } diff --git a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/BatchApplication.java b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/BatchApplication.java index 4023edf63..e793c7716 100644 --- a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/BatchApplication.java +++ b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/BatchApplication.java @@ -4,11 +4,10 @@ import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication - /** * バッチアプリケーションのメインクラス。 */ +@SpringBootApplication public class BatchApplication { /** diff --git a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/BatchConfiguration.java b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/BatchConfiguration.java index 06a32b683..47c1bc204 100644 --- a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/BatchConfiguration.java +++ b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/BatchConfiguration.java @@ -26,8 +26,8 @@ */ @Configuration @EnableBatchProcessing -@ComponentScan(basePackages = {"com.dressca"}) -@MapperScan(basePackages = {"com.dressca.infrastructure.repository.mybatis"}) +@ComponentScan(basePackages = { "com.dressca" }) +@MapperScan(basePackages = { "com.dressca.infrastructure.repository.mybatis" }) public class BatchConfiguration { @@ -37,8 +37,10 @@ public class BatchConfiguration { * @param catalogItemTasklet ステップで実行するTasklet */ @Bean - public Step catalogItem_tasklet_step1(JobRepository jobRepository, PlatformTransactionManager transactionManager, CatalogItemTasklet catalogItemTasklet) { - return new StepBuilder("catalogItem_tasklet_step1", jobRepository).tasklet(catalogItemTasklet, transactionManager).build(); + public Step catalogItem_tasklet_step1(JobRepository jobRepository, PlatformTransactionManager transactionManager, + CatalogItemTasklet catalogItemTasklet) { + return new StepBuilder("catalogItem_tasklet_step1", jobRepository).tasklet(catalogItemTasklet, transactionManager) + .build(); } /** @@ -55,9 +57,9 @@ public Job catalogItem_tasklet_job(JobRepository jobRepository, @Qualifier("cata /** * catalogItem_job用のstepの設定。 * - * @param catalogItemReader ステップで実行するReader + * @param catalogItemReader ステップで実行するReader * @param catalogItemProcessor ステップで実行するProcessor - * @param catalogItemWriter ステップで実行するWriter + * @param catalogItemWriter ステップで実行するWriter */ @Bean public Step catalogItem_step1(JobRepository jobRepository, PlatformTransactionManager transactionManager, @@ -87,8 +89,8 @@ public Step catalogItem_step1(JobRepository jobRepository, PlatformTransactionMa /** * catalogItem_job用の設定。 * - * @param listener 設定するLitener - * @param step1 ジョブで実行するstep + * @param listener 設定するListener + * @param step1 ジョブで実行するstep */ @Primary @Bean diff --git a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/JobCompletionNotificationListener.java b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/JobCompletionNotificationListener.java index c1cf0d822..cd735a0dd 100644 --- a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/JobCompletionNotificationListener.java +++ b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/JobCompletionNotificationListener.java @@ -8,6 +8,9 @@ import org.springframework.batch.core.JobExecutionListener; import org.springframework.stereotype.Component; +/** + * ジョブの完了を通知するためのクラスです。 + */ @Component public class JobCompletionNotificationListener implements JobExecutionListener { diff --git a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemProcessor.java b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemProcessor.java index 5da1b178a..ad6c8d13b 100644 --- a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemProcessor.java +++ b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemProcessor.java @@ -2,8 +2,8 @@ import org.springframework.batch.item.ItemProcessor; import org.springframework.beans.BeanUtils; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; - import com.dressca.applicationcore.catalog.CatalogItem; /** @@ -13,7 +13,7 @@ public class CatalogItemProcessor implements ItemProcessor { @Override - public CatalogItem process(final CatalogItem catalogItem) throws Exception { + public CatalogItem process(@NonNull final CatalogItem catalogItem) throws Exception { String name = catalogItem.getName(); // 商品名が10文字超える場合、先頭10文字にする if (name.length() > 10) { diff --git a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemReaderConf.java b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemReaderConf.java index 762ec363f..3cb1c390e 100644 --- a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemReaderConf.java +++ b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemReaderConf.java @@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - import com.dressca.applicationcore.catalog.CatalogItem; /** diff --git a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemWriterConf.java b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemWriterConf.java index d9f7d9b52..85f469191 100644 --- a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemWriterConf.java +++ b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/catalog/CatalogItemWriterConf.java @@ -1,7 +1,6 @@ package com.dressca.batch.job.catalog; import com.dressca.applicationcore.catalog.CatalogItem; - import org.springframework.batch.core.configuration.annotation.StepScope; import org.springframework.batch.item.file.FlatFileItemWriter; import org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor; diff --git a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/tasklet/catalog/CatalogItemTasklet.java b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/tasklet/catalog/CatalogItemTasklet.java index 2ea349bf1..87a3167a4 100644 --- a/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/tasklet/catalog/CatalogItemTasklet.java +++ b/samples/web-csr/dressca-backend/batch/src/main/java/com/dressca/batch/job/tasklet/catalog/CatalogItemTasklet.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; - import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.configuration.annotation.StepScope; import org.springframework.batch.core.scope.context.ChunkContext; @@ -17,7 +16,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.FileSystemResource; import org.springframework.stereotype.Component; - import com.dressca.applicationcore.catalog.CatalogItem; import com.dressca.applicationcore.catalog.CatalogRepository; diff --git a/samples/web-csr/dressca-backend/batch/src/test/java/com/dressca/batch/CatalogItemJobTest.java b/samples/web-csr/dressca-backend/batch/src/test/java/com/dressca/batch/CatalogItemJobTest.java index f70b2d4c1..1a25db4f5 100644 --- a/samples/web-csr/dressca-backend/batch/src/test/java/com/dressca/batch/CatalogItemJobTest.java +++ b/samples/web-csr/dressca-backend/batch/src/test/java/com/dressca/batch/CatalogItemJobTest.java @@ -1,12 +1,12 @@ package com.dressca.batch; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import javax.sql.DataSource; -// import org.junit.Assert; -import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,8 +24,8 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import com.dressca.batch.job.BatchConfiguration; -/* - * CatalogItemJobのテスト +/** + * CatalogItemJobのテストです。 */ @SpringBatchTest @SpringJUnitConfig(BatchConfiguration.class) @@ -42,8 +42,8 @@ public class CatalogItemJobTest { @Autowired JobRepository jobRepository; private JdbcTemplate jdbcTemplate; - private final String OUTPUT_FILE = "output/outputData.csv"; - private final String EXPECTED_FOLDER = "src/test/resources/expected/"; + private static final String OUTPUT_FILE = "output/outputData.csv"; + private static final String EXPECTED_FOLDER = "src/test/resources/expected/"; @Autowired public void setDataSource(DataSource dataSource) { @@ -55,6 +55,11 @@ public void initJobLauncherTestUtils() { jobLauncherTestUtils.setJob(catalogItemJob); } + /** + * 各テストを実施する前のセットアップメソッド。 + * + * @throws IOException 例外エラー + */ @BeforeEach /* DBのテストデータと出力ファイルのクリーンアップ */ public void clearData() throws IOException { @@ -77,7 +82,7 @@ public void jobTest_empty() throws Exception { String outputStr = (new FileSystemResource(OUTPUT_FILE)).getContentAsString(Charset.forName("UTF-8")); String expectedStr = (new FileSystemResource(expectedFile)).getContentAsString(Charset.forName("UTF-8")); // 期待値ファイルの改行コードは"\r\n"のため、出力ファイルの改行コード(OS依存)に変換して比較 - assertThat(outputStr).isEqualTo(expectedStr.replaceAll("\r\n",System.getProperty("line.separator"))); + assertThat(outputStr).isEqualTo(expectedStr.replaceAll("\r\n", System.getProperty("line.separator"))); } /* @@ -96,10 +101,9 @@ public void jobTest_10data() throws Exception { String outputStr = (new FileSystemResource(OUTPUT_FILE)).getContentAsString(Charset.forName("UTF-8")); String expectedStr = (new FileSystemResource(expectedFile)).getContentAsString(Charset.forName("UTF-8")); // 期待値ファイルの改行コードは"\r\n"のため、出力ファイルの改行コード(OS依存)に変換して比較 - assertThat(outputStr).isEqualTo(expectedStr.replaceAll("\r\n",System.getProperty("line.separator"))); + assertThat(outputStr).isEqualTo(expectedStr.replaceAll("\r\n", System.getProperty("line.separator"))); } - /* * ステップ単位でのテスト:データ10件 */ @@ -116,15 +120,13 @@ public void stepTest_10data() throws Exception { String outputStr = (new FileSystemResource(OUTPUT_FILE)).getContentAsString(Charset.forName("UTF-8")); String expectedStr = (new FileSystemResource(expectedFile)).getContentAsString(Charset.forName("UTF-8")); // 期待値ファイルの改行コードは"\r\n"のため、出力ファイルの改行コード(OS依存)に変換して比較 - assertThat(outputStr).isEqualTo(expectedStr.replaceAll("\r\n",System.getProperty("line.separator"))); + assertThat(outputStr).isEqualTo(expectedStr.replaceAll("\r\n", System.getProperty("line.separator"))); } private void insertTestData() { for (int i = 0; i < 10; i++) { - String insertItem = - "insert into catalog_items (id,name,description,price,product_code,catalog_category_id,catalog_brand_id) values (?,?,?,1000,'C000000001',1,1)"; - String insertItemAsset = - "insert into catalog_item_assets (id,asset_code,catalog_item_id) values (?,'dummy',?)"; + String insertItem = "insert into catalog_items (id,name,description,price,product_code,catalog_category_id,catalog_brand_id) values (?,?,?,1000,'C000000001',1,1)"; + String insertItemAsset = "insert into catalog_item_assets (id,asset_code,catalog_item_id) values (?,'dummy',?)"; jdbcTemplate.update(insertItem, 101 + i, "sample" + i, "商品説明" + i); jdbcTemplate.update(insertItemAsset, 101 + i, 101 + i); } diff --git a/samples/web-csr/dressca-backend/build.gradle b/samples/web-csr/dressca-backend/build.gradle index f0d363c7a..6f84b8f8a 100644 --- a/samples/web-csr/dressca-backend/build.gradle +++ b/samples/web-csr/dressca-backend/build.gradle @@ -50,6 +50,7 @@ subprojects { configDirectory = rootProject.file('config/checkstyle') } spotbugs { + excludeFilter.set(rootProject.file('config/spotbugs/exclude-filter.xml')) toolVersion = '4.7.3' ignoreFailures = true } diff --git a/samples/web-csr/dressca-backend/config/checkstyle/checkstyle.xml b/samples/web-csr/dressca-backend/config/checkstyle/checkstyle.xml index 9ddfb95de..89a12e970 100644 --- a/samples/web-csr/dressca-backend/config/checkstyle/checkstyle.xml +++ b/samples/web-csr/dressca-backend/config/checkstyle/checkstyle.xml @@ -15,6 +15,9 @@ Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. --> + + + @@ -27,10 +30,13 @@ + + diff --git a/samples/web-csr/dressca-backend/config/formatter/eclipse-formatter.xml b/samples/web-csr/dressca-backend/config/formatter/eclipse-formatter.xml index 2c502f8e6..2abedd902 100644 --- a/samples/web-csr/dressca-backend/config/formatter/eclipse-formatter.xml +++ b/samples/web-csr/dressca-backend/config/formatter/eclipse-formatter.xml @@ -1,4 +1,6 @@ + + diff --git a/samples/web-csr/dressca-backend/config/spotbugs/exclude-filter.xml b/samples/web-csr/dressca-backend/config/spotbugs/exclude-filter.xml new file mode 100644 index 000000000..6df04d974 --- /dev/null +++ b/samples/web-csr/dressca-backend/config/spotbugs/exclude-filter.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisAssetRepository.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisAssetRepository.java index d6d124375..efb602c1c 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisAssetRepository.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisAssetRepository.java @@ -5,15 +5,19 @@ import com.dressca.applicationcore.assets.AssetRepository; import com.dressca.infrastructure.repository.mybatis.generated.entity.AssetEntityExample; import com.dressca.infrastructure.repository.mybatis.generated.mapper.AssetMapper; -import com.dressca.infrastructure.repository.mybatis.translater.EntityTranslator; +import com.dressca.infrastructure.repository.mybatis.translator.EntityTranslator; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import lombok.AllArgsConstructor; +/** + * アセットリポジトリ。 + */ @Repository @AllArgsConstructor public class MybatisAssetRepository implements AssetRepository { - + @Autowired private AssetMapper assetMapper; diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisBasketRepository.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisBasketRepository.java index 671afccde..2a2b0e777 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisBasketRepository.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisBasketRepository.java @@ -12,11 +12,15 @@ import com.dressca.infrastructure.repository.mybatis.generated.mapper.BasketItemMapper; import com.dressca.infrastructure.repository.mybatis.generated.mapper.BasketMapper; import com.dressca.infrastructure.repository.mybatis.mapper.JoinedBasketMapper; -import com.dressca.infrastructure.repository.mybatis.translater.EntityTranslator; +import com.dressca.infrastructure.repository.mybatis.translator.EntityTranslator; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import lombok.AllArgsConstructor; +/** + * 買い物かごリポジトリ。 + */ @Repository @AllArgsConstructor public class MybatisBasketRepository implements BasketRepository { @@ -44,7 +48,7 @@ public Optional findByBuyerId(String buyerId) { public Basket add(Basket basket) { BasketEntity row = EntityTranslator.createBasketEntity(basket); basketMapper.insert(row); - + // 子要素(BasketItem)の追加 List itemRows = basket.getItems().stream() .map(EntityTranslator::createBasketItemEntity) @@ -52,7 +56,7 @@ public Basket add(Basket basket) { for (BasketItemEntity itemRow : itemRows) { basketItemMapper.insert(itemRow); } - + return joinedBasketMapper.findById(row.getId()); } @@ -67,7 +71,7 @@ public void remove(Basket basket) { .mapToLong(BasketEntity::getId) .distinct() .forEach(id -> removeBasketItem(id)); - + basketMapper.deleteByExample(basketExample); } @@ -75,7 +79,7 @@ public void remove(Basket basket) { public void update(Basket basket) { BasketEntity row = EntityTranslator.createBasketEntity(basket); basketMapper.updateByPrimaryKey(row); - + // 子要素(BasketItem)の更新 // 削除されたBasketItemにも対応できるようにDELETE-INSERTする removeBasketItem(basket.getId()); diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogBrandRepository.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogBrandRepository.java index c0ee3e9bd..e99d63f08 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogBrandRepository.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogBrandRepository.java @@ -6,11 +6,15 @@ import com.dressca.applicationcore.catalog.CatalogBrandRepository; import com.dressca.infrastructure.repository.mybatis.generated.entity.CatalogBrandEntityExample; import com.dressca.infrastructure.repository.mybatis.generated.mapper.CatalogBrandMapper; -import com.dressca.infrastructure.repository.mybatis.translater.EntityTranslator; +import com.dressca.infrastructure.repository.mybatis.translator.EntityTranslator; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import lombok.AllArgsConstructor; +/** + * カタログブランドリポジトリ。 + */ @Repository @AllArgsConstructor public class MybatisCatalogBrandRepository implements CatalogBrandRepository { diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogCategoryRepository.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogCategoryRepository.java index d7171797d..461a1917d 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogCategoryRepository.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogCategoryRepository.java @@ -6,11 +6,15 @@ import com.dressca.applicationcore.catalog.CatalogCategoryRepository; import com.dressca.infrastructure.repository.mybatis.generated.entity.CatalogCategoryEntityExample; import com.dressca.infrastructure.repository.mybatis.generated.mapper.CatalogCategoryMapper; -import com.dressca.infrastructure.repository.mybatis.translater.EntityTranslator; +import com.dressca.infrastructure.repository.mybatis.translator.EntityTranslator; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import lombok.AllArgsConstructor; +/** + * カタログカテゴリリポジトリ。 + */ @Repository @AllArgsConstructor public class MybatisCatalogCategoryRepository implements CatalogCategoryRepository { diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java index b71f11dc5..ec22d967a 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisCatalogRepository.java @@ -8,6 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; +/** + * カタログリポジトリ。 + */ @Repository @AllArgsConstructor public class MybatisCatalogRepository implements CatalogRepository { diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisOrderRepository.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisOrderRepository.java index 1804e8518..3a88b899a 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisOrderRepository.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/MybatisOrderRepository.java @@ -8,6 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; +/** + * 注文情報リポジトリ。 + */ @Repository @AllArgsConstructor public class MybatisOrderRepository implements OrderRepository { diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedBasketMapper.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedBasketMapper.java index 388592867..7f36b6bb3 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedBasketMapper.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedBasketMapper.java @@ -4,6 +4,9 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +/** + * 買い物かごのテーブルにアクセスするためのマッパークラスです。 + */ @Mapper public interface JoinedBasketMapper { diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedCatalogItemMapper.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedCatalogItemMapper.java index 589059046..eb412511f 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedCatalogItemMapper.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedCatalogItemMapper.java @@ -5,6 +5,9 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +/** + * カタログアイテムのテーブルにアクセスするためのマッパークラスです。 + */ @Mapper public interface JoinedCatalogItemMapper { diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedOrderMapper.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedOrderMapper.java index 3c2a8c910..34c99593f 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedOrderMapper.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/mapper/JoinedOrderMapper.java @@ -6,6 +6,9 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +/** + * 注文情報のテーブルにアクセスするためのマッパークラスです。 + */ @Mapper public interface JoinedOrderMapper { diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/translater/EntityTranslator.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/translator/EntityTranslator.java similarity index 97% rename from samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/translater/EntityTranslator.java rename to samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/translator/EntityTranslator.java index 25859c0d8..d77cb7806 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/translater/EntityTranslator.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/repository/mybatis/translator/EntityTranslator.java @@ -1,4 +1,4 @@ -package com.dressca.infrastructure.repository.mybatis.translater; +package com.dressca.infrastructure.repository.mybatis.translator; import com.dressca.applicationcore.assets.Asset; import com.dressca.applicationcore.baskets.Basket; @@ -20,6 +20,9 @@ import com.dressca.infrastructure.repository.mybatis.generated.entity.OrderItemEntity; import org.springframework.beans.BeanUtils; +/** + * エンティティとドメインオブジェクトを相互に変換するクラスです。 + */ public class EntityTranslator { /** @@ -87,7 +90,7 @@ public static BasketItemEntity createBasketItemEntity(BasketItem basketItem) { * * @param entity {@link CatalogBrandEntity} オブジェクト * @return {@link CatalogBrand} オブジェクト - */ + */ public static CatalogBrand catalogBrandEntityTranslate(CatalogBrandEntity entity) { CatalogBrand catalogBrand = new CatalogBrand(); BeanUtils.copyProperties(entity, catalogBrand); @@ -129,7 +132,7 @@ public static CatalogItemAsset catalogItemAssetEntityTranslate(CatalogItemAssetE BeanUtils.copyProperties(entity, catalogItemAsset); return catalogItemAsset; } - + /** * {@link OrderEntity} をドメインオブジェクトに変換します。 * diff --git a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/store/StaticFileAssetStore.java b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/store/StaticFileAssetStore.java index eabd62844..cd2941a60 100644 --- a/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/store/StaticFileAssetStore.java +++ b/samples/web-csr/dressca-backend/infrastructure/src/main/java/com/dressca/infrastructure/store/StaticFileAssetStore.java @@ -3,14 +3,11 @@ import java.nio.file.FileSystems; import java.nio.file.Path; import java.util.Optional; - import com.dressca.applicationcore.assets.Asset; import com.dressca.applicationcore.assets.AssetStore; - import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; - import lombok.RequiredArgsConstructor; import lombok.Setter; @@ -42,5 +39,5 @@ private Path getFilePath(Asset asset) { String imagePath = "images"; return FileSystems.getDefault().getPath(basePath, imagePath, asset.getAssetCode()); } - + } diff --git a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/constant/SystemPropertyConstants.java b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/constant/SystemPropertyConstants.java index dd6d7d5b9..4f986af55 100644 --- a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/constant/SystemPropertyConstants.java +++ b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/constant/SystemPropertyConstants.java @@ -1,9 +1,12 @@ package com.dressca.systemcommon.constant; +/** + * システムプロパティ用定数クラス。 + */ public class SystemPropertyConstants { /** アプリケーションログのロガー名。 */ public static final String APPLICATION_LOG_LOGGER = "application.log"; - - /** 改行文字 */ + + /** 改行文字。 */ public static final String LINE_SEPARATOR = System.getProperty("line.separator"); } diff --git a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/LogicException.java b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/LogicException.java index 652d4423d..6f4e0dbeb 100644 --- a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/LogicException.java +++ b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/LogicException.java @@ -24,7 +24,7 @@ public class LogicException extends Exception { * @param frontMessageValue メッセージ用プレースフォルダ(フロント用) * @param logMessageValue メッセージ用プレースフォルダ(ログ用) */ - public LogicException(Throwable cause, String exceptionId, + public LogicException(Throwable cause, String exceptionId, String[] frontMessageValue, String[] logMessageValue) { super(cause); this.exceptionId = exceptionId; diff --git a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/SystemException.java b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/SystemException.java index 0e8dceaff..71f8dd52a 100644 --- a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/SystemException.java +++ b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/SystemException.java @@ -3,6 +3,9 @@ import lombok.Getter; import lombok.Setter; +/** + * システム例外を表す例外クラスです。 + */ @Getter @Setter public class SystemException extends RuntimeException { @@ -16,12 +19,12 @@ public class SystemException extends RuntimeException { /** * コンストラクタ。 * - * @param cause 原因例外 - * @param exceptionId 例外ID + * @param cause 原因例外 + * @param exceptionId 例外ID * @param frontMessageValue メッセージ用プレースフォルダ(フロント用) - * @param logMessageValue メッセージ用プレースフォルダ(ログ用) + * @param logMessageValue メッセージ用プレースフォルダ(ログ用) */ - public SystemException(Throwable cause, String exceptionId, + public SystemException(Throwable cause, String exceptionId, String[] frontMessageValue, String[] logMessageValue) { super(cause); this.exceptionId = exceptionId; diff --git a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/response/ErrorResponse.java b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/response/ErrorResponse.java index 7221c23de..de99dcb16 100644 --- a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/response/ErrorResponse.java +++ b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/exception/response/ErrorResponse.java @@ -1,13 +1,10 @@ package com.dressca.systemcommon.exception.response; import java.util.Locale; - import com.dressca.systemcommon.exception.LogicException; import com.dressca.systemcommon.exception.SystemException; import com.dressca.systemcommon.util.ApplicationContextWrapper; - import org.springframework.context.MessageSource; - import lombok.Getter; import lombok.Setter; @@ -35,8 +32,7 @@ public class ErrorResponse { private String instance; /** メッセージソース。 */ - private static MessageSource messageSource = - (MessageSource) ApplicationContextWrapper.getBean(MessageSource.class); + private static MessageSource messageSource = (MessageSource) ApplicationContextWrapper.getBean(MessageSource.class); private static final String EXCEPTION_MESSAGE_SUFFIX_FRONT = "front"; private static final String PROPERTY_DELIMITER = "."; diff --git a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/util/ApplicationContextWrapper.java b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/util/ApplicationContextWrapper.java index 8fd6486d7..486c5e7d5 100644 --- a/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/util/ApplicationContextWrapper.java +++ b/samples/web-csr/dressca-backend/system-common/src/main/java/com/dressca/systemcommon/util/ApplicationContextWrapper.java @@ -5,11 +5,14 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; +/** + * ApplicationContextを保持するラッパークラスです。 + */ @Component public class ApplicationContextWrapper implements ApplicationContextAware { private static ApplicationContext context; - + @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { context = applicationContext; diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/WebApplication.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/WebApplication.java index 0ca124d04..dfd6bce4b 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/WebApplication.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/WebApplication.java @@ -7,10 +7,13 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.info.Info; +/** + * Dresscaアプリケーションを起動するためのmainクラスです。 + */ @SpringBootApplication @OpenAPIDefinition(info = @Info(title = "Dressca", description = "ECサイトDressca", version = "v1")) -@ComponentScan(basePackages = {"com.dressca"}) -@MapperScan(basePackages = {"com.dressca.infrastructure.repository.mybatis"}) +@ComponentScan(basePackages = { "com.dressca" }) +@MapperScan(basePackages = { "com.dressca.infrastructure.repository.mybatis" }) public class WebApplication { public static void main(String[] args) { diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/config/DresscaWebConfig.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/config/DresscaWebConfig.java index 8e2815774..5cce6eada 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/config/DresscaWebConfig.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/config/DresscaWebConfig.java @@ -14,6 +14,7 @@ public class DresscaWebConfig { /** * BuyerIdFilter の設定。 + * * @return BuyerIdFilter */ @Bean diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/AssetsController.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/AssetsController.java index 158d1eea0..18f938616 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/AssetsController.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/AssetsController.java @@ -6,7 +6,6 @@ import com.dressca.applicationcore.assets.AssetResourceInfo; import com.dressca.applicationcore.assets.AssetTypes; import com.dressca.systemcommon.exception.LogicException; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; @@ -44,9 +43,8 @@ public class AssetsController { */ @Operation(summary = "アセットを取得する.", description = "与えられたアセットコードに対応するアセットを返却する.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功.", - content = @Content(mediaType = "image/*", schema = @Schema(implementation = Resource.class))), - @ApiResponse(responseCode = "404", description = "アセットコードに対応するアセットがない.", content = @Content)}) + @ApiResponse(responseCode = "200", description = "成功.", content = @Content(mediaType = "image/*", schema = @Schema(implementation = Resource.class))), + @ApiResponse(responseCode = "404", description = "アセットコードに対応するアセットがない.", content = @Content) }) @GetMapping("{assetCode}") public ResponseEntity get( @Parameter(required = true, description = "アセットコード") @PathVariable("assetCode") String assetCode) diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/BasketItemController.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/BasketItemController.java index 3268918f7..07a1119ca 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/BasketItemController.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/BasketItemController.java @@ -22,13 +22,11 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; - import java.net.URI; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import jakarta.servlet.http.HttpServletRequest; - import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -63,9 +61,8 @@ public class BasketItemController { * @return 買い物かごアイテムの一覧 */ @Operation(summary = "買い物かごアイテムの一覧を取得する.", description = "買い物かごアイテムの一覧を返却する.") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "成功.", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = BasketResponse.class)))}) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "成功.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = BasketResponse.class))) }) @GetMapping public ResponseEntity getBasketItems(HttpServletRequest req) { String buyerId = req.getAttribute("buyerId").toString(); @@ -85,20 +82,20 @@ public ResponseEntity getBasketItems(HttpServletRequest req) { /** * 買い物かごアイテム内の数量を変更します. 買い物かご内に存在しないカタログアイテム ID は指定できません。 *

- * この API では、買い物かご内に存在する商品の数量を変更できます。買い物かご内に存在しないカタログアイテム Id を指定すると HTTP 400 を返却します。 + * この API では、買い物かご内に存在する商品の数量を変更できます。買い物かご内に存在しないカタログアイテム Id を指定すると HTTP 400 + * を返却します。 * またシステムに登録されていないカタログアイテム Id を指定した場合も HTTP 400 を返却します。 *

* * @param putBasketItems 変更する買い物かごアイテムのデータリスト * @return なし */ - @Operation(summary = "買い物かごアイテム内の数量を変更します.", - description = "買い物かごアイテム内の数量を変更します. 買い物かご内に存在しないカタログアイテム ID は指定できません.
" - + "この API では、買い物かご内に存在する商品の数量を変更できます. 買い物かご内に存在しないカタログアイテム Id を指定すると HTTP 400 を返却します.
" - + "またシステムに登録されていないカタログアイテム Id を指定した場合も HTTP 400 を返却します.") - @ApiResponses( - value = {@ApiResponse(responseCode = "204", description = "成功.", content = @Content), - @ApiResponse(responseCode = "400", description = "リクエストエラー", content = @Content)}) + @Operation(summary = "買い物かごアイテム内の数量を変更します.", description = "買い物かごアイテム内の数量を変更します. 買い物かご内に存在しないカタログアイテム ID は指定できません.
" + + "この API では、買い物かご内に存在する商品の数量を変更できます. 買い物かご内に存在しないカタログアイテム Id を指定すると HTTP 400 を返却します.
" + + "またシステムに登録されていないカタログアイテム Id を指定した場合も HTTP 400 を返却します.") + @ApiResponses(value = { + @ApiResponse(responseCode = "204", description = "成功.", content = @Content), + @ApiResponse(responseCode = "400", description = "リクエストエラー", content = @Content) }) @PutMapping() public ResponseEntity putBasketItem(@RequestBody List putBasketItems, HttpServletRequest req) { @@ -107,16 +104,15 @@ public ResponseEntity putBasketItem(@RequestBody List p } Map quantities = putBasketItems.stream() .collect(Collectors.toMap( - PutBasketItemRequest::getCatalogItemId, - PutBasketItemRequest::getQuantity - )); + PutBasketItemRequest::getCatalogItemId, + PutBasketItemRequest::getQuantity)); // 買い物かごに入っていないカタログアイテムが指定されていないか確認 String buyerId = req.getAttribute("buyerId").toString(); Basket basket = this.basketApplicationService.getOrCreateBasketForUser(buyerId); List notExistsInBasketCatalogIds = quantities.keySet().stream() - .filter(catalogItemId -> !basket.isInCatalogItem(catalogItemId)) - .collect(Collectors.toList()); + .filter(catalogItemId -> !basket.isInCatalogItem(catalogItemId)) + .collect(Collectors.toList()); if (!notExistsInBasketCatalogIds.isEmpty()) { return ResponseEntity.badRequest().build(); } @@ -143,22 +139,22 @@ public ResponseEntity putBasketItem(@RequestBody List p * すでに買い物かごに追加されているカタログアイテムを指定した場合、指定した数量、買い物かご内の数量を追加します。 *

*

- * 買い物かご内のカタログアイテムの数量が 0 未満になるように減じることはできません。 計算の結果数量が 0 未満になる場合 HTTP 500 を返却します。 + * 買い物かご内のカタログアイテムの数量が 0 未満になるように減じることはできません。 計算の結果数量が 0 未満になる場合 HTTP 500 + * を返却します。 *

* * @param postBasketItem 追加する商品の情報 * @return なし */ - @Operation(summary = "買い物かごに商品を追加します.", - description = "買い物かごに商品を追加します.
" - + "この API では、システムに登録されていないカタログアイテム Id を指定した場合 HTTP 400 を返却します." - + "また買い物かごに追加していないカタログアイテムを指定した場合、その商品を買い物かごに追加します." - + "すでに買い物かごに追加されているカタログアイテムを指定した場合、指定した数量、買い物かご内の数量を追加します.
" - + "買い物かご内のカタログアイテムの数量が 0 未満になるように減じることはできません. 計算の結果数量が 0 未満になる場合 HTTP 500 を返却します.") - @ApiResponses( - value = {@ApiResponse(responseCode = "201", description = "作成完了", content = @Content), - @ApiResponse(responseCode = "400", description = "リクエストエラー", content = @Content), - @ApiResponse(responseCode = "500", description = "サーバーエラー", content = @Content)}) + @Operation(summary = "買い物かごに商品を追加します.", description = "買い物かごに商品を追加します.
" + + "この API では、システムに登録されていないカタログアイテム Id を指定した場合 HTTP 400 を返却します." + + "また買い物かごに追加していないカタログアイテムを指定した場合、その商品を買い物かごに追加します." + + "すでに買い物かごに追加されているカタログアイテムを指定した場合、指定した数量、買い物かご内の数量を追加します.
" + + "買い物かご内のカタログアイテムの数量が 0 未満になるように減じることはできません. 計算の結果数量が 0 未満になる場合 HTTP 500 を返却します.") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "作成完了", content = @Content), + @ApiResponse(responseCode = "400", description = "リクエストエラー", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー", content = @Content) }) @PostMapping public ResponseEntity postBasketItem(@RequestBody PostBasketItemsRequest postBasketItem, HttpServletRequest req) { @@ -175,10 +171,9 @@ public ResponseEntity postBasketItem(@RequestBody PostBasketItemsRequest post try { this.basketApplicationService.addItemToBasket( basket.getId(), - postBasketItem.getCatalogItemId(), + postBasketItem.getCatalogItemId(), catalogItem.getPrice(), - postBasketItem.getAddedQuantity() - ); + postBasketItem.getAddedQuantity()); } catch (BasketNotFoundException e) { throw new SystemException(e, ExceptionIdConstant.E_SHARE0000, null, null); } @@ -189,22 +184,21 @@ public ResponseEntity postBasketItem(@RequestBody PostBasketItemsRequest post * 買い物かごから指定したカタログアイテム Id の商品を削除します。 *

* catalogItemId には買い物かご内に存在するカタログアイテム Id を指定してください。 カタログアイテム Id は 1 以上の整数です。 - * 0以下の値を指定したり、整数値ではない値を指定した場合 HTTP 400 を返却します。 買い物かご内に指定したカタログアイテムの商品が存在しない場合、 HTTP 404 を返却します。 + * 0以下の値を指定したり、整数値ではない値を指定した場合 HTTP 400 を返却します。 買い物かご内に指定したカタログアイテムの商品が存在しない場合、 + * HTTP 404 を返却します。 *

* * @param catalogItemId カタログアイテム Id * @return なし */ - @Operation(summary = "買い物かごから指定したカタログアイテム Id の商品を削除します.", - description = "買い物かごから指定したカタログアイテム Id の商品を削除します.
" - + "catalogItemId には買い物かご内に存在するカタログアイテム Id を指定してください. カタログアイテム Id は 1 以上の整数です." - + "0以下の値を指定したり、整数値ではない値を指定した場合 HTTP 400 を返却します. " - + "買い物かご内に指定したカタログアイテムの商品が存在しない場合、 HTTP 404 を返却します.") - @ApiResponses( - value = {@ApiResponse(responseCode = "204", description = "成功.", content = @Content), - @ApiResponse(responseCode = "400", description = "リクエストエラー.", content = @Content), - @ApiResponse(responseCode = "404", description = "買い物かご内に指定したカタログアイテム Id がない.", - content = @Content)}) + @Operation(summary = "買い物かごから指定したカタログアイテム Id の商品を削除します.", description = "買い物かごから指定したカタログアイテム Id の商品を削除します.
" + + "catalogItemId には買い物かご内に存在するカタログアイテム Id を指定してください. カタログアイテム Id は 1 以上の整数です." + + "0以下の値を指定したり、整数値ではない値を指定した場合 HTTP 400 を返却します. " + + "買い物かご内に指定したカタログアイテムの商品が存在しない場合、 HTTP 404 を返却します.") + @ApiResponses(value = { + @ApiResponse(responseCode = "204", description = "成功.", content = @Content), + @ApiResponse(responseCode = "400", description = "リクエストエラー.", content = @Content), + @ApiResponse(responseCode = "404", description = "買い物かご内に指定したカタログアイテム Id がない.", content = @Content) }) @DeleteMapping("{catalogItemId}") public ResponseEntity deleteBasketItemAsync(@PathVariable("catalogItemId") long catalogItemId, HttpServletRequest req) { diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogBrandsController.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogBrandsController.java index 8ddb9f318..ec17d1e8e 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogBrandsController.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogBrandsController.java @@ -38,15 +38,14 @@ public class CatalogBrandsController { * @return カタログブランドの一覧 */ @Operation(summary = "カタログブランドの一覧を取得する.", description = "カタログブランドの一覧を取得する.") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "成功", - content = @Content(mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = CatalogBrand.class))))}) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CatalogBrand.class)))) }) @GetMapping() public ResponseEntity> getCatalogBrand() { List brands = this.service.getBrands().stream() .map(CatalogBrandMapper::convert) .collect(Collectors.toList()); - + return ResponseEntity.ok().body(brands); } } diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogCategoriesController.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogCategoriesController.java index fa43a64e4..7f52f1635 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogCategoriesController.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogCategoriesController.java @@ -38,15 +38,14 @@ public class CatalogCategoriesController { * @return カタログカテゴリの一覧。 */ @Operation(summary = "カタログカテゴリの一覧を取得します.", description = "カタログカテゴリの一覧を取得します.") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "成功", - content = @Content(mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = CatalogCategory.class))))}) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = CatalogCategory.class)))) }) @GetMapping() public ResponseEntity> getCatalogCategories() { List categories = this.service.getCategories().stream() .map(CatalogCategoryMapper::convert) .collect(Collectors.toList()); - + return ResponseEntity.ok().body(categories); } } diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogItemsController.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogItemsController.java index e20c089e6..33597b70d 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogItemsController.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/CatalogItemsController.java @@ -2,7 +2,6 @@ import java.util.List; import java.util.stream.Collectors; - import com.dressca.applicationcore.catalog.CatalogApplicationService; import com.dressca.applicationcore.catalog.CatalogItem; import com.dressca.web.controller.dto.catalog.CatalogItemResponse; @@ -37,36 +36,32 @@ public class CatalogItemsController { /** * カタログアイテムを検索して返します。 * - * @param brandId ブランドID + * @param brandId ブランドID * @param categoryId カテゴリID - * @param page ページ番号。未指定の場合は1。 - * @param pageSize ページサイズ。未指定の場合は20。 + * @param page ページ番号。未指定の場合は1。 + * @param pageSize ページサイズ。未指定の場合は20。 * @return カタログアイテムの一覧 */ @Operation(summary = "カタログアイテムを検索して返します.", description = "カタログアイテムを検索して返します.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = PagedCatalogItemResponse.class))), - @ApiResponse(responseCode = "400", description = "リクエストエラー", content = @Content)}) + @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PagedCatalogItemResponse.class))), + @ApiResponse(responseCode = "400", description = "リクエストエラー", content = @Content) }) @GetMapping() public ResponseEntity getByQuery( @RequestParam(name = "brandId", defaultValue = "0") long brandId, @RequestParam(name = "categoryId", defaultValue = "0") long categoryId, @RequestParam(name = "page", defaultValue = "0") int page, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize) { - List items = - service.getCatalogItems(brandId, categoryId, page, pageSize).stream() - .map(CatalogItemMapper::convert) - .collect(Collectors.toList()); + List items = service.getCatalogItems(brandId, categoryId, page, pageSize).stream() + .map(CatalogItemMapper::convert) + .collect(Collectors.toList()); int totalCount = service.countCatalogItems(brandId, categoryId); PagedCatalogItemResponse returnValue = new PagedCatalogItemResponse( - items, + items, totalCount, page, - pageSize - ); + pageSize); return ResponseEntity.ok().body(returnValue); } } diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/OrderController.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/OrderController.java index 9031ba316..31692e7a9 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/OrderController.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/OrderController.java @@ -20,7 +20,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; - import java.net.URI; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; @@ -56,10 +55,8 @@ public class OrderController { */ @Operation(summary = "注文情報を取得します.", description = "注文情報を取得します.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "成功.", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = OrderResponse.class))), - @ApiResponse(responseCode = "404", description = "注文IDが存在しない.", content = @Content)}) + @ApiResponse(responseCode = "200", description = "成功.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = OrderResponse.class))), + @ApiResponse(responseCode = "404", description = "注文IDが存在しない.", content = @Content) }) @GetMapping("{orderId}") public ResponseEntity getById(@PathVariable("orderId") long orderId, HttpServletRequest req) { @@ -81,10 +78,9 @@ public ResponseEntity getById(@PathVariable("orderId") long order * @return なし */ @Operation(summary = "買い物かごに登録されている商品を注文します.", description = "買い物かごに登録されている商品を注文します.") - @ApiResponses( - value = {@ApiResponse(responseCode = "201", description = "成功.", content = @Content), - @ApiResponse(responseCode = "400", description = "リクエストエラー.", content = @Content), - @ApiResponse(responseCode = "500", description = "サーバーエラー.", content = @Content)}) + @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "成功.", content = @Content), + @ApiResponse(responseCode = "400", description = "リクエストエラー.", content = @Content), + @ApiResponse(responseCode = "500", description = "サーバーエラー.", content = @Content) }) @PostMapping public ResponseEntity postOrder(@RequestBody @Valid PostOrderRequest postOrderInput, HttpServletRequest req) { diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/accounting/AccountResponse.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/accounting/AccountResponse.java index 247e157a4..0c9e8b713 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/accounting/AccountResponse.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/accounting/AccountResponse.java @@ -6,6 +6,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * 買い物かごの会計情報を格納するdtoクラスです。 + */ @Data @NoArgsConstructor @AllArgsConstructor diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/BasketItemResponse.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/BasketItemResponse.java index fedcc82e6..a61265925 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/BasketItemResponse.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/BasketItemResponse.java @@ -7,6 +7,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * 買い物かごに格納された単一の商品情報を格納するレスポンスクラスです。 + */ @Data @NoArgsConstructor @AllArgsConstructor diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/BasketResponse.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/BasketResponse.java index d3d2d6239..7dc0533e2 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/BasketResponse.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/BasketResponse.java @@ -7,6 +7,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * 買い物かごアイテムの一覧を格納するためのdtoクラスです。 + */ @Data @NoArgsConstructor @AllArgsConstructor diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/PostBasketItemsRequest.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/PostBasketItemsRequest.java index c212e04bb..4c3da350c 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/PostBasketItemsRequest.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/PostBasketItemsRequest.java @@ -5,6 +5,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * 買い物かごにアイテムを追加する際に用いるdtoクラスです。 + */ @Data @NoArgsConstructor @AllArgsConstructor diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/PutBasketItemRequest.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/PutBasketItemRequest.java index d63d3dc3d..291338589 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/PutBasketItemRequest.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/baskets/PutBasketItemRequest.java @@ -5,6 +5,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * 買い物かごアイテム内の数量を変更する際に用いるdtoクラスです。 + */ @Data @NoArgsConstructor @AllArgsConstructor diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogBrandResponse.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogBrandResponse.java index faad22ccd..07301a6fa 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogBrandResponse.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogBrandResponse.java @@ -5,6 +5,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * カタログブランドの情報を取得する際に用いるdtoクラスです。 + */ @Data @AllArgsConstructor @NoArgsConstructor diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogCategoryResponse.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogCategoryResponse.java index f9447e992..ff53c2ae5 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogCategoryResponse.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogCategoryResponse.java @@ -5,6 +5,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * カタログカテゴリの情報を取得する際に用いるdtoクラスです。 + */ @Data @AllArgsConstructor @NoArgsConstructor diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogItemResponse.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogItemResponse.java index 11f487432..e349554ee 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogItemResponse.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/controller/dto/catalog/CatalogItemResponse.java @@ -4,12 +4,15 @@ import java.util.List; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.Setter; -@Getter -@Setter +/** + * カタログアイテムを取得する際に用いるdtoクラスです。 + */ +@Data +@EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor public class CatalogItemResponse extends CatalogItemSummaryResponse { @@ -25,14 +28,14 @@ public class CatalogItemResponse extends CatalogItemSummaryResponse { /** * コンストラクタ。 * - * @param id ID - * @param name 名前 - * @param productCode プロダクトコード - * @param assetCodes アセットコード - * @param description 商品説明 - * @param price 価格 + * @param id ID + * @param name 名前 + * @param productCode プロダクトコード + * @param assetCodes アセットコード + * @param description 商品説明 + * @param price 価格 * @param catalogCategoryId カタログカテゴリーID - * @param catalogBrandId カタログブランドID + * @param catalogBrandId カタログブランドID */ public CatalogItemResponse(long id, String name, String productCode, List assetCodes, String description, BigDecimal price, long catalogCategoryId, long catalogBrandId) { @@ -40,7 +43,7 @@ public CatalogItemResponse(long id, String name, String productCode, List - handleLogicException(LogicException e, HttpServletRequest req) { - aplog.error(createLogMessageStackTrace(e, e.getExceptionId(), e.getLogMessageValue())); + public ResponseEntity handleLogicException(LogicException e, HttpServletRequest req) { + apLog.error(createLogMessageStackTrace(e, e.getExceptionId(), e.getLogMessageValue())); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .contentType(MediaType.APPLICATION_JSON) - .body(createErrorResponse(e, req)); + .contentType(MediaType.APPLICATION_JSON) + .body(createErrorResponse(e, req)); } /** * その他のシステムエラーをステータースコード500で返却する。 * - * @param e その他の例外 + * @param e その他の例外 * @param req リクエスト * @return ステータースコード500のレスポンス */ @ExceptionHandler(SystemException.class) public ResponseEntity handleException(SystemException e, HttpServletRequest req) { - aplog.error(createLogMessageStackTrace(e, e.getExceptionId(), e.getLogMessageValue())); + apLog.error(createLogMessageStackTrace(e, e.getExceptionId(), e.getLogMessageValue())); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .contentType(MediaType.APPLICATION_JSON) - .body(createErrorResponse(e, req)); + .contentType(MediaType.APPLICATION_JSON) + .body(createErrorResponse(e, req)); } /** * 上記のいずれにも当てはまらない例外をステータースコード500で返却する。 * - * @param e その他の例外 + * @param e その他の例外 * @param req リクエスト * @return ステータースコード500のレスポンス */ @ExceptionHandler(Exception.class) public ResponseEntity handleException(Exception e, HttpServletRequest req) { - aplog.error(createLogMessageStackTrace(e, ExceptionIdConstant.E_SHARE0000, null)); + apLog.error(createLogMessageStackTrace(e, ExceptionIdConstant.E_SHARE0000, null)); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .contentType(MediaType.APPLICATION_JSON) - .body(createErrorResponse( - new SystemException(e, ExceptionIdConstant.E_SHARE0000, null, null), req)); + .contentType(MediaType.APPLICATION_JSON) + .body(createErrorResponse( + new SystemException(e, ExceptionIdConstant.E_SHARE0000, null, null), req)); } private ErrorResponse createErrorResponse(LogicException e, HttpServletRequest request) { @@ -100,7 +99,7 @@ private String createLogMessageStackTrace(Exception e, String exceptionId, Strin String code = String.join(PROPERTY_DELIMITER, exceptionId, EXCEPTION_MESSAGE_SUFFIX_LOG); String exceptionMessage = messageSource.getMessage(code, logMessageValue, Locale.getDefault()); builder.append(exceptionId).append(" ").append(exceptionMessage) - .append(SystemPropertyConstants.LINE_SEPARATOR); + .append(SystemPropertyConstants.LINE_SEPARATOR); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); builder.append(writer.getBuffer().toString()); diff --git a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/filter/BuyerIdFilter.java b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/filter/BuyerIdFilter.java index 947a712f9..431207e1e 100644 --- a/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/filter/BuyerIdFilter.java +++ b/samples/web-csr/dressca-backend/web/src/main/java/com/dressca/web/filter/BuyerIdFilter.java @@ -12,6 +12,9 @@ import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; +/** + * 購入者IDにフィルターをかけるクラスです。 + */ public class BuyerIdFilter implements Filter { private static final String DEFAULT_BUYER_COOKIE_NAME = "Dressca-Bid"; diff --git a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/applicationcore/assets/AssetApplicationServiceTest.java b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/applicationcore/assets/AssetApplicationServiceTest.java index b5b54554b..20626be0b 100644 --- a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/applicationcore/assets/AssetApplicationServiceTest.java +++ b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/applicationcore/assets/AssetApplicationServiceTest.java @@ -2,6 +2,9 @@ import org.junit.jupiter.api.Test; +/** + * {@link AssetApplicationService}の動作をテストするクラスです。 + */ public class AssetApplicationServiceTest { @Test void testGetAssetResourceInfo() { diff --git a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/WebApplicationTests.java b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/WebApplicationTests.java index bb6715155..4a0cb6732 100644 --- a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/WebApplicationTests.java +++ b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/WebApplicationTests.java @@ -7,6 +7,7 @@ class WebApplicationTests { @Test - void contextLoads() {} + void contextLoads() { + } } diff --git a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controller/AssetsControllerTest.java b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controller/AssetsControllerTest.java index 6d035c6ff..b9dd2b02a 100644 --- a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controller/AssetsControllerTest.java +++ b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controller/AssetsControllerTest.java @@ -7,15 +7,17 @@ import com.dressca.web.WebApplication; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; 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.http.MediaType; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.web.servlet.MockMvc; -@ExtendWith(SpringExtension.class) +/** + * {@link AssetsController}の動作をテストするクラスです。 + */ +@SpringJUnitConfig @SpringBootTest(classes = WebApplication.class) @AutoConfigureMockMvc public class AssetsControllerTest { @@ -31,8 +33,8 @@ void testGet_01() throws Exception { // 期待する戻り値 this.mockMvc.perform(get("/api/assets/" + assetCode)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.IMAGE_PNG_VALUE)); + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.IMAGE_PNG_VALUE)); } @Test @@ -42,6 +44,6 @@ void testGet_02() throws Exception { String assetCode = "NotExistAssetCode"; this.mockMvc.perform(get("/api/assets/" + assetCode)) - .andExpect(status().isNotFound()); + .andExpect(status().isNotFound()); } } diff --git a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controller/HealthCheckTest.java b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controller/HealthCheckTest.java index b268cca6b..15e89f6c9 100644 --- a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controller/HealthCheckTest.java +++ b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controller/HealthCheckTest.java @@ -7,34 +7,36 @@ import com.dressca.web.WebApplication; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; 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.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.web.servlet.MockMvc; -@ExtendWith(SpringExtension.class) +/** + * ヘルスチェックAPIの動作をテストするクラスです。 + */ +@SpringJUnitConfig @SpringBootTest(classes = WebApplication.class) @AutoConfigureMockMvc public class HealthCheckTest { - - @Autowired - private MockMvc mockMvc; - @Test - @DisplayName("testGet_03_ヘルスチェック_サーバ正常動作確認") - void testGet_serverCheck() throws Exception { - this.mockMvc.perform(get("/api/health/check")) + @Autowired + private MockMvc mockMvc; + + @Test + @DisplayName("testGet_03_ヘルスチェック_サーバ正常動作確認") + void testGet_serverCheck() throws Exception { + this.mockMvc.perform(get("/api/health/check")) .andExpect(status().isOk()) .andExpect(content().json("{'status':'UP'}")); - } - - @Test - @DisplayName("testGet_04_ヘルスチェック_DB正常動作確認") - void testGet_databaseCheck() throws Exception { - this.mockMvc.perform(get("/api/health/datasource")) + } + + @Test + @DisplayName("testGet_04_ヘルスチェック_DB正常動作確認") + void testGet_databaseCheck() throws Exception { + this.mockMvc.perform(get("/api/health/datasource")) .andExpect(status().isOk()) .andExpect(content().json("{'status':'UP'}")); - } + } } diff --git a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controlleradvice/ExceptionHandlerControllerAdviceTest.java b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controlleradvice/ExceptionHandlerControllerAdviceTest.java index 5b241db77..63273ad88 100644 --- a/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controlleradvice/ExceptionHandlerControllerAdviceTest.java +++ b/samples/web-csr/dressca-backend/web/src/test/java/com/dressca/web/controlleradvice/ExceptionHandlerControllerAdviceTest.java @@ -1,5 +1,13 @@ package com.dressca.web.controlleradvice; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.fail; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.times; + import com.dressca.web.controller.AssetsController; import com.dressca.systemcommon.constant.ExceptionIdConstant; import com.dressca.systemcommon.constant.SystemPropertyConstants; @@ -7,16 +15,14 @@ import com.dressca.systemcommon.exception.SystemException; import com.dressca.applicationcore.assets.AssetNotFoundException; import com.dressca.web.WebApplication; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; 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.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.web.servlet.MockMvc; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -29,19 +35,14 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.LoggerConfig; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.mockito.Mockito.*; - import com.dressca.systemcommon.util.ApplicationContextWrapper; import java.util.Locale; import org.springframework.context.MessageSource; -@ExtendWith(SpringExtension.class) +/** + * {@link ExceptionHandlerControllerAdvice }の動作をテストするクラスです。 + */ +@SpringJUnitConfig @SpringBootTest(classes = WebApplication.class) @AutoConfigureMockMvc public class ExceptionHandlerControllerAdviceTest { @@ -62,6 +63,9 @@ public class ExceptionHandlerControllerAdviceTest { @Captor private ArgumentCaptor logCaptor; + /** + * 各テスト実施前のセットアップを行うメソッド。 + */ @BeforeEach public void setup() { // アプリケーションログメッセージを取得する設定 @@ -97,19 +101,20 @@ void testException_01() throws LogicException { String assetCode = "b52dc7f712d94ca5812dd995bf926c04"; // 期待値の設定 String exceptionId = ExceptionIdConstant.E_ASSET0001; - String logMessageValue[] = {assetCode}; + String[] logMessageValue = { assetCode }; // モックの戻り値設定 Mockito.when(assetsController.get(anyString())) - .thenThrow(new AssetNotFoundException(assetCode)); - try { + .thenThrow(new AssetNotFoundException(assetCode)); + try { // APIの呼び出しとエラー時のレスポンスであることの確認 this.mockMvc.perform(get("/api/assets/" + assetCode)) - .andExpect(status().isInternalServerError()) - .andExpect(content().json("{\"type\":\"" + exceptionId + "\"}")); + .andExpect(status().isInternalServerError()) + .andExpect(content().json("{\"type\":\"" + exceptionId + "\"}")); // アプリケーションログのメッセージの確認 Mockito.verify(mockAppender, times(1)).append(logCaptor.capture()); assertThat(logCaptor.getValue().getLevel()).isEqualTo(Level.ERROR); - assertThat(logCaptor.getValue().getMessage().getFormattedMessage()).startsWith(createLogMessage(exceptionId, logMessageValue)); + assertThat(logCaptor.getValue().getMessage().getFormattedMessage()) + .startsWith(createLogMessage(exceptionId, logMessageValue)); } catch (Exception e) { e.printStackTrace(); fail(); @@ -123,20 +128,22 @@ void testException_02() throws LogicException { String assetCode = "b52dc7f712d94ca5812dd995bf926c04"; // 期待値の設定 String exceptionId = ExceptionIdConstant.E_SHARE0000; - String frontMessageValue[] = null; - String logMessageValue[] = null; + String[] frontMessageValue = null; + String[] logMessageValue = null; // モックの戻り値設定 Mockito.when(assetsController.get(anyString())) - .thenThrow(new SystemException(new AssetNotFoundException(assetCode), exceptionId, frontMessageValue, logMessageValue)); + .thenThrow(new SystemException(new AssetNotFoundException(assetCode), exceptionId, frontMessageValue, + logMessageValue)); try { // APIの呼び出しとエラー時のレスポンスであることの確認 this.mockMvc.perform(get("/api/assets/" + assetCode)) - .andExpect(status().isInternalServerError()) - .andExpect(content().json("{\"type\":\"" + exceptionId + "\"}")); + .andExpect(status().isInternalServerError()) + .andExpect(content().json("{\"type\":\"" + exceptionId + "\"}")); // アプリケーションログのメッセージの確認 Mockito.verify(mockAppender, times(1)).append(logCaptor.capture()); assertThat(logCaptor.getValue().getLevel()).isEqualTo(Level.ERROR); - assertThat(logCaptor.getValue().getMessage().getFormattedMessage()).startsWith(createLogMessage(exceptionId, logMessageValue)); + assertThat(logCaptor.getValue().getMessage().getFormattedMessage()) + .startsWith(createLogMessage(exceptionId, logMessageValue)); } catch (Exception e) { e.printStackTrace(); fail(); @@ -150,19 +157,20 @@ void testException_03() throws LogicException { String assetCode = "b52dc7f712d94ca5812dd995bf926c04"; // 期待値の設定 String exceptionId = ExceptionIdConstant.E_SHARE0000; - String logMessageValue[] = null; + String[] logMessageValue = null; // モックの戻り値設定 Mockito.when(assetsController.get(anyString())) - .thenThrow(new RuntimeException()); + .thenThrow(new RuntimeException()); try { // APIの呼び出しとエラー時のレスポンスであることの確認 this.mockMvc.perform(get("/api/assets/" + assetCode)) - .andExpect(status().isInternalServerError()) - .andExpect(content().json("{\"type\":\"" + exceptionId + "\"}")); + .andExpect(status().isInternalServerError()) + .andExpect(content().json("{\"type\":\"" + exceptionId + "\"}")); // アプリケーションログのメッセージの確認 Mockito.verify(mockAppender, times(1)).append(logCaptor.capture()); assertThat(logCaptor.getValue().getLevel()).isEqualTo(Level.ERROR); - assertThat(logCaptor.getValue().getMessage().getFormattedMessage()).startsWith(createLogMessage(exceptionId, logMessageValue)); + assertThat(logCaptor.getValue().getMessage().getFormattedMessage()) + .startsWith(createLogMessage(exceptionId, logMessageValue)); } catch (Exception e) { e.printStackTrace(); fail(); @@ -177,6 +185,3 @@ private String createLogMessage(String exceptionId, String[] logMessageValue) { return exceptionId + " " + exceptionMessage + SystemPropertyConstants.LINE_SEPARATOR; } } - - -