Search in sources :

Example 1 with CustomerSyncStatistics

use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.

the class CustomerSyncIT method sync_WithSameCustomer_ShouldNotUpdateCustomer.

@Test
void sync_WithSameCustomer_ShouldNotUpdateCustomer() {
    final CustomerDraft sameCustomerDraft = CustomerDraftBuilder.of(customerDraftJohnDoe).build();
    final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(singletonList(sameCustomerDraft)).toCompletableFuture().join();
    assertThat(errorMessages).isEmpty();
    assertThat(warningMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    assertThat(customerSyncStatistics).hasValues(1, 0, 0, 0);
    assertThat(customerSyncStatistics.getReportMessage()).isEqualTo("Summary: 1 customers were processed in total (0 created, 0 updated and 0 failed to sync).");
}
Also used : CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) Test(org.junit.jupiter.api.Test)

Example 2 with CustomerSyncStatistics

use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.

the class CustomerSyncIT method sync_WithUpdates_ShouldReturnProperStatistics.

@Test
void sync_WithUpdates_ShouldReturnProperStatistics() {
    final List<Customer> customers = CTP_SOURCE_CLIENT.execute(CustomerQuery.of()).toCompletableFuture().join().getResults();
    final List<CustomerDraft> updatedCustomerDrafts = prepareUpdatedCustomerDrafts(customers);
    final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(updatedCustomerDrafts).toCompletableFuture().join();
    assertThat(errorMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    AssertionsForStatistics.assertThat(customerSyncStatistics).hasValues(2, 1, 1, 0);
    assertThat(customerSyncStatistics.getReportMessage()).isEqualTo("Summary: 2 customers were processed in total (1 created, 1 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)

Example 3 with CustomerSyncStatistics

use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.

the class CustomerSyncIT method sync_WithUpdatedAllFieldsOfCustomer_ShouldUpdateCustomerWithAllExpectedActions.

@Test
void sync_WithUpdatedAllFieldsOfCustomer_ShouldUpdateCustomerWithAllExpectedActions() {
    final Store storeCologne = createStore(CTP_TARGET_CLIENT, "store-cologne");
    final CustomerGroup customerGroupSilverMember = createCustomerGroup(CTP_TARGET_CLIENT, "silver members", "silver");
    final CustomerDraft updatedCustomerDraft = CustomerDraftBuilder.of("jane@example.com", "54321").customerNumber(// can not be changed after it set.
    "gold-1").key("customer-key-john-doe").stores(asList(// new store
    ResourceIdentifier.ofKey(storeCologne.getKey()), ResourceIdentifier.ofKey("store-munich"), ResourceIdentifier.ofKey("store-hamburg"), ResourceIdentifier.ofKey("store-berlin"))).firstName("Jane").lastName("Doe").middleName("").title("Miss").salutation("").dateOfBirth(LocalDate.now().minusYears(26)).companyName("Acme Corporation 2").vatId("DE000000000").emailVerified(true).customerGroup(ResourceIdentifier.ofKey(customerGroupSilverMember.getKey())).addresses(asList(Address.of(CountryCode.DE).withCity("berlin").withKey("address1"), Address.of(CountryCode.DE).withCity("munich").withKey("address3"), Address.of(CountryCode.DE).withCity("cologne").withKey("address4"))).defaultBillingAddress(// 0 becomes 2 -> berlin to cologne.
    2).billingAddresses(// 0, 1 becomes 2 -> berlin, hamburg to cologne.
    singletonList(2)).defaultShippingAddress(// 2 becomes 1 -> munich to munich.
    1).shippingAddresses(// 2 become 0, 1 -> munich to berlin, munich.
    asList(0, 1)).custom(CustomFieldsDraft.ofTypeKeyAndJson("customer-type-gold", createCustomFieldsJsonMap())).locale(Locale.FRENCH).build();
    final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(singletonList(updatedCustomerDraft)).toCompletableFuture().join();
    assertThat(errorMessages).isEmpty();
    assertThat(warningMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    final Map<String, String> addressKeyToIdMap = customerJohnDoe.getAddresses().stream().collect(toMap(Address::getKey, Address::getId));
    assertThat(updateActionList).containsExactly(ChangeEmail.of("jane@example.com"), SetFirstName.of("Jane"), SetMiddleName.of(""), SetTitle.of("Miss"), SetSalutation.of(""), SetCustomerGroup.of(Reference.of(CustomerGroup.referenceTypeId(), customerGroupSilverMember.getId())), SetCompanyName.of("Acme Corporation 2"), SetDateOfBirth.of(LocalDate.now().minusYears(26)), SetVatId.of("DE000000000"), SetLocale.of(Locale.FRENCH), RemoveAddress.of(addressKeyToIdMap.get("address2")), AddAddress.of(Address.of(CountryCode.DE).withCity("cologne").withKey("address4")), RemoveBillingAddressId.of(addressKeyToIdMap.get("address1")), SetDefaultBillingAddress.ofKey("address4"), AddShippingAddressId.ofKey("address1"), AddBillingAddressId.ofKey("address4"), SetCustomField.ofJson(LOCALISED_STRING_CUSTOM_FIELD_NAME, JsonNodeFactory.instance.objectNode().put("de", "rot").put("en", "red")), SetCustomField.ofJson(BOOLEAN_CUSTOM_FIELD_NAME, JsonNodeFactory.instance.booleanNode(false)), AddStore.of(ResourceIdentifier.ofKey(storeCologne.getKey())));
    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 : SetCustomerGroup(io.sphere.sdk.customers.commands.updateactions.SetCustomerGroup) CustomerGroup(io.sphere.sdk.customergroups.CustomerGroup) CustomerGroupITUtils.createCustomerGroup(com.commercetools.sync.integration.commons.utils.CustomerGroupITUtils.createCustomerGroup) 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 4 with CustomerSyncStatistics

use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.

the class CustomerSyncTest method sync_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate.

@Test
void sync_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate() {
    // 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(exceptionallyCompletedFuture(new SphereException(new ConcurrentModificationException()))).thenReturn(completedFuture(mockCustomer));
    when(mockCustomerService.fetchCustomerByKey("customerKey")).thenReturn(completedFuture(Optional.empty()));
    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, 0, 1);
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Not found when attempting to fetch while retrying after concurrency modification.");
    assertThat(exceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasNoCause();
}
Also used : CustomerService(com.commercetools.sync.services.CustomerService) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) Customer(io.sphere.sdk.customers.Customer) SyncException(com.commercetools.sync.commons.exceptions.SyncException) SphereException(io.sphere.sdk.models.SphereException) 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 5 with CustomerSyncStatistics

use of com.commercetools.sync.customers.helpers.CustomerSyncStatistics in project commercetools-sync-java by commercetools.

the class CustomerSyncTest method sync_WithoutEmail_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.

@Test
void sync_WithoutEmail_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
    final CustomerSync customerSync = new CustomerSync(syncOptions);
    // test
    final CustomerSyncStatistics customerSyncStatistics = customerSync.sync(singletonList(CustomerDraftBuilder.of(" ", "pass").key("key").build())).toCompletableFuture().join();
    AssertionsForStatistics.assertThat(customerSyncStatistics).hasValues(1, 0, 0, 1);
    // assertions
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).isEqualTo(format(CUSTOMER_DRAFT_EMAIL_NOT_SET, "key"));
}
Also used : CustomerSyncStatistics(com.commercetools.sync.customers.helpers.CustomerSyncStatistics) 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