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