Search in sources :

Example 6 with CustomerSyncOptions

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) CustomerServiceImpl(com.commercetools.sync.services.impl.CustomerServiceImpl) CustomerCreateCommand(io.sphere.sdk.customers.commands.CustomerCreateCommand) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.spy(org.mockito.Mockito.spy) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) CustomerQuery(io.sphere.sdk.customers.queries.CustomerQuery) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) CustomerService(com.commercetools.sync.services.CustomerService) Collections.emptySet(java.util.Collections.emptySet) ChangeEmail(io.sphere.sdk.customers.commands.updateactions.ChangeEmail) QueryPredicate(io.sphere.sdk.queries.QueryPredicate) CustomerDraftBuilder(io.sphere.sdk.customers.CustomerDraftBuilder) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Customer(io.sphere.sdk.customers.Customer) String.format(java.lang.String.format) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) CustomerSyncOptionsBuilder(com.commercetools.sync.customers.CustomerSyncOptionsBuilder) List(java.util.List) CustomerITUtils.deleteCustomers(com.commercetools.sync.integration.commons.utils.CustomerITUtils.deleteCustomers) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) Optional(java.util.Optional) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) CustomerServiceImpl(com.commercetools.sync.services.impl.CustomerServiceImpl) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with 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();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) CustomerServiceImpl(com.commercetools.sync.services.impl.CustomerServiceImpl) CustomerCreateCommand(io.sphere.sdk.customers.commands.CustomerCreateCommand) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.spy(org.mockito.Mockito.spy) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) CustomerQuery(io.sphere.sdk.customers.queries.CustomerQuery) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) CustomerService(com.commercetools.sync.services.CustomerService) Collections.emptySet(java.util.Collections.emptySet) ChangeEmail(io.sphere.sdk.customers.commands.updateactions.ChangeEmail) QueryPredicate(io.sphere.sdk.queries.QueryPredicate) CustomerDraftBuilder(io.sphere.sdk.customers.CustomerDraftBuilder) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Customer(io.sphere.sdk.customers.Customer) String.format(java.lang.String.format) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) CustomerSyncOptionsBuilder(com.commercetools.sync.customers.CustomerSyncOptionsBuilder) List(java.util.List) CustomerITUtils.deleteCustomers(com.commercetools.sync.integration.commons.utils.CustomerITUtils.deleteCustomers) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) Optional(java.util.Optional) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) SphereClient(io.sphere.sdk.client.SphereClient) CustomerServiceImpl(com.commercetools.sync.services.impl.CustomerServiceImpl) Test(org.junit.jupiter.api.Test)

