Search in sources :

Example 1 with LOCALISED_STRING_CUSTOM_FIELD_NAME

use of com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME in project commercetools-sync-java by commercetools.

the class ProductSyncWithPricesIT method withMixedCasesOfPriceMatches_ShouldBuildActions.

@Test
void withMixedCasesOfPriceMatches_ShouldBuildActions() {
    // Preparation
    createExistingProductWithPrices();
    final ProductDraft newProductDraft = createProductDraftWithNewPrices();
    final ObjectNode lTextWithEnDe = JsonNodeFactory.instance.objectNode().put("de", "rot").put("en", "red");
    final PriceDraft de222EurCust1Ofid = PriceDraftBuilder.of(DRAFT_DE_222_EUR_CUST1).customerGroup(cust1).build();
    final PriceDraft de333UsdCust1Ofid = PriceDraftBuilder.of(DRAFT_DE_333_USD_CUST1).customerGroup(cust1).build();
    final PriceDraft us666Usd0102Cust2OfId = PriceDraftBuilder.of(DRAFT_US_666_USD_CUST2_01_02).customerGroup(cust2).build();
    final CustomFieldsDraft customType1WithEnDeOfId = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), createCustomFieldsJsonMap(LOCALISED_STRING_CUSTOM_FIELD_NAME, lTextWithEnDe));
    final PriceDraft withChannel1CustomType1WithEnDeOfId = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithEnDeOfId);
    final PriceDraft withChannel2CustomType1WithEnDeOfId = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel2.getId(), customType1WithEnDeOfId);
    // test
    final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
    // assertion
    assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
    final Integer masterVariantId = product.getMasterData().getStaged().getMasterVariant().getId();
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof RemovePrice).hasSize(5);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof ChangePrice).hasSize(3);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomType).hasSize(1);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(1);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof AddPrice).hasSize(9).containsExactlyInAnyOrder(AddPrice.ofVariantId(masterVariantId, de222EurCust1Ofid, true), AddPrice.ofVariantId(masterVariantId, DRAFT_DE_111_EUR_01_02, true), AddPrice.ofVariantId(masterVariantId, DRAFT_DE_111_EUR_03_04, true), AddPrice.ofVariantId(masterVariantId, de333UsdCust1Ofid, true), AddPrice.ofVariantId(masterVariantId, DRAFT_UK_999_GBP, true), AddPrice.ofVariantId(masterVariantId, us666Usd0102Cust2OfId, true), AddPrice.ofVariantId(masterVariantId, DRAFT_FR_888_EUR_01_03, true), AddPrice.ofVariantId(masterVariantId, DRAFT_FR_999_EUR_03_06, true), AddPrice.ofVariantId(masterVariantId, DRAFT_NE_777_EUR_05_07, true));
    final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
    assertThat(productProjection).isNotNull();
    final List<PriceDraft> newPricesWithReferenceIds = asList(DRAFT_DE_111_EUR, de222EurCust1Ofid, DRAFT_DE_111_EUR_01_02, DRAFT_DE_111_EUR_03_04, withChannel1CustomType1WithEnDeOfId, withChannel2CustomType1WithEnDeOfId, de333UsdCust1Ofid, DRAFT_DE_22_USD, DRAFT_UK_111_GBP_01_02, DRAFT_UK_999_GBP, us666Usd0102Cust2OfId, DRAFT_FR_888_EUR_01_03, DRAFT_FR_999_EUR_03_06, DRAFT_NE_777_EUR_01_04, DRAFT_NE_777_EUR_05_07);
    assertPricesAreEqual(productProjection.getMasterVariant().getPrices(), newPricesWithReferenceIds);
}
Also used : SetProductPriceCustomType(io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomType) PriceDraftFixtures.getPriceDraftWithKeys(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.getPriceDraftWithKeys) BeforeEach(org.junit.jupiter.api.BeforeEach) PRODUCT_TYPE_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_RESOURCE_PATH) SyncException(com.commercetools.sync.commons.exceptions.SyncException) USD(io.sphere.sdk.models.DefaultCurrencyUnits.USD) DRAFT_UK_111_GBP(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_UK_111_GBP) ITUtils.createVariantDraft(com.commercetools.sync.integration.commons.utils.ITUtils.createVariantDraft) PriceCompositeId(com.commercetools.sync.internals.helpers.PriceCompositeId) ChannelITUtils.createChannel(com.commercetools.sync.integration.commons.utils.ChannelITUtils.createChannel) Channel(io.sphere.sdk.channels.Channel) Collections.singletonList(java.util.Collections.singletonList) DRAFT_DE_111_USD(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_111_USD) AfterAll(org.junit.jupiter.api.AfterAll) BigDecimal(java.math.BigDecimal) NullNode(com.fasterxml.jackson.databind.node.NullNode) EMPTY_SET_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.EMPTY_SET_CUSTOM_FIELD_NAME) DRAFT_DE_333_USD_CUST1(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_333_USD_CUST1) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DRAFT_NE_777_EUR_01_04(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_NE_777_EUR_01_04) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) JsonNode(com.fasterxml.jackson.databind.JsonNode) ProductProjection(io.sphere.sdk.products.ProductProjection) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) DRAFT_UK_333_GBP_03_05(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_UK_333_GBP_03_05) AssetDraft(io.sphere.sdk.models.AssetDraft) DRAFT_DE_111_EUR_01_02(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_111_EUR_01_02) Price(io.sphere.sdk.products.Price) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductSyncOptionsBuilder(com.commercetools.sync.products.ProductSyncOptionsBuilder) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) DRAFT_DE_222_EUR_CUST1_KEY(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_222_EUR_CUST1_KEY) DRAFT_DE_111_EUR_02_03(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_111_EUR_02_03) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) ProductITUtils.deleteAllProducts(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts) EUR(io.sphere.sdk.models.DefaultCurrencyUnits.EUR) ArrayList(java.util.ArrayList) PriceDraftBuilder(io.sphere.sdk.products.PriceDraftBuilder) DRAFT_UK_999_GBP(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_UK_999_GBP) ProductSync(com.commercetools.sync.products.ProductSync) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) CustomerGroup(io.sphere.sdk.customergroups.CustomerGroup) DRAFT_DE_22_USD(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_22_USD) PriceDraftFixtures.byMonth(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.byMonth) PriceDraft(io.sphere.sdk.products.PriceDraft) DRAFT_DE_111_EUR(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_111_EUR) DRAFT_UK_111_GBP_01_02(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_UK_111_GBP_01_02) DRAFT_US_666_USD_CUST2_01_02_KEY(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_US_666_USD_CUST2_01_02_KEY) Asset(io.sphere.sdk.models.Asset) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Type(io.sphere.sdk.types.Type) ProductITUtils.createPricesCustomType(com.commercetools.sync.integration.commons.utils.ProductITUtils.createPricesCustomType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) ProductITUtils.deleteProductSyncTestData(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData) DRAFT_DE_222_EUR_CUST1(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_222_EUR_CUST1) Locale(java.util.Locale) DE(com.neovisionaries.i18n.CountryCode.DE) ProductDraft(io.sphere.sdk.products.ProductDraft) DRAFT_NE_777_EUR_05_07(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_NE_777_EUR_05_07) DRAFT_FR_888_EUR_01_03(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_FR_888_EUR_01_03) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Collections.emptyList(java.util.Collections.emptyList) Product(io.sphere.sdk.products.Product) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.jupiter.api.Test) List(java.util.List) ProductProjectionType(io.sphere.sdk.products.ProductProjectionType) AddPrice(io.sphere.sdk.products.commands.updateactions.AddPrice) Optional(java.util.Optional) ProductCreateCommand(io.sphere.sdk.products.commands.ProductCreateCommand) DRAFT_FR_999_EUR_03_06(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_FR_999_EUR_03_06) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) PriceDraftFixtures.getPriceDraft(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.getPriceDraft) NULL_SET_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.NULL_SET_CUSTOM_FIELD_NAME) DRAFT_US_666_USD_CUST2_01_02(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_US_666_USD_CUST2_01_02) DRAFT_DE_333_USD_CUST1_KEY(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_333_USD_CUST1_KEY) CollectionUtils.collectionToMap(com.commercetools.sync.commons.utils.CollectionUtils.collectionToMap) ProductType(io.sphere.sdk.producttypes.ProductType) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DRAFT_NE_123_EUR_01_04(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_NE_123_EUR_01_04) DRAFT_UK_111_GBP_02_03(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_UK_111_GBP_02_03) RemovePrice(io.sphere.sdk.products.commands.updateactions.RemovePrice) Assertions.as(org.assertj.core.api.Assertions.as) NON_EMPTY_SEY_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.NON_EMPTY_SEY_CUSTOM_FIELD_NAME) Nonnull(javax.annotation.Nonnull) PriceDraftFixtures.createCustomFieldsJsonMap(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.createCustomFieldsJsonMap) DRAFT_DE_111_EUR_03_04(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_DE_111_EUR_03_04) ProductType.referenceOfId(io.sphere.sdk.producttypes.ProductType.referenceOfId) DRAFT_FR_777_EUR_01_04(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_FR_777_EUR_01_04) TriFunction(com.commercetools.sync.commons.utils.TriFunction) CustomerGroupITUtils.createCustomerGroup(com.commercetools.sync.integration.commons.utils.CustomerGroupITUtils.createCustomerGroup) ChangePrice(io.sphere.sdk.products.commands.updateactions.ChangePrice) DRAFT_US_111_USD(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_US_111_USD) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) DRAFT_NE_321_EUR_04_06(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.DRAFT_NE_321_EUR_04_06) ProductProjectionByKeyGet(io.sphere.sdk.products.queries.ProductProjectionByKeyGet) SetProductPriceCustomField(io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomField) LOCALISED_STRING_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME) NULL_NODE_SET_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.NULL_NODE_SET_CUSTOM_FIELD_NAME) ChangePrice(io.sphere.sdk.products.commands.updateactions.ChangePrice) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SetProductPriceCustomType(io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomType) PriceDraft(io.sphere.sdk.products.PriceDraft) PriceDraftFixtures.getPriceDraft(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.getPriceDraft) SetProductPriceCustomField(io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomField) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductProjection(io.sphere.sdk.products.ProductProjection) RemovePrice(io.sphere.sdk.products.commands.updateactions.RemovePrice) ProductDraft(io.sphere.sdk.products.ProductDraft) AddPrice(io.sphere.sdk.products.commands.updateactions.AddPrice) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) Test(org.junit.jupiter.api.Test)

