use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-sync-java by commercetools.
the class CustomerSyncIT method setUpCustomerSync.
private void setUpCustomerSync() {
errorMessages = new ArrayList<>();
exceptions = new ArrayList<>();
final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception);
}).build();
customerSync = new CustomerSync(customerSyncOptions);
referenceIdToKeyCache = new CaffeineReferenceIdToKeyCacheImpl();
}
use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-sync-java by commercetools.
the class CustomerUpdateActionUtilsTest method buildSetCustomerNumberUpdateAction_withDifferentValues_ShouldNotReturnActionAndAddWarningCallback.
@Test
void buildSetCustomerNumberUpdateAction_withDifferentValues_ShouldNotReturnActionAndAddWarningCallback() {
final List<String> warningMessages = new ArrayList<>();
final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(mock(SphereClient.class)).warningCallback((exception, oldResource, newResource) -> warningMessages.add(exception.getMessage())).build();
final Optional<UpdateAction<Customer>> result = buildSetCustomerNumberUpdateAction(old, newDifferent, customerSyncOptions);
assertThat(result).isEmpty();
assertThat(warningMessages).containsExactly(format(CUSTOMER_NUMBER_EXISTS_WARNING, old.getKey(), "1234"));
}
use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-sync-java by commercetools.
the class CustomerUpdateActionUtilsTest method buildSetCustomerNumberUpdateAction_withNullOldValueAndANewValue_ShouldReturnAction.
@Test
void buildSetCustomerNumberUpdateAction_withNullOldValueAndANewValue_ShouldReturnAction() {
final List<String> warningMessages = new ArrayList<>();
final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(mock(SphereClient.class)).warningCallback((exception, oldResource, newResource) -> warningMessages.add(exception.getMessage())).build();
Customer oldCustomer = mock(Customer.class);
when(oldCustomer.getCustomerNumber()).thenReturn(null);
CustomerDraft newCustomer = mock(CustomerDraft.class);
when(newCustomer.getCustomerNumber()).thenReturn("customer-number");
final Optional<UpdateAction<Customer>> result = buildSetCustomerNumberUpdateAction(oldCustomer, newCustomer, customerSyncOptions);
assertThat(result).containsInstanceOf(SetCustomerNumber.class);
assertThat(result).contains(SetCustomerNumber.of("customer-number"));
assertThat(warningMessages).isEmpty();
}
use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-sync-java by commercetools.
the class CustomerReferenceResolverTest method setup.
@BeforeEach
void setup() {
final CustomerSyncOptions syncOptions = CustomerSyncOptionsBuilder.of(mock(SphereClient.class)).build();
typeService = getMockTypeService();
customerGroupService = getMockCustomerGroupService(getMockCustomerGroup(CUSTOMER_GROUP_ID, CUSTOMER_GROUP_KEY));
referenceResolver = new CustomerReferenceResolver(syncOptions, typeService, customerGroupService);
}
use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-project-sync by commercetools.
the class CustomerSyncer method of.
public static CustomerSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<CustomerDraft>, Optional<Customer>, List<UpdateAction<Customer>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "customer", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<CustomerDraft>, Optional<Customer>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "customer", exception, oldResource);
final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final CustomerSync customerSync = new CustomerSync(customerSyncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new CustomerSyncer(customerSync, sourceClient, targetClient, customObjectService, clock);
}
Aggregations