Search in sources :

Example 1 with TAXCATEGORY_NAME_1

use of com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_NAME_1 in project commercetools-sync-java by commercetools.

the class TaxCategoryServiceImplIT method createTaxCategory_WithValidTaxCategory_ShouldCreateTaxCategoryAndCacheId.

@Test
void createTaxCategory_WithValidTaxCategory_ShouldCreateTaxCategoryAndCacheId() {
    final TaxCategoryDraft newTaxCategoryDraft = TaxCategoryDraftBuilder.of(TAXCATEGORY_NAME_1, singletonList(createTaxRateDraft()), TAXCATEGORY_DESCRIPTION_1).key(TAXCATEGORY_KEY_1).build();
    final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
    final TaxCategorySyncOptions spyOptions = TaxCategorySyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final TaxCategoryService spyTaxCategoryService = new TaxCategoryServiceImpl(spyOptions);
    // test
    final Optional<TaxCategory> createdTaxCategory = spyTaxCategoryService.createTaxCategory(newTaxCategoryDraft).toCompletableFuture().join();
    final Optional<TaxCategory> queriedOptional = CTP_TARGET_CLIENT.execute(TaxCategoryQuery.of().withPredicates(taxCategoryQueryModel -> taxCategoryQueryModel.key().is(TAXCATEGORY_KEY_1))).toCompletableFuture().join().head();
    assertThat(queriedOptional).hasValueSatisfying(queried -> assertThat(createdTaxCategory).hasValueSatisfying(created -> {
        assertThat(created.getKey()).isEqualTo(queried.getKey());
        assertThat(created.getDescription()).isEqualTo(queried.getDescription());
        assertThat(created.getName()).isEqualTo(queried.getName());
    }));
    // Assert that the created taxCategory is cached
    final Optional<String> taxCategoryId = spyTaxCategoryService.fetchCachedTaxCategoryId(TAXCATEGORY_KEY_1).toCompletableFuture().join();
    assertThat(taxCategoryId).isPresent();
    verify(spyClient, times(0)).execute(any(TaxCategoryQuery.class));
}
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) SphereClient(io.sphere.sdk.client.SphereClient) TaxCategoryService(com.commercetools.sync.services.TaxCategoryService) TaxCategoryQuery(io.sphere.sdk.taxcategories.queries.TaxCategoryQuery) Test(org.junit.jupiter.api.Test)

Example 2 with TAXCATEGORY_NAME_1

use of com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_NAME_1 in project commercetools-sync-java by commercetools.

the class TaxCategoryServiceImplIT method createTaxCategory_WithInvalidTaxCategory_ShouldHaveEmptyOptionalAsAResult.

@Test
void createTaxCategory_WithInvalidTaxCategory_ShouldHaveEmptyOptionalAsAResult() {
    // preparation
    final TaxCategoryDraft newTaxCategoryDraft = TaxCategoryDraftBuilder.of(TAXCATEGORY_NAME_1, singletonList(createTaxRateDraft()), TAXCATEGORY_DESCRIPTION_1).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).containsExactly("Failed to create draft with key: ''. Reason: Draft key is blank!");
}
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) TaxCategoryService(com.commercetools.sync.services.TaxCategoryService) Test(org.junit.jupiter.api.Test)

Example 3 with TAXCATEGORY_NAME_1

use of com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_NAME_1 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)

Aggregations

CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)3 TAXCATEGORY_DESCRIPTION_1 (com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_DESCRIPTION_1)3 TAXCATEGORY_KEY (com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_KEY)3 TAXCATEGORY_KEY_1 (com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_KEY_1)3 TAXCATEGORY_NAME_1 (com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_NAME_1)3 TaxCategoryITUtils.createTaxCategory (com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.createTaxCategory)3 TaxCategoryITUtils.createTaxRateDraft (com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.createTaxRateDraft)3 TaxCategoryITUtils.deleteTaxCategories (com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.deleteTaxCategories)3 TaxCategoryService (com.commercetools.sync.services.TaxCategoryService)3 TaxCategoryServiceImpl (com.commercetools.sync.services.impl.TaxCategoryServiceImpl)3 TaxCategorySyncOptions (com.commercetools.sync.taxcategories.TaxCategorySyncOptions)3 TaxCategorySyncOptionsBuilder (com.commercetools.sync.taxcategories.TaxCategorySyncOptionsBuilder)3 CompletionStageUtil.executeBlocking (com.commercetools.tests.utils.CompletionStageUtil.executeBlocking)3 BadGatewayException (io.sphere.sdk.client.BadGatewayException)3 ErrorResponseException (io.sphere.sdk.client.ErrorResponseException)3 SphereClient (io.sphere.sdk.client.SphereClient)3 DuplicateFieldError (io.sphere.sdk.models.errors.DuplicateFieldError)3 TaxCategory (io.sphere.sdk.taxcategories.TaxCategory)3 TaxCategoryDraft (io.sphere.sdk.taxcategories.TaxCategoryDraft)3 TaxCategoryDraftBuilder (io.sphere.sdk.taxcategories.TaxCategoryDraftBuilder)3