Example 8 with CustomerSyncOptions

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Reference(io.sphere.sdk.models.Reference) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) SetCustomerNumber(io.sphere.sdk.customers.commands.updateactions.SetCustomerNumber) CUSTOMER_NUMBER_EXISTS_WARNING(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.CUSTOMER_NUMBER_EXISTS_WARNING) CustomerUpdateActionUtils.buildSetMiddleNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetMiddleNameUpdateAction) SetMiddleName(io.sphere.sdk.customers.commands.updateactions.SetMiddleName) SetFirstName(io.sphere.sdk.customers.commands.updateactions.SetFirstName) SetDateOfBirth(io.sphere.sdk.customers.commands.updateactions.SetDateOfBirth) Locale(java.util.Locale) SphereClient(io.sphere.sdk.client.SphereClient) SetLocale(io.sphere.sdk.customers.commands.updateactions.SetLocale) CustomerUpdateActionUtils.buildSetCustomerNumberUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCustomerNumberUpdateAction) CustomerUpdateActionUtils.buildSetLocaleUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetLocaleUpdateAction) SetExternalId(io.sphere.sdk.customers.commands.updateactions.SetExternalId) CustomerUpdateActionUtils.buildSetVatIdUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetVatIdUpdateAction) ChangeEmail(io.sphere.sdk.customers.commands.updateactions.ChangeEmail) UUID(java.util.UUID) Customer(io.sphere.sdk.customers.Customer) String.format(java.lang.String.format) CustomerUpdateActionUtils.buildSetFirstNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetFirstNameUpdateAction) Test(org.junit.jupiter.api.Test) CustomerUpdateActionUtils.buildSetSalutationUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetSalutationUpdateAction) CustomerSyncOptionsBuilder(com.commercetools.sync.customers.CustomerSyncOptionsBuilder) CustomerName(io.sphere.sdk.customers.CustomerName) List(java.util.List) SetCustomerGroup(io.sphere.sdk.customers.commands.updateactions.SetCustomerGroup) SetVatId(io.sphere.sdk.customers.commands.updateactions.SetVatId) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) CustomerUpdateActionUtils.buildSetLastNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetLastNameUpdateAction) SetTitle(io.sphere.sdk.customers.commands.updateactions.SetTitle) CustomerUpdateActionUtils.buildSetTitleUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetTitleUpdateAction) CustomerUpdateActionUtils.buildSetCustomerGroupUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCustomerGroupUpdateAction) ArrayList(java.util.ArrayList) SetLastName(io.sphere.sdk.customers.commands.updateactions.SetLastName) CustomerGroup(io.sphere.sdk.customergroups.CustomerGroup) SetCompanyName(io.sphere.sdk.customers.commands.updateactions.SetCompanyName) SetSalutation(io.sphere.sdk.customers.commands.updateactions.SetSalutation) CustomerUpdateActionUtils.buildSetCompanyNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCompanyNameUpdateAction) CustomerDraftBuilder(io.sphere.sdk.customers.CustomerDraftBuilder) CustomerUpdateActionUtils.buildSetExternalIdUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetExternalIdUpdateAction) Mockito.when(org.mockito.Mockito.when) CustomerUpdateActionUtils.buildChangeEmailUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildChangeEmailUpdateAction) CustomerUpdateActionUtils.buildSetDateOfBirthUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetDateOfBirthUpdateAction) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) UpdateAction(io.sphere.sdk.commands.UpdateAction) CustomerUpdateActionUtils.buildSetMiddleNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetMiddleNameUpdateAction) CustomerUpdateActionUtils.buildSetCustomerNumberUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCustomerNumberUpdateAction) CustomerUpdateActionUtils.buildSetLocaleUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetLocaleUpdateAction) CustomerUpdateActionUtils.buildSetVatIdUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetVatIdUpdateAction) CustomerUpdateActionUtils.buildSetFirstNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetFirstNameUpdateAction) CustomerUpdateActionUtils.buildSetSalutationUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetSalutationUpdateAction) CustomerUpdateActionUtils.buildSetLastNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetLastNameUpdateAction) CustomerUpdateActionUtils.buildSetTitleUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetTitleUpdateAction) CustomerUpdateActionUtils.buildSetCustomerGroupUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCustomerGroupUpdateAction) CustomerUpdateActionUtils.buildSetCompanyNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCompanyNameUpdateAction) CustomerUpdateActionUtils.buildSetExternalIdUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetExternalIdUpdateAction) CustomerUpdateActionUtils.buildChangeEmailUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildChangeEmailUpdateAction) CustomerUpdateActionUtils.buildSetDateOfBirthUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetDateOfBirthUpdateAction) SphereClient(io.sphere.sdk.client.SphereClient) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 9 with CustomerSyncOptions

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Reference(io.sphere.sdk.models.Reference) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) SetCustomerNumber(io.sphere.sdk.customers.commands.updateactions.SetCustomerNumber) CUSTOMER_NUMBER_EXISTS_WARNING(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.CUSTOMER_NUMBER_EXISTS_WARNING) CustomerUpdateActionUtils.buildSetMiddleNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetMiddleNameUpdateAction) SetMiddleName(io.sphere.sdk.customers.commands.updateactions.SetMiddleName) SetFirstName(io.sphere.sdk.customers.commands.updateactions.SetFirstName) SetDateOfBirth(io.sphere.sdk.customers.commands.updateactions.SetDateOfBirth) Locale(java.util.Locale) SphereClient(io.sphere.sdk.client.SphereClient) SetLocale(io.sphere.sdk.customers.commands.updateactions.SetLocale) CustomerUpdateActionUtils.buildSetCustomerNumberUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCustomerNumberUpdateAction) CustomerUpdateActionUtils.buildSetLocaleUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetLocaleUpdateAction) SetExternalId(io.sphere.sdk.customers.commands.updateactions.SetExternalId) CustomerUpdateActionUtils.buildSetVatIdUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetVatIdUpdateAction) ChangeEmail(io.sphere.sdk.customers.commands.updateactions.ChangeEmail) UUID(java.util.UUID) Customer(io.sphere.sdk.customers.Customer) String.format(java.lang.String.format) CustomerUpdateActionUtils.buildSetFirstNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetFirstNameUpdateAction) Test(org.junit.jupiter.api.Test) CustomerUpdateActionUtils.buildSetSalutationUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetSalutationUpdateAction) CustomerSyncOptionsBuilder(com.commercetools.sync.customers.CustomerSyncOptionsBuilder) CustomerName(io.sphere.sdk.customers.CustomerName) List(java.util.List) SetCustomerGroup(io.sphere.sdk.customers.commands.updateactions.SetCustomerGroup) SetVatId(io.sphere.sdk.customers.commands.updateactions.SetVatId) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) CustomerUpdateActionUtils.buildSetLastNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetLastNameUpdateAction) SetTitle(io.sphere.sdk.customers.commands.updateactions.SetTitle) CustomerUpdateActionUtils.buildSetTitleUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetTitleUpdateAction) CustomerUpdateActionUtils.buildSetCustomerGroupUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCustomerGroupUpdateAction) ArrayList(java.util.ArrayList) SetLastName(io.sphere.sdk.customers.commands.updateactions.SetLastName) CustomerGroup(io.sphere.sdk.customergroups.CustomerGroup) SetCompanyName(io.sphere.sdk.customers.commands.updateactions.SetCompanyName) SetSalutation(io.sphere.sdk.customers.commands.updateactions.SetSalutation) CustomerUpdateActionUtils.buildSetCompanyNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCompanyNameUpdateAction) CustomerDraftBuilder(io.sphere.sdk.customers.CustomerDraftBuilder) CustomerUpdateActionUtils.buildSetExternalIdUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetExternalIdUpdateAction) Mockito.when(org.mockito.Mockito.when) CustomerUpdateActionUtils.buildChangeEmailUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildChangeEmailUpdateAction) CustomerUpdateActionUtils.buildSetDateOfBirthUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetDateOfBirthUpdateAction) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) CustomerSyncOptions(com.commercetools.sync.customers.CustomerSyncOptions) Customer(io.sphere.sdk.customers.Customer) UpdateAction(io.sphere.sdk.commands.UpdateAction) CustomerUpdateActionUtils.buildSetMiddleNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetMiddleNameUpdateAction) CustomerUpdateActionUtils.buildSetCustomerNumberUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCustomerNumberUpdateAction) CustomerUpdateActionUtils.buildSetLocaleUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetLocaleUpdateAction) CustomerUpdateActionUtils.buildSetVatIdUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetVatIdUpdateAction) CustomerUpdateActionUtils.buildSetFirstNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetFirstNameUpdateAction) CustomerUpdateActionUtils.buildSetSalutationUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetSalutationUpdateAction) CustomerUpdateActionUtils.buildSetLastNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetLastNameUpdateAction) CustomerUpdateActionUtils.buildSetTitleUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetTitleUpdateAction) CustomerUpdateActionUtils.buildSetCustomerGroupUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCustomerGroupUpdateAction) CustomerUpdateActionUtils.buildSetCompanyNameUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetCompanyNameUpdateAction) CustomerUpdateActionUtils.buildSetExternalIdUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetExternalIdUpdateAction) CustomerUpdateActionUtils.buildChangeEmailUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildChangeEmailUpdateAction) CustomerUpdateActionUtils.buildSetDateOfBirthUpdateAction(com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.buildSetDateOfBirthUpdateAction) SphereClient(io.sphere.sdk.client.SphereClient) ArrayList(java.util.ArrayList) CustomerDraft(io.sphere.sdk.customers.CustomerDraft) Test(org.junit.jupiter.api.Test)

