Search in sources :

Example 1 with CustomerServiceImpl

use of com.commercetools.sync.services.impl.CustomerServiceImpl 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 2 with CustomerServiceImpl

use of com.commercetools.sync.services.impl.CustomerServiceImpl 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)

Aggregations

CustomerSyncOptions (com.commercetools.sync.customers.CustomerSyncOptions)2 CustomerSyncOptionsBuilder (com.commercetools.sync.customers.CustomerSyncOptionsBuilder)2 CustomerITUtils.deleteCustomers (com.commercetools.sync.integration.commons.utils.CustomerITUtils.deleteCustomers)2 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)2 CustomerService (com.commercetools.sync.services.CustomerService)2 CustomerServiceImpl (com.commercetools.sync.services.impl.CustomerServiceImpl)2 SphereClient (io.sphere.sdk.client.SphereClient)2 Customer (io.sphere.sdk.customers.Customer)2 CustomerDraft (io.sphere.sdk.customers.CustomerDraft)2 CustomerDraftBuilder (io.sphere.sdk.customers.CustomerDraftBuilder)2 CustomerCreateCommand (io.sphere.sdk.customers.commands.CustomerCreateCommand)2 ChangeEmail (io.sphere.sdk.customers.commands.updateactions.ChangeEmail)2 CustomerQuery (io.sphere.sdk.customers.queries.CustomerQuery)2 QueryPredicate (io.sphere.sdk.queries.QueryPredicate)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 Collections.emptySet (java.util.Collections.emptySet)2 Collections.singleton (java.util.Collections.singleton)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2