Aggregations

AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)1 SyncException (com.commercetools.sync.commons.exceptions.SyncException)1 CollectionUtils.collectionToMap (com.commercetools.sync.commons.utils.CollectionUtils.collectionToMap)1 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)1 TriConsumer (com.commercetools.sync.commons.utils.TriConsumer)1 TriFunction (com.commercetools.sync.commons.utils.TriFunction)1 ChannelITUtils.createChannel (com.commercetools.sync.integration.commons.utils.ChannelITUtils.createChannel)1 CustomerGroupITUtils.createCustomerGroup (com.commercetools.sync.integration.commons.utils.CustomerGroupITUtils.createCustomerGroup)1 EMPTY_SET_CUSTOM_FIELD_NAME (com.commercetools.sync.integration.commons.utils.ITUtils.EMPTY_SET_CUSTOM_FIELD_NAME)1 LOCALISED_STRING_CUSTOM_FIELD_NAME (com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME)1 NON_EMPTY_SEY_CUSTOM_FIELD_NAME (com.commercetools.sync.integration.commons.utils.ITUtils.NON_EMPTY_SEY_CUSTOM_FIELD_NAME)1 NULL_NODE_SET_CUSTOM_FIELD_NAME (com.commercetools.sync.integration.commons.utils.ITUtils.NULL_NODE_SET_CUSTOM_FIELD_NAME)1 NULL_SET_CUSTOM_FIELD_NAME (com.commercetools.sync.integration.commons.utils.ITUtils.NULL_SET_CUSTOM_FIELD_NAME)1 ITUtils.createVariantDraft (com.commercetools.sync.integration.commons.utils.ITUtils.createVariantDraft)1 ProductITUtils.createPricesCustomType (com.commercetools.sync.integration.commons.utils.ProductITUtils.createPricesCustomType)1 ProductITUtils.deleteAllProducts (com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts)1 ProductITUtils.deleteProductSyncTestData (com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData)1 ProductTypeITUtils.createProductType (com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType)1 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)1 PriceCompositeId (com.commercetools.sync.internals.helpers.PriceCompositeId)1