use of com.commercetools.sync.services.impl.CategoryServiceImpl in project commercetools-sync-java by commercetools.
the class CategorySyncTest method sync_WithFailOnCachingKeysToIds_ShouldTriggerErrorCallbackAndReturnProperStats.
@Test
void sync_WithFailOnCachingKeysToIds_ShouldTriggerErrorCallbackAndReturnProperStats() {
// preparation
final SphereClient mockClient = mock(SphereClient.class);
when(mockClient.execute(any(ResourceKeyIdGraphQlRequest.class))).thenReturn(supplyAsync(() -> {
throw new SphereException();
}));
final CategorySyncOptions syncOptions = CategorySyncOptionsBuilder.of(mockClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final CategoryService categoryServiceSpy = spy(new CategoryServiceImpl(syncOptions));
final CategorySync mockCategorySync = new CategorySync(syncOptions, getMockTypeService(), categoryServiceSpy, mockUnresolvedReferencesService);
CategoryDraft categoryDraft = getMockCategoryDraft(Locale.ENGLISH, "name", "newKey", "parentKey", "customTypeId", new HashMap<>());
// test
final CategorySyncStatistics syncStatistics = mockCategorySync.sync(singletonList(categoryDraft)).toCompletableFuture().join();
// assertions
assertThat(syncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorCallBackMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to build a cache of keys to ids.");
assertThat(errorCallBackExceptions).hasSize(1).singleElement().matches(throwable -> throwable instanceof CompletionException && throwable.getCause() instanceof SphereException);
}
use of com.commercetools.sync.services.impl.CategoryServiceImpl in project commercetools-sync-java by commercetools.
the class CategoryReferenceResolverTest method resolveParentReference_WithExceptionOnFetch_ShouldNotResolveReferences.
@Test
void resolveParentReference_WithExceptionOnFetch_ShouldNotResolveReferences() {
// Preparation
final SphereClient ctpClient = mock(SphereClient.class);
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(ctpClient).build();
final CategoryService categoryService = new CategoryServiceImpl(categorySyncOptions);
final CompletableFuture<PagedQueryResult<Category>> futureThrowingSphereException = new CompletableFuture<>();
futureThrowingSphereException.completeExceptionally(new SphereException("CTP error on fetch"));
when(ctpClient.execute(any(CategoryQuery.class))).thenReturn(futureThrowingSphereException);
final CategoryDraftBuilder categoryDraft = getMockCategoryDraftBuilder(Locale.ENGLISH, "myDraft", "key", "nonExistingCategoryKey", "customTypeKey", new HashMap<>());
final CategoryReferenceResolver categoryReferenceResolver = new CategoryReferenceResolver(categorySyncOptions, typeService, categoryService);
// Test and assertion
assertThat(categoryReferenceResolver.resolveParentReference(categoryDraft)).failsWithin(1, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(SphereException.class).withMessageContaining("CTP error on fetch");
}
Aggregations