use of com.commercetools.sync.services.CategoryService in project commercetools-sync-java by commercetools.
the class CategorySyncTest method sync_WithIdenticalExistingCategory_ShouldNotUpdateCategory.
@Test
void sync_WithIdenticalExistingCategory_ShouldNotUpdateCategory() {
final Category mockCategory = getMockCategory(UUID.randomUUID().toString(), "key");
final CategoryDraft identicalCategoryDraft = CategoryDraftBuilder.of(mockCategory).build();
final CategoryService mockCategoryService = mockCategoryService(singleton(mockCategory), null, mockCategory);
when(mockCategoryService.fetchCategory(Mockito.eq("key"))).thenReturn(CompletableFuture.completedFuture(Optional.of(mockCategory)));
final CategorySync mockCategorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
final List<CategoryDraft> categoryDrafts = singletonList(identicalCategoryDraft);
final CategorySyncStatistics syncStatistics = mockCategorySync.sync(categoryDrafts).toCompletableFuture().join();
assertThat(errorCallBackMessages).hasSize(0);
assertThat(errorCallBackExceptions).hasSize(0);
assertThat(syncStatistics).hasValues(1, 0, 0, 0);
}
use of com.commercetools.sync.services.CategoryService 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.services.CategoryService in project commercetools-sync-java by commercetools.
the class CategoryReferenceResolverTest method setup.
/**
* Sets up the services and the options needed for reference resolution.
*/
@BeforeEach
void setup() {
typeService = getMockTypeService();
categoryService = mock(CategoryService.class);
when(categoryService.fetchCachedCategoryId(CACHED_CATEGORY_KEY)).thenReturn(CompletableFuture.completedFuture(Optional.of(CACHED_CATEGORY_ID)));
final CategorySyncOptions syncOptions = CategorySyncOptionsBuilder.of(mock(SphereClient.class)).build();
referenceResolver = new CategoryReferenceResolver(syncOptions, typeService, categoryService);
}
use of com.commercetools.sync.services.CategoryService 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.services.CategoryService 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();
}
Aggregations