use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.
the class CustomerSyncTest method sync_WithOnlyDraftsToCreate_ShouldCallBeforeCreateCallbackAndIncrementCreated.
@Test
void sync_WithOnlyDraftsToCreate_ShouldCallBeforeCreateCallbackAndIncrementCreated() {
// preparation
final CustomerService mockCustomerService = mock(CustomerService.class);
final Customer mockCustomer = mock(Customer.class);
when(mockCustomerService.fetchMatchingCustomersByKeys(singleton("customerKey"))).thenReturn(completedFuture(new HashSet<>(singletonList(mockCustomer))));
when(mockCustomerService.createCustomer(any())).thenReturn(completedFuture(Optional.of(mockCustomer)));
final CustomerSyncOptions spyCustomerSyncOptions = spy(syncOptions);
final CustomerSync customerSync = new CustomerSync(spyCustomerSyncOptions, mockCustomerService, mock(TypeService.class), mock(CustomerGroupService.class));
final CustomerDraft customerDraft = CustomerDraftBuilder.of("email", "pass").key("customerKey").build();
// test
final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(singletonList(customerDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(customerSyncStatistics).hasValues(1, 1, 0, 0);
verify(spyCustomerSyncOptions).applyBeforeCreateCallback(customerDraft);
verify(spyCustomerSyncOptions, never()).applyBeforeUpdateCallback(any(), any(), any());
}
use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.
the class CustomerSyncTest method sync_WithOnlyDraftsToUpdate_ShouldOnlyCallBeforeUpdateCallback.
@Test
void sync_WithOnlyDraftsToUpdate_ShouldOnlyCallBeforeUpdateCallback() {
// preparation
final CustomerService mockCustomerService = mock(CustomerService.class);
final Customer mockCustomer = mock(Customer.class);
when(mockCustomer.getKey()).thenReturn("customerKey");
when(mockCustomerService.fetchMatchingCustomersByKeys(anySet())).thenReturn(completedFuture(singleton(mockCustomer)));
when(mockCustomerService.updateCustomer(any(), anyList())).thenReturn(completedFuture(mockCustomer));
final CustomerSyncOptions spyCustomerSyncOptions = spy(syncOptions);
final CustomerSync customerSync = new CustomerSync(spyCustomerSyncOptions, mockCustomerService, mock(TypeService.class), mock(CustomerGroupService.class));
final CustomerDraft customerDraft = CustomerDraftBuilder.of("email", "pass").key("customerKey").build();
// test
final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(singletonList(customerDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(customerSyncStatistics).hasValues(1, 0, 1, 0);
verify(spyCustomerSyncOptions).applyBeforeUpdateCallback(any(), any(), any());
verify(spyCustomerSyncOptions, never()).applyBeforeCreateCallback(customerDraft);
}
use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.
the class CustomerSyncIT method sync_WithUpdatedCustomer_ShouldUpdateCustomer.
@Test
void sync_WithUpdatedCustomer_ShouldUpdateCustomer() {
final Store storeCologne = createStore(CTP_TARGET_CLIENT, "store-cologne");
final CustomerDraft updatedCustomerDraft = CustomerDraftBuilder.of(customerDraftJohnDoe).customerNumber(// from gold-1, but can not be changed.
"gold-new").email(// from john@example.com
"john-new@example.com").stores(asList(ResourceIdentifier.ofKey(storeCologne.getKey()), ResourceIdentifier.ofKey("store-hamburg"), ResourceIdentifier.ofKey("store-berlin"))).build();
final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(singletonList(updatedCustomerDraft)).toCompletableFuture().join();
assertThat(errorMessages).isEmpty();
assertThat(warningMessages).containsExactly(format(CUSTOMER_NUMBER_EXISTS_WARNING, updatedCustomerDraft.getKey(), "gold-1"));
assertThat(exceptions).isEmpty();
assertThat(updateActionList).containsExactly(ChangeEmail.of("john-new@example.com"), SetStores.of(asList(ResourceIdentifier.ofKey("store-cologne"), ResourceIdentifier.ofKey("store-hamburg"), ResourceIdentifier.ofKey("store-berlin"))));
assertThat(customerSyncStatistics).hasValues(1, 0, 1, 0);
assertThat(customerSyncStatistics.getReportMessage()).isEqualTo("Summary: 1 customers were processed in total (0 created, 1 updated and 0 failed to sync).");
}
use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics 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).");
}
use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.
the class CustomerSyncIT method sync_WithoutUpdates_ShouldReturnProperStatistics.
@Test
void sync_WithoutUpdates_ShouldReturnProperStatistics() {
final List<Customer> customers = CTP_SOURCE_CLIENT.execute(CustomerQuery.of()).toCompletableFuture().join().getResults();
final List<CustomerDraft> customerDrafts = CustomerTransformUtils.toCustomerDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, customers).join();
final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(customerDrafts).toCompletableFuture().join();
assertThat(errorMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(customerSyncStatistics).hasValues(2, 1, 0, 0);
assertThat(customerSyncStatistics.getReportMessage()).isEqualTo("Summary: 2 customers were processed in total (1 created, 0 updated and 0 failed to sync).");
}
Aggregations