use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncTest method sync_WithNoExistingCategory_ShouldCreateCategory.
@Test
void sync_WithNoExistingCategory_ShouldCreateCategory() {
final Category mockCategory = getMockCategory(UUID.randomUUID().toString(), "newKey");
final Category mockParentCategory = getMockCategory(UUID.randomUUID().toString(), "parentKey");
final CategoryService mockCategoryService = mockCategoryService(singleton(mockParentCategory), mockCategory);
when(mockCategoryService.fetchCachedCategoryId(Mockito.eq("parentKey"))).thenReturn(CompletableFuture.completedFuture(Optional.of("parentId")));
final CategorySync mockCategorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
final List<CategoryDraft> categoryDrafts = singletonList(getMockCategoryDraft(Locale.ENGLISH, "name", "newKey", "parentKey", "customTypeId", new HashMap<>()));
final CategorySyncStatistics syncStatistics = mockCategorySync.sync(categoryDrafts).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(1, 1, 0, 0);
assertThat(errorCallBackMessages).hasSize(0);
assertThat(errorCallBackExceptions).hasSize(0);
}
use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncTest method sync_WithExistingCategoryButWithNoCustomType_ShouldSync.
@Test
void sync_WithExistingCategoryButWithNoCustomType_ShouldSync() {
final Category mockCategory = getMockCategory(UUID.randomUUID().toString(), "key");
final CategoryService mockCategoryService = mockCategoryService(singleton(mockCategory), null, mockCategory);
when(mockCategoryService.fetchCategory(Mockito.eq("key"))).thenReturn(CompletableFuture.completedFuture(Optional.of(mockCategory)));
final CategorySync categorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
final CategoryDraft categoryDraft = mock(CategoryDraft.class);
when(categoryDraft.getName()).thenReturn(LocalizedString.of(Locale.ENGLISH, "name"));
when(categoryDraft.getKey()).thenReturn("key");
when(categoryDraft.getCustom()).thenReturn(null);
final List<CategoryDraft> categoryDrafts = singletonList(categoryDraft);
final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
assertThat(errorCallBackMessages).hasSize(0);
assertThat(errorCallBackExceptions).hasSize(0);
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
}
use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncTest method sync_WithEmptyListOfDrafts_ShouldNotProcessAnyCategories.
@Test
void sync_WithEmptyListOfDrafts_ShouldNotProcessAnyCategories() {
final CategoryService mockCategoryService = mockCategoryService(emptySet(), null);
final CategorySync mockCategorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
final CategorySyncStatistics syncStatistics = mockCategorySync.sync(emptyList()).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(0, 0, 0, 0);
assertThat(errorCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
}
use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncTest method sync_WithExistingCategoryButWithEmptyParentReference_ShouldFailSync.
@Test
void sync_WithExistingCategoryButWithEmptyParentReference_ShouldFailSync() {
final Category mockCategory = getMockCategory(UUID.randomUUID().toString(), "key");
final CategoryService mockCategoryService = mockCategoryService(singleton(mockCategory), null, mockCategory);
when(mockCategoryService.fetchCategory(Mockito.eq("key"))).thenReturn(CompletableFuture.completedFuture(Optional.of(mockCategory)));
final CategorySync categorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
final List<CategoryDraft> categoryDrafts = singletonList(getMockCategoryDraft(Locale.ENGLISH, "name", "key", "", "customTypeId", new HashMap<>()));
final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorCallBackMessages).hasSize(1);
assertThat(errorCallBackMessages.get(0)).contains(BLANK_KEY_VALUE_ON_RESOURCE_IDENTIFIER);
assertThat(errorCallBackExceptions).hasSize(1);
}
use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncTest method sync_WithANullDraft_ShouldBeCountedAsFailed.
@Test
void sync_WithANullDraft_ShouldBeCountedAsFailed() {
final CategoryService mockCategoryService = mockCategoryService(emptySet(), null);
final CategorySync mockCategorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
final CategorySyncStatistics syncStatistics = mockCategorySync.sync(singletonList(null)).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorCallBackMessages).hasSize(1);
assertThat(errorCallBackMessages.get(0)).isEqualTo("CategoryDraft is null.");
assertThat(errorCallBackExceptions).hasSize(1);
assertThat(errorCallBackExceptions.get(0)).isEqualTo(null);
}
Aggregations