Search in sources :

Example 36 with CategorySyncStatistics

use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.

the class CategorySyncIT method syncDrafts_withExistingCategoriesThatChangeParents_ShouldUpdateCategories.

@Test
void syncDrafts_withExistingCategoriesThatChangeParents_ShouldUpdateCategories() {
    // -----------------Test Setup------------------------------------
    // Delete all categories in target project
    deleteAllCategories(CTP_TARGET_CLIENT);
    // Create a total of 3 categories in the target project (2 roots and 1 child to the first root)
    final List<Category> subFamily = createChildren(2, null, "root", CTP_TARGET_CLIENT);
    final Category firstRoot = subFamily.get(0);
    createChildren(1, firstRoot, "child", CTP_TARGET_CLIENT);
    // ---------------------------------------------------------------
    // Create a total of 2 categories in the source project (2 roots and 1 child to the second root)
    final List<Category> sourceSubFamily = createChildren(2, null, "root", CTP_SOURCE_CLIENT);
    final Category secondRoot = sourceSubFamily.get(1);
    createChildren(1, secondRoot, "child", CTP_SOURCE_CLIENT);
    // ---------------------------------------------------------------
    // Fetch categories from source project
    final List<Category> categories = CTP_SOURCE_CLIENT.execute(CategoryQuery.of()).toCompletableFuture().join().getResults();
    final List<CategoryDraft> categoryDrafts = CategoryTransformUtils.toCategoryDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, categories).join();
    Collections.shuffle(categoryDrafts);
    CategorySync categorySyncWith1BatchSize = new CategorySync(buildCategorySyncOptions(1));
    final CategorySyncStatistics syncStatistics = categorySyncWith1BatchSize.sync(categoryDrafts).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(3, 0, 1, 0, 0);
    assertThat(callBackErrorResponses).isEmpty();
    assertThat(callBackExceptions).isEmpty();
    assertThat(callBackWarningResponses).isEmpty();
}
Also used : Category(io.sphere.sdk.categories.Category) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategorySync(com.commercetools.sync.categories.CategorySync) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Aggregations

CategorySyncStatistics (com.commercetools.sync.categories.helpers.CategorySyncStatistics)36 Test (org.junit.jupiter.api.Test)36 CategoryDraft (io.sphere.sdk.categories.CategoryDraft)34 Category (io.sphere.sdk.categories.Category)22 ArrayList (java.util.ArrayList)14 MockUtils.mockCategoryService (com.commercetools.sync.commons.MockUtils.mockCategoryService)13 CategoryService (com.commercetools.sync.services.CategoryService)13 HashMap (java.util.HashMap)13 LocalizedString (io.sphere.sdk.models.LocalizedString)12 CategorySyncMockUtils.getMockCategoryDraft (com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategoryDraft)11 CategorySyncMockUtils.getMockCategory (com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategory)10 CategorySync (com.commercetools.sync.categories.CategorySync)9 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)7 CategoryDraftBuilder (io.sphere.sdk.categories.CategoryDraftBuilder)7 CategoryCreateCommand (io.sphere.sdk.categories.commands.CategoryCreateCommand)7 CategoryQuery (io.sphere.sdk.categories.queries.CategoryQuery)7 ResourceIdentifier (io.sphere.sdk.models.ResourceIdentifier)7 CustomFieldsDraft (io.sphere.sdk.types.CustomFieldsDraft)7 Collections (java.util.Collections)7 List (java.util.List)7