@Test public void queryByRole() { final ChannelRole channelRole = ChannelRole.PRODUCT_DISTRIBUTION; withChannelOfRole(client(), channelRole, channel -> { final ChannelQuery query = ChannelQuery.of() .plusPredicates(m -> m.roles().containsAny(singleton(channelRole))) .plusPredicates(m -> m.is(channel)); final List<Channel> results = client().executeBlocking(query).getResults(); assertThat(results).hasSize(1); }); }
@Test public void queryByGeoLocation() { final Point geoLocation = Point.of(52.0, 40.0); final ChannelDraft channelDraft = ChannelDraft.of(randomKey()) .withGeoLocation(geoLocation); withChannel(client(), channelDraft, channel -> { final ChannelQuery withinCircleQuery = ChannelQuery.of() .plusPredicates(m -> m.is(channel)) .plusPredicates(m -> m.geoLocation().withinCircle(geoLocation, 1.0)); final List<Channel> withinCircleResults = client().executeBlocking(withinCircleQuery).getResults(); assertThat(withinCircleResults).hasSize(1); assertThat(withinCircleResults.get(0)).isEqualTo(channel); final ChannelQuery isPresentQuery = ChannelQuery.of() .plusPredicates(m -> m.is(channel)) .plusPredicates(m -> m.geoLocation().isPresent()); final List<Channel> isPresentResults = client().executeBlocking(isPresentQuery).getResults(); assertThat(isPresentResults).hasSize(1); assertThat(isPresentResults.get(0)).isEqualTo(channel); }); } }
@Test public void queryByNameAndDescription() { final LocalizedString name = randomSlug(); final LocalizedString description = randomSlug(); final ChannelDraft channelDraft = ChannelDraft.of(randomKey()) .withName(name) .withDescription(description); withChannel(client(), channelDraft, channel -> { final ChannelQuery query = ChannelQuery.of() .plusPredicates(m -> m.is(channel)) .plusPredicates(m -> m.name().locale(ENGLISH).is(name.get(ENGLISH))) .plusPredicates(m -> m.description().locale(ENGLISH).is(description.get(ENGLISH))); final List<Channel> results = client().executeBlocking(query).getResults(); assertThat(results).hasSize(1); }); }
@Test public void queryByReviewRating() { withChannelOfRole(client(), ChannelRole.PRIMARY , channel -> { withReview(client(), b -> b.target(channel).rating(1), review1 -> { withReview(client(), b -> b.target(channel).rating(3), review2 -> { final ChannelQuery query = ChannelQuery.of() .withPredicates(m -> m.reviewRatingStatistics().averageRating().is(2.0)) .plusPredicates(m -> m.reviewRatingStatistics().count().is(2)) .plusPredicates(m -> m.is(channel)); assertEventually(() -> { final List<Channel> results = client().executeBlocking(query).getResults(); assertThat(results).hasSize(1); final Channel loadedChannel = results.get(0); assertThat(loadedChannel.getId()).isEqualTo(channel.getId()); assertThat(loadedChannel.getReviewRatingStatistics().getCount()).isEqualTo(2); }); }); }); }); }