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).");
}
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).");
}
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).");
}
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();
}
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"));
}
Aggregations