Search in sources :

Example 1 with DE

use of com.neovisionaries.i18n.CountryCode.DE 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 DE

use of com.neovisionaries.i18n.CountryCode.DE 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 DE

use of com.neovisionaries.i18n.CountryCode.DE 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 DE

use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-jvm-sdk by commercetools.

the class OrderUpdateCommandIntegrationTest method setBillingAddress.

@Test
public void setBillingAddress() {
    withOrder(client(), order -> {
        assertThat(order.getBillingAddress()).isNull();
        final Address newAddress = Address.of(DE).withStreetNumber("5");
        final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, SetBillingAddress.of(newAddress)));
        assertThat(updatedOrder.getBillingAddress().getStreetNumber()).isEqualTo("5");
        // there is also a message
        final Query<OrderBillingAddressSetMessage> messageQuery = MessageQuery.of().withPredicates(m -> m.resource().is(order)).forMessageType(OrderBillingAddressSetMessage.MESSAGE_HINT);
        assertEventually(() -> {
            final Optional<OrderBillingAddressSetMessage> billingAddressSetMessageOptional = client().executeBlocking(messageQuery).head();
            assertThat(billingAddressSetMessageOptional).isPresent();
            final OrderBillingAddressSetMessage orderBillingAddressSetMessage = billingAddressSetMessageOptional.get();
            assertThat(orderBillingAddressSetMessage.getAddress()).isEqualTo(newAddress);
        });
        return updatedOrder;
    });
}
Also used : SphereTestUtils(io.sphere.sdk.test.SphereTestUtils) java.util(java.util) Reference(io.sphere.sdk.models.Reference) io.sphere.sdk.orders(io.sphere.sdk.orders) StateFixtures.withStateByBuilder(io.sphere.sdk.states.StateFixtures.withStateByBuilder) Payment(io.sphere.sdk.payments.Payment) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SphereInternalUtils.setOf(io.sphere.sdk.utils.SphereInternalUtils.setOf) io.sphere.sdk.orders.messages(io.sphere.sdk.orders.messages) Address(io.sphere.sdk.models.Address) ProductFixtures.withUpdateableProduct(io.sphere.sdk.products.ProductFixtures.withUpdateableProduct) SetTaxCategory(io.sphere.sdk.products.commands.updateactions.SetTaxCategory) io.sphere.sdk.orders.commands.updateactions(io.sphere.sdk.orders.commands.updateactions) io.sphere.sdk.carts(io.sphere.sdk.carts) Arrays.asList(java.util.Arrays.asList) StateFixtures.withStandardStates(io.sphere.sdk.states.StateFixtures.withStandardStates) Query(io.sphere.sdk.queries.Query) StateType(io.sphere.sdk.states.StateType) DE(com.neovisionaries.i18n.CountryCode.DE) CartDeleteCommand(io.sphere.sdk.carts.commands.CartDeleteCommand) MessageQuery(io.sphere.sdk.messages.queries.MessageQuery) CountryCode(com.neovisionaries.i18n.CountryCode) StoreFixtures(io.sphere.sdk.stores.StoreFixtures) IntegrationTest(io.sphere.sdk.test.IntegrationTest) OrderFixtures(io.sphere.sdk.orders.OrderFixtures) Not.not(org.assertj.core.condition.Not.not) StoreFixtures.withStore(io.sphere.sdk.stores.StoreFixtures.withStore) Test(org.junit.Test) Product(io.sphere.sdk.products.Product) State(io.sphere.sdk.states.State) NotThreadSafe(net.jcip.annotations.NotThreadSafe) ChannelFixtures.withOrderExportChannel(io.sphere.sdk.channels.ChannelFixtures.withOrderExportChannel) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) SphereInternalUtils.asSet(io.sphere.sdk.utils.SphereInternalUtils.asSet) Condition(org.assertj.core.api.Condition) TaxCategoryFixtures(io.sphere.sdk.taxcategories.TaxCategoryFixtures) PaymentFixtures.withPayment(io.sphere.sdk.payments.PaymentFixtures.withPayment) ProductUpdateCommand(io.sphere.sdk.products.commands.ProductUpdateCommand) CustomerFixtures(io.sphere.sdk.customers.CustomerFixtures) Referenceable(io.sphere.sdk.models.Referenceable) OrderQuery(io.sphere.sdk.orders.queries.OrderQuery) OrderByIdGet(io.sphere.sdk.orders.queries.OrderByIdGet) Address(io.sphere.sdk.models.Address) IntegrationTest(io.sphere.sdk.test.IntegrationTest) Test(org.junit.Test)

