public final class ChangeAddress extends UpdateActionImpl<Customer>
See also CustomerInStoreUpdateCommand.
withCustomerWithOneAddress(client(), customer -> { final String city = "new city"; assertThat(customer.getAddresses()).hasSize(1); assertThat(customer.getAddresses().get(0).getCity()).isNotEqualTo(city); final Address oldAddress = customer.getAddresses().get(0); assertThat(oldAddress.getId()) .overridingErrorMessage("only fetched address contains an ID") .isNotNull(); final Address newAddress = oldAddress.withCity(city); final ChangeAddress updateAction = ChangeAddress.ofOldAddressToNewAddress(oldAddress, newAddress); final Customer customerWithReplacedAddress = client().executeBlocking(CustomerUpdateCommand.of(customer, updateAction)); assertThat(customerWithReplacedAddress.getAddresses()).hasSize(1); assertThat(customerWithReplacedAddress.getAddresses().get(0).getCity()).contains(city); Query<CustomerAddressChangedMessage> messageQuery = MessageQuery.of() .withPredicates(m -> m.resource().is(customer)) .withSort(m -> m.createdAt().sort().desc()) .withLimit(1L) .forMessageType(CustomerAddressChangedMessage.MESSAGE_HINT); assertEventually(() -> { final PagedQueryResult<CustomerAddressChangedMessage> queryResult = client().executeBlocking(messageQuery); assertThat(queryResult.head()).isPresent(); final CustomerAddressChangedMessage message = queryResult.head().get(); assertThat(message.getAddress()).isEqualTo(newAddress); }); });
See the test code.
Customer
Modifier and Type | Method and Description |
---|---|
Address |
getAddress() |
String |
getAddressId() |
String |
getAddressKey() |
static ChangeAddress |
of(Address address,
String addressKey) |
static ChangeAddress |
of(String addressId,
Address address) |
static ChangeAddress |
ofOldAddressToNewAddress(Address oldAddress,
Address newAddress) |
getAction
public static ChangeAddress of(String addressId, Address address)
public static ChangeAddress of(Address address, String addressKey)
public static ChangeAddress ofOldAddressToNewAddress(Address oldAddress, Address newAddress)
public Address getAddress()
public String getAddressId()
public String getAddressKey()