Example 10 with CustomerSyncOptions

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

Aggregations

CustomerSyncOptions (com.commercetools.sync.customers.CustomerSyncOptions)11 CustomerDraft (io.sphere.sdk.customers.CustomerDraft)10 CustomerSyncOptionsBuilder (com.commercetools.sync.customers.CustomerSyncOptionsBuilder)9 Customer (io.sphere.sdk.customers.Customer)9 List (java.util.List)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Test (org.junit.jupiter.api.Test)9 CustomerDraftBuilder (io.sphere.sdk.customers.CustomerDraftBuilder)8 ArrayList (java.util.ArrayList)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 SphereClient (io.sphere.sdk.client.SphereClient)7 ChangeEmail (io.sphere.sdk.customers.commands.updateactions.ChangeEmail)7 UpdateAction (io.sphere.sdk.commands.UpdateAction)6 ResourceIdentifier (io.sphere.sdk.models.ResourceIdentifier)6 CUSTOMER_NUMBER_EXISTS_WARNING (com.commercetools.sync.customers.utils.CustomerUpdateActionUtils.CUSTOMER_NUMBER_EXISTS_WARNING)5 CustomerGroup (io.sphere.sdk.customergroups.CustomerGroup)5 SetCompanyName (io.sphere.sdk.customers.commands.updateactions.SetCompanyName)5 SetCustomerGroup (io.sphere.sdk.customers.commands.updateactions.SetCustomerGroup)5 SetDateOfBirth (io.sphere.sdk.customers.commands.updateactions.SetDateOfBirth)5 SetFirstName (io.sphere.sdk.customers.commands.updateactions.SetFirstName)5