public final class AddDelivery extends UpdateActionImpl<Order>
See also OrderUpdateCommand.
withOrder(client(), order -> { assertThat(order.getShippingInfo().getDeliveries()).isEmpty(); final String lineItemId = order.getLineItems().get(0).getId(); final List<ParcelDraft> parcels = asList(ParcelDraftBuilder.of().measurements(SMALL_PARCEL_MEASUREMENTS).trackingData(TRACKING_DATA).plusItems(DeliveryItem.of(lineItemId,1)).build()); final LineItem lineItem = order.getLineItems().get(0); final long availableItemsToShip = 1; final List<DeliveryItem> items = asList(DeliveryItem.of(lineItem, availableItemsToShip)); final Address deliveryAddress = Address.of(CountryCode.DE); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, AddDelivery.of(items, parcels).withAddress(deliveryAddress))); final Delivery delivery = updatedOrder.getShippingInfo().getDeliveries().get(0); assertThat(delivery.getItems()).isEqualTo(items); assertThat(delivery.getAddress()).isEqualTo(deliveryAddress); final Parcel parcel = delivery.getParcels().get(0); assertThat(parcel.getMeasurements()).isEqualTo(SMALL_PARCEL_MEASUREMENTS); assertThat(parcel.getTrackingData()).isEqualTo(TRACKING_DATA); //you can observe a message final Query<DeliveryAddedMessage> messageQuery = MessageQuery.of() .withPredicates(m -> m.resource().is(order)) .forMessageType(DeliveryAddedMessage.MESSAGE_HINT); assertEventually(() -> { final Optional<DeliveryAddedMessage> deliveryAddedMessageOptional = client().executeBlocking(messageQuery).head(); assertThat(deliveryAddedMessageOptional).isPresent(); final DeliveryAddedMessage deliveryAddedMessage = deliveryAddedMessageOptional.get(); final Delivery deliveryFromMessage = deliveryAddedMessage.getDelivery(); assertThat(deliveryFromMessage.getId()).isEqualTo(delivery.getId()); assertThat(deliveryFromMessage.getCreatedAt()).isEqualTo(delivery.getCreatedAt()); assertThat(deliveryFromMessage.getParcels()) .as("warning initial parcels are not contained in the message!") .isNotEqualTo(delivery.getParcels()) .isEmpty(); assertThat(deliveryFromMessage.getItems()).isEqualTo(delivery.getItems()); }); return updatedOrder; });
See the test code.
Modifier and Type | Method and Description |
---|---|
Address |
getAddress() |
CustomFields |
getCustom() |
List<DeliveryItem> |
getItems() |
List<ParcelDraft> |
getParcels() |
static AddDelivery |
of(List<DeliveryItem> items) |
static AddDelivery |
of(List<DeliveryItem> items,
List<ParcelDraft> parcels) |
AddDelivery |
withAddress(Address address) |
getAction
public static AddDelivery of(List<DeliveryItem> items, List<ParcelDraft> parcels)
public static AddDelivery of(List<DeliveryItem> items)
public AddDelivery withAddress(@Nullable Address address)
public List<DeliveryItem> getItems()
public List<ParcelDraft> getParcels()
@Nullable public CustomFields getCustom()