use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_TARGET_2 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithSeveralBatches_ShouldReturnProperStatistics.
@Test
void sync_WithSeveralBatches_ShouldReturnProperStatistics() {
// preparation
final List<String> sortOrders = getSortOrders(100);
// Default batch size is 50 (check CartDiscountSyncOptionsBuilder) so we have 2 batches of 50
final List<CartDiscountDraft> cartDiscountDrafts = IntStream.range(0, 100).mapToObj(i -> CartDiscountDraftBuilder.of(CART_DISCOUNT_NAME_2, CART_DISCOUNT_CART_PREDICATE_2, CART_DISCOUNT_VALUE_2, CART_DISCOUNT_TARGET_2, sortOrders.get(i), false).key(format("key__%s", Integer.toString(i))).active(false).build()).collect(Collectors.toList());
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
// test
final CartDiscountSyncStatistics cartDiscountSyncStatistics = cartDiscountSync.sync(cartDiscountDrafts).toCompletableFuture().join();
// assertion
assertThat(cartDiscountSyncStatistics).hasValues(100, 100, 0, 0);
}
use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_TARGET_2 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithUpdatedCartDiscount_WithNewTarget_ShouldUpdateCartDiscountWithNewTarget.
@Test
void sync_WithUpdatedCartDiscount_WithNewTarget_ShouldUpdateCartDiscountWithNewTarget() {
// preparation
final CartDiscountDraft newCartDiscountDraftWithExistingKey = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_1).target(CART_DISCOUNT_TARGET_2).build();
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final List<UpdateAction<CartDiscount>> updateActionsList = new ArrayList<>();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception);
}).beforeUpdateCallback((updateActions, newCartDiscount, oldCartDiscount) -> {
updateActionsList.addAll(updateActions);
return updateActions;
}).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(cartDiscountSyncOptions);
// test
final CartDiscountSyncStatistics cartDiscountSyncStatistics = cartDiscountSync.sync(singletonList(newCartDiscountDraftWithExistingKey)).toCompletableFuture().join();
// assertions
assertThat(errorMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(updateActionsList).containsExactly(ChangeTarget.of(CART_DISCOUNT_TARGET_2));
assertThat(cartDiscountSyncStatistics.getReportMessage()).isEqualTo("Summary: 1 cart discounts were processed in total" + " (0 created, 1 updated and 0 failed to sync).");
assertThat(cartDiscountSyncStatistics).hasValues(1, 0, 1, 0);
}
use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_TARGET_2 in project commercetools-sync-java by commercetools.
the class CartDiscountServiceImplIT method createCartDiscount_WithValidCartDiscount_ShouldCreateCartDiscount.
@Test
void createCartDiscount_WithValidCartDiscount_ShouldCreateCartDiscount() {
// preparation
final CartDiscountDraft newCartDiscountDraft = CartDiscountDraftBuilder.of(CART_DISCOUNT_NAME_2, CART_DISCOUNT_CART_PREDICATE_2, CART_DISCOUNT_VALUE_2, CART_DISCOUNT_TARGET_2, SORT_ORDER_2, false).key(CART_DISCOUNT_KEY_2).active(false).build();
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
final CartDiscountSyncOptions spyOptions = CartDiscountSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, actions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception);
}).build();
final CartDiscountService spyCartDiscountService = new CartDiscountServiceImpl(spyOptions);
// test
final Optional<CartDiscount> createdCartDiscount = spyCartDiscountService.createCartDiscount(newCartDiscountDraft).toCompletableFuture().join();
final Optional<CartDiscount> queriedOptional = CTP_TARGET_CLIENT.execute(CartDiscountQuery.of().withPredicates(cartDiscountQueryModel -> cartDiscountQueryModel.key().is(CART_DISCOUNT_KEY_2))).toCompletableFuture().join().head();
assertThat(queriedOptional).hasValueSatisfying(queried -> assertThat(createdCartDiscount).hasValueSatisfying(created -> {
assertThat(created.getKey()).isEqualTo(queried.getKey());
assertThat(created.getName()).isEqualTo(queried.getName());
assertThat(created.getCartPredicate()).isEqualTo(queried.getCartPredicate());
assertThat(created.getValue()).isEqualTo(queried.getValue());
assertThat(created.getTarget()).isEqualTo(queried.getTarget());
assertThat(created.getSortOrder()).isEqualTo(queried.getSortOrder());
}));
}
use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_TARGET_2 in project commercetools-sync-java by commercetools.
the class CartDiscountServiceImplIT method createCartDiscount_WithDuplicateSortOrder_ShouldHaveEmptyOptionalAsAResult.
@Test
void createCartDiscount_WithDuplicateSortOrder_ShouldHaveEmptyOptionalAsAResult() {
// preparation
final CartDiscountDraft newCartDiscountDraft = CartDiscountDraftBuilder.of(CART_DISCOUNT_NAME_2, CART_DISCOUNT_CART_PREDICATE_2, CART_DISCOUNT_VALUE_2, CART_DISCOUNT_TARGET_2, SORT_ORDER_1, false).key(CART_DISCOUNT_KEY_2).active(false).build();
final CartDiscountSyncOptions options = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception);
}).build();
cartDiscountService = new CartDiscountServiceImpl(options);
// test
final Optional<CartDiscount> result = cartDiscountService.createCartDiscount(newCartDiscountDraft).toCompletableFuture().join();
// assertion
assertThat(result).isEmpty();
assertThat(errorCallBackMessages).hasSize(1).singleElement(as(STRING)).contains(format("A duplicate value '\"%s\"' exists for field 'sortOrder'.", SORT_ORDER_1));
ensureErrorCallbackIsDuplicateFieldError();
}
use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_TARGET_2 in project commercetools-sync-java by commercetools.
the class CartDiscountServiceImplIT method createCartDiscount_WithDuplicateCartDiscountKey_ShouldHaveEmptyOptionalAsAResult.
@Test
void createCartDiscount_WithDuplicateCartDiscountKey_ShouldHaveEmptyOptionalAsAResult() {
// preparation
final CartDiscountDraft newCartDiscountDraft = CartDiscountDraftBuilder.of(CART_DISCOUNT_NAME_2, CART_DISCOUNT_CART_PREDICATE_2, CART_DISCOUNT_VALUE_2, CART_DISCOUNT_TARGET_2, SORT_ORDER_2, false).key(CART_DISCOUNT_KEY_1).active(false).build();
final CartDiscountSyncOptions options = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception);
}).build();
cartDiscountService = new CartDiscountServiceImpl(options);
// test
final Optional<CartDiscount> result = cartDiscountService.createCartDiscount(newCartDiscountDraft).toCompletableFuture().join();
// assertion
assertThat(result).isEmpty();
assertThat(errorCallBackMessages).hasSize(1).singleElement(as(STRING)).contains(format("A duplicate value '\"%s\"' exists for field 'key'.", CART_DISCOUNT_KEY_1));
ensureErrorCallbackIsDuplicateFieldError();
}
Aggregations