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);
}
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);
}
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);
}
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();
}
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();
}
Aggregations