use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-sync-java by commercetools.
the class CustomerServiceImplIT method setupTest.
/**
* Deletes Customers from target CTP projects, then it populates target CTP project with customer
* test data.
*/
@BeforeEach
void setupTest() {
errorCallBackMessages = new ArrayList<>();
errorCallBackExceptions = new ArrayList<>();
warningCallBackMessages = new ArrayList<>();
deleteCustomers(CTP_TARGET_CLIENT);
final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.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();
// Create a mock new customer in the target project.
CustomerDraft customerDraft = CustomerDraftBuilder.of("mail@mail.com", "password").key(EXISTING_CUSTOMER_KEY).build();
customer = CTP_TARGET_CLIENT.execute(CustomerCreateCommand.of(customerDraft)).toCompletableFuture().join().getCustomer();
customerService = new CustomerServiceImpl(customerSyncOptions);
}
use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-sync-java by commercetools.
the class CustomerServiceImplIT method cacheKeysToIds_WithCachedKeys_ShouldReturnCacheWithoutAnyRequests.
@Test
void cacheKeysToIds_WithCachedKeys_ShouldReturnCacheWithoutAnyRequests() {
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).warningCallback((exception, oldResource, newResource) -> warningCallBackMessages.add(exception.getMessage())).build();
final CustomerServiceImpl spyCustomerService = new CustomerServiceImpl(customerSyncOptions);
Map<String, String> cache = spyCustomerService.cacheKeysToIds(singleton(EXISTING_CUSTOMER_KEY)).toCompletableFuture().join();
assertThat(cache).hasSize(1);
cache = spyCustomerService.cacheKeysToIds(singleton(EXISTING_CUSTOMER_KEY)).toCompletableFuture().join();
assertThat(cache).hasSize(1);
verify(spyClient, times(1)).execute(any());
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
}
use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-sync-java by commercetools.
the class CustomerUpdateActionUtilsTest method buildSetCustomerNumberUpdateAction_withSameValues_ShouldReturnEmptyOptional.
@Test
void buildSetCustomerNumberUpdateAction_withSameValues_ShouldReturnEmptyOptional() {
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, newSame, customerSyncOptions);
assertThat(result).isEmpty();
assertThat(warningMessages).isEmpty();
}
use of com.commercetools.sync.customers.CustomerSyncOptions in project commercetools-sync-java by commercetools.
the class CustomerUpdateActionUtilsTest method buildSetCustomerNumberUpdateAction_withEmptyOldValueAndANewValue_ShouldReturnAction.
@Test
void buildSetCustomerNumberUpdateAction_withEmptyOldValueAndANewValue_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(" ");
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 CustomerSyncIT method sync_WithNewCustomer_ShouldCreateCustomer.
@Test
void sync_WithNewCustomer_ShouldCreateCustomer() {
final CustomerDraft newCustomerDraft = CustomerDraftBuilder.of(customerDraftJohnDoe).emailVerified(false).email("john-2@example.com").customerNumber("gold-2").key("customer-key-john-doe-2").build();
final CustomerSyncOptions customerSyncOptions = CustomerSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final CustomerSync customerSync = new CustomerSync(customerSyncOptions);
final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(singletonList(newCustomerDraft)).toCompletableFuture().join();
assertThat(errorMessages).isEmpty();
assertThat(warningMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(updateActionList).isEmpty();
assertThat(customerSyncStatistics).hasValues(1, 1, 0, 0);
assertThat(customerSyncStatistics.getReportMessage()).isEqualTo("Summary: 1 customers were processed in total (1 created, 0 updated and 0 failed to sync).");
}
Aggregations