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);
}
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);
}
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);
}
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());
}
Aggregations