Search in sources :

Example 6 with ReferenceIdToKeyCache

use of com.commercetools.sync.commons.utils.ReferenceIdToKeyCache in project commercetools-sync-java by commercetools.

the class CustomerSyncIT method prepareUpdatedCustomerDrafts.

private List<CustomerDraft> prepareUpdatedCustomerDrafts(@Nonnull final List<Customer> customers) {
    final Store storeCologne = createStore(CTP_TARGET_CLIENT, "store-cologne");
    final List<CustomerDraft> customerDrafts = CustomerTransformUtils.toCustomerDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, customers).join();
    return customerDrafts.stream().map(customerDraft -> CustomerDraftBuilder.of(customerDraft).plusStores(ResourceIdentifier.ofKey(storeCologne.getKey())).custom(CustomFieldsDraft.ofTypeKeyAndJson("customer-type-gold", createCustomFieldsJsonMap())).addresses(singletonList(Address.of(CountryCode.DE).withCity("cologne").withKey("address1"))).defaultBillingAddress(0).billingAddresses(singletonList(0)).defaultShippingAddress(0).shippingAddresses(singletonList(0)).build()).collect(Collectors.toList());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CustomerTransformUtils(com.commercetools.sync.customers.utils.CustomerTransformUtils) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) Address(io.sphere.sdk.models.Address) CustomerITUtils.deleteCustomerSyncTestData(com.commercetools.sync.integration.commons.utils.CustomerITUtils.deleteCustomerSyncTestData) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) CustomerITUtils.createSampleCustomerJohnDoe(com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJohnDoe) CustomerQuery(io.sphere.sdk.customers.queries.CustomerQuery) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) Nonnull(javax.annotation.Nonnull) CountryCode(com.neovisionaries.i18n.CountryCode) CustomerITUtils.createSampleCustomerJaneDoe(com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJaneDoe) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) StoreITUtils.createStore(com.commercetools.sync.integration.commons.utils.StoreITUtils.createStore) CustomerDraftBuilder(io.sphere.sdk.customers.CustomerDraftBuilder) Store(io.sphere.sdk.stores.Store) CustomerSync(com.commercetools.sync.customers.CustomerSync) ITUtils.createCustomFieldsJsonMap(com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap) Customer(io.sphere.sdk.customers.Customer) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CustomerSyncOptionsBuilder(com.commercetools.sync.customers.CustomerSyncOptionsBuilder) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) List(java.util.List) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) AssertionsForStatistics(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) StoreITUtils.createStore(com.commercetools.sync.integration.commons.utils.StoreITUtils.createStore) Store(io.sphere.sdk.stores.Store) CustomerDraft(io.sphere.sdk.customers.CustomerDraft)

Example 7 with ReferenceIdToKeyCache

use of com.commercetools.sync.commons.utils.ReferenceIdToKeyCache in project commercetools-sync-java by commercetools.

the class ProductReferenceResolverIT method setupTest.

/**
 * Deletes Products and Types from target CTP projects, then it populates target CTP project with
 * product test data.
 */
