Search in sources :

Example 11 with CartDiscountSyncOptions

use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.

the class CartDiscountServiceImplTest method fetchCartDiscount_WithEmptyKey_ShouldNotFetchAnyCartDiscount.

@Test
void fetchCartDiscount_WithEmptyKey_ShouldNotFetchAnyCartDiscount() {
    // preparation
    final SphereClient sphereClient = mock(SphereClient.class);
    final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(sphereClient).build();
    final CartDiscountService cartDiscountService = new CartDiscountServiceImpl(cartDiscountSyncOptions);
    // test
    final CompletionStage<Optional<CartDiscount>> result = cartDiscountService.fetchCartDiscount("");
    // assertions
    assertThat(result).isCompletedWithValue(Optional.empty());
    verify(sphereClient, never()).execute(any());
}
Also used : Optional(java.util.Optional) CartDiscountService(com.commercetools.sync.services.CartDiscountService) SphereClient(io.sphere.sdk.client.SphereClient) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) Test(org.junit.jupiter.api.Test)

Example 12 with CartDiscountSyncOptions

use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.

the class CartDiscountSyncUtilsTest method buildActions_FromDraftsWithDifferentNameValues_ShouldBuildUpdateActions.

@Test
void buildActions_FromDraftsWithDifferentNameValues_ShouldBuildUpdateActions() {
    final LocalizedString newName = LocalizedString.of(Locale.GERMAN, "Neu Name", Locale.ENGLISH, "new name");
    final CartDiscountDraft newCartDiscount = CartDiscountDraftBuilder.of(cartDiscountDraft).name(newName).build();
    final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_CLIENT).build();
    final List<UpdateAction<CartDiscount>> updateActions = buildActions(cartDiscount, newCartDiscount, cartDiscountSyncOptions);
    assertThat(updateActions).isNotEmpty();
    assertThat(updateActions).containsExactly(ChangeName.of(newName));
}
Also used : CartDiscountDraft(io.sphere.sdk.cartdiscounts.CartDiscountDraft) UpdateAction(io.sphere.sdk.commands.UpdateAction) LocalizedString(io.sphere.sdk.models.LocalizedString) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) Test(org.junit.jupiter.api.Test)

Example 13 with CartDiscountSyncOptions

use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.

the class CartDiscountSyncUtilsTest method buildActions_WithSameValues_ShouldNotBuildUpdateActions.

@Test
void buildActions_WithSameValues_ShouldNotBuildUpdateActions() {
    final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_CLIENT).build();
    final List<UpdateAction<CartDiscount>> updateActions = buildActions(cartDiscount, cartDiscountDraft, cartDiscountSyncOptions);
    assertThat(updateActions).isEmpty();
}
Also used : UpdateAction(io.sphere.sdk.commands.UpdateAction) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) Test(org.junit.jupiter.api.Test)

Example 14 with CartDiscountSyncOptions

use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.

the class CartDiscountSyncUtilsTest method buildActions_FromDraftsWithAllDifferentValues_ShouldBuildAllUpdateActions.

@Test
void buildActions_FromDraftsWithAllDifferentValues_ShouldBuildAllUpdateActions() {
    final LocalizedString newName = LocalizedString.of(Locale.GERMAN, "Neu Name", Locale.ENGLISH, "new name");
    final CartPredicate newCartDiscountPredicate = CartPredicate.of("1 = 1");
    final CartDiscountValue newCartDiscountValue = CartDiscountValue.ofAbsolute(MoneyImpl.of(10, EUR));
    final CartDiscountTarget newCartDiscountTarget = LineItemsTarget.of("quantity > 1");
    final String newSortOrder = "0.3";
    final LocalizedString newDesc = LocalizedString.of(Locale.GERMAN, "Neu Beschreibung", Locale.ENGLISH, "new description");
    final ZonedDateTime newValidFrom = ZonedDateTime.parse("2019-11-01T00:00:00.000Z");
    final ZonedDateTime newValidUntil = ZonedDateTime.parse("2019-11-15T00:00:00.000Z");
    final boolean newIsActive = true;
    final boolean newRequireDiscountCode = true;
    final StackingMode newStackingMode = StackingMode.STOP_AFTER_THIS_DISCOUNT;
    final CustomFieldsDraft newCustomFieldsDraft = CustomFieldsDraftBuilder.ofTypeId(UUID.randomUUID().toString()).build();
    final CartDiscountDraft newCartDiscount = CartDiscountDraftBuilder.of(newName, newCartDiscountPredicate, newCartDiscountValue, newCartDiscountTarget, newSortOrder, newRequireDiscountCode).active(newIsActive).description(newDesc).validFrom(newValidFrom).validUntil(newValidUntil).stackingMode(newStackingMode).custom(newCustomFieldsDraft).build();
    final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_CLIENT).build();
    final List<UpdateAction<CartDiscount>> updateActions = buildActions(cartDiscount, newCartDiscount, cartDiscountSyncOptions);
    assertThat(updateActions).containsExactly(ChangeValue.of(newCartDiscountValue), ChangeCartPredicate.of(newCartDiscountPredicate), ChangeTarget.of(newCartDiscountTarget), ChangeIsActive.of(newIsActive), ChangeName.of(newName), SetDescription.of(newDesc), ChangeSortOrder.of(newSortOrder), ChangeRequiresDiscountCode.of(newRequireDiscountCode), SetValidFromAndUntil.of(newValidFrom, newValidUntil), ChangeStackingMode.of(newStackingMode), SetCustomType.ofTypeIdAndJson(newCustomFieldsDraft.getType().getId(), emptyMap()));
}
Also used : CartPredicate(io.sphere.sdk.cartdiscounts.CartPredicate) ChangeCartPredicate(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeCartPredicate) CartDiscountDraft(io.sphere.sdk.cartdiscounts.CartDiscountDraft) UpdateAction(io.sphere.sdk.commands.UpdateAction) StackingMode(io.sphere.sdk.cartdiscounts.StackingMode) ChangeStackingMode(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeStackingMode) CartDiscountValue(io.sphere.sdk.cartdiscounts.CartDiscountValue) LocalizedString(io.sphere.sdk.models.LocalizedString) LocalizedString(io.sphere.sdk.models.LocalizedString) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) ZonedDateTime(java.time.ZonedDateTime) CartDiscountTarget(io.sphere.sdk.cartdiscounts.CartDiscountTarget) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) Test(org.junit.jupiter.api.Test)

