Search in sources :

Example 11 with TaxCategorySyncOptions

use of com.commercetools.sync.taxcategories.TaxCategorySyncOptions in project commercetools-sync-java by commercetools.

the class TaxCategoryServiceImplIT method createTaxCategory_WithDuplicateKey_ShouldHaveEmptyOptionalAsAResult.

@Test
void createTaxCategory_WithDuplicateKey_ShouldHaveEmptyOptionalAsAResult() {
    // preparation
    final TaxCategoryDraft newTaxCategoryDraft = TaxCategoryDraftBuilder.of(TAXCATEGORY_NAME_1, singletonList(createTaxRateDraft()), TAXCATEGORY_DESCRIPTION_1).key(TAXCATEGORY_KEY).build();
    final TaxCategorySyncOptions options = TaxCategorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final TaxCategoryService taxCategoryService = new TaxCategoryServiceImpl(options);
    // test
    final Optional<TaxCategory> result = taxCategoryService.createTaxCategory(newTaxCategoryDraft).toCompletableFuture().join();
    // assertion
    assertThat(result).isEmpty();
    assertThat(errorCallBackMessages).hasSize(1).singleElement(as(STRING)).contains("A duplicate value");
    assertThat(errorCallBackExceptions).hasSize(1).singleElement().matches(exception -> {
        assertThat(exception).isExactlyInstanceOf(ErrorResponseException.class);
        final ErrorResponseException errorResponseException = (ErrorResponseException) exception;
        final List<DuplicateFieldError> fieldErrors = errorResponseException.getErrors().stream().map(sphereError -> {
            assertThat(sphereError.getCode()).isEqualTo(DuplicateFieldError.CODE);
            return sphereError.as(DuplicateFieldError.class);
        }).collect(toList());
        return fieldErrors.size() == 1;
    });
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) TaxCategoryDraft(io.sphere.sdk.taxcategories.TaxCategoryDraft) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaxCategoryITUtils.createTaxCategory(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.createTaxCategory) TaxCategoryQuery(io.sphere.sdk.taxcategories.queries.TaxCategoryQuery) TAXCATEGORY_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_DESCRIPTION_1) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) StringUtils(org.apache.commons.lang3.StringUtils) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) SetKey(io.sphere.sdk.taxcategories.commands.updateactions.SetKey) Collections.singleton(java.util.Collections.singleton) TAXCATEGORY_KEY_1(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_KEY_1) Assertions.as(org.assertj.core.api.Assertions.as) SphereClient(io.sphere.sdk.client.SphereClient) TaxCategoryService(com.commercetools.sync.services.TaxCategoryService) TaxCategoryDraftBuilder(io.sphere.sdk.taxcategories.TaxCategoryDraftBuilder) TaxCategoryITUtils.createTaxRateDraft(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.createTaxRateDraft) BadGatewayException(io.sphere.sdk.client.BadGatewayException) TaxCategorySyncOptionsBuilder(com.commercetools.sync.taxcategories.TaxCategorySyncOptionsBuilder) CompletionStageUtil.executeBlocking(com.commercetools.tests.utils.CompletionStageUtil.executeBlocking) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ChangeName(io.sphere.sdk.taxcategories.commands.updateactions.ChangeName) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) TaxCategorySyncOptions(com.commercetools.sync.taxcategories.TaxCategorySyncOptions) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) TaxCategoryServiceImpl(com.commercetools.sync.services.impl.TaxCategoryServiceImpl) Optional(java.util.Optional) TAXCATEGORY_KEY(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_KEY) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) TaxCategoryITUtils.deleteTaxCategories(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.deleteTaxCategories) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) TAXCATEGORY_NAME_1(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_NAME_1) TaxCategory(io.sphere.sdk.taxcategories.TaxCategory) TaxCategoryServiceImpl(com.commercetools.sync.services.impl.TaxCategoryServiceImpl) TaxCategoryDraft(io.sphere.sdk.taxcategories.TaxCategoryDraft) TaxCategorySyncOptions(com.commercetools.sync.taxcategories.TaxCategorySyncOptions) TaxCategoryITUtils.createTaxCategory(com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.createTaxCategory) TaxCategory(io.sphere.sdk.taxcategories.TaxCategory) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) TaxCategoryService(com.commercetools.sync.services.TaxCategoryService) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) Test(org.junit.jupiter.api.Test)

Example 12 with TaxCategorySyncOptions

use of com.commercetools.sync.taxcategories.TaxCategorySyncOptions in project commercetools-sync-java by commercetools.

the class TaxCategorySyncIT method sync_withNewTaxCategory_shouldCreateTaxCategory.

