@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 canExpandCustomerGroupOfPrices() throws Exception { withCustomerGroup(client(), customerGroup -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withCustomerGroup(customerGroup), product -> { final ExpansionPath<Product> expansionPath = ProductExpansionModel.of().masterData().staged().masterVariant().prices().customerGroup().expansionPaths().get(0); final Query<Product> query = query(product).withExpansionPaths(expansionPath); final List<Price> prices = client().executeBlocking(query).head().get().getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getCustomerGroup()).map(customerGroupReference -> customerGroupReference.getObj() != null).orElse(false))) .isTrue(); return product; }); } ); }
@Test public void canExpandChannelOfPrices() throws Exception { ChannelFixtures.withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withChannel(channel), product -> { final ExpansionPath<Product> expansionPath = ProductExpansionModel.of().masterData().staged().masterVariant().prices().channel().expansionPaths().get(0); final Query<Product> query = query(product).withExpansionPaths(expansionPath); final List<Price> prices = client().executeBlocking(query).head().get().getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getChannel()).map(channelRef -> channelRef.getObj() != null).orElse(false))) .isTrue(); return product; }); }); }
@Test public void expandVariants() { CustomerGroupFixtures.withB2cCustomerGroup(client(), customerGroup -> ProductFixtures.withProductType(client(), randomString(), productType -> withProduct(client(), new VariantsCottonTShirtProductDraftSupplier(productType, randomString(), customerGroup), product -> { final PagedQueryResult<Product> result = client().executeBlocking(ProductQuery.of() .withPredicates(m -> m.id().is(product.getId())) .withExpansionPaths(m -> m.masterData().staged().variants().prices().customerGroup()) .withLimit(1L)); final Price priceWithCustomerGroup = result.head().get().getMasterData().getStaged().getVariants().get(0).getPrices().stream() .filter(price -> Objects.equals(price.getCustomerGroup(), customerGroup.toReference())) .findFirst().get(); assertThat(priceWithCustomerGroup.getCustomerGroup().getObj()).isNotNull().isEqualTo(customerGroup); }) ) ); }
@Test public void productType() throws Exception { final Consumer<Product> user = product -> { final Query<Product> query = ProductQuery.of(). bySlug(ProductProjectionType.CURRENT, Locale.ENGLISH, englishSlugOf(product.getMasterData().getStaged())). withExpansionPaths(ProductExpansionModel.of().productType()). toQuery(); final PagedQueryResult<Product> queryResult = client().executeBlocking(query); final Reference<ProductType> productTypeReference = queryResult.head().get().getProductType(); assertThat(productTypeReference).is(expanded()); }; withProduct(client(), "productTypeReferenceExpansion", user); }
@Test public void taxCategory() throws Exception { TaxCategoryFixtures.withTransientTaxCategory(client(), taxCategory -> withProduct(client(), product -> { final Product productWithTaxCategory = client().executeBlocking(ProductUpdateCommand.of(product, SetTaxCategory.of(taxCategory))); assertThat(productWithTaxCategory.getTaxCategory()).isNotNull(); final Query<Product> query = ProductQuery.of(). bySlug(ProductProjectionType.CURRENT, Locale.ENGLISH, englishSlugOf(product.getMasterData().getStaged())). withExpansionPaths(ProductExpansionModel.of().taxCategory()). toQuery(); final PagedQueryResult<Product> queryResult = client().executeBlocking(query); final Reference<TaxCategory> productTypeReference = firstOf(queryResult).getTaxCategory(); assertThat(productTypeReference).is(expanded()); }) ); } }