public static OrderUpdateCommand of(final Versioned<Order> order, final UpdateAction<Order> updateAction) { return of(order, asList(updateAction)); } }
@Test public void changeOrderStateByOrderNumber() throws Exception { withOrder(client(), order -> { assertThat(order.getOrderState()).isEqualTo(OrderState.OPEN); final String orderNumber = randomString(); final Order orderWithOrderNumber = client().executeBlocking(OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber))); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.ofOrderNumber(orderNumber, orderWithOrderNumber.getVersion(), ChangeOrderState.of(OrderState.COMPLETE))); assertThat(updatedOrder.getOrderState()).isEqualTo(OrderState.COMPLETE); return updatedOrder; }); }
static OrderUpdateCommand of(final Versioned<Order> order, final UpdateAction<Order> updateAction) { return of(order, Collections.singletonList(updateAction)); } }
@Test public void changeOrderState() throws Exception { withOrder(client(), order -> { assertThat(order.getOrderState()).isEqualTo(OrderState.OPEN); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, ChangeOrderState.of(OrderState.COMPLETE))); assertThat(updatedOrder.getOrderState()).isEqualTo(OrderState.COMPLETE); return updatedOrder; }); }
@Test public void testRemoveAddressesToOrderUpdateAction() { withFilledCartAndMultipleAddresses(client(), cart -> { withCustomer(client(),customer -> { withOrder(client(),customer,cart,order -> { final List<Address> addresses = order.getItemShippingAddresses(); final String addressKey = addresses.get(0).getKey(); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, RemoveItemShippingAddress.of(addressKey))); assertThat(updatedOrder.getItemShippingAddresses()).hasSize(addresses.size() - 1); assertThat(updatedOrder.getItemShippingAddresses().stream().filter(address -> addressKey.equals(address.getKey())).collect(Collectors.toList())).isEmpty(); return updatedOrder; }); }); }); }
@Test public void setReturnPaymentState() throws Exception { withOrderAndReturnInfo(client(), (order, returnInfo) -> { final ReturnItem returnItem = returnInfo.getItems().get(0); final ReturnPaymentState newPaymentState = ReturnPaymentState.REFUNDED; assertThat(returnItem.getPaymentState()).isNotEqualTo(newPaymentState); final SetReturnPaymentState action = SetReturnPaymentState.of(returnItem, newPaymentState); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, action)); final ReturnPaymentState updatedPaymentState = updatedOrder.getReturnInfo().get(0).getItems().get(0).getPaymentState(); assertThat(updatedPaymentState).isEqualTo(newPaymentState); return updatedOrder; }); }
@Test public void locale() { withOrder(client(), order -> { assertThat(order.getLocale()).isNull(); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, SetLocale.of(Locale.GERMAN))); assertThat(updatedOrder.getLocale()).isEqualTo(GERMAN); return updatedOrder; }); }
@Test public void changePaymentState() throws Exception { withOrder(client(), order -> { final PaymentState newState = PaymentState.PAID; assertThat(order.getPaymentState()).isNotEqualTo(newState); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, ChangePaymentState.of(newState))); assertThat(updatedOrder.getPaymentState()).isEqualTo(newState); return updatedOrder; }); }
@Test public void testAddAddressesToCartUpdateAction() { final List<Address> addressList = createAddressArray(); withFilledCart(client(), cart -> { withCustomer(client(),customer -> { withOrder(client(),customer,cart,order -> { assertThat(order.getItemShippingAddresses()).isEmpty(); List<UpdateAction<Order>> addAddresses = addressList.stream().map(AddItemShippingAddress::of).collect(Collectors.toList()); Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order,addAddresses )); assertThat(updatedOrder.getItemShippingAddresses()).hasSameSizeAs(addressList); return updatedOrder; }); }); }); }
@Test public void setOrderNumber() throws Exception { withOrder(client(), order -> { assertThat(order.getOrderNumber()).isNull(); final String orderNumber = randomString(); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber))); assertThat(updatedOrder.getOrderNumber()).isEqualTo(orderNumber); return updatedOrder; }); }
public static void withOrderAndReturnInfo(final BlockingSphereClient client, final BiFunction<Order, ReturnInfo, Order> f) { withOrder(client, order -> { Assertions.assertThat(order.getReturnInfo()).isEmpty(); final String lineItemId = order.getLineItems().get(0).getId(); final List<LineItemReturnItemDraft> items = asList(LineItemReturnItemDraft.of(1L, lineItemId, ReturnShipmentState.RETURNED, "foo bar")); final AddReturnInfo action = AddReturnInfo.of(items); final AddDelivery addDelivery = AddDelivery.of(asList(DeliveryItem.of(lineItemId, 1))); final Order updatedOrder = client.executeBlocking(OrderUpdateCommand.of(order, asList(action, addDelivery))); final ReturnInfo returnInfo = updatedOrder.getReturnInfo().get(0); return f.apply(updatedOrder, returnInfo); }); } }
@Test public void setCustomType() { withUpdateableType(client(), type -> { withOrder(client(), order -> { final Order orderWithType = client().executeBlocking(OrderUpdateCommand.of(order, SetCustomType.ofTypeIdAndObjects(type.getId(), CUSTOM_FIELDS_MAP))); assertThat(orderWithType.getCustom().getType()).isEqualTo(type.toReference()); assertThat(orderWithType.getCustom().getField(STRING_FIELD_NAME, TypeReferences.stringTypeReference())).isEqualTo("hello"); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(orderWithType, SetCustomField.ofObject(STRING_FIELD_NAME, "other"))); assertThat(updatedOrder.getCustom().getField(STRING_FIELD_NAME, TypeReferences.stringTypeReference())).isEqualTo("other"); //test clean up return client().executeBlocking(OrderUpdateCommand.of(updatedOrder, SetCustomType.ofRemoveType())); }); return type; }); }
@Test public void referenceExpansion() throws Exception { withOrder(client(), order -> { assertThat(order.getOrderNumber()).isNull(); final String orderNumber = randomString(); final OrderUpdateCommand orderUpdateCommand = OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber)).plusExpansionPaths(m -> m.cart()); final Order updatedOrder = client().executeBlocking(orderUpdateCommand); assertThat(updatedOrder.getCart().getObj()).isNotNull(); return updatedOrder; }); }
@Test public void execution() throws Exception { withOrder(client(), order -> { final String orderNumber = randomString(); final Order orderWithOrderNumber = client().executeBlocking(OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber))); final Order loadedOrder = client().executeBlocking(OrderByOrderNumberGet.of(orderNumber)); assertThat(loadedOrder.getOrderNumber()).isEqualTo(orderNumber); return orderWithOrderNumber; }); } }
@Test public void importCustomLineItemState() throws Exception { withStandardStates(client(), (State initialState, State nextState) -> withOrderOfCustomLineItems(client(), order -> { final CustomLineItem customLineItem = order.getCustomLineItems().get(0); assertThat(customLineItem).has(state(initialState)).has(not(state(nextState))); final Set<ItemState> itemStates = asSet(ItemState.of(nextState, 1L), ItemState.of(initialState, customLineItem.getQuantity() - 1)); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, ImportCustomLineItemState.of(customLineItem, itemStates))); assertThat(updatedOrder.getCustomLineItems().get(0)).has(itemStates(itemStates)); }) ); }
@Test public void orderNumber() throws Exception { assertOrderIsFoundWithPredicate( order -> client().executeBlocking(OrderUpdateCommand.of(order, SetOrderNumber.of(randomKey()))), order -> MODEL.orderNumber().is(order.getOrderNumber())); }
@Test public void deleteByOrderNumber() throws Exception { withOrder(client(), order -> { final String orderNumber = randomString(); final Order orderWithOrderNumber = client().executeBlocking(OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber))); final Order deletedOrder = client().executeBlocking(OrderDeleteCommand.ofOrderNumber(orderNumber, orderWithOrderNumber.getVersion())); final Order queriedDeletedOrder = client().executeBlocking(OrderByIdGet.of(deletedOrder)); assertThat(queriedDeletedOrder).isNull(); }); }
@Test public void deleteByOrderNumberEraseData() throws Exception { withOrder(client(), order -> { final String orderNumber = randomString(); final Order orderWithOrderNumber = client().executeBlocking(OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber))); final Order deletedOrder = client().executeBlocking(OrderDeleteCommand.ofOrderNumber(orderNumber, orderWithOrderNumber.getVersion(),true)); final Order queriedDeletedOrder = client().executeBlocking(OrderByIdGet.of(deletedOrder)); assertThat(queriedDeletedOrder).isNull(); }); } }
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) ))); }
@Test public void syncInfo() throws Exception { final Channel channel = persistentChannelOfRole(client(), ORDER_EXPORT); final String externalId = randomKey(); assertOrderIsFoundWithPredicate( order -> client().executeBlocking(OrderUpdateCommand.of(order, UpdateSyncInfo.of(channel).withExternalId(externalId))), order -> MODEL.syncInfo().channel().is(channel).and(MODEL.syncInfo().externalId().is(externalId)).and(MODEL.syncInfo().isNotEmpty())); }