Search in sources :

Example 11 with ShoppingListSyncStatistics

use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.

the class ShoppingListSyncIT method sync_WithSameShoppingList_ShouldNotUpdateShoppingList.

@Test
void sync_WithSameShoppingList_ShouldNotUpdateShoppingList() {
    final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraftSampleCarrotCake)).toCompletableFuture().join();
    assertThat(errorMessages).isEmpty();
    assertThat(warningMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    assertThat(shoppingListSyncStatistics).hasValues(1, 0, 0, 0);
    assertThat(shoppingListSyncStatistics.getReportMessage()).isEqualTo("Summary: 1 shopping lists were processed in total " + "(0 created, 0 updated and 0 failed to sync).");
}
Also used : ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) Test(org.junit.jupiter.api.Test)

Example 12 with ShoppingListSyncStatistics

use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.

the class ShoppingListSyncIT method sync_WithoutUpdates_ShouldReturnProperStatistics.

@Test
void sync_WithoutUpdates_ShouldReturnProperStatistics() {
    final List<ShoppingList> shoppingLists = CTP_SOURCE_CLIENT.execute(buildShoppingListQuery()).toCompletableFuture().join().getResults();
    final List<ShoppingListDraft> shoppingListDrafts = ShoppingListTransformUtils.toShoppingListDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, shoppingLists).join();
    final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(shoppingListDrafts).toCompletableFuture().join();
    assertThat(errorMessages).isEmpty();
    assertThat(warningMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    assertThat(updateActionList).isEmpty();
    assertThat(shoppingListSyncStatistics).hasValues(2, 1, 0, 0);
    assertThat(shoppingListSyncStatistics.getReportMessage()).isEqualTo("Summary: 2 shopping lists were processed in total " + "(1 created, 0 updated and 0 failed to sync).");
}
Also used : ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ShoppingListITUtils.createShoppingList(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createShoppingList) ShoppingListDraft(io.sphere.sdk.shoppinglists.ShoppingListDraft) Test(org.junit.jupiter.api.Test)

Example 13 with ShoppingListSyncStatistics

use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.

the class ShoppingListSyncIT method sync_WithUpdatedCustomerOnShoppingList_ShouldReturnProperStatistics.

@Test
void sync_WithUpdatedCustomerOnShoppingList_ShouldReturnProperStatistics() {
    final List<ShoppingList> shoppingLists = CTP_SOURCE_CLIENT.execute(buildShoppingListQuery()).toCompletableFuture().join().getResults();
    createSampleCustomerJaneDoe(CTP_SOURCE_CLIENT);
    final Customer sampleCustomerJaneDoe = createSampleCustomerJaneDoe(CTP_TARGET_CLIENT);
    final List<ShoppingListDraft> updatedShoppingListDrafts = ShoppingListTransformUtils.toShoppingListDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, shoppingLists).join().stream().map(shoppingListDraft -> ShoppingListDraftBuilder.of(shoppingListDraft).name(LocalizedString.ofEnglish("second-shopping-list")).anonymousId(null).customer(ResourceIdentifier.ofKey(sampleCustomerJaneDoe.getKey())).build()).collect(Collectors.toList());
    final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(updatedShoppingListDrafts).toCompletableFuture().join();
    assertThat(errorMessages).isEmpty();
    assertThat(warningMessages).isEmpty();
    assertThat(exceptions).isEmpty();
    // order is important, otherwise the error below could occur:
    // "message" : "The resource was already claimed by a customer..
    // "action" : {
    // "action" : "setAnonymousId"
    // }
    assertThat(updateActionList).containsExactly(ChangeName.of(LocalizedString.ofEnglish("second-shopping-list")), SetAnonymousId.of(null), SetCustomer.of(Reference.of(Customer.referenceTypeId(), sampleCustomerJaneDoe.getId())));
    AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(2, 1, 1, 0);
    assertThat(shoppingListSyncStatistics.getReportMessage()).isEqualTo("Summary: 2 shopping lists were processed in total " + "(1 created, 1 updated and 0 failed to sync).");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Reference(io.sphere.sdk.models.Reference) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) SetAnonymousId(io.sphere.sdk.shoppinglists.commands.updateactions.SetAnonymousId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ShoppingListSyncOptionsBuilder(com.commercetools.sync.shoppinglists.ShoppingListSyncOptionsBuilder) ShoppingListTransformUtils(com.commercetools.sync.shoppinglists.utils.ShoppingListTransformUtils) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) ShoppingListITUtils.createShoppingList(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createShoppingList) ReferenceIdToKeyCache(com.commercetools.sync.commons.utils.ReferenceIdToKeyCache) ShoppingListDraftBuilder(io.sphere.sdk.shoppinglists.ShoppingListDraftBuilder) CustomerITUtils.createSampleCustomerJaneDoe(com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJaneDoe) CaffeineReferenceIdToKeyCacheImpl(com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) ShoppingListITUtils.deleteShoppingListTestData(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.deleteShoppingListTestData) ChangeName(io.sphere.sdk.shoppinglists.commands.updateactions.ChangeName) ShoppingListITUtils.createSampleShoppingListCarrotCake(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createSampleShoppingListCarrotCake) Customer(io.sphere.sdk.customers.Customer) Collectors(java.util.stream.Collectors) ShoppingListReferenceResolutionUtils.buildShoppingListQuery(com.commercetools.sync.shoppinglists.utils.ShoppingListReferenceResolutionUtils.buildShoppingListQuery) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) ShoppingListDraft(io.sphere.sdk.shoppinglists.ShoppingListDraft) List(java.util.List) SetCustomer(io.sphere.sdk.shoppinglists.commands.updateactions.SetCustomer) AssertionsForStatistics(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) Customer(io.sphere.sdk.customers.Customer) SetCustomer(io.sphere.sdk.shoppinglists.commands.updateactions.SetCustomer) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ShoppingListITUtils.createShoppingList(com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createShoppingList) ShoppingListDraft(io.sphere.sdk.shoppinglists.ShoppingListDraft) Test(org.junit.jupiter.api.Test)