@BeforeEach
void setupTest() {
    deleteAllProducts(CTP_TARGET_CLIENT);
    deleteAllProducts(CTP_SOURCE_CLIENT);
    errorCallBackMessages = new ArrayList<>();
    errorCallBackExceptions = new ArrayList<>();
    warningCallBackMessages = new ArrayList<>();
    final ProductSyncOptions syncOptions = ProductSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).warningCallback((exception, oldResource, newResource) -> warningCallBackMessages.add(exception.getMessage())).build();
    productSync = new ProductSync(syncOptions);
    referenceIdToKeyCache = new CaffeineReferenceIdToKeyCacheImpl();
}
Also used : ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) 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_TYPE_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_RESOURCE_PATH) ReferenceResolutionException(com.commercetools.sync.commons.exceptions.ReferenceResolutionException) StateITUtils.createState(com.commercetools.sync.integration.commons.utils.StateITUtils.createState) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CategoryITUtils.getCategoryDrafts(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getCategoryDrafts) TaxCategoryITUtils.createTaxCategory(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.createTaxCategory) 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) PRODUCT_TYPE_WITH_REFERENCES_FOR_VARIANT_ATTRIBUTES_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_WITH_REFERENCES_FOR_VARIANT_ATTRIBUTES_RESOURCE_PATH) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductProjection(io.sphere.sdk.products.ProductProjection) PRODUCT_KEY_1_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_RESOURCE_PATH) 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) Category(io.sphere.sdk.categories.Category) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) Customer(io.sphere.sdk.customers.Customer) CategoryITUtils.getReferencesWithIds(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getReferencesWithIds) State(io.sphere.sdk.states.State) PRODUCT_TYPE_NO_KEY_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_TYPE_NO_KEY_RESOURCE_PATH) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) List(java.util.List) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ProductSyncOptionsBuilder(com.commercetools.sync.products.ProductSyncOptionsBuilder) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) ProductSyncMockUtils.createProductDraft(com.commercetools.sync.products.ProductSyncMockUtils.createProductDraft) ProductCreateCommand(io.sphere.sdk.products.commands.ProductCreateCommand) 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) 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) PRODUCT_KEY_1_NO_ATTRIBUTES_RESOURCE_PATH(com.commercetools.sync.products.ProductSyncMockUtils.PRODUCT_KEY_1_NO_ATTRIBUTES_RESOURCE_PATH) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProductTransformUtils(com.commercetools.sync.products.utils.ProductTransformUtils) ProductSync(com.commercetools.sync.products.ProductSync) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) Nonnull(javax.annotation.Nonnull) CustomerITUtils.createSampleCustomerJaneDoe(com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJaneDoe) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) AttributeDraft(io.sphere.sdk.products.attributes.AttributeDraft) ProductSyncMockUtils.createRandomCategoryOrderHints(com.commercetools.sync.products.ProductSyncMockUtils.createRandomCategoryOrderHints) BLANK_KEY_VALUE_ON_RESOURCE_IDENTIFIER(com.commercetools.sync.commons.helpers.BaseReferenceResolver.BLANK_KEY_VALUE_ON_RESOURCE_IDENTIFIER) ProductVariantDraftBuilder(io.sphere.sdk.products.ProductVariantDraftBuilder) ProductSync(com.commercetools.sync.products.ProductSync) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ReferenceIdToKeyCache

use of com.commercetools.sync.commons.utils.ReferenceIdToKeyCache in project commercetools-sync-java by commercetools.

the class ProductSyncWithUnexpandedReferencesIT method setup.

