use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.JANUARY_UNTIL in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithoutCartPredicate_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.
@Test
void sync_WithoutCartPredicate_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
// prepare
// Draft without "cartPredicate" throws a commercetools exception because "cartPredicate" is a
// required value
final CartDiscountDraft newCartDiscountDraftWithoutName = CartDiscountDraftBuilder.of(CART_DISCOUNT_NAME_1, (String) null, CART_DISCOUNT_VALUE_1, CART_DISCOUNT_TARGET_1, SORT_ORDER_1, false).key(CART_DISCOUNT_KEY_1).active(false).description(CART_DISCOUNT_DESC_1).validFrom(JANUARY_FROM).validUntil(JANUARY_UNTIL).build();
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception);
}).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
// test
final CartDiscountSyncStatistics cartDiscountSyncStatistics = cartDiscountSync.sync(singletonList(newCartDiscountDraftWithoutName)).toCompletableFuture().join();
// assertions
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to update cart discount with key: 'key_1'.");
assertThat(exceptions).hasSize(1).singleElement().matches(throwable -> {
assertThat(throwable).isExactlyInstanceOf(SyncException.class);
assertThat(throwable).hasCauseExactlyInstanceOf(CompletionException.class);
assertThat(throwable.getCause()).hasCauseExactlyInstanceOf(ErrorResponseException.class);
assertThat(throwable.getCause()).hasMessageContaining("cartPredicate: Missing required value");
return true;
});
assertThat(cartDiscountSyncStatistics).hasValues(1, 0, 0, 1);
}
use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.JANUARY_UNTIL in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithoutValue_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.
@Test
void sync_WithoutValue_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
// prepare
// Draft without "value" throws a commercetools exception because "value" is a required value
final CartDiscountDraft newCartDiscountDraftWithoutValue = CartDiscountDraftBuilder.of(CART_DISCOUNT_NAME_1, CART_DISCOUNT_CART_PREDICATE_1, null, CART_DISCOUNT_TARGET_1, SORT_ORDER_1, false).key(CART_DISCOUNT_KEY_1).active(false).description(CART_DISCOUNT_DESC_1).validFrom(JANUARY_FROM).validUntil(JANUARY_UNTIL).build();
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception);
}).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
// test
final CartDiscountSyncStatistics cartDiscountSyncStatistics = cartDiscountSync.sync(singletonList(newCartDiscountDraftWithoutValue)).toCompletableFuture().join();
// assertions
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to update cart discount with key: 'key_1'.");
assertThat(exceptions).hasSize(1).singleElement().matches(throwable -> {
assertThat(throwable).isExactlyInstanceOf(SyncException.class);
assertThat(throwable).hasCauseExactlyInstanceOf(CompletionException.class);
assertThat(throwable.getCause()).hasCauseExactlyInstanceOf(ErrorResponseException.class);
assertThat(throwable.getCause()).hasMessageContaining("value: Missing required value");
return true;
});
assertThat(cartDiscountSyncStatistics).hasValues(1, 0, 0, 1);
}
Aggregations