Search in sources :

Example 1 with CategorySyncOptions

use of com.commercetools.sync.categories.CategorySyncOptions 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()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryUpdateCommand(io.sphere.sdk.categories.commands.CategoryUpdateCommand) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CategoryQuery(io.sphere.sdk.categories.queries.CategoryQuery) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Locale(java.util.Locale) OLD_CATEGORY_CUSTOM_TYPE_NAME(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) JsonNode(com.fasterxml.jackson.databind.JsonNode) OLD_CATEGORY_CUSTOM_TYPE_KEY(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) Category(io.sphere.sdk.categories.Category) CategoryCreateCommand(io.sphere.sdk.categories.commands.CategoryCreateCommand) String.format(java.lang.String.format) TYPE_DOES_NOT_EXIST(com.commercetools.sync.commons.helpers.CustomReferenceResolver.TYPE_DOES_NOT_EXIST) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) CategoryITUtils.getCustomFieldsDraft(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getCustomFieldsDraft) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryDraftBuilder(io.sphere.sdk.categories.CategoryDraftBuilder) ArrayList(java.util.ArrayList) BOOLEAN_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.BOOLEAN_CUSTOM_FIELD_NAME) CategorySync(com.commercetools.sync.categories.CategorySync) Nonnull(javax.annotation.Nonnull) CategoryITUtils.deleteAllCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Mockito.when(org.mockito.Mockito.when) CategorySyncOptionsBuilder(com.commercetools.sync.categories.CategorySyncOptionsBuilder) ITUtils.createCustomFieldsJsonMap(com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) AfterEach(org.junit.jupiter.api.AfterEach) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) LOCALISED_STRING_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME) Collections(java.util.Collections) SphereClient(io.sphere.sdk.client.SphereClient) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) ArrayList(java.util.ArrayList) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) LocalizedString(io.sphere.sdk.models.LocalizedString) CategorySync(com.commercetools.sync.categories.CategorySync) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 2 with CategorySyncOptions

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

the class CategorySyncIT method setupTest.

/**
 * Deletes Categories and Types from target CTP project, then it populates it with category test
 * data.
 */
@BeforeEach
void setupTest() {
    deleteAllCategories(CTP_TARGET_CLIENT);
    final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    categorySync = new CategorySync(categorySyncOptions);
    // Create a mock in the target project.
    final CategoryDraft oldCategoryDraft = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "furniture"), LocalizedString.of(Locale.ENGLISH, "furniture")).key(oldCategoryKey).custom(getCustomFieldsDraft()).build();
    CTP_TARGET_CLIENT.execute(CategoryCreateCommand.of(oldCategoryDraft)).toCompletableFuture().join();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryUpdateCommand(io.sphere.sdk.categories.commands.CategoryUpdateCommand) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CategoryQuery(io.sphere.sdk.categories.queries.CategoryQuery) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Locale(java.util.Locale) OLD_CATEGORY_CUSTOM_TYPE_NAME(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) JsonNode(com.fasterxml.jackson.databind.JsonNode) OLD_CATEGORY_CUSTOM_TYPE_KEY(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) Category(io.sphere.sdk.categories.Category) CategoryCreateCommand(io.sphere.sdk.categories.commands.CategoryCreateCommand) String.format(java.lang.String.format) TYPE_DOES_NOT_EXIST(com.commercetools.sync.commons.helpers.CustomReferenceResolver.TYPE_DOES_NOT_EXIST) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) CategoryITUtils.getCustomFieldsDraft(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getCustomFieldsDraft) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryDraftBuilder(io.sphere.sdk.categories.CategoryDraftBuilder) ArrayList(java.util.ArrayList) BOOLEAN_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.BOOLEAN_CUSTOM_FIELD_NAME) CategorySync(com.commercetools.sync.categories.CategorySync) Nonnull(javax.annotation.Nonnull) CategoryITUtils.deleteAllCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Mockito.when(org.mockito.Mockito.when) CategorySyncOptionsBuilder(com.commercetools.sync.categories.CategorySyncOptionsBuilder) ITUtils.createCustomFieldsJsonMap(com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) AfterEach(org.junit.jupiter.api.AfterEach) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) LOCALISED_STRING_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME) Collections(java.util.Collections) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) CategorySync(com.commercetools.sync.categories.CategorySync) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CategorySyncOptions

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

the class CategorySyncIT method syncDrafts_WithConcurrentModificationException_ShouldRetryToUpdateNewCategoryWithSuccess.

