use of com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_DRAFT_1 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithUpdatedCartDiscount_WithNewCartPredicate_ShouldUpdateCartDiscountWithNewCartPredicate.
@Test
void sync_WithUpdatedCartDiscount_WithNewCartPredicate_ShouldUpdateCartDiscountWithNewCartPredicate() {
// preparation
final CartDiscountDraft newCartDiscountDraftWithExistingKey = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_1).cartPredicate(CART_DISCOUNT_CART_PREDICATE_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(ChangeCartPredicate.of(CART_DISCOUNT_CART_PREDICATE_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_DRAFT_1 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithUpdatedCartDiscount_WithNewCustomField_ShouldUpdateCartDiscountWithNewCustomField.
@Test
void sync_WithUpdatedCartDiscount_WithNewCustomField_ShouldUpdateCartDiscountWithNewCustomField() {
// preparation
final Map<String, JsonNode> customFieldsJsons = createCustomFieldsJsonMap();
customFieldsJsons.put(BOOLEAN_CUSTOM_FIELD_NAME, JsonNodeFactory.instance.booleanNode(true));
final CartDiscountDraft newCartDiscountDraftWithExistingKey = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_1).custom(CustomFieldsDraft.ofTypeKeyAndJson(OLD_CART_DISCOUNT_TYPE_KEY, customFieldsJsons)).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(SetCustomField.ofJson(BOOLEAN_CUSTOM_FIELD_NAME, JsonNodeFactory.instance.booleanNode(true)));
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_DRAFT_1 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_DRAFT_1 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithUpdatedCartDiscount_WithNewCustomType_ShouldUpdateCartDiscountWithNewCustomType.
@Test
void sync_WithUpdatedCartDiscount_WithNewCustomType_ShouldUpdateCartDiscountWithNewCustomType() {
// preparation
final Type newCustomType = createCartDiscountCustomType("new-type", Locale.ENGLISH, "new-type", CTP_TARGET_CLIENT);
final CartDiscountDraft newCartDiscountDraftWithExistingKey = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_1).custom(CustomFieldsDraft.ofTypeKeyAndJson(newCustomType.getKey(), emptyMap())).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(SetCustomType.ofTypeIdAndJson(newCustomType.getId(), emptyMap()));
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_DRAFT_1 in project commercetools-sync-java by commercetools.
the class CartDiscountSyncIT method sync_WithUpdatedCartDiscount_WithNonExistingResIdentifier_ShouldFailToResolveReference.
@Test
void sync_WithUpdatedCartDiscount_WithNonExistingResIdentifier_ShouldFailToResolveReference() {
// preparation
final CartDiscountDraft newCartDiscountDraftWithExistingKey = CartDiscountDraftBuilder.of(CART_DISCOUNT_DRAFT_1).custom(CustomFieldsDraft.ofTypeKeyAndJson("not-existing-key", emptyMap())).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(newCartDiscountDraftWithExistingKey)).toCompletableFuture().join();
// assertions
assertThat(cartDiscountSyncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorMessages).containsExactly("Failed to process the CartDiscountDraft with key:'key_1'. Reason: " + ReferenceResolutionException.class.getCanonicalName() + ": " + "Failed to resolve custom type reference on CartDiscountDraft with key:'key_1'. " + "Reason: Type with key 'not-existing-key' doesn't exist.");
}
Aggregations