use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithUnchangedShoppingListDraftAndUpdatedTextLineItemDraft_ShouldIncrementUpdated.
@Test
void sync_WithUnchangedShoppingListDraftAndUpdatedTextLineItemDraft_ShouldIncrementUpdated() {
// preparation
final ShoppingList mockShoppingList = mock(ShoppingList.class);
when(mockShoppingList.getKey()).thenReturn("shoppingListKey");
when(mockShoppingList.getName()).thenReturn(LocalizedString.ofEnglish("shoppingListName"));
final TextLineItem mockTextLineItem = mock(TextLineItem.class);
when(mockTextLineItem.getName()).thenReturn(LocalizedString.ofEnglish("textLineItemName"));
when(mockTextLineItem.getQuantity()).thenReturn(10L);
final ShoppingListService mockShoppingListService = mock(ShoppingListService.class);
when(mockShoppingListService.fetchMatchingShoppingListsByKeys(anySet())).thenReturn(completedFuture(singleton(mockShoppingList)));
when(mockShoppingListService.updateShoppingList(any(), anyList())).thenReturn(completedFuture(mockShoppingList));
final ShoppingListSyncOptions spySyncOptions = spy(syncOptions);
final ShoppingListSync shoppingListSync = new ShoppingListSync(spySyncOptions, mockShoppingListService, mock(CustomerService.class), mock(TypeService.class));
final List<TextLineItemDraft> textLineItemDrafts = singletonList(TextLineItemDraftBuilder.of(LocalizedString.ofEnglish("textLineItemName"), 5L).build());
final ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("shoppingListName")).key("shoppingListKey").textLineItems(textLineItemDrafts).build();
// test
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(1, 0, 1, 0);
verify(spySyncOptions).applyBeforeUpdateCallback(any(), any(), any());
verify(spySyncOptions, never()).applyBeforeCreateCallback(shoppingListDraft);
}
use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithEmptyKeyDraft_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.
@Test
void sync_WithEmptyKeyDraft_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
// preparation
ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("shopping-list-name")).key("").build();
ShoppingListSync shoppingListSync = new ShoppingListSync(syncOptions);
// 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(format(SHOPPING_LIST_DRAFT_KEY_NOT_SET, shoppingListDraft.getName()));
}
use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithOnlyDraftsToCreate_ShouldCallBeforeCreateCallbackAndIncrementCreated.
@Test
void sync_WithOnlyDraftsToCreate_ShouldCallBeforeCreateCallbackAndIncrementCreated() {
// preparation
final ShoppingListService mockShoppingListService = mock(ShoppingListService.class);
final ShoppingList mockShoppingList = mock(ShoppingList.class);
when(mockShoppingListService.fetchMatchingShoppingListsByKeys(singleton("shoppingListKey"))).thenReturn(completedFuture(new HashSet<>(singletonList(mockShoppingList))));
when(mockShoppingListService.createShoppingList(any())).thenReturn(completedFuture(Optional.of(mockShoppingList)));
final ShoppingListSyncOptions spySyncOptions = spy(syncOptions);
final ShoppingListSync shoppingListSync = new ShoppingListSync(spySyncOptions, mockShoppingListService, mock(CustomerService.class), mock(TypeService.class));
final ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("NAME")).key("shoppingListKey").build();
// test
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(1, 1, 0, 0);
verify(spySyncOptions).applyBeforeCreateCallback(shoppingListDraft);
verify(spySyncOptions, never()).applyBeforeUpdateCallback(any(), any(), any());
}
use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithoutUpdateActions_ShouldNotIncrementUpdated.
@Test
void sync_WithoutUpdateActions_ShouldNotIncrementUpdated() {
// preparation
final ShoppingListService mockShoppingListService = mock(ShoppingListService.class);
final ShoppingList mockShoppingList = mock(ShoppingList.class);
when(mockShoppingList.getKey()).thenReturn("shoppingListKey");
when(mockShoppingList.getName()).thenReturn(LocalizedString.ofEnglish("shoppingListName"));
when(mockShoppingList.getDescription()).thenReturn(LocalizedString.ofEnglish("shoppingListDesc"));
when(mockShoppingList.getSlug()).thenReturn(LocalizedString.ofEnglish("shoppingListSlug"));
when(mockShoppingList.getAnonymousId()).thenReturn("shoppingListAnonymousId");
when(mockShoppingList.getDeleteDaysAfterLastModification()).thenReturn(360);
when(mockShoppingListService.fetchMatchingShoppingListsByKeys(anySet())).thenReturn(completedFuture(singleton(mockShoppingList)));
final ShoppingListSyncOptions spySyncOptions = spy(syncOptions);
final ShoppingListSync shoppingListSync = new ShoppingListSync(spySyncOptions, mockShoppingListService, mock(CustomerService.class), mock(TypeService.class));
final ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("shoppingListName")).key("shoppingListKey").description(mockShoppingList.getDescription()).slug(mockShoppingList.getSlug()).anonymousId(mockShoppingList.getAnonymousId()).deleteDaysAfterLastModification(mockShoppingList.getDeleteDaysAfterLastModification()).build();
// test
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(1, 0, 0, 0);
verify(spySyncOptions).applyBeforeUpdateCallback(emptyList(), shoppingListDraft, mockShoppingList);
verify(spySyncOptions, never()).applyBeforeCreateCallback(shoppingListDraft);
}
use of com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics in project commercetools-sync-java by commercetools.
the class ShoppingListSyncTest method sync_WithBadRequestException_ShouldFailToUpdateAndIncreaseFailedCounter.
@Test
void sync_WithBadRequestException_ShouldFailToUpdateAndIncreaseFailedCounter() {
// preparation
final ShoppingListService mockShoppingListService = mock(ShoppingListService.class);
final ShoppingList mockShoppingList = mock(ShoppingList.class);
when(mockShoppingList.getKey()).thenReturn("shoppingListKey");
when(mockShoppingListService.fetchMatchingShoppingListsByKeys(anySet())).thenReturn(completedFuture(singleton(mockShoppingList)));
when(mockShoppingListService.updateShoppingList(any(), anyList())).thenReturn(exceptionallyCompletedFuture(new BadRequestException("Invalid request")));
final ShoppingListSyncOptions spySyncOptions = spy(syncOptions);
final ShoppingListSync shoppingListSync = new ShoppingListSync(spySyncOptions, mockShoppingListService, mock(CustomerService.class), mock(TypeService.class));
final ShoppingListDraft shoppingListDraft = ShoppingListDraftBuilder.of(LocalizedString.ofEnglish("shoppingListName")).key("shoppingListKey").build();
// test
final ShoppingListSyncStatistics shoppingListSyncStatistics = shoppingListSync.sync(singletonList(shoppingListDraft)).toCompletableFuture().join();
// assertions
AssertionsForStatistics.assertThat(shoppingListSyncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Invalid request");
assertThat(exceptions).hasSize(1).singleElement(as(THROWABLE)).isExactlyInstanceOf(SyncException.class).hasRootCauseExactlyInstanceOf(BadRequestException.class);
}
Aggregations