static ProductProjectionQuery ofStaged() { return of(ProductProjectionType.STAGED); }
static ProductProjectionQuery ofCurrent() { return of(ProductProjectionType.CURRENT); }
static ProductProjectionQuery ofCurrent() { return of(ProductProjectionType.CURRENT); }
static ProductProjectionQuery ofStaged() { return of(ProductProjectionType.STAGED); }
static ProductProjectionQuery ofCurrent() { return of(ProductProjectionType.CURRENT); }
static ProductProjectionQuery ofStaged() { return of(ProductProjectionType.STAGED); }
public static ProductProjectionQueryBuilder of(final ProductProjectionType productProjectionType) { return new ProductProjectionQueryBuilder(ProductProjectionQuery.of(productProjectionType)); }
public static ProductProjectionQueryBuilder of(final ProductProjectionType productProjectionType) { return new ProductProjectionQueryBuilder(ProductProjectionQuery.of(productProjectionType)); }
static ProductProjectionQueryBuilder of(final ProductProjectionType productProjectionType) { return new ProductProjectionQueryBuilder(ProductProjectionQuery.of(productProjectionType)); }
private void checkOneResult(final Product product, final QueryPredicate<ProductProjection> predicate) { final PagedQueryResult<ProductProjection> queryResult = client().executeBlocking(ProductProjectionQuery.of(STAGED).withPredicates(predicate)); assertThat(ids(queryResult)).containsOnly(product.getId()); }
@Test public void expandCustomerGroupInPrice() throws Exception { withCustomerGroup(client(), customerGroup -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withCustomerGroup(customerGroup), product -> { final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())) .withExpansionPaths(m -> m.masterVariant().prices().customerGroup()); final List<Price> prices = client().executeBlocking(query).head().get().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getCustomerGroup()).map(customerGroupReference -> customerGroupReference.getObj() != null).orElse(false))) .isTrue(); return product; }); } ); }
@Test public void variantIdentifierIsAvailable() throws Exception { withProduct(client(), product -> { final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())); final ProductProjection productProjection = client().executeBlocking(query).head().get(); final ByIdVariantIdentifier identifier = productProjection.getMasterVariant().getIdentifier(); assertThat(identifier).isEqualTo(ByIdVariantIdentifier.of(product.getId(), 1)); }); }
@Test public void expandChannelInPrice() 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 Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())) .withExpansionPaths(m -> m.masterVariant().prices().channel()); final List<Price> prices = client().executeBlocking(query).head().get().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getChannel()).map(channelRef -> channelRef.getObj() != null).orElse(false))) .isTrue(); return product; }); }); }
@Test public void queryById() throws Exception { with2products("queryById", (p1, p2) -> { final Query<ProductProjection> query1 = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().isIn(asList(p1.getId(), p2.getId()))); assertThat(ids(client().executeBlocking(query1))).containsOnly(p1.getId(), p2.getId()); final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().is(p1.getId())); assertThat(ids(client().executeBlocking(query))).containsOnly(p1.getId()); }); }
@Test public void queryByProductType() throws Exception { with2products("queryByProductType", (p1, p2) ->{ final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .byProductType(p1.getProductType()) .withExpansionPaths(m -> m.productType()); final PagedQueryResult<ProductProjection> queryResult = client().executeBlocking(query); assertThat(queryResult.head().get().getProductType()).is(expanded()); assertThat(ids(queryResult)).containsOnly(p1.getId()); }); }
@Test public void differentiateBetweenCurrentAndStaged() throws Exception { withUpdateableProduct(client(), product -> { final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); final Product mixedDataProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, ChangeName.of(randomSlug()))); final LocalizedString nameInCurrent = mixedDataProduct.getMasterData().getCurrent().getName(); final LocalizedString nameInStaged = mixedDataProduct.getMasterData().getStaged().getName(); final ProductProjectionQuery stagedQuery = ProductProjectionQuery.of(STAGED).withPredicates(m -> m.id().is(product.getId())); assertThat(client().executeBlocking(stagedQuery).head().get().getName()).isEqualTo(nameInStaged); final ProductProjectionQuery currentQuery = ProductProjectionQuery.of(CURRENT).withPredicates(m -> m.id().is(product.getId())); assertThat(client().executeBlocking(currentQuery).head().get().getName()).isEqualTo(nameInCurrent); return mixedDataProduct; }); }
@Test public void queryBySlug() throws Exception { with2products("queryBySlug", (p1, p2) ->{ final Query<ProductProjection> query1 = ProductProjectionQuery.of(STAGED).bySlug(ENGLISH, p1.getMasterData().getStaged().getSlug().get(ENGLISH)); assertThat(ids(client().executeBlocking(query1))).containsOnly(p1.getId()); }); }
@Test public void expandTaxCategory() throws Exception { TaxCategoryFixtures.withTransientTaxCategory(client(), taxCategory -> withProduct(client(), product -> { final Product productWithTaxCategory = client().executeBlocking(ProductUpdateCommand.of(product, SetTaxCategory.of(taxCategory))); final ProductProjectionQuery query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(productWithTaxCategory.getId())) .withExpansionPaths(m -> m.taxCategory()); final PagedQueryResult<ProductProjection> pagedQueryResult = client().executeBlocking(query); assertThat(pagedQueryResult.head().get().getTaxCategory()).is(expanded()); }) ); }
@Test public void queryByName() throws Exception { with2products("queryByName", (p1, p2) ->{ final Query<ProductProjection> query1 = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.name().lang(ENGLISH).is(en(p1.getMasterData().getStaged().getName()))) .withSort(m -> m.createdAt().sort().desc()) .withLimit(1L); assertThat(ids(client().executeBlocking(query1))).containsOnly(p1.getId()); }); }
@Test public void queryByHasStagedChanges() throws Exception { withProduct(client(), product -> { final Product updated = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(randomSlug()))); final ProductProjectionQuery query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.hasStagedChanges().is(true)) .withSort(m -> m.createdAt().sort().desc()); final PagedQueryResult<ProductProjection> pagedQueryResult = client().executeBlocking(query); assertThat(ids(pagedQueryResult)).contains(updated.getId()); }); }