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