use of com.commercetools.sync.taxcategories.TaxCategorySyncOptions in project commercetools-sync-java by commercetools.
the class TaxCategorySyncIT method sync_WithUpdatedTaxCategory_ShouldUpdateTaxCategory.
@Test
void sync_WithUpdatedTaxCategory_ShouldUpdateTaxCategory() {
// preparation
final SubRate subRate1 = SubRate.of("subRate-1", 0.07);
final SubRate subRate2 = SubRate.of("subRate-2", 0.09);
final TaxRateDraft taxRateDraft = TaxRateDraftBuilder.of("%16 VAT", 0.16, true, CountryCode.DE).subRates(asList(subRate1, subRate2)).build();
final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraftBuilder.of("tax-category-name-updated", singletonList(taxRateDraft), "tax-category-description-updated").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();
// assertion
assertThat(taxCategorySyncStatistics).hasValues(1, 0, 1, 0);
final Optional<TaxCategory> oldTaxCategoryAfter = getTaxCategoryByKey(CTP_TARGET_CLIENT, "tax-category-key");
Assertions.assertThat(oldTaxCategoryAfter).hasValueSatisfying(taxCategory -> {
Assertions.assertThat(taxCategory.getName()).isEqualTo("tax-category-name-updated");
Assertions.assertThat(taxCategory.getDescription()).isEqualTo("tax-category-description-updated");
final TaxRate taxRate = taxCategory.getTaxRates().get(0);
Assertions.assertThat(taxRate.getName()).isEqualTo("%16 VAT");
Assertions.assertThat(taxRate.getAmount()).isEqualTo(0.16);
Assertions.assertThat(taxRate.getCountry()).isEqualTo(CountryCode.DE);
Assertions.assertThat(taxRate.isIncludedInPrice()).isEqualTo(true);
Assertions.assertThat(taxRate.getSubRates()).isEqualTo(asList(subRate1, subRate2));
});
}
use of com.commercetools.sync.taxcategories.TaxCategorySyncOptions in project commercetools-sync-java by commercetools.
the class TaxCategorySyncIT method sync_withChangedTaxCategoryButConcurrentModificationException_shouldRetryAndUpdateTaxCategory.
@Test
void sync_withChangedTaxCategoryButConcurrentModificationException_shouldRetryAndUpdateTaxCategory() {
// preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdate();
List<String> errorCallBackMessages = new ArrayList<>();
List<String> warningCallBackMessages = new ArrayList<>();
List<Throwable> errorCallBackExceptions = new ArrayList<>();
final TaxCategorySyncOptions spyOptions = TaxCategorySyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final TaxCategorySync taxCategorySync = new TaxCategorySync(spyOptions);
final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraftBuilder.of("tax-category-name-updated", null, "tax-category-description-updated").key("tax-category-key").build();
// test
final TaxCategorySyncStatistics taxCategorySyncStatistics = taxCategorySync.sync(singletonList(taxCategoryDraft)).toCompletableFuture().join();
assertThat(taxCategorySyncStatistics).hasValues(1, 0, 1, 0);
Assertions.assertThat(errorCallBackExceptions).isEmpty();
Assertions.assertThat(errorCallBackMessages).isEmpty();
Assertions.assertThat(warningCallBackMessages).isEmpty();
}
use of com.commercetools.sync.taxcategories.TaxCategorySyncOptions in project commercetools-sync-java by commercetools.
the class TaxCategorySyncIT method sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate.
@Test
void sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate() {
// preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndFailedFetchOnRetry();
List<String> errorCallBackMessages = new ArrayList<>();
List<Throwable> errorCallBackExceptions = new ArrayList<>();
final TaxCategorySyncOptions spyOptions = TaxCategorySyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final TaxCategorySync taxCategorySync = new TaxCategorySync(spyOptions);
final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraftBuilder.of("tax-category-name-updated", null, "tax-category-description-updated").key("tax-category-key").build();
// test
final TaxCategorySyncStatistics taxCategorySyncStatistics = taxCategorySync.sync(singletonList(taxCategoryDraft)).toCompletableFuture().join();
// Test and assertion
assertThat(taxCategorySyncStatistics).hasValues(1, 0, 0, 1);
Assertions.assertThat(errorCallBackMessages).hasSize(1);
Assertions.assertThat(errorCallBackExceptions).hasSize(1);
Assertions.assertThat(errorCallBackExceptions.get(0).getCause()).isExactlyInstanceOf(BadGatewayException.class);
Assertions.assertThat(errorCallBackMessages.get(0)).contains(format("Failed to update tax category with key: '%s'. Reason: Failed to fetch from CTP while retrying " + "after concurrency modification.", taxCategoryDraft.getKey()));
}
use of com.commercetools.sync.taxcategories.TaxCategorySyncOptions in project commercetools-sync-java by commercetools.
the class TaxCategorySyncIT method sync_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate.
@Test
void sync_WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate() {
// preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndNotFoundFetchOnRetry();
List<String> errorCallBackMessages = new ArrayList<>();
List<Throwable> errorCallBackExceptions = new ArrayList<>();
final TaxCategorySyncOptions spyOptions = TaxCategorySyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final TaxCategorySync taxCategorySync = new TaxCategorySync(spyOptions);
final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraftBuilder.of("tax-category-name-updated", null, "tax-category-description-updated").key("tax-category-key").build();
final TaxCategorySyncStatistics taxCategorySyncStatistics = taxCategorySync.sync(singletonList(taxCategoryDraft)).toCompletableFuture().join();
// Test and assertion
assertThat(taxCategorySyncStatistics).hasValues(1, 0, 0, 1);
Assertions.assertThat(errorCallBackMessages).hasSize(1);
Assertions.assertThat(errorCallBackExceptions).hasSize(1);
Assertions.assertThat(errorCallBackMessages.get(0)).contains(format("Failed to update tax category with key: '%s'. Reason: Not found when attempting to fetch while" + " retrying after concurrency modification.", taxCategoryDraft.getKey()));
}
use of com.commercetools.sync.taxcategories.TaxCategorySyncOptions in project commercetools-sync-java by commercetools.
the class TaxCategoryServiceImplIT method fetchMatchingTaxCategoriesByKeys_WithBadGateWayExceptionAlways_ShouldFail.
@Test
void fetchMatchingTaxCategoriesByKeys_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
when(spyClient.execute(any(TaxCategoryQuery.class))).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new BadGatewayException())).thenCallRealMethod();
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);
final Set<String> keys = new HashSet<>();
keys.add(TAXCATEGORY_KEY);
// test and assert
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(spyTaxCategoryService.fetchMatchingTaxCategoriesByKeys(keys)).failsWithin(10, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(BadGatewayException.class);
}
Aggregations