@Test public void changeShipmentState() throws Exception { withOrder(client(), order -> { final ShipmentState newState = ShipmentState.SHIPPED; assertThat(order.getShipmentState()).isNotEqualTo(newState); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, ChangeShipmentState.of(newState))); assertThat(updatedOrder.getShipmentState()).isEqualTo(newState); //you can observe a message final Query<OrderShipmentStateChangedMessage> messageQuery = MessageQuery.of() .withPredicates(m -> m.resource().is(order)) .forMessageType(OrderShipmentStateChangedMessage.MESSAGE_HINT); assertEventually(() -> { final Optional<OrderShipmentStateChangedMessage> orderShipmentStateChangedMessageOptional = client().executeBlocking(messageQuery).head(); assertThat(orderShipmentStateChangedMessageOptional).isPresent(); final OrderShipmentStateChangedMessage orderShipmentStateChangedMessage = orderShipmentStateChangedMessageOptional.get(); assertThat(orderShipmentStateChangedMessage.getShipmentState()).isNotNull(); }); return updatedOrder; }); }
private static Order createOrderFromCart(BlockingSphereClient client, Customer customer, Cart cart) { final TaxCategory taxCategory = TaxCategoryFixtures.defaultTaxCategory(client); final SetCustomShippingMethod shippingMethodAction = SetCustomShippingMethod.of("custom shipping method", ShippingRate.of(EURO_10), taxCategory); final SetCustomerEmail emailAction = SetCustomerEmail.of(CUSTOMER_EMAIL); client.executeBlocking(CartUpdateCommand.of(cart, asList(shippingMethodAction, emailAction))); final CustomerSignInCommand signInCommand = CustomerSignInCommand.of(customer.getEmail(), CustomerFixtures.PASSWORD, cart.getId()); final CustomerSignInResult signInResult = client.executeBlocking(signInCommand); final Order order = client.executeBlocking(OrderFromCartCreateCommand.of(signInResult.getCart())); return client.executeBlocking(OrderUpdateCommand.of(order, asList( ChangeShipmentState.of(ShipmentState.READY), ChangePaymentState.of(PaymentState.PENDING) ))); }