Example 5 with DE

use of com.neovisionaries.i18n.CountryCode.DE in project commercetools-sync-java by commercetools.

the class ProductSyncWithPricesIT method sync_withSomeChangedMatchingPrices_ShouldAddAndRemovePrices.

@Test
void sync_withSomeChangedMatchingPrices_ShouldAddAndRemovePrices() {
    // Preparation
    final List<PriceDraft> oldPrices = asList(DRAFT_DE_111_EUR, DRAFT_UK_111_GBP, DRAFT_DE_111_EUR_03_04, DRAFT_DE_111_EUR_01_02);
    final PriceDraft price1WithCustomerGroupWithKey = getPriceDraftWithKeys(BigDecimal.valueOf(222), EUR, DE, "cust1", null, null, null, null);
    final PriceDraft price2WithCustomerGroupWithKey = getPriceDraftWithKeys(BigDecimal.valueOf(333), USD, DE, "cust1", null, null, null, null);
    final PriceDraft price1WithCustomerGroupReferenceWithCust1Id = PriceDraftBuilder.of(getPriceDraft(BigDecimal.valueOf(222), EUR, DE, cust1.getId(), null, null, null, null)).customerGroup(cust1).build();
    final PriceDraft price2WithCustomerGroupReferenceWithCust1Id = PriceDraftBuilder.of(getPriceDraft(BigDecimal.valueOf(333), USD, DE, cust1.getId(), null, null, null, null)).customerGroup(cust1).build();
    final List<PriceDraft> newPrices = asList(DRAFT_DE_111_EUR, DRAFT_UK_111_GBP, price1WithCustomerGroupWithKey, price2WithCustomerGroupWithKey);
    final ProductDraft existingProductDraft = ProductDraftBuilder.of(productType.toReference(), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, oldPrices)).key("bar").build();
    product = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)));
    final ProductDraft newProductDraft = ProductDraftBuilder.of(referenceOfId(productType.getKey()), ofEnglish("foo"), ofEnglish("bar"), createVariantDraft("foo", null, newPrices)).key("bar").build();
    // 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(2);
    assertThat(updateActionsFromSync).filteredOn(action -> action instanceof AddPrice).hasSize(2).containsExactlyInAnyOrder(AddPrice.ofVariantId(masterVariantId, price1WithCustomerGroupReferenceWithCust1Id, true), AddPrice.ofVariantId(masterVariantId, price2WithCustomerGroupReferenceWithCust1Id, true));
    final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
    assertThat(productProjection).isNotNull();
    final List<PriceDraft> newPricesWithIds = asList(DRAFT_DE_111_EUR, DRAFT_UK_111_GBP, price1WithCustomerGroupReferenceWithCust1Id, price2WithCustomerGroupReferenceWithCust1Id);
    assertPricesAreEqual(productProjection.getMasterVariant().getPrices(), newPricesWithIds);
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) 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) 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) PriceDraft(io.sphere.sdk.products.PriceDraft) PriceDraftFixtures.getPriceDraft(com.commercetools.sync.products.utils.productvariantupdateactionutils.prices.PriceDraftFixtures.getPriceDraft) Test(org.junit.jupiter.api.Test)

Aggregations

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