Search in sources :

Example 6 with CustomerSyncStatistics

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());
}
Also used : CustomerService(com.commercetools.sync.services.CustomerService) Customer(io.sphere.sdk.customers.Customer) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) HashSet(java.util.HashSet) TypeService(com.commercetools.sync.services.TypeService) CustomerGroupService(com.commercetools.sync.services.CustomerGroupService) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) Test(org.junit.jupiter.api.Test)

Example 7 with CustomerSyncStatistics

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);
}
Also used : CustomerService(com.commercetools.sync.services.CustomerService) Customer(io.sphere.sdk.customers.Customer) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) TypeService(com.commercetools.sync.services.TypeService) CustomerGroupService(com.commercetools.sync.services.CustomerGroupService) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) Test(org.junit.jupiter.api.Test)

Example 8 with CustomerSyncStatistics

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).");
}
Also used : Store(io.sphere.sdk.stores.Store) StoreITUtils.createStore(com.commercetools.sync.integration.commons.utils.StoreITUtils.createStore) AddStore(io.sphere.sdk.customers.commands.updateactions.AddStore) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) Test(org.junit.jupiter.api.Test)

Example 9 with CustomerSyncStatistics

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).");
}
Also used : CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) CustomerSync(com.commercetools.sync.customers.CustomerSync) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) Test(org.junit.jupiter.api.Test)

Example 10 with CustomerSyncStatistics

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).");
}
Also used : Customer(io.sphere.sdk.customers.Customer) CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) Test(org.junit.jupiter.api.Test)

Aggregations

CustomerSyncStatistics (com.commercetools.sync.customers.helpers.CustomerSyncStatistics)20 Test (org.junit.jupiter.api.Test)20 CustomerDraft (io.sphere.sdk.customers.CustomerDraft)16 CustomerGroupService (com.commercetools.sync.services.CustomerGroupService)11 CustomerService (com.commercetools.sync.services.CustomerService)11 TypeService (com.commercetools.sync.services.TypeService)11 Customer (io.sphere.sdk.customers.Customer)10 SphereException (io.sphere.sdk.models.SphereException)5 SyncException (com.commercetools.sync.commons.exceptions.SyncException)3 ConcurrentModificationException (io.sphere.sdk.client.ConcurrentModificationException)3 HashSet (java.util.HashSet)3 CompletionException (java.util.concurrent.CompletionException)3 StoreITUtils.createStore (com.commercetools.sync.integration.commons.utils.StoreITUtils.createStore)2 AddStore (io.sphere.sdk.customers.commands.updateactions.AddStore)2 Store (io.sphere.sdk.stores.Store)2 CustomerSync (com.commercetools.sync.customers.CustomerSync)1 CustomerSyncOptions (com.commercetools.sync.customers.CustomerSyncOptions)1 CustomerGroupITUtils.createCustomerGroup (com.commercetools.sync.integration.commons.utils.CustomerGroupITUtils.createCustomerGroup)1 TypeServiceImpl (com.commercetools.sync.services.impl.TypeServiceImpl)1 BadRequestException (io.sphere.sdk.client.BadRequestException)1