Search in sources :

Example 6 with SyncFilter

use of com.commercetools.sync.products.SyncFilter in project commercetools-sync-java by commercetools.

the class FilterUtilsTest method executeSupplierIfPassesFilter_WithDefault_ShouldFilterInEveryThing.

@Test
void executeSupplierIfPassesFilter_WithDefault_ShouldFilterInEveryThing() {
    final SyncFilter syncFilter = SyncFilter.of();
    final List<UpdateAction<Product>> updateActionsAfterPricesFilter = executeSupplierIfPassesFilter(syncFilter, PRICES, () -> passingUpdateActions, () -> defaultActions);
    assertThat(updateActionsAfterPricesFilter).hasSize(2);
    assertThat(updateActionsAfterPricesFilter).isSameAs(passingUpdateActions);
    final List<UpdateAction<Product>> updateActionsAfterImagesFilter = executeSupplierIfPassesFilter(syncFilter, IMAGES, () -> passingUpdateActions, () -> defaultActions);
    assertThat(updateActionsAfterImagesFilter).hasSize(2);
    assertThat(updateActionsAfterImagesFilter).isSameAs(passingUpdateActions);
    final List<UpdateAction<Product>> updateActionsAfterCategoriesFilter = executeSupplierIfPassesFilter(syncFilter, CATEGORIES, () -> passingUpdateActions, () -> defaultActions);
    assertThat(updateActionsAfterCategoriesFilter).hasSize(2);
    assertThat(updateActionsAfterCategoriesFilter).isSameAs(passingUpdateActions);
}
Also used : SyncFilter(com.commercetools.sync.products.SyncFilter) UpdateAction(io.sphere.sdk.commands.UpdateAction) Test(org.junit.jupiter.api.Test)

Example 7 with SyncFilter

use of com.commercetools.sync.products.SyncFilter in project commercetools-sync-java by commercetools.

the class FilterUtilsTest method executeSupplierIfPassesFilter_WithGroupInBlackList_ShouldFilterOutOnlyThisGroup.

@Test
void executeSupplierIfPassesFilter_WithGroupInBlackList_ShouldFilterOutOnlyThisGroup() {
    final SyncFilter syncFilter = SyncFilter.ofBlackList(IMAGES);
    final List<UpdateAction<Product>> updateActionsAfterImagesFilter = executeSupplierIfPassesFilter(syncFilter, IMAGES, () -> passingUpdateActions, () -> defaultActions);
    assertThat(updateActionsAfterImagesFilter).hasSize(1);
    assertThat(updateActionsAfterImagesFilter).isSameAs(defaultActions);
    final List<UpdateAction<Product>> updateActionsAfterPricesFilter = executeSupplierIfPassesFilter(syncFilter, PRICES, () -> passingUpdateActions, () -> defaultActions);
    assertThat(updateActionsAfterPricesFilter).hasSize(2);
    assertThat(updateActionsAfterPricesFilter).isSameAs(passingUpdateActions);
    final List<UpdateAction<Product>> updateActionsAfterCategoriesFilter = executeSupplierIfPassesFilter(syncFilter, CATEGORIES, () -> passingUpdateActions, () -> defaultActions);
    assertThat(updateActionsAfterCategoriesFilter).hasSize(2);
    assertThat(updateActionsAfterCategoriesFilter).isSameAs(passingUpdateActions);
}
Also used : SyncFilter(com.commercetools.sync.products.SyncFilter) UpdateAction(io.sphere.sdk.commands.UpdateAction) Test(org.junit.jupiter.api.Test)

Example 8 with SyncFilter

use of com.commercetools.sync.products.SyncFilter in project commercetools-sync-java by commercetools.

the class FilterUtilsTest method executeSupplierIfPassesFilter_WithGroupNotInBlackList_ShouldFilterInThisGroup.

@Test
void executeSupplierIfPassesFilter_WithGroupNotInBlackList_ShouldFilterInThisGroup() {
    final SyncFilter syncFilter = SyncFilter.ofBlackList(PRICES);
    final List<UpdateAction<Product>> updateActionsAfterImagesFilter = executeSupplierIfPassesFilter(syncFilter, IMAGES, () -> passingUpdateActions, () -> defaultActions);
    assertThat(updateActionsAfterImagesFilter).hasSize(2);
    assertThat(updateActionsAfterImagesFilter).isSameAs(passingUpdateActions);
    final List<UpdateAction<Product>> updateActionsAfterPricesFilter = executeSupplierIfPassesFilter(syncFilter, PRICES, () -> passingUpdateActions, () -> defaultActions);
    assertThat(updateActionsAfterPricesFilter).hasSize(1);
    assertThat(updateActionsAfterPricesFilter).isSameAs(defaultActions);
}
Also used : SyncFilter(com.commercetools.sync.products.SyncFilter) UpdateAction(io.sphere.sdk.commands.UpdateAction) Test(org.junit.jupiter.api.Test)

Example 9 with SyncFilter

use of com.commercetools.sync.products.SyncFilter in project commercetools-sync-java by commercetools.

