From 2174972d438003296371e4902d890e6e7f01618f Mon Sep 17 00:00:00 2001 From: Hesham Massoud Date: Wed, 27 Sep 2017 16:49:21 +0200 Subject: [PATCH] #99: Add channel support in IT utils. --- .../commons/utils/ProductITUtils.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/integration-test/java/com/commercetools/sync/integration/commons/utils/ProductITUtils.java b/src/integration-test/java/com/commercetools/sync/integration/commons/utils/ProductITUtils.java index af0ade89b1..4de565cbe5 100644 --- a/src/integration-test/java/com/commercetools/sync/integration/commons/utils/ProductITUtils.java +++ b/src/integration-test/java/com/commercetools/sync/integration/commons/utils/ProductITUtils.java @@ -1,11 +1,20 @@ package com.commercetools.sync.integration.commons.utils; import com.commercetools.sync.commons.utils.CtpQueryUtils; +import io.sphere.sdk.channels.Channel; import io.sphere.sdk.client.SphereClient; +import io.sphere.sdk.models.Reference; +import io.sphere.sdk.products.PriceDraft; +import io.sphere.sdk.products.PriceDraftBuilder; import io.sphere.sdk.products.Product; +import io.sphere.sdk.products.ProductDraft; +import io.sphere.sdk.products.ProductDraftBuilder; +import io.sphere.sdk.products.ProductVariantDraft; +import io.sphere.sdk.products.ProductVariantDraftBuilder; import io.sphere.sdk.products.commands.ProductDeleteCommand; import io.sphere.sdk.products.commands.ProductUpdateCommand; import io.sphere.sdk.products.commands.updateactions.Unpublish; +import io.sphere.sdk.products.expansion.ProductExpansionModel; import io.sphere.sdk.products.queries.ProductQuery; import io.sphere.sdk.producttypes.ProductType; import io.sphere.sdk.producttypes.ProductTypeDraft; @@ -22,7 +31,9 @@ import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories; import static com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes; +import static com.commercetools.sync.integration.inventories.utils.InventoryITUtils.deleteSupplyChannels; import static io.sphere.sdk.json.SphereJsonUtils.readObjectFromResource; +import static java.util.stream.Collectors.toList; public final class ProductITUtils { /** @@ -52,6 +63,7 @@ public static void deleteProductSyncTestData(@Nonnull final SphereClient ctpClie deleteProductTypes(ctpClient); deleteAllCategories(ctpClient); deleteTypes(ctpClient); + deleteSupplyChannels(ctpClient); } /** @@ -108,4 +120,35 @@ public static ProductQuery getProductQuery() { .plusExpansionPaths(channelExpansionModel -> channelExpansionModel.masterData().staged().allVariants().prices().channel()); } + + /** + * Gets the supplied {@link ProductDraft} with the price channel reference attached. + * + * @param productDraft TODO + * @param channelReference TODO + * @return TODO. + */ + public static ProductDraft getDraftWithPriceChannelReferences(@Nonnull final ProductDraft productDraft, + @Nonnull final Reference channelReference) { + final List allVariants = productDraft + .getVariants().stream().map(productVariant -> { + final List priceDraftsWithChannelReferences = + productVariant.getPrices().stream() + .map(price -> PriceDraftBuilder.of(price).channel(channelReference).build()) + .collect(toList()); + return ProductVariantDraftBuilder.of(productVariant) + .prices(priceDraftsWithChannelReferences) + .build(); + }) + .collect(toList()); + final List masterVariantPriceDrafts = productDraft + .getMasterVariant().getPrices().stream().map(price -> PriceDraftBuilder.of(price) + .channel(channelReference) + .build()).collect(toList()); + return ProductDraftBuilder.of(productDraft) + .masterVariant(ProductVariantDraftBuilder.of(productDraft.getMasterVariant()) + .prices(masterVariantPriceDrafts).build()) + .variants(allVariants) + .build(); + } }