@BeforeEach
void setup() {
    errorCallBackMessages = new ArrayList<>();
    errorCallBackExceptions = new ArrayList<>();
    warningCallBackMessages = new ArrayList<>();
    final ProductSyncOptions syncOptions = ProductSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).warningCallback((exception, oldResource, newResource) -> warningCallBackMessages.add(exception.getMessage())).build();
    productSync = new ProductSync(syncOptions);
    referenceIdToKeyCache = new CaffeineReferenceIdToKeyCacheImpl();
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ProductVariantDraft(io.sphere.sdk.products.ProductVariantDraft) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductTypeCreateCommand(io.sphere.sdk.producttypes.commands.ProductTypeCreateCommand) Collections.singletonList(java.util.Collections.singletonList) FieldDefinition(io.sphere.sdk.types.FieldDefinition) ProductITUtils.deleteProductSyncTestData(com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteProductSyncTestData) AfterAll(org.junit.jupiter.api.AfterAll) BigDecimal(java.math.BigDecimal) TaxRateDraft(io.sphere.sdk.taxcategories.TaxRateDraft) Collections.singleton(java.util.Collections.singleton) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) StateCreateCommand(io.sphere.sdk.states.commands.StateCreateCommand) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) CustomerGroupCreateCommand(io.sphere.sdk.customergroups.commands.CustomerGroupCreateCommand) StateType(io.sphere.sdk.states.StateType) DE(com.neovisionaries.i18n.CountryCode.DE) ProductDraft(io.sphere.sdk.products.ProductDraft) ProductProjection(io.sphere.sdk.products.ProductProjection) TaxCategoryDraftBuilder(io.sphere.sdk.taxcategories.TaxCategoryDraftBuilder) AssetDraft(io.sphere.sdk.models.AssetDraft) AssetDraftBuilder(io.sphere.sdk.models.AssetDraftBuilder) ProductTypeDraftBuilder(io.sphere.sdk.producttypes.ProductTypeDraftBuilder) Collections.emptyList(java.util.Collections.emptyList) CategoryCreateCommand(io.sphere.sdk.categories.commands.CategoryCreateCommand) CustomerGroupDraftBuilder(io.sphere.sdk.customergroups.CustomerGroupDraftBuilder) State(io.sphere.sdk.states.State) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) 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) TextInputHint(io.sphere.sdk.models.TextInputHint) ChannelCreateCommand(io.sphere.sdk.channels.commands.ChannelCreateCommand) ProductCreateCommand(io.sphere.sdk.products.commands.ProductCreateCommand) StateDraft(io.sphere.sdk.states.StateDraft) AssertionsForStatistics(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics) 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) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) TaxCategory(io.sphere.sdk.taxcategories.TaxCategory) ResourceTypeIdsSetBuilder(io.sphere.sdk.types.ResourceTypeIdsSetBuilder) TaxCategoryDraft(io.sphere.sdk.taxcategories.TaxCategoryDraft) ProductType(io.sphere.sdk.producttypes.ProductType) EUR(io.sphere.sdk.models.DefaultCurrencyUnits.EUR) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryDraftBuilder(io.sphere.sdk.categories.CategoryDraftBuilder) ArrayList(java.util.ArrayList) PriceDraftBuilder(io.sphere.sdk.products.PriceDraftBuilder) ProductTransformUtils(com.commercetools.sync.products.utils.ProductTransformUtils) ProductSync(com.commercetools.sync.products.ProductSync) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) ProductDraftBuilder(io.sphere.sdk.products.ProductDraftBuilder) StateDraftBuilder(io.sphere.sdk.states.StateDraftBuilder) StringFieldType(io.sphere.sdk.types.StringFieldType) CountryCode(com.neovisionaries.i18n.CountryCode) ChannelRole(io.sphere.sdk.channels.ChannelRole) Collections.emptyMap(java.util.Collections.emptyMap) CustomerGroup(io.sphere.sdk.customergroups.CustomerGroup) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) AssetSourceBuilder(io.sphere.sdk.models.AssetSourceBuilder) TypeCreateCommand(io.sphere.sdk.types.commands.TypeCreateCommand) ChannelDraftBuilder(io.sphere.sdk.channels.ChannelDraftBuilder) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) PriceDraft(io.sphere.sdk.products.PriceDraft) ProductITUtils.createPriceDraft(com.commercetools.sync.integration.commons.utils.ProductITUtils.createPriceDraft) CustomerGroupDraft(io.sphere.sdk.customergroups.CustomerGroupDraft) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) TaxRateDraftBuilder(io.sphere.sdk.taxcategories.TaxRateDraftBuilder) TaxCategoryCreateCommand(io.sphere.sdk.taxcategories.commands.TaxCategoryCreateCommand) Collections(java.util.Collections) ProductVariantDraftBuilder(io.sphere.sdk.products.ProductVariantDraftBuilder) Type(io.sphere.sdk.types.Type) ProductSync(com.commercetools.sync.products.ProductSync) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ReferenceIdToKeyCache

use of com.commercetools.sync.commons.utils.ReferenceIdToKeyCache in project commercetools-sync-java by commercetools.

the class CartDiscountSyncIT method sync_WithUpdates_ShouldReturnProperStatistics.