@Test
void syncDrafts_WithConcurrentModificationException_ShouldRetryToUpdateNewCategoryWithSuccess() {
    // Preparation
    final SphereClient spyClient = buildClientWithConcurrentModificationUpdate();
    final LocalizedString newCategoryName = LocalizedString.of(Locale.ENGLISH, "Modern Furniture");
    final CategoryDraft categoryDraft = CategoryDraftBuilder.of(newCategoryName, LocalizedString.of(Locale.ENGLISH, "modern-furniture")).key(oldCategoryKey).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, createCustomFieldsJsonMap())).build();
    final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(spyClient).build();
    final CategorySync categorySync = new CategorySync(categorySyncOptions);
    // Test
    final CategorySyncStatistics statistics = categorySync.sync(Collections.singletonList(categoryDraft)).toCompletableFuture().join();
    // Assertion
    assertThat(statistics).hasValues(1, 0, 1, 0);
    // Assert CTP state.
    final PagedQueryResult<Category> queryResult = CTP_TARGET_CLIENT.execute(CategoryQuery.of().plusPredicates(categoryQueryModel -> categoryQueryModel.key().is(categoryDraft.getKey()))).toCompletableFuture().join();
    assertThat(queryResult.head()).hasValueSatisfying(category -> assertThat(category.getName()).isEqualTo(newCategoryName));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryUpdateCommand(io.sphere.sdk.categories.commands.CategoryUpdateCommand) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CategoryQuery(io.sphere.sdk.categories.queries.CategoryQuery) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Locale(java.util.Locale) OLD_CATEGORY_CUSTOM_TYPE_NAME(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) JsonNode(com.fasterxml.jackson.databind.JsonNode) OLD_CATEGORY_CUSTOM_TYPE_KEY(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) Category(io.sphere.sdk.categories.Category) CategoryCreateCommand(io.sphere.sdk.categories.commands.CategoryCreateCommand) String.format(java.lang.String.format) TYPE_DOES_NOT_EXIST(com.commercetools.sync.commons.helpers.CustomReferenceResolver.TYPE_DOES_NOT_EXIST) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) CategoryITUtils.getCustomFieldsDraft(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getCustomFieldsDraft) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryDraftBuilder(io.sphere.sdk.categories.CategoryDraftBuilder) ArrayList(java.util.ArrayList) BOOLEAN_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.BOOLEAN_CUSTOM_FIELD_NAME) CategorySync(com.commercetools.sync.categories.CategorySync) Nonnull(javax.annotation.Nonnull) CategoryITUtils.deleteAllCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Mockito.when(org.mockito.Mockito.when) CategorySyncOptionsBuilder(com.commercetools.sync.categories.CategorySyncOptionsBuilder) ITUtils.createCustomFieldsJsonMap(com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) AfterEach(org.junit.jupiter.api.AfterEach) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) LOCALISED_STRING_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME) Collections(java.util.Collections) Category(io.sphere.sdk.categories.Category) SphereClient(io.sphere.sdk.client.SphereClient) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) CategorySync(com.commercetools.sync.categories.CategorySync) LocalizedString(io.sphere.sdk.models.LocalizedString) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 4 with CategorySyncOptions

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

the class CategorySyncIT method syncDrafts_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate.

@Test
void syncDrafts_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate() {
    // Preparation
    final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndFailedFetchOnRetry();
    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(errors.get(0).getCause()).isExactlyInstanceOf(BadGatewayException.class);
    assertThat(errorMessages.get(0)).contains("Reason: Failed to fetch from CTP while retrying after concurrency modification.");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryUpdateCommand(io.sphere.sdk.categories.commands.CategoryUpdateCommand) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CategoryQuery(io.sphere.sdk.categories.queries.CategoryQuery) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Locale(java.util.Locale) OLD_CATEGORY_CUSTOM_TYPE_NAME(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) JsonNode(com.fasterxml.jackson.databind.JsonNode) OLD_CATEGORY_CUSTOM_TYPE_KEY(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) Category(io.sphere.sdk.categories.Category) CategoryCreateCommand(io.sphere.sdk.categories.commands.CategoryCreateCommand) String.format(java.lang.String.format) TYPE_DOES_NOT_EXIST(com.commercetools.sync.commons.helpers.CustomReferenceResolver.TYPE_DOES_NOT_EXIST) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) CategoryITUtils.getCustomFieldsDraft(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getCustomFieldsDraft) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryDraftBuilder(io.sphere.sdk.categories.CategoryDraftBuilder) ArrayList(java.util.ArrayList) BOOLEAN_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.BOOLEAN_CUSTOM_FIELD_NAME) CategorySync(com.commercetools.sync.categories.CategorySync) Nonnull(javax.annotation.Nonnull) CategoryITUtils.deleteAllCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Mockito.when(org.mockito.Mockito.when) CategorySyncOptionsBuilder(com.commercetools.sync.categories.CategorySyncOptionsBuilder) ITUtils.createCustomFieldsJsonMap(com.commercetools.sync.integration.commons.utils.ITUtils.createCustomFieldsJsonMap) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) AfterEach(org.junit.jupiter.api.AfterEach) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) LOCALISED_STRING_CUSTOM_FIELD_NAME(com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME) Collections(java.util.Collections) SphereClient(io.sphere.sdk.client.SphereClient) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) ArrayList(java.util.ArrayList) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) LocalizedString(io.sphere.sdk.models.LocalizedString) CategorySync(com.commercetools.sync.categories.CategorySync) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 5 with CategorySyncOptions

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

