use of com.commercetools.sync.taxcategories.TaxCategorySync 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.TaxCategorySync 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.TaxCategorySync 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.TaxCategorySync 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.TaxCategorySync in project commercetools-project-sync by commercetools.
the class TaxCategorySyncer method of.
@Nonnull
public static TaxCategorySyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<TaxCategoryDraft>, Optional<TaxCategory>, List<UpdateAction<TaxCategory>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "tax category", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<TaxCategoryDraft>, Optional<TaxCategory>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "tax category", exception, oldResource);
final TaxCategorySyncOptions syncOptions = TaxCategorySyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final TaxCategorySync taxCategorySync = new TaxCategorySync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new TaxCategorySyncer(taxCategorySync, sourceClient, targetClient, customObjectService, clock);
}
Aggregations