use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncIT method syncDrafts_WithNewCategoryWithExistingParent_ShouldCreateCategory.
@Test
void syncDrafts_WithNewCategoryWithExistingParent_ShouldCreateCategory() {
// Category draft coming from external source.
final CategoryDraft categoryDraft = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "Modern Furniture"), LocalizedString.of(Locale.ENGLISH, "modern-furniture")).key("newCategory").parent(ResourceIdentifier.ofKey(oldCategoryKey)).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_WithOneBatchSyncing_ShouldSync.
@Test
void syncDrafts_WithOneBatchSyncing_ShouldSync() {
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();
final CategoryDraft categoryDraft2 = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "cat1"), LocalizedString.of(Locale.ENGLISH, "modern-furniture1")).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, 1, 0, 0);
}
use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncIT method syncDrafts_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate.
@Test
void syncDrafts_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate() {
// Preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndNotFoundFetchOnRetry();
final CategoryDraft categoryDraft = 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();
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> errors = new ArrayList<>();
final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorMessages.add(exception.getMessage());
errors.add(exception.getCause());
}).build();
final CategorySync categorySync = new CategorySync(categorySyncOptions);
final CategorySyncStatistics statistics = categorySync.sync(Collections.singletonList(categoryDraft)).toCompletableFuture().join();
// Test and assertion
assertThat(statistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).hasSize(1);
assertThat(errors).hasSize(1);
assertThat(errorMessages.get(0)).contains(format("Failed to update Category with key: '%s'. Reason: Not found when attempting to fetch while" + " retrying after concurrency modification.", categoryDraft.getKey()));
}
use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncIT method syncDrafts_WithMultipleBatchSyncingWithAlreadyProcessedDrafts_ShouldSync.
@Test
void syncDrafts_WithMultipleBatchSyncingWithAlreadyProcessedDrafts_ShouldSync() {
// Category draft coming from external source.
CategoryDraft categoryDraft1 = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "new name"), LocalizedString.of(Locale.ENGLISH, "new-slug")).key(oldCategoryKey).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
final List<CategoryDraft> batch1 = new ArrayList<>();
batch1.add(categoryDraft1);
// Process same draft again in a different batch but with a different name.
final LocalizedString anotherNewName = LocalizedString.of(Locale.ENGLISH, "another new name");
categoryDraft1 = CategoryDraftBuilder.of(categoryDraft1).name(anotherNewName).build();
final List<CategoryDraft> batch2 = new ArrayList<>();
batch2.add(categoryDraft1);
final CategorySyncStatistics syncStatistics = categorySync.sync(batch1).thenCompose(result -> categorySync.sync(batch2)).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(2, 0, 2, 0, 0);
final Optional<Category> optionalResult = CTP_TARGET_CLIENT.execute(CategoryQuery.of().bySlug(Locale.ENGLISH, categoryDraft1.getSlug().get(Locale.ENGLISH))).toCompletableFuture().join().head();
assertThat(optionalResult).isNotEmpty();
assertThat(optionalResult.get().getName()).isEqualTo(anotherNewName);
}
use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.
the class CategorySyncIT method syncDrafts_WithDraftWithAMissingParentKey_ShouldNotSyncIt.
@Test
void syncDrafts_WithDraftWithAMissingParentKey_ShouldNotSyncIt() {
// 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 String nonExistingParentKey = "nonExistingParent";
final CategoryDraft categoryDraftWithMissingParent = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "furniture"), LocalizedString.of(Locale.ENGLISH, "new-furniture1")).key("cat1").parent(ResourceIdentifier.ofKey(nonExistingParentKey)).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
final List<CategoryDraft> categoryDrafts = new ArrayList<>();
categoryDrafts.add(categoryDraft);
categoryDrafts.add(categoryDraftWithMissingParent);
final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(2, 1, 0, 0, 1);
}
Aggregations