Example 15 with CartDiscountSyncOptions

use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.

the class CartDiscountServiceImplIT method setup.

/**
 * Deletes types & cart discounts from the target CTP project, then it populates the project with
 * test data.
 */
@BeforeEach
void setup() {
    deleteCartDiscountsFromTargetAndSource();
    populateTargetProject();
    errorCallBackMessages = new ArrayList<>();
    errorCallBackExceptions = new ArrayList<>();
    final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception);
    }).build();
    cartDiscountService = new CartDiscountServiceImpl(cartDiscountSyncOptions);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) CartDiscountServiceImpl(com.commercetools.sync.services.impl.CartDiscountServiceImpl) CART_DISCOUNT_KEY_2(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_KEY_2) CART_DISCOUNT_KEY_1(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_KEY_1) CART_DISCOUNT_NAME_2(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_NAME_2) CartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PagedResult(io.sphere.sdk.queries.PagedResult) CartDiscountSyncOptionsBuilder(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptionsBuilder) CART_DISCOUNT_VALUE_2(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_VALUE_2) Mockito.spy(org.mockito.Mockito.spy) ChangeCartPredicate(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeCartPredicate) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) Collections.singletonList(java.util.Collections.singletonList) CartDiscountQuery(io.sphere.sdk.cartdiscounts.queries.CartDiscountQuery) ArrayList(java.util.ArrayList) InstanceOfAssertFactories.throwable(org.assertj.core.api.InstanceOfAssertFactories.throwable) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) CartDiscountService(com.commercetools.sync.services.CartDiscountService) CartDiscountDraftBuilder(io.sphere.sdk.cartdiscounts.CartDiscountDraftBuilder) Assertions.as(org.assertj.core.api.Assertions.as) ChangeName(io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeName) SphereClient(io.sphere.sdk.client.SphereClient) CompletableFutureUtils.exceptionallyCompletedFuture(io.sphere.sdk.utils.CompletableFutureUtils.exceptionallyCompletedFuture) CartDiscountDraft(io.sphere.sdk.cartdiscounts.CartDiscountDraft) CartDiscountITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.populateTargetProject) SORT_ORDER_1(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.SORT_ORDER_1) SORT_ORDER_2(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.SORT_ORDER_2) CartDiscountByKeyGet(io.sphere.sdk.cartdiscounts.queries.CartDiscountByKeyGet) BadGatewayException(io.sphere.sdk.client.BadGatewayException) CART_DISCOUNT_TARGET_2(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_TARGET_2) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CART_DISCOUNT_CART_PREDICATE_2(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_CART_PREDICATE_2) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) Optional(java.util.Optional) CartDiscountITUtils.deleteCartDiscountsFromTargetAndSource(com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.deleteCartDiscountsFromTargetAndSource) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) CartDiscountServiceImpl(com.commercetools.sync.services.impl.CartDiscountServiceImpl) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CartDiscountSyncOptions (com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions)33 Test (org.junit.jupiter.api.Test)31 CartDiscount (io.sphere.sdk.cartdiscounts.CartDiscount)27 CartDiscountDraft (io.sphere.sdk.cartdiscounts.CartDiscountDraft)25 CartDiscountQuery (io.sphere.sdk.cartdiscounts.queries.CartDiscountQuery)24 SphereClient (io.sphere.sdk.client.SphereClient)24 Optional (java.util.Optional)24 CartDiscountSyncOptionsBuilder (com.commercetools.sync.cartdiscounts.CartDiscountSyncOptionsBuilder)23 UpdateAction (io.sphere.sdk.commands.UpdateAction)23 List (java.util.List)23 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)22 ChangeCartPredicate (io.sphere.sdk.cartdiscounts.commands.updateactions.ChangeCartPredicate)20 BeforeEach (org.junit.jupiter.api.BeforeEach)20 CartDiscountITUtils.populateTargetProject (com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.populateTargetProject)19 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)19 CartDiscountDraftBuilder (io.sphere.sdk.cartdiscounts.CartDiscountDraftBuilder)19 ArrayList (java.util.ArrayList)19 AfterAll (org.junit.jupiter.api.AfterAll)19 CART_DISCOUNT_CART_PREDICATE_2 (com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_CART_PREDICATE_2)17 CART_DISCOUNT_KEY_1 (com.commercetools.sync.integration.commons.utils.CartDiscountITUtils.CART_DISCOUNT_KEY_1)17