the class ProductSyncIT method sync_withChangedAttributes_ShouldUpdateProducts.

@Test
void sync_withChangedAttributes_ShouldUpdateProducts() {
    // Preparation
    // Create custom options with whitelisting and action filter callback..
    final ProductSyncOptions customSyncOptions = ProductSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> errorCallback(exception.getMessage(), exception.getCause())).warningCallback((exception, oldResource, newResources) -> warningCallBackMessages.add(exception.getMessage())).beforeUpdateCallback(this::beforeUpdateCallback).syncFilter(SyncFilter.ofWhiteList(ATTRIBUTES)).build();
    final ProductSync customSync = new ProductSync(customSyncOptions);
    // Create existing products in target project with keys (productKey1)
    final ProductDraft existingProductDraft = createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH, targetProductType.toReference(), targetTaxCategory.toReference(), targetProductState.toReference(), targetCategoryReferencesWithIds, createRandomCategoryOrderHints(targetCategoryReferencesWithIds));
    CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)).toCompletableFuture().join();
    // Create existing product with productKey1 in source project with changed attributes
    final ProductDraft newProductDraftWithProductReference = createProductDraftBuilder(PRODUCT_KEY_1_CHANGED_ATTRIBUTES_RESOURCE_PATH, sourceProductType.toReference()).taxCategory(sourceTaxCategory.toReference()).state(sourceProductState.toReference()).categories(Collections.emptySet()).categoryOrderHints(null).build();
    CTP_SOURCE_CLIENT.execute(ProductCreateCommand.of(newProductDraftWithProductReference)).toCompletableFuture().join();
    // Test
    final List<ProductProjection> products = CTP_SOURCE_CLIENT.execute(ProductProjectionQuery.ofStaged()).toCompletableFuture().join().getResults();
    final List<ProductDraft> productDrafts = ProductTransformUtils.toProductDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, products).join();
    final ProductSyncStatistics syncStatistics = customSync.sync(productDrafts).toCompletableFuture().join();
    // Assertion
    assertThat(syncStatistics).hasValues(1, 0, 1, 0);
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(errorCallBackExceptions).isEmpty();
    assertThat(warningCallBackMessages).isEmpty();
    final AttributeDraft priceInfoAttrDraft = AttributeDraft.of("priceInfo", JsonNodeFactory.instance.textNode("100/kg"));
    final AttributeDraft angebotAttrDraft = AttributeDraft.of("angebot", JsonNodeFactory.instance.textNode("big discount"));
    assertThat(updateActions).containsExactlyInAnyOrder(SetAttributeInAllVariants.of(priceInfoAttrDraft, true), SetAttribute.of(1, angebotAttrDraft, true), SetAttributeInAllVariants.ofUnsetAttribute("size", true), SetAttributeInAllVariants.ofUnsetAttribute("rinderrasse", true), SetAttributeInAllVariants.ofUnsetAttribute("herkunft", true), SetAttributeInAllVariants.ofUnsetAttribute("teilstueck", true), SetAttributeInAllVariants.ofUnsetAttribute("fuetterung", true), SetAttributeInAllVariants.ofUnsetAttribute("reifung", true), SetAttributeInAllVariants.ofUnsetAttribute("haltbarkeit", true), SetAttributeInAllVariants.ofUnsetAttribute("verpackung", true), SetAttributeInAllVariants.ofUnsetAttribute("anlieferung", true), SetAttributeInAllVariants.ofUnsetAttribute("zubereitung", true), SetAttribute.ofUnsetAttribute(1, "localisedText", true), Publish.of());
}
Also used : ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) SUPPLY_CHANNEL_KEY_1(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.SUPPLY_CHANNEL_KEY_1) Reference(io.sphere.sdk.models.Reference) ProductVariantDraft(io.sphere.sdk.products.ProductVariantDraft) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) PRODUCT_KEY_2_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_2_RESOURCE_PATH) PRODUCT_TYPE_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_RESOURCE_PATH) StateITUtils.createState(com.commercetools.sync.integration.commons.utils.StateITUtils.createState) ProductITUtils.createPricesCustomType(com.commercetools.sync.integration.commons.utils.ProductITUtils.createPricesCustomType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CategoryITUtils.getCategoryDrafts(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getCategoryDrafts) PRODUCT_KEY_1_CHANGED_WITH_PRICES_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_CHANGED_WITH_PRICES_RESOURCE_PATH) TaxCategoryITUtils.createTaxCategory(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.createTaxCategory) ProductSyncMockUtils.createProductDraftBuilder(com.commercetools.sync.products.ProductSyncMockUtils.createProductDraftBuilder) UpdateAction(io.sphere.sdk.commands.UpdateAction) Channel(io.sphere.sdk.channels.Channel) Collections.singletonList(java.util.Collections.singletonList) ProductITUtils.deleteProductSyncTestData(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData) AfterAll(org.junit.jupiter.api.AfterAll) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) BeforeAll(org.junit.jupiter.api.BeforeAll) Locale(java.util.Locale) OLD_CATEGORY_CUSTOM_TYPE_NAME(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME) StateType(io.sphere.sdk.states.StateType) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductProjection(io.sphere.sdk.products.ProductProjection) ProductITUtils.getDraftWithPriceReferences(com.commercetools.sync.integration.commons.utils.ProductITUtils.getDraftWithPriceReferences) PRODUCT_KEY_1_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_RESOURCE_PATH) ENGLISH(java.util.Locale.ENGLISH) OLD_CATEGORY_CUSTOM_TYPE_KEY(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) Collections.emptyList(java.util.Collections.emptyList) Category(io.sphere.sdk.categories.Category) SetAttributeInAllVariants(io.sphere.sdk.products.commands.updateactions.SetAttributeInAllVariants) Product(io.sphere.sdk.products.Product) PRODUCT_KEY_1_CHANGED_ATTRIBUTES_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_CHANGED_ATTRIBUTES_RESOURCE_PATH) CategoryITUtils.getReferencesWithIds(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getReferencesWithIds) State(io.sphere.sdk.states.State) Test(org.junit.jupiter.api.Test) ProductSyncMockUtils.getReferenceSetAttributeDraft(com.commercetools.sync.products.ProductSyncMockUtils.getReferenceSetAttributeDraft) List(java.util.List) 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) Publish(io.sphere.sdk.products.commands.updateactions.Publish) ProductSyncMockUtils.createProductDraft(com.commercetools.sync.products.ProductSyncMockUtils.createProductDraft) ChannelCreateCommand(io.sphere.sdk.channels.commands.ChannelCreateCommand) ProductCreateCommand(io.sphere.sdk.products.commands.ProductCreateCommand) ChannelDraft(io.sphere.sdk.channels.ChannelDraft) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) TaxCategory(io.sphere.sdk.taxcategories.TaxCategory) CategoryITUtils.createCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategories) ProductByKeyGet(io.sphere.sdk.products.queries.ProductByKeyGet) ProductType(io.sphere.sdk.producttypes.ProductType) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) ProductITUtils.deleteAllProducts(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) SyncFilter(com.commercetools.sync.products.SyncFilter) ProductTransformUtils(com.commercetools.sync.products.utils.ProductTransformUtils) Attribute(io.sphere.sdk.products.attributes.Attribute) ATTRIBUTES(com.commercetools.sync.products.ActionGroup.ATTRIBUTES) ProductSync(com.commercetools.sync.products.ProductSync) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) SetAttribute(io.sphere.sdk.products.commands.updateactions.SetAttribute) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Collections.emptyMap(java.util.Collections.emptyMap) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) PRODUCT_KEY_1_WITH_PRICES_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_WITH_PRICES_RESOURCE_PATH) PRODUCT_KEY_1_CHANGED_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_CHANGED_RESOURCE_PATH) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) ProductSyncMockUtils.getProductReferenceWithId(com.commercetools.sync.products.ProductSyncMockUtils.getProductReferenceWithId) ProductSyncMockUtils.createRandomCategoryOrderHints(com.commercetools.sync.products.ProductSyncMockUtils.createRandomCategoryOrderHints) Collections(java.util.Collections) ProductVariantDraftBuilder(io.sphere.sdk.products.ProductVariantDraftBuilder) Type(io.sphere.sdk.types.Type) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductProjection(io.sphere.sdk.products.ProductProjection) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductSyncMockUtils.createProductDraft(com.commercetools.sync.products.ProductSyncMockUtils.createProductDraft) ProductSyncMockUtils.getReferenceSetAttributeDraft(com.commercetools.sync.products.ProductSyncMockUtils.getReferenceSetAttributeDraft) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) ProductSync(com.commercetools.sync.products.ProductSync) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) Test(org.junit.jupiter.api.Test)

