public interface CustomerCreateCommand extends DraftBasedCreateCommandDsl<CustomerSignInResult,CustomerDraft,CustomerCreateCommand>, MetaModelReferenceExpansionDsl<CustomerSignInResult,CustomerCreateCommand,CustomerSignInResultExpansionModel<CustomerSignInResult>>
final CustomerGroup customerGroup = CustomerGroupFixtures.b2cCustomerGroup(client());
final CustomerName name = CustomerName.ofFirstAndLastName("John", "Smith");
final String email = randomEmail(CustomerCreateCommandIntegrationTest.class);
final String externalId = randomString();
final String password = "secret";
final LocalDate dateOfBirth = LocalDate.of(1985, 5, 7);
final String companyName = "ct";
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)
.withExternalId(externalId)
.withDateOfBirth(dateOfBirth)
.withCompanyName(companyName)
.withVatId(vatId)
.withEmailVerified(emailVerified)
.withCustomerGroup(customerGroup)
.withAddresses(addresses)
.withDefaultBillingAddress(0)
.withDefaultShippingAddress(1)
.withShippingAddresses(singletonList(2))
.withBillingAddresses(singletonList(3));
final CustomerCreateCommand sphereRequest = CustomerCreateCommand.of(draft)
.withExpansionPaths(m -> m.customer().customerGroup());
final CustomerSignInResult result = client().executeBlocking(sphereRequest);
assertThat(result.getCart())
.as("no cart id given in creation, so this field is empty")
.isNull();
final Customer customer = result.getCustomer();
final Cart cart = result.getCart();
assertThat(customer.getName()).isEqualTo(name);
assertThat(customer.getEmail()).isEqualTo(email);
assertThat(customer.getPassword())
.as("password is not stored in clear text")
.isNotEqualTo(password);
assertThat(customer.getExternalId()).contains(externalId);
assertThat(customer.getLocale()).isEqualTo(GERMAN);
assertThat(cart).isNull();
assertThat(customer.getDateOfBirth()).isEqualTo(dateOfBirth);
assertThat(customer.getCompanyName()).contains(companyName);
assertThat(customer.getVatId()).contains(vatId);
assertThat(customer.isEmailVerified()).isEqualTo(emailVerified);
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)));
See the test code.
final Cart cart = client().executeBlocking(CartCreateCommand.of(CartDraft.of(EUR)));//could of course be filled with products
final String email = randomEmail(CustomerCreateCommandIntegrationTest.class);
final CustomerDraft draft = CustomerDraftDsl.of(CUSTOMER_NAME, email, PASSWORD).withCart(cart);
final CustomerSignInResult result = client().executeBlocking(CustomerCreateCommand.of(draft));
assertThat(result.getCart()).isNotNull();
assertThat(result.getCart().getId()).isEqualTo(cart.getId());
See the test code.
Customer
Modifier and Type | Method and Description |
---|---|
static CustomerCreateCommand |
of(CustomerDraft draft) |
getDraft, withDraft
canDeserialize, deserialize, httpRequestIntent
plusExpansionPaths, withExpansionPaths
plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths
expansionPaths
static CustomerCreateCommand of(CustomerDraft draft)