use of com.commercetools.sync.services.TaxCategoryService in project commercetools-sync-java by commercetools.
the class TaxCategorySyncTest method sync_WithErrorCreating_ShouldIncrementFailedButNotApplyErrorCallback.
@Test
void sync_WithErrorCreating_ShouldIncrementFailedButNotApplyErrorCallback() {
final List<String> errors = new ArrayList<>();
final TaxCategorySyncOptions options = TaxCategorySyncOptionsBuilder.of(mock(SphereClient.class)).errorCallback((exception, draft, entry, actions) -> errors.add(exception.getMessage())).build();
final TaxCategorySync sync = new TaxCategorySync(options, taxCategoryService);
final TaxCategoryDraft draft = TaxCategoryDraftBuilder.of("someName", emptyList(), null).key("someKey").build();
when(taxCategoryService.fetchMatchingTaxCategoriesByKeys(any())).thenReturn(completedFuture(emptySet()));
when(taxCategoryService.createTaxCategory(any())).thenReturn(completedFuture(empty()));
final TaxCategorySyncStatistics result = sync.sync(singletonList(draft)).toCompletableFuture().join();
assertAll(() -> assertThat(result.getProcessed().get()).isEqualTo(1), () -> assertThat(result.getFailed().get()).isEqualTo(1), () -> assertThat(errors).isEmpty());
verify(taxCategoryService, times(1)).fetchMatchingTaxCategoriesByKeys(any());
verify(taxCategoryService, times(1)).createTaxCategory(any());
verifyNoMoreInteractions(taxCategoryService);
}
use of com.commercetools.sync.services.TaxCategoryService in project commercetools-sync-java by commercetools.
the class TaxCategorySyncTest method sync_WithErrorUpdatingAndTryingToRecoverWithEmptyResponse_ShouldApplyErrorCallbackAndIncrementFailed.
@Test
void sync_WithErrorUpdatingAndTryingToRecoverWithEmptyResponse_ShouldApplyErrorCallbackAndIncrementFailed() {
final List<String> errors = new ArrayList<>();
final TaxCategorySyncOptions options = TaxCategorySyncOptionsBuilder.of(mock(SphereClient.class)).errorCallback((exception, draft, entry, actions) -> errors.add(exception.getMessage())).build();
final TaxCategorySync sync = new TaxCategorySync(options, taxCategoryService);
final TaxCategoryDraft draft = TaxCategoryDraftBuilder.of("someName", emptyList(), "changed").key("someKey").build();
final TaxCategory taxCategory = mock(TaxCategory.class);
when(taxCategory.getKey()).thenReturn("someKey");
when(taxCategoryService.fetchMatchingTaxCategoriesByKeys(any())).thenReturn(completedFuture(new HashSet<>(singletonList(taxCategory))));
when(taxCategoryService.updateTaxCategory(any(), any())).thenReturn(supplyAsync(() -> {
throw new ConcurrentModificationException();
}));
when(taxCategoryService.fetchTaxCategory(any())).thenReturn(completedFuture(Optional.empty()));
final TaxCategorySyncStatistics result = sync.sync(singletonList(draft)).toCompletableFuture().join();
assertAll(() -> assertThat(result.getProcessed().get()).isEqualTo(1), () -> assertThat(result.getUpdated().get()).isEqualTo(0), () -> assertThat(result.getFailed().get()).isEqualTo(1), () -> assertThat(errors).hasSize(1), () -> assertThat(errors).singleElement(as(STRING)).contains("Not found when attempting to fetch while retrying after concurrency modification."));
verify(taxCategoryService, times(1)).fetchMatchingTaxCategoriesByKeys(any());
verify(taxCategoryService, times(1)).updateTaxCategory(any(), any());
verify(taxCategoryService, times(1)).fetchTaxCategory(any());
verifyNoMoreInteractions(taxCategoryService);
}
Aggregations