public Address withCity(final String city) { Objects.requireNonNull(city); return withCity(Optional.of(city)); }
public Address withCity(final String city) { Objects.requireNonNull(city); return withCity(Optional.of(city)); }
@Test public void setAddress() throws Exception { withUpdatableChannelOfRole(client(), asSet(PRIMARY), channel -> { final Address address = Address.of(DE).withCity("Berlin"); final Channel updatedChannel = client().executeBlocking(ChannelUpdateCommand.of(channel, SetAddress.of(address))); assertThat(updatedChannel.getAddress()).isEqualTo(address); return updatedChannel; }); }
@Test public void execution() throws Exception { final String key = "demo-key"; final Address address = Address.of(DE).withCity("Berlin"); final Point geoLocation = Point.of(52.5200070, 13.4049540); final ChannelDraft channelDraft = ChannelDraft.of(key) .withName(LocalizedString.of(ENGLISH, "name")) .withDescription(LocalizedString.of(ENGLISH, "description")) .withRoles(ChannelRole.INVENTORY_SUPPLY) .withAddress(address) .withGeoLocation(geoLocation); final Channel channel = client().executeBlocking(ChannelCreateCommand.of(channelDraft)); assertThat(channel.getKey()).isEqualTo(key); assertThat(channel.getName()).isEqualTo(LocalizedString.of(ENGLISH, "name")); assertThat(channel.getDescription()).isEqualTo(LocalizedString.of(ENGLISH, "description")); assertThat(channel.getRoles()).isEqualTo(asSet(ChannelRole.INVENTORY_SUPPLY)); assertThat(channel.getAddress()).isEqualTo(address); assertThat(channel.getGeoLocation()).isEqualTo(geoLocation); }
@Test public void changeAddress() throws Exception { 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); }); }); }