@Test
void sync_WithUpdates_ShouldReturnProperStatistics() {
    // preparation
    final List<CartDiscount> cartDiscounts = CTP_SOURCE_CLIENT.execute(CartDiscountQuery.of()).toCompletableFuture().join().getResults();
    final String newTypeKey = "new-type";
    createCartDiscountCustomType(newTypeKey, Locale.ENGLISH, newTypeKey, CTP_SOURCE_CLIENT);
    final Type newTargetCustomType = createCartDiscountCustomType(newTypeKey, Locale.ENGLISH, newTypeKey, CTP_TARGET_CLIENT);
    final List<CartDiscountDraft> cartDiscountDrafts = CartDiscountTransformUtils.toCartDiscountDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, cartDiscounts).join();
    // Apply some changes
    final List<CartDiscountDraft> updatedCartDiscountDrafts = cartDiscountDrafts.stream().map(draft -> CartDiscountDraftBuilder.of(draft).cartPredicate(CartPredicate.of("totalPrice >= \"100 EUR\"")).value(AbsoluteCartDiscountValue.of(MoneyImpl.of(40, EUR))).target(ShippingCostTarget.of()).custom(CustomFieldsDraft.ofTypeKeyAndJson(newTypeKey, emptyMap())).build()).collect(Collectors.toList());
    final List<String> errorMessages = new ArrayList<>();
    final List<Throwable> exceptions = new ArrayList<>();
    final List<UpdateAction<CartDiscount>> updateActionsList = new ArrayList<>();
    final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception);
    }).beforeUpdateCallback((updateActions, newCartDiscount, oldCartDiscount) -> {
        updateActionsList.addAll(updateActions);
        return updateActions;
    }).build();
    final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
    // test
    final CartDiscountSyncStatistics cartDiscountSyncStatistics = cartDiscountSync.sync(updatedCartDiscountDrafts).toCompletableFuture().join();
    // assertion
    assertThat(errorMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    assertThat(updateActionsList).containsExactly(ChangeValue.of(CartDiscountValue.ofAbsolute(Collections.singletonList(MoneyImpl.of(40, EUR)))), ChangeCartPredicate.of("totalPrice >= \"100 EUR\""), ChangeTarget.of(ShippingCostTarget.of()), SetCustomType.ofTypeIdAndJson(newTargetCustomType.getId(), emptyMap()));
    assertThat(cartDiscountSyncStatistics).hasValues(2, 1, 1, 0);
    assertThat(cartDiscountSyncStatistics.getReportMessage()).isEqualTo("Summary: 2 cart discounts were processed in total" + " (1 created, 1 updated and 0 failed to sync).");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) CartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount) MoneyImpl(io.sphere.sdk.utils.MoneyImpl) ITUtils.deleteTypesFromTargetAndSource(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypesFromTargetAndSource) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CartPredicate(io.sphere.sdk.cartdiscounts.CartPredicate) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) CartDiscountSyncOptionsBuilder(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptionsBuilder) EUR(io.sphere.sdk.models.DefaultCurrencyUnits.EUR) ChangeCartPredicate(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeCartPredicate) CartDiscountQuery(io.sphere.sdk.cartdiscounts.queries.CartDiscountQuery) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) CartDiscountDraftBuilder(io.sphere.sdk.cartdiscounts.CartDiscountDraftBuilder) CartDiscountSyncStatistics(com.commercetools.sync.cartdiscounts.helpers.CartDiscountSyncStatistics) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) Locale(java.util.Locale) CartDiscountTransformUtils(com.commercetools.sync.cartdiscounts.utils.CartDiscountTransformUtils) CartDiscountSync(com.commercetools.sync.cartdiscounts.CartDiscountSync) CartDiscountDraft(io.sphere.sdk.cartdiscounts.CartDiscountDraft) ChangeTarget(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeTarget) ChangeValue(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeValue) CartDiscountITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.populateTargetProject) CartDiscountITUtils.populateSourceProject(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.populateSourceProject) Collections.emptyMap(java.util.Collections.emptyMap) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) CartDiscountValue(io.sphere.sdk.cartdiscounts.CartDiscountValue) AbsoluteCartDiscountValue(io.sphere.sdk.cartdiscounts.AbsoluteCartDiscountValue) CartDiscountITUtils.createCartDiscountCustomType(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.createCartDiscountCustomType) SetCustomType(io.sphere.sdk.cartdiscounts.commands.updateactions.SetCustomType) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) List(java.util.List) CartDiscountITUtils.deleteCartDiscountsFromTargetAndSource(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.deleteCartDiscountsFromTargetAndSource) ShippingCostTarget(io.sphere.sdk.cartdiscounts.ShippingCostTarget) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) Type(io.sphere.sdk.types.Type) CartDiscountSync(com.commercetools.sync.cartdiscounts.CartDiscountSync) CartDiscountDraft(io.sphere.sdk.cartdiscounts.CartDiscountDraft) UpdateAction(io.sphere.sdk.commands.UpdateAction) CartDiscountSyncStatistics(com.commercetools.sync.cartdiscounts.helpers.CartDiscountSyncStatistics) ArrayList(java.util.ArrayList) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) CartDiscountITUtils.createCartDiscountCustomType(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.createCartDiscountCustomType) SetCustomType(io.sphere.sdk.cartdiscounts.commands.updateactions.SetCustomType) Type(io.sphere.sdk.types.Type) CartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount) Test(org.junit.jupiter.api.Test)

Example 10 with ReferenceIdToKeyCache

use of com.commercetools.sync.commons.utils.ReferenceIdToKeyCache in project commercetools-sync-java by commercetools.

the class CartDiscountSyncIT method sync_WithoutUpdates_ShouldReturnProperStatistics.

