Search in sources :

Example 1 with NULL_SET_CUSTOM_FIELD_NAME

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

the class ProductSyncWithPricesIT method sync_WithNullNewCustomFields_ShouldCorrectlyUpdateCustomFields.

@Test
void sync_WithNullNewCustomFields_ShouldCorrectlyUpdateCustomFields() {
    // preparation
    final ArrayNode emptySet = JsonNodeFactory.instance.arrayNode();
    final Map<String, JsonNode> customFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
    final ArrayNode nonEmptySet = JsonNodeFactory.instance.arrayNode();
    nonEmptySet.add("foo");
    customFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptySet);
    final CustomFieldsDraft customType1WithSet = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), customFieldsJsonMap);
    final PriceDraft withChannel1CustomType1WithSet = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithSet);
    final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithSet))).key("bar").build();
    product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
    final CustomFieldsDraft customType1WithEmptySet = CustomFieldsDraft.ofTypeKeyAndJson(customType1.getKey(), new HashMap<>());
    final PriceDraft withChannel1CustomType1WithNullSet = getPriceDraftWithKeys(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getKey(), customType1WithEmptySet);
    final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithNullSet))).key("bar").build();
    // test
    final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
    // assertion
    assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(2);
    final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
    assertThat(productProjection).isNotNull();
    final List<Price> prices = productProjection.getMasterVariant().getPrices();
    for (Price price : prices) {
        assertThat(price.getCustom().getFieldAsStringSet(EMPTY_SET_CUSTOM_FIELD_NAME)).isNull();
        assertThat(price.getCustom().getFieldAsStringSet(NULL_SET_CUSTOM_FIELD_NAME)).isNull();
        assertThat(price.getCustom().getFieldAsStringSet(NULL_NODE_SET_CUSTOM_FIELD_NAME)).isNull();
        assertThat(price.getCustom().getFieldAsStringSet(NON_EMPTY_SEY_CUSTOM_FIELD_NAME)).isNull();
    }
}
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) PriceDraft(io.sphere.sdk.products.PriceDraft) PriceDraftFixtures.getPriceDraft(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.getPriceDraft) JsonNode(com.fasterxml.jackson.databind.JsonNode) SetProductPriceCustomField(io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomField) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductProjection(io.sphere.sdk.products.ProductProjection) ProductDraft(io.sphere.sdk.products.ProductDraft) Price(io.sphere.sdk.products.Price) AddPrice(io.sphere.sdk.products.commands.updateactions.AddPrice) RemovePrice(io.sphere.sdk.products.commands.updateactions.RemovePrice) ChangePrice(io.sphere.sdk.products.commands.updateactions.ChangePrice) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) Test(org.junit.jupiter.api.Test)

Example 2 with NULL_SET_CUSTOM_FIELD_NAME

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

the class ProductSyncWithPricesIT method sync_WithEmptySetNewCustomFields_ShouldCorrectlyUpdateCustomFields.

