public final class OutOfStockError extends SphereError
withTaxedProduct(client(), product -> { final int itemsLeft = 3; final String sku = getSku(product); client().executeBlocking(InventoryEntryCreateCommand.of(InventoryEntryDraft.of(sku, itemsLeft))); final int itemCountToOrder = 5; final CartDraftDsl draft = CartDraft.of(DefaultCurrencyUnits.EUR) .withCountry(CountryCode.DE) .withInventoryMode(InventoryMode.RESERVE_ON_ORDER) .withShippingAddress(Address.of(CountryCode.DE)) .withLineItems(Collections.singletonList(LineItemDraft.of(product, 1, itemCountToOrder))); final Cart cart = client().executeBlocking(CartCreateCommand.of(draft)); final Throwable throwable = catchThrowable(() -> client().executeBlocking(OrderFromCartCreateCommand.of(cart))); assertThat(throwable).isInstanceOf(ErrorResponseException.class); final ErrorResponseException e = (ErrorResponseException) throwable; assertThat(e.hasErrorCode(OutOfStockError.CODE)); final OutOfStockError outOfStockError = e.getErrors().stream() .filter(err -> err.getCode().equals(OutOfStockError.CODE)) .findFirst().get().as(OutOfStockError.class); assertThat(outOfStockError.getSkus()).containsExactly(sku); assertThat(outOfStockError.getLineItems()).containsExactly(cart.getLineItems().get(0).getId()); });
See the test code.
Modifier and Type | Method and Description |
---|---|
List<String> |
getLineItems() |
List<String> |
getSkus() |
static OutOfStockError |
of(String message,
List<String> lineItems,
List<String> skus) |
as, getCode, getMessage, of