@Override public boolean matches(final T value) { return value.getObj() != null; } };
@Override public boolean matches(final T value) { return value.getObj() != null; } };
public void checkIsExpanded() { if (actual.getObj() == null) { failWithMessage(format("The reference %s is not expanded.", actual)); } }
public ReferenceAssert hasAnExpanded(final Resource<?> model) { checkIsExpanded(); if (!actual.getObj().equals(model)) { failWithMessage(format("%s does not contain an expanded %s.", actual, model)); } return this; }
public void checkIsExpanded() { if (!actual.getObj().isPresent()) { failIfCustomMessageIsSet(); throw failure(String.format("The reference %s is not expanded.", actual)); } }
public void checkIsExpanded() { if (!actual.getObj().isPresent()) { failIfCustomMessageIsSet(); throw failure(String.format("The reference %s is not expanded.", actual)); } }
public ReferenceAssert hasAnExpanded(final DefaultModel<?> model) { checkIsExpanded(); if (!actual.getObj().get().equals(model)) { failIfCustomMessageIsSet(); throw failure(String.format("%s does not contain an expanded %s.", actual, model)); } return this; }
public ReferenceAssert hasAnExpanded(final DefaultModel<?> model) { checkIsExpanded(); if (!actual.getObj().get().equals(model)) { failIfCustomMessageIsSet(); throw failure(String.format("%s does not contain an expanded %s.", actual, model)); } return this; }
protected void fillShippingInfoDescription(final ShippingInfoBean bean, final CartLike<?> cartLike) { if (cartLike.getShippingInfo() != null) { final Reference<ShippingMethod> ref = cartLike.getShippingInfo().getShippingMethod(); if (ref != null && ref.getObj() != null) { bean.setDescription(ref.getObj().getDescription()); } } }
static <T> Attribute of(final NamedAttributeAccess<T> namedAttributeAccess, final T value) { final String name = namedAttributeAccess.getName(); //here is not the attributeMapper used to keep LocalizedEnum values which //are transformed to just the key so the attribute could not be read anymore final JsonNode jsonNode = SphereJsonUtils.toJsonNode(value); if (value instanceof Reference && jsonNode instanceof ObjectNode) { final Reference<?> reference = (Reference<?>) value; if (reference.getObj() != null) { ((ObjectNode) jsonNode).replace("obj", SphereJsonUtils.toJsonNode(reference.getObj())); } } return of(name, jsonNode); }
@Test public void createFilledReference() throws Exception { final Reference<TestEntity> reference = newFilledReference(); assertThat(reference.getId()).isEqualTo(id); assertThat(reference.getTypeId()).isEqualTo(typeId); assertThat(reference.getObj()).isEqualTo(new TestEntity("value")); }
@Test public void execution() throws Exception { withShippingMethod(client(), shippingMethod -> { final ShippingMethodByIdGet fetch = ShippingMethodByIdGet.of(shippingMethod) .withExpansionPaths(m -> m.taxCategory()); final ShippingMethod loadedShippingMethod = client().executeBlocking(fetch); final String actualFetchedId = loadedShippingMethod.getId(); assertThat(actualFetchedId).isEqualTo(shippingMethod.getId()); assertThat(loadedShippingMethod.getTaxCategory().getObj()).isNotNull(); }); } }
@Test public void expandedDiscountedPrice() throws Exception { final Product product = SphereJsonUtils.readObjectFromResource("product-with-expanded-discounted-price.json", Product.typeReference()); final Price price = product.getMasterData().getStaged().getMasterVariant().getPrices().get(0); final DiscountedPrice discountedPrice = price.getDiscounted(); final ProductDiscount productDiscount = discountedPrice.getDiscount().getObj(); assertThat(productDiscount.getName().get(Locale.ENGLISH)).isEqualTo("demo product discount"); assertThat(productDiscount.getValue()).isInstanceOf(AbsoluteProductDiscountValue.class); }
@Test public void execution() throws Exception { withInventoryEntryAndSupplyChannel(client(), INVENTORY_SUPPLY, (entry, channel) -> { final SphereRequest<InventoryEntry> sphereRequest = InventoryEntryByIdGet.of(entry) .withExpansionPaths(m -> m.supplyChannel()); final InventoryEntry actual = client().executeBlocking(sphereRequest); assertThat(actual.getId()).contains(entry.getId()); assertThat(actual.getSupplyChannel().getObj().getId()).isEqualTo(channel.getId()); }); } }
@Test public void referencesAreNotByDefaultExpanded() { withCustomerInGroup(client(), (customer, customerGroup) -> { final CustomerByIdGet customerByIdGet = CustomerByIdGet.of(customer); final Customer loadedCustomer = client().executeBlocking(customerByIdGet); final Reference<CustomerGroup> customerGroupReference = loadedCustomer.getCustomerGroup(); assertThat(customerGroupReference.getId()).isEqualTo(customerGroup.getId()); assertThat(customerGroupReference.getObj()) .as("reference is not expanded") .isNull(); }); }
@Test public void canExpandItsCategories() throws Exception { withProductInCategory(client(), (product, category) -> { final Query<Product> query = query(product) .withExpansionPaths(ProductExpansionModel.of().masterData().staged().categories()); assertThat(client().executeBlocking(query).head().get().getMasterData().getStaged().getCategories().stream().anyMatch(reference -> reference.getObj() != null)) .isTrue(); }); }
@Test public void execution() throws Exception { withCustomerInGroup(client(), (customer, customerGroup) -> { final Get<Customer> fetch = CustomerByIdGet.of(customer) .withExpansionPaths(CustomerExpansionModel.of().customerGroup()); final Customer fetchedCustomer = client().executeBlocking(fetch); assertThat(fetchedCustomer.getId()).isEqualTo(customer.getId()); assertThat(fetchedCustomer.getCustomerGroup().getObj().getId()).isEqualTo(customerGroup.getId()); }); } }
@Test public void referenceExpansion() throws Exception { withOrder(client(), order -> { assertThat(order.getOrderNumber()).isNull(); final String orderNumber = randomString(); final OrderUpdateCommand orderUpdateCommand = OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber)).plusExpansionPaths(m -> m.cart()); final Order updatedOrder = client().executeBlocking(orderUpdateCommand); assertThat(updatedOrder.getCart().getObj()).isNotNull(); return updatedOrder; }); }
@Test public void referenceExpansion() throws Exception { final Category parent = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomSlug(), randomSlug()).build())); final Category category = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomSlug(), randomSlug()).parent(parent).build())); final CategoryDeleteCommand deleteCommand = CategoryDeleteCommand.of(category).plusExpansionPaths(m -> m.parent()); final Category deletedCategory = client().executeBlocking(deleteCommand); assertThat(deletedCategory.getParent().getObj()).isNotNull().isEqualTo(parent); client().executeBlocking(CategoryDeleteCommand.of(parent)); }