@Test
void sync_WithEmptySetNewCustomFields_ShouldCorrectlyUpdateCustomFields() {
    // preparation
    final ArrayNode emptySet = JsonNodeFactory.instance.arrayNode();
    final Map<String, JsonNode> customFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
    final ArrayNode nonEmptySet = JsonNodeFactory.instance.arrayNode();
    nonEmptySet.add("foo");
    customFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptySet);
    final CustomFieldsDraft customType1WithSet = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), customFieldsJsonMap);
    final PriceDraft withChannel1CustomType1WithSet = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithSet);
    final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithSet))).key("bar").build();
    product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
    final Map<String, JsonNode> newCustomFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
    newCustomFieldsJsonMap.put(NULL_SET_CUSTOM_FIELD_NAME, emptySet);
    newCustomFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, emptySet);
    newCustomFieldsJsonMap.put(NULL_NODE_SET_CUSTOM_FIELD_NAME, emptySet);
    final CustomFieldsDraft customType1WithEmptySet = CustomFieldsDraft.ofTypeKeyAndJson(customType1.getKey(), newCustomFieldsJsonMap);
    final PriceDraft withChannel1CustomType1WithNullSet = getPriceDraftWithKeys(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getKey(), customType1WithEmptySet);
    final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithNullSet))).key("bar").build();
    // test
    final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
    // assertion
    assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(3);
    final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
    assertThat(productProjection).isNotNull();
    final List<Price> prices = productProjection.getMasterVariant().getPrices();
    for (Price price : prices) {
        assertThat(price.getCustom().getFieldAsStringSet(EMPTY_SET_CUSTOM_FIELD_NAME)).isEmpty();
        assertThat(price.getCustom().getFieldAsStringSet(NULL_SET_CUSTOM_FIELD_NAME)).isEmpty();
        assertThat(price.getCustom().getFieldAsStringSet(NULL_NODE_SET_CUSTOM_FIELD_NAME)).isEmpty();
        assertThat(price.getCustom().getFieldAsStringSet(NON_EMPTY_SEY_CUSTOM_FIELD_NAME)).isEmpty();
    }
}
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) PriceDraft(io.sphere.sdk.products.PriceDraft) PriceDraftFixtures.getPriceDraft(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.getPriceDraft) JsonNode(com.fasterxml.jackson.databind.JsonNode) SetProductPriceCustomField(io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomField) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductProjection(io.sphere.sdk.products.ProductProjection) ProductDraft(io.sphere.sdk.products.ProductDraft) Price(io.sphere.sdk.products.Price) AddPrice(io.sphere.sdk.products.commands.updateactions.AddPrice) RemovePrice(io.sphere.sdk.products.commands.updateactions.RemovePrice) ChangePrice(io.sphere.sdk.products.commands.updateactions.ChangePrice) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) Test(org.junit.jupiter.api.Test)

Example 3 with NULL_SET_CUSTOM_FIELD_NAME

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

the class ProductSyncWithPricesIT method sync_WithNullJsonNodeNewCustomFields_ShouldCorrectlyUpdateCustomFields.

@Test
void sync_WithNullJsonNodeNewCustomFields_ShouldCorrectlyUpdateCustomFields() {
    // preparation
    final ArrayNode emptySet = JsonNodeFactory.instance.arrayNode();
    final Map<String, JsonNode> customFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
    final ArrayNode nonEmptySet = JsonNodeFactory.instance.arrayNode();
    nonEmptySet.add("foo");
    customFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptySet);
    final CustomFieldsDraft customType1WithSet = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), customFieldsJsonMap);
    final PriceDraft withChannel1CustomType1WithSet = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithSet);
    final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithSet))).key("bar").build();
    product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
    final NullNode nullJsonNode = JsonNodeFactory.instance.nullNode();
    final Map<String, JsonNode> newCustomFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, nullJsonNode);
    newCustomFieldsJsonMap.put(NULL_SET_CUSTOM_FIELD_NAME, nullJsonNode);
    newCustomFieldsJsonMap.put(NULL_NODE_SET_CUSTOM_FIELD_NAME, nullJsonNode);
    newCustomFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nullJsonNode);
    final CustomFieldsDraft customType1WithEmptySet = CustomFieldsDraft.ofTypeKeyAndJson(customType1.getKey(), newCustomFieldsJsonMap);
    final PriceDraft withChannel1CustomType1WithNullSet = getPriceDraftWithKeys(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getKey(), customType1WithEmptySet);
    final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithNullSet))).key("bar").build();
    // test
    final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
    // assertion
    assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(2);
    final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
    assertThat(productProjection).isNotNull();
    final List<Price> prices = productProjection.getMasterVariant().getPrices();
    for (Price price : prices) {
        assertThat(price.getCustom().getFieldAsStringSet(EMPTY_SET_CUSTOM_FIELD_NAME)).isNull();
        assertThat(price.getCustom().getFieldAsStringSet(NULL_SET_CUSTOM_FIELD_NAME)).isNull();
        assertThat(price.getCustom().getFieldAsStringSet(NULL_NODE_SET_CUSTOM_FIELD_NAME)).isNull();
        assertThat(price.getCustom().getFieldAsStringSet(NON_EMPTY_SEY_CUSTOM_FIELD_NAME)).isNull();
    }
}
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) PriceDraft(io.sphere.sdk.products.PriceDraft) PriceDraftFixtures.getPriceDraft(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.getPriceDraft) JsonNode(com.fasterxml.jackson.databind.JsonNode) SetProductPriceCustomField(io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomField) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductProjection(io.sphere.sdk.products.ProductProjection) ProductDraft(io.sphere.sdk.products.ProductDraft) Price(io.sphere.sdk.products.Price) AddPrice(io.sphere.sdk.products.commands.updateactions.AddPrice) RemovePrice(io.sphere.sdk.products.commands.updateactions.RemovePrice) ChangePrice(io.sphere.sdk.products.commands.updateactions.ChangePrice) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) NullNode(com.fasterxml.jackson.databind.node.NullNode) Test(org.junit.jupiter.api.Test)

