Search in sources :

Example 31 with CategorySyncStatistics

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

the class CategorySyncIT method syncDrafts_WithANewCategoryWithNewSlug_ShouldCreateCategory.

@Test
void syncDrafts_WithANewCategoryWithNewSlug_ShouldCreateCategory() {
    // Category draft coming from external source.
    final CategoryDraft categoryDraft = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "furniture"), LocalizedString.of(Locale.ENGLISH, "new-furniture")).key("newCategoryKey").custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    final CategorySyncStatistics syncStatistics = categorySync.sync(Collections.singletonList(categoryDraft)).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(1, 1, 0, 0, 0);
}
Also used : CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 32 with CategorySyncStatistics

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

the class CategorySyncIT method syncDrafts_WithSameSlugDraft_ShouldNotSyncIt.

@Test
void syncDrafts_WithSameSlugDraft_ShouldNotSyncIt() {
    final List<CategoryDraft> newCategoryDrafts = new ArrayList<>();
    // Category draft coming from external source.
    final CategoryDraft categoryDraft1 = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "Modern Furniture"), LocalizedString.of(Locale.ENGLISH, "modern-furniture")).key(oldCategoryKey).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    // Same slug draft
    final CategoryDraft categoryDraft2 = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "cat1"), LocalizedString.of(Locale.ENGLISH, "modern-furniture")).key("cat1").custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    final CategoryDraft categoryDraft3 = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "cat2"), LocalizedString.of(Locale.ENGLISH, "modern-furniture2")).key("cat2").parent(ResourceIdentifier.ofKey("cat1")).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    final CategoryDraft categoryDraft4 = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "cat3"), LocalizedString.of(Locale.ENGLISH, "modern-furniture3")).key("cat3").parent(ResourceIdentifier.ofKey("cat1")).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    final CategoryDraft categoryDraft5 = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "cat4"), LocalizedString.of(Locale.ENGLISH, "modern-furniture4")).key("cat4").custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    final CategoryDraft categoryDraft6 = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "cat5"), LocalizedString.of(Locale.ENGLISH, "modern-furniture5")).key("cat5").parent(ResourceIdentifier.ofKey("cat4")).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    newCategoryDrafts.add(categoryDraft1);
    newCategoryDrafts.add(categoryDraft2);
    newCategoryDrafts.add(categoryDraft3);
    newCategoryDrafts.add(categoryDraft4);
    newCategoryDrafts.add(categoryDraft5);
    newCategoryDrafts.add(categoryDraft6);
    final CategorySyncStatistics syncStatistics = categorySync.sync(newCategoryDrafts).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(6, 5, 0, 1, 0);
}
Also used : CategoryDraft(io.sphere.sdk.categories.CategoryDraft) ArrayList(java.util.ArrayList) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 33 with CategorySyncStatistics

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

the class CategorySyncIT method syncDrafts_WithANewCategoryWithDuplicateSlug_ShouldNotCreateCategory.

@Test
void syncDrafts_WithANewCategoryWithDuplicateSlug_ShouldNotCreateCategory() {
    // Category draft coming from external source.
    final CategoryDraft categoryDraft = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "furniture"), LocalizedString.of(Locale.ENGLISH, "furniture")).key("newCategoryKey").custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    final CategorySyncStatistics syncStatistics = categorySync.sync(Collections.singletonList(categoryDraft)).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(1, 0, 0, 1, 0);
}
Also used : CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 34 with CategorySyncStatistics

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

the class CategorySyncIT method syncDrafts_withChangesOnly_ShouldUpdateCategories.

@Test
void syncDrafts_withChangesOnly_ShouldUpdateCategories() {
    createCategories(CTP_SOURCE_CLIENT, getCategoryDraftsWithPrefix(Locale.ENGLISH, "new", null, 2));
    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();
    final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(2, 0, 2, 0);
    assertThat(callBackErrorResponses).isEmpty();
    assertThat(callBackExceptions).isEmpty();
    assertThat(callBackWarningResponses).isEmpty();
}
Also used : Category(io.sphere.sdk.categories.Category) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 35 with CategorySyncStatistics

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

the class CategorySyncIT method syncDrafts_withNewShuffledBatchOfCategories_ShouldCreateCategories.

@Test
void syncDrafts_withNewShuffledBatchOfCategories_ShouldCreateCategories() {
    // -----------------Test Setup------------------------------------
    // Delete all categories in target project
    deleteAllCategories(CTP_TARGET_CLIENT);
    // Create a total of 130 categories in the source project
    final List<Category> subFamily = createChildren(5, null, "root", CTP_SOURCE_CLIENT);
    for (final Category child : subFamily) {
        final List<Category> subsubFamily = createChildren(5, child, child.getName().get(Locale.ENGLISH), CTP_SOURCE_CLIENT);
        for (final Category subChild : subsubFamily) {
            createChildren(4, subChild, subChild.getName().get(Locale.ENGLISH), CTP_SOURCE_CLIENT);
        }
    }
    // ---------------------------------------------------------------
    // Fetch categories from source project
    final List<Category> categories = CTP_SOURCE_CLIENT.execute(CategoryQuery.of().withLimit(QueryExecutionUtils.DEFAULT_PAGE_SIZE)).toCompletableFuture().join().getResults();
    final List<CategoryDraft> categoryDrafts = CategoryTransformUtils.toCategoryDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, categories).join();
    // Make sure there is no hierarchical order
    Collections.shuffle(categoryDrafts);
    CategorySync categorySyncWith13BatchSize = new CategorySync(buildCategorySyncOptions(13));
    final CategorySyncStatistics syncStatistics = categorySyncWith13BatchSize.sync(categoryDrafts).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(130, 130, 0, 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