public Address build() { return new Address(this); }
private void applyShippingAddress(final Address address) { this.titleShipping = address.getTitle(); this.firstNameShipping = address.getFirstName(); this.lastNameShipping = address.getLastName(); this.streetNameShipping = address.getStreetName(); this.additionalStreetInfoShipping = address.getAdditionalStreetInfo(); this.cityShipping = address.getCity(); this.postalCodeShipping = address.getPostalCode(); this.countryShipping = address.getCountry().getAlpha2(); this.regionShipping = address.getRegion(); this.phoneShipping = address.getPhone(); this.emailShipping = address.getEmail(); }
private Location createLocation(final Address address) { final CountryCode country = address.getCountry(); final Location location; if (address.getState() != null) { location = Location.of(country, address.getState()); } else { location = Location.of(country); } return location; } }
final String vatId = "123456"; final boolean emailVerified = true; final List<Address> addresses = asList(Address.of(DE), Address.of(GB), Address.of(US), Address.of(FR)); final CustomerDraft draft = CustomerDraftDsl.of(name, email, password) .withLocale(GERMAN) assertThat(customer.getCustomerGroup()).isEqualTo(customerGroup.toReference()); final List<Address> loadedAddresses = customer.getAddresses(); assertThat(loadedAddresses.stream().map(a -> a.withId(null)).collect(toList())).isEqualTo(addresses); assertThat(customer.getDefaultBillingAddress().withId(null)).isEqualTo(addresses.get(0)); assertThat(customer.findDefaultShippingAddress().get().withId(null)).isEqualTo(addresses.get(1)); assertThat(customer.getBillingAddressIds()) .containsExactly(loadedAddresses.get(0).getId(), loadedAddresses.get(3).getId()); assertThat(customer.getBillingAddresses()).extracting(Address::getCountry).containsExactly(DE, FR); assertThat(customer.getShippingAddressIds()) .containsExactly(loadedAddresses.get(1).getId(), loadedAddresses.get(2).getId()); assertThat(customer.getShippingAddresses()).extracting(Address::getCountry).containsExactly(GB, US); assertThat(customer.getCustomerGroup().getObj()) .as("customer group can be expanded") .isNotNull(); String addressId = loadedAddresses.get(0).getId(); final Address addressById = customer.findAddressById(addressId).get(); assertThat(addressById.equals(loadedAddresses.get(0)));
@Test public void createByJson() { final JsonNodeReferenceResolver referenceResolver = new JsonNodeReferenceResolver(); withB2cCustomerGroup(client(), customerGroup -> { referenceResolver.addResourceByKey("b2c", customerGroup); final CustomerDraft customerDraft = draftFromJsonResource("drafts-tests/customer.json", CustomerDraftDsl.class, referenceResolver); CustomerFixtures.withCustomer(client(), customerDraft, customer -> { assertThat(customer.getLastName()).isEqualTo("Osgood"); assertThat(customer.getCustomerGroup()).isEqualTo(customerGroup.toReference()); assertThat(customer.getAddresses()).hasSize(2); assertThat(customer.getDefaultShippingAddress().withId(null)) .isEqualTo(Address.of(DE).withLastName("Osgood").withExternalId("external-ID-DE")); }); }); }
@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); }); }); }
@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 addShippingAddressId() { final List<Address> addresses = asList(Address.of(DE), Address.of(FR)); final CustomerDraft draft = newCustomerDraft().withAddresses(addresses); withCustomer(client(), draft, customer -> { assertThat(customer.getShippingAddressIds()).isEmpty(); final Address addressForShipping = customer.getAddresses().get(1); final String addressId = addressForShipping.getId(); final AddShippingAddressId updateAction = AddShippingAddressId.of(addressId); final Customer updatedCustomer = client().executeBlocking(CustomerUpdateCommand.of(customer, updateAction)); assertThat(updatedCustomer.getShippingAddressIds()).containsExactly(addressId); }); }
@Test public void equalsIgnoreId() { final Address addressWithoutId = Address.of(CountryCode.DE); final Address addressWithId = addressWithoutId.withId("foo"); assertThat(addressWithoutId) .isNotEqualTo(addressWithId) .matches(address -> address.equalsIgnoreId(addressWithId)); }
@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; }); }
private CompletionStage<Cart> setAddressToCart(final Cart cart, final Address shippingAddress, @Nullable final Address billingAddress) { final List<UpdateAction<Cart>> updateActions = new ArrayList<>(); updateActions.add(SetCountry.of(shippingAddress.getCountry())); updateActions.add(SetShippingAddress.of(shippingAddress)); updateActions.add(SetBillingAddress.of(billingAddress)); Optional.ofNullable(shippingAddress.getEmail()) .ifPresent(email -> updateActions.add(SetCustomerEmail.of(email))); final CartUpdateCommand cmd = CartUpdateCommand.of(cart, updateActions); return executeCartUpdateCommandWithHooks(cmd); } }
public Address withId(final String id) { Objects.requireNonNull(id); return withId(Optional.of(id)); }
public Address withApartment(final String apartment) { Objects.requireNonNull(apartment); return withApartment(Optional.of(apartment)); }
@Test public void fullExample() throws Exception { final Address shippingAddress = Address.of(CountryCode.DE).withAdditionalAddressInfo("shipping"); final Address billingAddress = Address.of(CountryCode.DE).withAdditionalAddressInfo("billing");
public Address withAdditionalAddressInfo(final String additionalAddressInfo) { Objects.requireNonNull(additionalAddressInfo); return withAdditionalAddressInfo(Optional.of(additionalAddressInfo)); }
public Address withCity(final String city) { Objects.requireNonNull(city); return withCity(Optional.of(city)); }
public Address withEmail(final String email) { Objects.requireNonNull(email); return withEmail(Optional.of(email)); }