Example 4 with NULL_SET_CUSTOM_FIELD_NAME

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

the class ProductSyncWithPricesIT method sync_WithNonEmptySetNewCustomFields_ShouldCorrectlyUpdateCustomFields.

@Test
void sync_WithNonEmptySetNewCustomFields_ShouldCorrectlyUpdateCustomFields() {
    // preparation
    final ArrayNode emptySet = JsonNodeFactory.instance.arrayNode();
    final Map<String, JsonNode> customFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, emptySet);
    final ArrayNode nonEmptySet = JsonNodeFactory.instance.arrayNode();
    nonEmptySet.add("foo");
    customFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptySet);
    final CustomFieldsDraft customType1WithSet = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), customFieldsJsonMap);
    final PriceDraft withChannel1CustomType1WithSet = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithSet);
    final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithSet))).key("bar").build();
    product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
    final ArrayNode nonEmptyNewSet = JsonNodeFactory.instance.arrayNode();
    nonEmptyNewSet.add("bar");
    final Map<String, JsonNode> newCustomFieldsJsonMap = createCustomFieldsJsonMap(EMPTY_SET_CUSTOM_FIELD_NAME, nonEmptyNewSet);
    newCustomFieldsJsonMap.put(NULL_SET_CUSTOM_FIELD_NAME, nonEmptyNewSet);
    newCustomFieldsJsonMap.put(NON_EMPTY_SEY_CUSTOM_FIELD_NAME, nonEmptyNewSet);
    newCustomFieldsJsonMap.put(NULL_NODE_SET_CUSTOM_FIELD_NAME, nonEmptyNewSet);
    final CustomFieldsDraft customType1WithEmptySet = CustomFieldsDraft.ofTypeKeyAndJson(customType1.getKey(), newCustomFieldsJsonMap);
    final PriceDraft withChannel1CustomType1WithNullSet = getPriceDraftWithKeys(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getKey(), customType1WithEmptySet);
    final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, singletonList(withChannel1CustomType1WithNullSet))).key("bar").build();
    // test
    final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
    // assertion
    assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(4);
    final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
    assertThat(productProjection).isNotNull();
    final List<Price> prices = productProjection.getMasterVariant().getPrices();
    for (Price price : prices) {
        assertThat(price.getCustom().getFieldAsStringSet(EMPTY_SET_CUSTOM_FIELD_NAME)).containsOnly("bar");
        assertThat(price.getCustom().getFieldAsStringSet(NULL_SET_CUSTOM_FIELD_NAME)).containsOnly("bar");
        assertThat(price.getCustom().getFieldAsStringSet(NULL_NODE_SET_CUSTOM_FIELD_NAME)).containsOnly("bar");
        assertThat(price.getCustom().getFieldAsStringSet(NON_EMPTY_SEY_CUSTOM_FIELD_NAME)).containsOnly("bar");
    }
}
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) PriceDraft(io.sphere.sdk.products.PriceDraft) PriceDraftFixtures.getPriceDraft(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.getPriceDraft) JsonNode(com.fasterxml.jackson.databind.JsonNode) SetProductPriceCustomField(io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomField) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductProjection(io.sphere.sdk.products.ProductProjection) ProductDraft(io.sphere.sdk.products.ProductDraft) Price(io.sphere.sdk.products.Price) AddPrice(io.sphere.sdk.products.commands.updateactions.AddPrice) RemovePrice(io.sphere.sdk.products.commands.updateactions.RemovePrice) ChangePrice(io.sphere.sdk.products.commands.updateactions.ChangePrice) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) Test(org.junit.jupiter.api.Test)

Aggregations

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