@Test public void filtersByAnyTerm() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(productModel -> productModel.allVariants().attribute().ofNumber(ATTR_NAME_SIZE).isIn(asList(valueOf(36), valueOf(38)))); testResultIds(search, resultIds -> assertThat(resultIds).containsOnly(product1.getId(), product2.getId())); }
@Test public void filterByEvilCharacterWord() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(productModel -> productModel.allVariants().attribute().ofString(ATTR_NAME_EVIL).is(EVIL_CHARACTER_WORD)); assertEventually(Duration.ofSeconds(60), Duration.ofMillis(200), () -> { final PagedSearchResult<ProductProjection> result = executeEvilSearch(search); assertThat(result.getTotal()).as("total").isEqualTo(1); }); }
@Test public void filtersByAllRanges() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(productModel -> productModel.allVariants().attribute().ofNumber(ATTR_NAME_SIZE).isBetweenAll(asList(atLeast(valueOf(39)), atMost(valueOf(43))))); testResultIds(search, resultIds -> assertThat(resultIds).containsOnly(product3.getId())); }
@Test public void onNumberAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofNumber(ATTR_NAME_NUMBER).is(NUMBER_5), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onBooleanSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofBooleanSet(ATTR_NAME_BOOLEAN_SET).is(false), ids -> assertThat(ids).containsOnly(product1.getId())); }
@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 onNumberSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofNumberSet(ATTR_NAME_NUMBER_SET).is(NUMBER_10), 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 onDateTimeRangedSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofDateTimeSet(ATTR_NAME_DATE_TIME_SET).isGreaterThanOrEqualTo(DATE_TIME_2002_23H), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void filtersByRange() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(productModel -> productModel.allVariants().attribute().ofNumber(ATTR_NAME_SIZE).isGreaterThanOrEqualTo(valueOf(44))); testResultIds(search, resultIds -> assertThat(resultIds).containsOnly(product1.getId(), product2.getId())); }
@Test public void onMoneyAmountAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofMoney(ATTR_NAME_MONEY).centAmount().is(toCents(MONEY_500_EUR)), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onReferenceAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofReference(ATTR_NAME_REF).id().is(productA.getId()), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void filtersByTerm() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(productModel -> productModel.allVariants().attribute().ofString(ATTR_NAME_COLOR).is("red")); testResultIds(search, resultIds -> assertThat(resultIds).containsOnly(product2.getId())); }
@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 onReferenceSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofReferenceSet(ATTR_NAME_REF_SET).id().is(productB.getId()), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onMoneyAmountSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofMoneySet(ATTR_NAME_MONEY_SET).centAmount().is(toCents(MONEY_1000_USD)), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onLocEnumLabelAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnum(ATTR_NAME_LOC_ENUM).label().locale(GERMAN).is(LOC_ENUM_TWO.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void onLocEnumLabelSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnumSet(ATTR_NAME_LOC_ENUM_SET).label().locale(GERMAN).is(LOC_ENUM_THREE.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId())); }