Aggregations

SyncFilter (com.commercetools.sync.products.SyncFilter)9 UpdateAction (io.sphere.sdk.commands.UpdateAction)8 Test (org.junit.jupiter.api.Test)6 ProductSyncOptions (com.commercetools.sync.products.ProductSyncOptions)5 Product (io.sphere.sdk.products.Product)4 ProductDraft (io.sphere.sdk.products.ProductDraft)4 ProductProjection (io.sphere.sdk.products.ProductProjection)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ATTRIBUTES (com.commercetools.sync.products.ActionGroup.ATTRIBUTES)3 AttributeMetaData (com.commercetools.sync.products.AttributeMetaData)3 ProductSyncOptionsBuilder (com.commercetools.sync.products.ProductSyncOptionsBuilder)3 ProductVariantDraft (io.sphere.sdk.products.ProductVariantDraft)3 RemoveVariant (io.sphere.sdk.products.commands.updateactions.RemoveVariant)3 SetAttributeInAllVariants (io.sphere.sdk.products.commands.updateactions.SetAttributeInAllVariants)3 Collections.emptyList (java.util.Collections.emptyList)3 Collections.emptyMap (java.util.Collections.emptyMap)3 Collections.singletonList (java.util.Collections.singletonList)3 Map (java.util.Map)3 Nonnull (javax.annotation.Nonnull)3