the class CategoryServiceImplIT method setupTest.

/**
 * Deletes Categories and Types from target CTP projects, then it populates target CTP project
 * with category test data.
 */
@BeforeEach
void setupTest() {
    errorCallBackMessages = new ArrayList<>();
    errorCallBackExceptions = new ArrayList<>();
    warningCallBackMessages = new ArrayList<>();
    deleteAllCategories(CTP_TARGET_CLIENT);
    final CategorySyncOptions categorySyncOptions = CategorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).warningCallback((exception, oldResource, newResource) -> warningCallBackMessages.add(exception.getMessage())).build();
    // Create a mock new category in the target project.
    final CategoryDraft oldCategoryDraft = CategoryDraftBuilder.of(LocalizedString.of(Locale.ENGLISH, "furniture"), LocalizedString.of(Locale.ENGLISH, "furniture")).key(oldCategoryKey).custom(getCustomFieldsDraft()).build();
    oldCategory = CTP_TARGET_CLIENT.execute(CategoryCreateCommand.of(oldCategoryDraft)).toCompletableFuture().join();
    categoryService = new CategoryServiceImpl(categorySyncOptions);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) StringUtils(org.apache.commons.lang3.StringUtils) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) ChangeName(io.sphere.sdk.categories.commands.updateactions.ChangeName) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) CategoryDraftBuilder(io.sphere.sdk.categories.CategoryDraftBuilder) ArrayList(java.util.ArrayList) CategoryQuery(io.sphere.sdk.categories.queries.CategoryQuery) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Locale(java.util.Locale) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) OLD_CATEGORY_CUSTOM_TYPE_KEY(com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) CategoryITUtils.deleteAllCategories(com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Category(io.sphere.sdk.categories.Category) CategoryCreateCommand(io.sphere.sdk.categories.commands.CategoryCreateCommand) Set(java.util.Set) CategoryITUtils.createCategoriesCustomType(com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType) Mockito.times(org.mockito.Mockito.times) CategoryService(com.commercetools.sync.services.CategoryService) CompletionException(java.util.concurrent.CompletionException) Mockito.when(org.mockito.Mockito.when) CategorySyncOptionsBuilder(com.commercetools.sync.categories.CategorySyncOptionsBuilder) ChangeSlug(io.sphere.sdk.categories.commands.updateactions.ChangeSlug) Mockito.verify(org.mockito.Mockito.verify) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) CategoryITUtils.getCustomFieldsDraft(com.commercetools.sync.integration.commons.utils.CategoryITUtils.getCustomFieldsDraft) Optional(java.util.Optional) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) CategoryServiceImpl(com.commercetools.sync.services.impl.CategoryServiceImpl) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) CategoryServiceImpl(com.commercetools.sync.services.impl.CategoryServiceImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CategorySyncOptions (com.commercetools.sync.categories.CategorySyncOptions)21 SphereClient (io.sphere.sdk.client.SphereClient)19 Test (org.junit.jupiter.api.Test)18 Category (io.sphere.sdk.categories.Category)17 CategoryDraft (io.sphere.sdk.categories.CategoryDraft)17 CategorySyncOptionsBuilder (com.commercetools.sync.categories.CategorySyncOptionsBuilder)16 ArrayList (java.util.ArrayList)16 Optional (java.util.Optional)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 Mockito.when (org.mockito.Mockito.when)15 LocalizedString (io.sphere.sdk.models.LocalizedString)14 Locale (java.util.Locale)14 List (java.util.List)13 CategoryDraftBuilder (io.sphere.sdk.categories.CategoryDraftBuilder)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 CategoryQuery (io.sphere.sdk.categories.queries.CategoryQuery)10 UpdateAction (io.sphere.sdk.commands.UpdateAction)9 OLD_CATEGORY_CUSTOM_TYPE_KEY (com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY)8 CategoryITUtils.createCategoriesCustomType (com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategoriesCustomType)8 CategoryITUtils.deleteAllCategories (com.commercetools.sync.integration.commons.utils.CategoryITUtils.deleteAllCategories)8