@Test
void sync_withNewTaxCategory_shouldCreateTaxCategory() {
    final SubRate subRate1 = SubRate.of("subRate-1", 0.05);
    final SubRate subRate2 = SubRate.of("subRate-2", 0.06);
    final TaxRateDraft taxRateDraft = TaxRateDraftBuilder.of("%11 US", 0.11, false, CountryCode.US).subRates(asList(subRate1, subRate2)).build();
    final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraftBuilder.of("tax-category-name-new", singletonList(taxRateDraft), "tax-category-description-new").key("tax-category-key-new").build();
    final TaxCategorySyncOptions taxCategorySyncOptions = TaxCategorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final TaxCategorySync taxCategorySync = new TaxCategorySync(taxCategorySyncOptions);
    // test
    final TaxCategorySyncStatistics taxCategorySyncStatistics = taxCategorySync.sync(singletonList(taxCategoryDraft)).toCompletableFuture().join();
    assertThat(taxCategorySyncStatistics).hasValues(1, 1, 0, 0);
}
Also used : TaxCategoryDraft(io.sphere.sdk.taxcategories.TaxCategoryDraft) TaxCategorySync(com.commercetools.sync.taxcategories.TaxCategorySync) TaxCategorySyncOptions(com.commercetools.sync.taxcategories.TaxCategorySyncOptions) TaxCategorySyncStatistics(com.commercetools.sync.taxcategories.helpers.TaxCategorySyncStatistics) SubRate(io.sphere.sdk.taxcategories.SubRate) TaxRateDraft(io.sphere.sdk.taxcategories.TaxRateDraft) Test(org.junit.jupiter.api.Test)

Example 13 with TaxCategorySyncOptions

use of com.commercetools.sync.taxcategories.TaxCategorySyncOptions in project commercetools-sync-java by commercetools.

the class TaxCategorySyncIT method sync_withEqualTaxCategory_shouldNotUpdateTaxCategory.

@Test
void sync_withEqualTaxCategory_shouldNotUpdateTaxCategory() {
    final SubRate subRate1 = SubRate.of("subRate-1", 0.08);
    final SubRate subRate2 = SubRate.of("subRate-2", 0.11);
    final TaxRateDraft taxRateDraft = TaxRateDraftBuilder.of("%19 VAT DE", 0.19, false, CountryCode.DE).subRates(asList(subRate1, subRate2)).build();
    final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraftBuilder.of("tax-category-name", singletonList(taxRateDraft), "tax-category-description").key("tax-category-key").build();
    final TaxCategorySyncOptions taxCategorySyncOptions = TaxCategorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final TaxCategorySync taxCategorySync = new TaxCategorySync(taxCategorySyncOptions);
    // test
    final TaxCategorySyncStatistics taxCategorySyncStatistics = taxCategorySync.sync(singletonList(taxCategoryDraft)).toCompletableFuture().join();
    assertThat(taxCategorySyncStatistics).hasValues(1, 0, 0, 0);
}
Also used : TaxCategoryDraft(io.sphere.sdk.taxcategories.TaxCategoryDraft) TaxCategorySync(com.commercetools.sync.taxcategories.TaxCategorySync) TaxCategorySyncOptions(com.commercetools.sync.taxcategories.TaxCategorySyncOptions) TaxCategorySyncStatistics(com.commercetools.sync.taxcategories.helpers.TaxCategorySyncStatistics) SubRate(io.sphere.sdk.taxcategories.SubRate) TaxRateDraft(io.sphere.sdk.taxcategories.TaxRateDraft) Test(org.junit.jupiter.api.Test)

Aggregations

TaxCategorySyncOptions (com.commercetools.sync.taxcategories.TaxCategorySyncOptions)13 TaxCategoryDraft (io.sphere.sdk.taxcategories.TaxCategoryDraft)13 Test (org.junit.jupiter.api.Test)12 TaxCategory (io.sphere.sdk.taxcategories.TaxCategory)11 TaxCategorySyncOptionsBuilder (com.commercetools.sync.taxcategories.TaxCategorySyncOptionsBuilder)10 SphereClient (io.sphere.sdk.client.SphereClient)10 TaxCategoryDraftBuilder (io.sphere.sdk.taxcategories.TaxCategoryDraftBuilder)10 TaxCategoryQuery (io.sphere.sdk.taxcategories.queries.TaxCategoryQuery)10 List (java.util.List)10 Optional (java.util.Optional)10 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)8 TaxCategoryITUtils.deleteTaxCategories (com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.deleteTaxCategories)8 CompletionStageUtil.executeBlocking (com.commercetools.tests.utils.CompletionStageUtil.executeBlocking)8 BadGatewayException (io.sphere.sdk.client.BadGatewayException)8 CompletableFutureUtils (io.sphere.sdk.utils.CompletableFutureUtils)8 ArrayList (java.util.ArrayList)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)8 Mockito.when (org.mockito.Mockito.when)8 TaxCategorySync (com.commercetools.sync.taxcategories.TaxCategorySync)7