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