use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.
the class CartDiscountServiceImplTest method createCartDiscount_WithNullCartDiscountKey_ShouldNotCreateCartDiscount.
@Test
void createCartDiscount_WithNullCartDiscountKey_ShouldNotCreateCartDiscount() {
// preparation
final CartDiscountDraft mockCartDiscountDraft = mock(CartDiscountDraft.class);
final Map<String, Throwable> errors = new HashMap<>();
when(mockCartDiscountDraft.getKey()).thenReturn(null);
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(mock(SphereClient.class)).errorCallback((exception, oldResource, newResource, actions) -> errors.put(exception.getMessage(), exception)).build();
final CartDiscountService cartDiscountService = new CartDiscountServiceImpl(cartDiscountSyncOptions);
// test
final CompletionStage<Optional<CartDiscount>> result = cartDiscountService.createCartDiscount(mockCartDiscountDraft);
// assertions
assertThat(result).isCompletedWithValue(Optional.empty());
assertThat(errors.keySet()).containsExactly("Failed to create draft with key: 'null'. Reason: Draft key is blank!");
verify(cartDiscountSyncOptions.getCtpClient(), times(0)).execute(any());
}
use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.
the class CartDiscountServiceImplTest method createCartDiscount_WithEmptyCartDiscountKey_ShouldHaveEmptyOptionalAsAResult.
@Test
void createCartDiscount_WithEmptyCartDiscountKey_ShouldHaveEmptyOptionalAsAResult() {
// preparation
final SphereClient sphereClient = mock(SphereClient.class);
final CartDiscountDraft mockCartDiscountDraft = mock(CartDiscountDraft.class);
final Map<String, Throwable> errors = new HashMap<>();
when(mockCartDiscountDraft.getKey()).thenReturn("");
final CartDiscountSyncOptions options = CartDiscountSyncOptionsBuilder.of(sphereClient).errorCallback((exception, oldResource, newResource, actions) -> errors.put(exception.getMessage(), exception)).build();
final CartDiscountServiceImpl cartDiscountService = new CartDiscountServiceImpl(options);
// test
final CompletionStage<Optional<CartDiscount>> result = cartDiscountService.createCartDiscount(mockCartDiscountDraft);
// assertion
assertThat(result).isCompletedWithValue(Optional.empty());
assertThat(errors.keySet()).containsExactly("Failed to create draft with key: ''. Reason: Draft key is blank!");
verify(options.getCtpClient(), times(0)).execute(any());
}
use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.
the class CartDiscountServiceImplTest method updateCartDiscount_WithMockSuccessfulCtpResponse_ShouldCallCartDiscountUpdateCommand.
@Test
void updateCartDiscount_WithMockSuccessfulCtpResponse_ShouldCallCartDiscountUpdateCommand() {
// preparation
final CartDiscount mockCartDiscount = mock(CartDiscount.class);
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(mock(SphereClient.class)).build();
when(cartDiscountSyncOptions.getCtpClient().execute(any())).thenReturn(completedFuture(mockCartDiscount));
final CartDiscountService cartDiscountService = new CartDiscountServiceImpl(cartDiscountSyncOptions);
final List<UpdateAction<CartDiscount>> updateActions = singletonList(SetDescription.of(LocalizedString.ofEnglish("new_desc")));
// test
final CompletionStage<CartDiscount> result = cartDiscountService.updateCartDiscount(mockCartDiscount, updateActions);
// assertions
assertThat(result).isCompletedWithValue(mockCartDiscount);
verify(cartDiscountSyncOptions.getCtpClient()).execute(eq(CartDiscountUpdateCommand.of(mockCartDiscount, updateActions)));
}
Aggregations