@Test public void buildsTermFacetExpressionWithAlias() throws Exception { final TermFacetExpression<Object> facet = TermFacetExpression.of(ATTRIBUTE_PATH + AS_ALIAS); assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH + AS_ALIAS); assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH); assertThat(facet.value()).isNull(); assertThat(facet.alias()).isEqualTo(ALIAS); assertThat(facet.resultPath()).isEqualTo(ALIAS); }
@Test public void buildsTermFacetExpressionWithAlias() throws Exception { final TermFacetExpression<Object> facet = TermFacetSearchModel.of(ATTRIBUTE_PATH, ofString()).withAlias(ALIAS).allTerms(); assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH + AS_ALIAS); assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH); assertThat(facet.value()).isNull(); assertThat(facet.alias()).isEqualTo(ALIAS); assertThat(facet.resultPath()).isEqualTo(ALIAS); }
@Test public void usesAlias() throws Exception { final RangeTermFacetSearchModel<ProductProjection, BigDecimal> path = FACET_ATTR.ofNumber("size"); assertThat(path.withAlias("my-facet").allTerms().expression()).isEqualTo("variants.attributes.size as my-facet"); assertThat(path.withAlias("my-facet").onlyTerm(valueOf(38)).expression()).isEqualTo("variants.attributes.size:38 as my-facet"); assertThat(path.withAlias("my-facet").onlyLessThan(valueOf(38)).expression()).isEqualTo("variants.attributes.size:range(* to 38) as my-facet"); }
@Test public void buildsTermFacetExpression() throws Exception { final TermFacetExpression<Object> facet = TermFacetSearchModel.of(ATTRIBUTE_PATH, ofString()).allTerms(); assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH); assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH); assertThat(facet.value()).isNull(); assertThat(facet.alias()).isNull(); assertThat(facet.resultPath()).isEqualTo(ATTRIBUTE_PATH); }
@Test public void canAccessNumberCustomAttributes() throws Exception { final String attrName = "length"; assertThat(FACET_ATTR.ofNumber(attrName).allTerms().expression()).isEqualTo("variants.attributes.length"); assertThat(FILTER_ATTR.ofNumber(attrName).is(valueOf(4))).extracting(expression()).containsExactly("variants.attributes.length:4"); assertThat(SORT_ATTR.ofNumber(attrName).descWithMinValue().expression()).isEqualTo("variants.attributes.length desc.min"); }
@Test public void canAccessTextCustomAttributes() throws Exception { final String attrName = "brand"; assertThat(FACET_ATTR.ofString(attrName).allTerms().expression()).isEqualTo("variants.attributes.brand"); assertThat(FILTER_ATTR.ofString(attrName).is("Apple")).extracting(expression()).containsExactly("variants.attributes.brand:\"Apple\""); assertThat(SORT_ATTR.ofString(attrName).ascWithMaxValue().expression()).isEqualTo("variants.attributes.brand asc.max"); }
@Test public void canCreateDateTimeAttributeExpressions() throws Exception { final String attrName = "createdDate"; assertThat(FACET_ATTR.ofDateTime(attrName).allTerms().expression()).isEqualTo("variants.attributes.createdDate"); assertThat(FILTER_ATTR.ofDateTime(attrName).is(dateTime("2001-09-11T22:05:09.203+00:00"))).extracting(expression()).containsExactly("variants.attributes.createdDate:\"2001-09-11T22:05:09.203Z\""); assertThat(SORT_ATTR.ofDateTime(attrName).ascWithMaxValue().expression()).isEqualTo("variants.attributes.createdDate asc.max"); }
@Test public void canAccessLastModifiedAt() throws Exception { assertThat(FACET_MODEL.lastModifiedAt().allTerms().expression()).isEqualTo("lastModifiedAt"); assertThat(FILTER_MODEL.lastModifiedAt().is(dateTime("2001-09-11T22:05:09.203+00:00"))).extracting(expression()).containsExactly("lastModifiedAt:\"2001-09-11T22:05:09.203Z\""); assertThat(SORT_MODEL.lastModifiedAt().asc().expression()).isEqualTo("lastModifiedAt asc"); }
@Test public void canCreateDateAttributeExpressions() throws Exception { final String attrName = "expirationDate"; assertThat(FACET_ATTR.ofDate(attrName).allTerms().expression()).isEqualTo("variants.attributes.expirationDate"); assertThat(FILTER_ATTR.ofDate(attrName).is(date("2001-09-11"))).extracting(expression()).containsExactly("variants.attributes.expirationDate:\"2001-09-11\""); assertThat(SORT_ATTR.ofDateTime(attrName).ascWithMaxValue().expression()).isEqualTo("variants.attributes.expirationDate asc.max"); }
@Test public void canAccessReferenceCustomAttributes() throws Exception { final String attrName = "recommendedProduct"; assertThat(FACET_ATTR.ofReference(attrName).id().allTerms().expression()).isEqualTo("variants.attributes.recommendedProduct.id"); assertThat(FILTER_ATTR.ofReference(attrName).id().is("some-id")).extracting(expression()).containsExactly("variants.attributes.recommendedProduct.id:\"some-id\""); }
@Test public void canAccessEnumLabelCustomAttributes() throws Exception { final String attrName = "originCountry"; assertThat(FACET_ATTR.ofEnum(attrName).label().allTerms().expression()).isEqualTo("variants.attributes.originCountry.label"); assertThat(FILTER_ATTR.ofEnum(attrName).label().is("Italy")).extracting(expression()).containsExactly("variants.attributes.originCountry.label:\"Italy\""); assertThat(SORT_ATTR.ofEnum(attrName).label().ascWithMaxValue().expression()).isEqualTo("variants.attributes.originCountry.label asc.max"); }
@Test public void canAccessProductType() throws Exception { assertThat(FACET_MODEL.productType().id().allTerms().expression()).isEqualTo("productType.id"); assertThat(FILTER_MODEL.productType().id().is("some-id")).extracting(expression()).containsExactly("productType.id:\"some-id\""); }
@Test public void canAccessLocTextCustomAttributes() throws Exception { final String attrName = "material"; assertThat(FACET_ATTR.ofLocalizedString(attrName).locale(ENGLISH).allTerms().expression()).isEqualTo("variants.attributes.material.en"); assertThat(FILTER_ATTR.ofLocalizedString(attrName).locale(ENGLISH).is("steel")).extracting(expression()).containsExactly("variants.attributes.material.en:\"steel\""); assertThat(SORT_ATTR.ofLocalizedString(attrName).locale(ENGLISH).descWithMinValue().expression()).isEqualTo("variants.attributes.material.en desc.min"); }
@Test public void canAccessEnumKeyCustomAttributes() throws Exception { final String attrName = "originCountry"; assertThat(FACET_ATTR.ofEnum(attrName).key().allTerms().expression()).isEqualTo("variants.attributes.originCountry.key"); assertThat(FILTER_ATTR.ofEnum(attrName).key().is("Italy")).extracting(expression()).containsExactly("variants.attributes.originCountry.key:\"Italy\""); assertThat(SORT_ATTR.ofEnum(attrName).key().descWithMinValue().expression()).isEqualTo("variants.attributes.originCountry.key desc.min"); }
@Test public void canAccessMoneyCentAmountCustomAttributes() throws Exception { final String attrName = "originalPrice"; assertThat(FACET_ATTR.ofMoney(attrName).centAmount().allTerms().expression()).isEqualTo("variants.attributes.originalPrice.centAmount"); assertThat(FILTER_ATTR.ofMoney(attrName).centAmount().is(1000L)).extracting(expression()).containsExactly("variants.attributes.originalPrice.centAmount:1000"); assertThat(SORT_ATTR.ofMoney(attrName).centAmount().ascWithMaxValue().expression()).isEqualTo("variants.attributes.originalPrice.centAmount asc.max"); }
@Test public void canAccessScopedPriceDiscounted() throws Exception { assertThat(FACET_MODEL.allVariants().scopedPriceDiscounted().allTerms().expression()).isEqualTo("variants.scopedPriceDiscounted"); assertThat(FILTER_MODEL.allVariants().scopedPriceDiscounted().is(true)).extracting(expression()).containsExactly("variants.scopedPriceDiscounted:true"); assertThat(SORT_MODEL.allVariants().scopedPriceDiscounted().asc().expression()).isEqualTo("variants.scopedPriceDiscounted asc"); }
@Test public void canAccessLocEnumKeyCustomAttributes() throws Exception { final String attrName = "color"; assertThat(FACET_ATTR.ofLocalizedEnum(attrName).key().allTerms().expression()).isEqualTo("variants.attributes.color.key"); assertThat(FILTER_ATTR.ofLocalizedEnum(attrName).key().is("ROT")).extracting(expression()).containsExactly("variants.attributes.color.key:\"ROT\""); assertThat(SORT_ATTR.ofLocalizedEnum(attrName).key().descWithMinValue().expression()).isEqualTo("variants.attributes.color.key desc.min"); }
@Test public void canAccessCurrencyCustomAttributes() throws Exception { final String attrName = "originalPrice"; assertThat(FACET_ATTR.ofMoney(attrName).currency().allTerms().expression()).isEqualTo("variants.attributes.originalPrice.currencyCode"); assertThat(FILTER_ATTR.ofMoney(attrName).currency().is(currency("EUR"))).extracting(expression()).containsExactly("variants.attributes.originalPrice.currencyCode:\"EUR\""); assertThat(SORT_ATTR.ofMoney(attrName).currency().descWithMinValue().expression()).isEqualTo("variants.attributes.originalPrice.currencyCode desc.min"); }
@Test public void canAccessPriceAmount() throws Exception { assertThat(FACET_MODEL.allVariants().price().centAmount().allTerms().expression()).isEqualTo("variants.price.centAmount"); assertThat(FILTER_MODEL.allVariants().price().centAmount().is(1000L)).extracting(expression()).containsExactly("variants.price.centAmount:1000"); assertThat(SORT_MODEL.allVariants().price().descWithMinValue().expression()).isEqualTo("price desc.min"); }
@Test public void canAccessPriceCurrency() throws Exception { assertThat(FACET_MODEL.allVariants().price().currency().allTerms().expression()).isEqualTo("variants.price.currencyCode"); assertThat(FILTER_MODEL.allVariants().price().currency().is(currency("EUR"))).extracting(expression()).containsExactly("variants.price.currencyCode:\"EUR\""); }