/** * Finds all variants that match the search criteria used in the search request, if any. * @return the list containing all matching variants */ default List<ProductVariant> findMatchingVariants() { return getAllVariants().stream() .filter(v -> Optional.ofNullable(v.isMatchingVariant()).orElse(false)) .collect(Collectors.toList()); }
/** * Finds all variants that match the search criteria used in the search request, if any. * @return the list containing all matching variants */ default List<ProductVariant> findMatchingVariants() { return getAllVariants().stream() .filter(v -> Optional.ofNullable(v.isMatchingVariant()).orElse(false)) .collect(Collectors.toList()); }
/** * Finds all variants that match the search criteria used in the search request, if any. * @return the list containing all matching variants */ default List<ProductVariant> findMatchingVariants() { return getAllVariants().stream() .filter(v -> Optional.ofNullable(v.isMatchingVariant()).orElse(false)) .collect(Collectors.toList()); }
assertThat(productProjectionOptional).isPresent(); final ProductProjection productProjection = productProjectionOptional.get(); assertThat(productProjection.getMasterVariant().isMatchingVariant()).isFalse(); final ProductVariant variantWithAttribute2 = productProjection.getVariants().get(0); assertThat(variantWithAttribute2.isMatchingVariant()).isFalse(); final ProductVariant positiveVariant = productProjection.getVariants().get(1); assertThat(positiveVariant.getAttribute(attributeName).getValueAsString()).isEqualTo("3"); assertThat(positiveVariant.isMatchingVariant()).isTrue(); }); assertEventually(() -> { final Optional<ProductProjection> productProjectionOptional = client().executeBlocking(withoutFlagSearchRequest).head(); assertThat(productProjectionOptional).isPresent(); assertThat(productProjectionOptional.get().getMasterVariant().isMatchingVariant()).isNull(); assertThat(productProjectionOptional.get().getVariants().get(0).isMatchingVariant()).isNull(); final ProductVariant positiveVariant = productProjectionOptional.get().getVariants().get(1); assertThat(positiveVariant.getAttribute(attributeName).getValueAsString()).isEqualTo("3"); assertThat(positiveVariant.isMatchingVariant()).isNull(); });
@Test public void findMatchingVariantByFulltextSearch() throws Exception { final Condition<ProductVariant> allMatchingVariants = new Condition<>(variant -> variant.isMatchingVariant(), "all are matching variants"); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().withMarkingMatchingVariants(true).withText(ENGLISH, "shoe"); assertThat(executeSearch(search).getResults()) .flatExtracting(p -> p.getAllVariants()) .are(allMatchingVariants); }