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