@Test
void sync_WithoutUpdates_ShouldReturnProperStatistics() {
    // preparation
    final List<CartDiscount> cartDiscounts = CTP_SOURCE_CLIENT.execute(CartDiscountQuery.of()).toCompletableFuture().join().getResults();
    final List<CartDiscountDraft> cartDiscountDrafts = CartDiscountTransformUtils.toCartDiscountDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, cartDiscounts).join();
    final List<String> errorMessages = new ArrayList<>();
    final List<Throwable> exceptions = new ArrayList<>();
    final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception);
    }).build();
    final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
    // test
    final CartDiscountSyncStatistics cartDiscountSyncStatistics = cartDiscountSync.sync(cartDiscountDrafts).toCompletableFuture().join();
    // assertion
    assertThat(errorMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    assertThat(cartDiscountSyncStatistics).hasValues(2, 1, 0, 0);
    assertThat(cartDiscountSyncStatistics.getReportMessage()).isEqualTo("Summary: 2 cart discounts were processed in total" + " (1 created, 0 updated and 0 failed to sync).");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) CartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount) MoneyImpl(io.sphere.sdk.utils.MoneyImpl) ITUtils.deleteTypesFromTargetAndSource(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypesFromTargetAndSource) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CartPredicate(io.sphere.sdk.cartdiscounts.CartPredicate) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) CartDiscountSyncOptionsBuilder(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptionsBuilder) EUR(io.sphere.sdk.models.DefaultCurrencyUnits.EUR) ChangeCartPredicate(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeCartPredicate) CartDiscountQuery(io.sphere.sdk.cartdiscounts.queries.CartDiscountQuery) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) CartDiscountDraftBuilder(io.sphere.sdk.cartdiscounts.CartDiscountDraftBuilder) CartDiscountSyncStatistics(com.commercetools.sync.cartdiscounts.helpers.CartDiscountSyncStatistics) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) Locale(java.util.Locale) CartDiscountTransformUtils(com.commercetools.sync.cartdiscounts.utils.CartDiscountTransformUtils) CartDiscountSync(com.commercetools.sync.cartdiscounts.CartDiscountSync) CartDiscountDraft(io.sphere.sdk.cartdiscounts.CartDiscountDraft) ChangeTarget(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeTarget) ChangeValue(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeValue) CartDiscountITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.populateTargetProject) CartDiscountITUtils.populateSourceProject(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.populateSourceProject) Collections.emptyMap(java.util.Collections.emptyMap) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) CartDiscountValue(io.sphere.sdk.cartdiscounts.CartDiscountValue) AbsoluteCartDiscountValue(io.sphere.sdk.cartdiscounts.AbsoluteCartDiscountValue) CartDiscountITUtils.createCartDiscountCustomType(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.createCartDiscountCustomType) SetCustomType(io.sphere.sdk.cartdiscounts.commands.updateactions.SetCustomType) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) List(java.util.List) CartDiscountITUtils.deleteCartDiscountsFromTargetAndSource(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.deleteCartDiscountsFromTargetAndSource) ShippingCostTarget(io.sphere.sdk.cartdiscounts.ShippingCostTarget) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) Type(io.sphere.sdk.types.Type) CartDiscountSync(com.commercetools.sync.cartdiscounts.CartDiscountSync) CartDiscountDraft(io.sphere.sdk.cartdiscounts.CartDiscountDraft) CartDiscountSyncStatistics(com.commercetools.sync.cartdiscounts.helpers.CartDiscountSyncStatistics) ArrayList(java.util.ArrayList) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) CartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount) Test(org.junit.jupiter.api.Test)

Aggregations

CaffeineReferenceIdToKeyCacheImpl (com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl)35 ReferenceIdToKeyCache (com.commercetools.sync.commons.utils.ReferenceIdToKeyCache)35 Test (org.junit.jupiter.api.Test)35 List (java.util.List)34 ArrayList (java.util.ArrayList)26 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)26 BeforeEach (org.junit.jupiter.api.BeforeEach)24 CTP_SOURCE_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT)22 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)22 SphereClient (io.sphere.sdk.client.SphereClient)22 AfterAll (org.junit.jupiter.api.AfterAll)21 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)20 Collectors (java.util.stream.Collectors)20 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)20 Mockito.when (org.mockito.Mockito.when)20 Arrays.asList (java.util.Arrays.asList)19 Collections.singletonList (java.util.Collections.singletonList)18 Collections (java.util.Collections)17 Optional (java.util.Optional)17 CompletionStage (java.util.concurrent.CompletionStage)17