public final static List<Address> createAddressArray() { final Address address1 = Address.of(CountryCode.DE).withKey(SphereTestUtils.randomKey()); final Address address2 = Address.of(CountryCode.FR).withKey(SphereTestUtils.randomKey()); final Address address3 = Address.of(CountryCode.MA).withKey(SphereTestUtils.randomKey()); final Address address4 = Address.of(CountryCode.IT).withKey(SphereTestUtils.randomKey()); return Arrays.asList(address1, address2, address3, address4); }
public final static List<Address> createAddressArray() { final Address address1 = Address.of(CountryCode.DE).withKey(SphereTestUtils.randomKey()); final Address address2 = Address.of(CountryCode.FR).withKey(SphereTestUtils.randomKey()); final Address address3 = Address.of(CountryCode.MA).withKey(SphereTestUtils.randomKey()); final Address address4 = Address.of(CountryCode.IT).withKey(SphereTestUtils.randomKey()); return Arrays.asList(address1, address2, address3, address4); }
@Test public void testUpdateAddressesToCartUpdateAction() { withFilledCartAndMultipleAddresses(client(), cart -> { final List<Address> addresses = cart.getItemShippingAddresses(); final Address firstAddress = addresses.get(0); assertThat(firstAddress.getCountry()).isNotEqualByComparingTo(CountryCode.CA); final String firstAddressKey = firstAddress.getKey(); final Address updatedAddress = Address.of(CountryCode.CA).withKey(firstAddressKey); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, UpdateItemShippingAddress.of(updatedAddress))); List<Address> newAddresses = updatedCart.getItemShippingAddresses().stream().filter(address -> address.getKey().equals(firstAddressKey)).collect(Collectors.toList()); assertThat(newAddresses).hasSize(1); assertThat(newAddresses.get(0).getCountry()).isEqualByComparingTo(CountryCode.CA); }); }
@Test public void testUpdateAddressesToOrderUpdateAction() { withFilledCartAndMultipleAddresses(client(), cart -> { withCustomer(client(),customer -> { withOrder(client(),customer,cart,order -> { final List<Address> addresses = order.getItemShippingAddresses(); final Address firstAddress = addresses.get(0); assertThat(firstAddress.getCountry()).isNotEqualByComparingTo(CountryCode.CA); final String firstAddressKey = firstAddress.getKey(); final Address updatedAddress = Address.of(CountryCode.CA).withKey(firstAddressKey); final Order updatedOrder= client().executeBlocking(OrderUpdateCommand.of(order, UpdateItemShippingAddress.of(updatedAddress))); List<Address> newAddresses = updatedOrder.getItemShippingAddresses().stream().filter(address -> address.getKey().equals(firstAddressKey)).collect(Collectors.toList()); assertThat(newAddresses).hasSize(1); assertThat(newAddresses.get(0).getCountry()).isEqualByComparingTo(CountryCode.CA); return updatedOrder; }); }); }); }