@Test public void sortByAttributeAscending() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withSort(productModel -> productModel.allVariants().attribute().ofNumber(ATTR_NAME_SIZE).asc()); testResultIds(search, resultIds -> assertThat(resultIds).containsExactly(product2.getId(), product1.getId(), product3.getId())); }
@Test public void facetedSearchOnReferenceAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofReference(ATTR_NAME_REF).id().is(productA.getId()), ids -> assertThat(ids).as("expected products in result").containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(productA.getId(), 1L), TermStats.of(productB.getId(), 1L))); }
@Test public void facetedSearchOnNumberRangedSetAttributes() throws Exception { testResultWithRange(PRODUCT_MODEL.allVariants().attribute().ofNumberSet(ATTR_NAME_NUMBER_SET).isBetween(atLeast(NUMBER_10.toPlainString())), ids -> assertThat(ids).containsOnly(product1.getId()), rangeStats -> { assertThat(rangeStats.getLowerEndpoint()).isEqualTo(null); assertThat(rangeStats.getUpperEndpoint()).isEqualTo(null); assertThat(rangeStats.getCount()).isEqualTo(2L); assertThat(rangeStats.getMin()).isEqualTo("5.0"); assertThat(rangeStats.getMax()).isEqualTo("10.0"); }); }
@Test public void facetedSearchOnDateRangedSetAttributes() throws Exception { testResultWithRange(PRODUCT_MODEL.allVariants().attribute().ofDateSet(ATTR_NAME_DATE_SET).isBetween(atLeast(DATE_2002.toString())), ids -> assertThat(ids).containsOnly(product1.getId()), rangeStats -> { assertThat(rangeStats.getLowerEndpoint()).isEqualTo(null); assertThat(rangeStats.getUpperEndpoint()).isEqualTo(null); assertThat(rangeStats.getCount()).isEqualTo(2L); assertThat(rangeStats.getMin()).isEqualTo("1.0001664E12"); assertThat(rangeStats.getMax()).isEqualTo("1.0343808E12"); }); }
@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 variantIdentifierIsAvailable() throws Exception { withProduct(client(), product -> { final ByIdVariantIdentifier identifier = product.getMasterData().getStaged().getMasterVariant().getIdentifier(); assertThat(identifier).isEqualTo(ByIdVariantIdentifier.of(product.getId(), 1)); }); }
@Test public void facetedSearchOnDateSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofDateSet(ATTR_NAME_DATE_SET).is(DATE_2002.toString()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of("2001-09-11", 2L), TermStats.of("2002-10-12", 1L))); }
@Test public void onDateTimeAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofDateTime(ATTR_NAME_DATE_TIME).is(DATE_TIME_2001_22H), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onTextSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofStringSet(ATTR_NAME_TEXT_SET).is(TEXT_BAR), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onTimeRangedSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofTimeSet(ATTR_NAME_TIME_SET).isGreaterThanOrEqualTo(TIME_23H), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void facetedSearchOnMoneyCurrencySetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofMoneySet(ATTR_NAME_MONEY_SET).currency().is(MONEY_1000_USD.getCurrency().getCurrencyCode()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of("EUR", 2L), TermStats.of("USD", 1L))); }
@Test public void facetedSearchOnDateAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofDate(ATTR_NAME_DATE).is(DATE_2001.toString()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of("2001-09-11", 1L), TermStats.of("2002-10-12", 1L))); }
@Test public void facetedSearchOnDateTimeAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofDateTime(ATTR_NAME_DATE_TIME).is(DATE_TIME_2001_22H.toString()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of("2002-10-12T23:06:10.204+0000", 1L), TermStats.of("2001-09-11T22:05:09.203+0000", 1L))); }
@Test public void onLocTextAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofLocalizedString(ATTR_NAME_LOC_TEXT).locale(ENGLISH).is(LOC_TEXT_FOO.get(ENGLISH)), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onEnumKeyAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofEnum(ATTR_NAME_ENUM).key().is(ENUM_TWO.getKey()), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void facetedSearchOnEnumKeyAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofEnum(ATTR_NAME_ENUM).key().is(ENUM_TWO.getKey()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(ENUM_TWO.getKey(), 1L), TermStats.of(ENUM_THREE.getKey(), 1L))); }
@Test public void facetedSearchOnEnumLabelAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofEnum(ATTR_NAME_ENUM).label().is(ENUM_TWO.getLabel()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(ENUM_TWO.getLabel(), 1L), TermStats.of(ENUM_THREE.getLabel(), 1L))); }
@Test(expected = NotFoundException.class) public void executeInvalidQuery(){ withUpdateableProductDiscount(client(),((productDiscount, product) -> { final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final Price invalidPice = Price.of(MoneyImpl.of(0, DefaultCurrencyUnits.USD)); final ProductDiscount queryedProductDiscount = client().executeBlocking(MatchingProductDiscountGet.of(product.getId(), masterVariant.getId(), true, invalidPice)); return productDiscount; })); }