Example 14 with ShoppingListSyncStatistics

use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.

the class ShoppingListSyncTest method sync_WithNullDraft_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.

@Test
void sync_WithNullDraft_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
    // preparation
    ShoppingListSync shoppingListSync = new ShoppingListSync(syncOptions);
    // test
    ShoppingListSyncStatistics statistics = shoppingListSync.sync(singletonList(null)).toCompletableFuture().join();
    AssertionsForStatistics.assertThat(statistics).hasValues(1, 0, 0, 1);
    // assertions
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).isEqualTo(SHOPPING_LIST_DRAFT_IS_NULL);
}
Also used : ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) Test(org.junit.jupiter.api.Test)

Example 15 with ShoppingListSyncStatistics

use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.

the class ShoppingListSyncTest method sync_WithExceptionOnCachingKeysToIds_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.

@Test
void sync_WithExceptionOnCachingKeysToIds_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
    // preparation
    final TypeService typeService = mock(TypeService.class);
    final CustomerService customerService = mock(CustomerService.class);
    when(typeService.cacheKeysToIds(any())).thenReturn(supplyAsync(() -> {
        throw new SphereException();
    }));
    when(customerService.cacheKeysToIds(any())).thenReturn(supplyAsync(() -> {
        throw new SphereException();
    }));
    final ShoppingListSync shoppingListSync = new ShoppingListSync(syncOptions, mock(ShoppingListService.class), customerService, typeService);
    ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("shopping-list-name")).key("shopping-list-key").customer(ResourceIdentifier.ofKey("customer-key")).custom(CustomFieldsDraft.ofTypeKeyAndJson("typeKey", emptyMap())).build();
    // test
    ShoppingListSyncStatistics statistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
    AssertionsForStatistics.assertThat(statistics).hasValues(1, 0, 0, 1);
    // assertions
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).isEqualTo("Failed to build a cache of keys to ids.");
    assertThat(exceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasCauseExactlyInstanceOf(CompletionException.class).hasRootCauseExactlyInstanceOf(SphereException.class);
}
Also used : ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) CustomerService(com.commercetools.sync.services.CustomerService) ShoppingListService(com.commercetools.sync.services.ShoppingListService) CompletionException(java.util.concurrent.CompletionException) ShoppingListDraft(io.sphere.sdk.shoppinglists.ShoppingListDraft) SphereException(io.sphere.sdk.models.SphereException) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Aggregations

ShoppingListSyncStatistics (com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics)21 Test (org.junit.jupiter.api.Test)21 ShoppingListDraft (io.sphere.sdk.shoppinglists.ShoppingListDraft)19 CustomerService (com.commercetools.sync.services.CustomerService)13 ShoppingListService (com.commercetools.sync.services.ShoppingListService)13 TypeService (com.commercetools.sync.services.TypeService)13 ShoppingList (io.sphere.sdk.shoppinglists.ShoppingList)13 SphereException (io.sphere.sdk.models.SphereException)6 SyncException (com.commercetools.sync.commons.exceptions.SyncException)3 ConcurrentModificationException (io.sphere.sdk.client.ConcurrentModificationException)3 ShoppingListITUtils.createShoppingList (com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createShoppingList)2 TextLineItem (io.sphere.sdk.shoppinglists.TextLineItem)2 TextLineItemDraft (io.sphere.sdk.shoppinglists.TextLineItemDraft)2 CompletionException (java.util.concurrent.CompletionException)2 AssertionsForStatistics (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics)1 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)1 CaffeineReferenceIdToKeyCacheImpl (com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl)1 ReferenceIdToKeyCache (com.commercetools.sync.commons.utils.ReferenceIdToKeyCache)1 CustomerITUtils.createSampleCustomerJaneDoe (com.commercetools.sync.integration.commons.utils.CustomerITUtils.createSampleCustomerJaneDoe)1 ShoppingListITUtils.createSampleShoppingListCarrotCake (com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.createSampleShoppingListCarrotCake)1