public final class AddParcelToDelivery extends UpdateActionImpl<Order>
See also OrderUpdateCommand.
withOrder(client(), order -> { final LineItem lineItem = order.getLineItems().get(0); final List<DeliveryItem> items = asList(DeliveryItem.of(lineItem)); final Order orderWithDelivery = client().executeBlocking(OrderUpdateCommand.of(order, AddDelivery.of(items))); final Delivery delivery = orderWithDelivery.getShippingInfo().getDeliveries().get(0); assertThat(delivery.getParcels()).isEmpty(); final ParcelDraft parcelDraft = ParcelDraft.of(SMALL_PARCEL_MEASUREMENTS, TRACKING_DATA); final AddParcelToDelivery action = AddParcelToDelivery.of(delivery, parcelDraft); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(orderWithDelivery, action)); final Parcel actualParcel = updatedOrder.getShippingInfo().getDeliveries().get(0).getParcels().get(0); assertThat(actualParcel.getMeasurements()).isEqualTo(SMALL_PARCEL_MEASUREMENTS); assertThat(actualParcel.getTrackingData()).isEqualTo(TRACKING_DATA); //you can observe a message final Query<ParcelAddedToDeliveryMessage> messageQuery = MessageQuery.of() .withPredicates(m -> m.resource().is(order)) .forMessageType(ParcelAddedToDeliveryMessage.MESSAGE_HINT); assertEventually(() -> { final Optional<ParcelAddedToDeliveryMessage> parcelAddedToDeliveryMessageOptional = client().executeBlocking(messageQuery).head(); assertThat(parcelAddedToDeliveryMessageOptional).isPresent(); final ParcelAddedToDeliveryMessage parcelAddedToDeliveryMessage = parcelAddedToDeliveryMessageOptional.get(); final Delivery deliveryFromMessage = parcelAddedToDeliveryMessage.getDelivery(); assertThat(deliveryFromMessage.getId()).isEqualTo(delivery.getId()); assertThat(deliveryFromMessage.getCreatedAt()).isEqualTo(delivery.getCreatedAt()); assertThat(deliveryFromMessage.getItems()).isEqualTo(delivery.getItems()); final Parcel parcelFromMessage = parcelAddedToDeliveryMessage.getParcel(); assertThat(parcelFromMessage).isEqualTo(actualParcel); }); return updatedOrder; });
See the test code.
Delivery.getParcels()
Modifier and Type | Method and Description |
---|---|
String |
getDeliveryId() |
ParcelMeasurements |
getMeasurements() |
TrackingData |
getTrackingData() |
static AddParcelToDelivery |
of(Delivery delivery,
ParcelDraft parcelDraft) |
static AddParcelToDelivery |
of(Delivery delivery,
ParcelDraft parcelDraft,
List<DeliveryItem> items) |
static AddParcelToDelivery |
of(String deliveryId,
ParcelDraft parcelDraft) |
static AddParcelToDelivery |
of(String deliveryId,
ParcelDraft parcelDraft,
List<DeliveryItem> items) |
getAction
public static AddParcelToDelivery of(String deliveryId, ParcelDraft parcelDraft)
public static AddParcelToDelivery of(Delivery delivery, ParcelDraft parcelDraft)
public static AddParcelToDelivery of(String deliveryId, ParcelDraft parcelDraft, List<DeliveryItem> items)
public static AddParcelToDelivery of(Delivery delivery, ParcelDraft parcelDraft, List<DeliveryItem> items)
public String getDeliveryId()
@Nullable public ParcelMeasurements getMeasurements()
@Nullable public TrackingData getTrackingData()