this.authorizationTypeSupport = authorizationTypeSupport;
}
- private static HighlightBuilder.Field createHighlighterField() {
- HighlightBuilder.Field field = new HighlightBuilder.Field(FIELD_NAME);
- field.highlighterType("fvh");
- field.matchedFields(
- Stream.concat(
- Stream.of(FIELD_NAME),
- Arrays
- .stream(NAME_ANALYZERS)
- .map(a -> a.subField(FIELD_NAME)))
- .toArray(String[]::new));
- return field;
- }
-
- public ComponentIndexResults search(ComponentIndexQuery query) {
- return search(query, ComponentTextSearchFeatureRepertoire.values());
+ public ComponentIndexResults searchSuggestions(SuggestionQuery query) {
+ return searchSuggestions(query, ComponentTextSearchFeatureRepertoire.values());
}
@VisibleForTesting
- ComponentIndexResults search(ComponentIndexQuery query, ComponentTextSearchFeature... features) {
+ ComponentIndexResults searchSuggestions(SuggestionQuery query, ComponentTextSearchFeature... features) {
Collection<String> qualifiers = query.getQualifiers();
if (qualifiers.isEmpty()) {
return ComponentIndexResults.newBuilder().build();
return aggregationsToQualifiers(response);
}
- private static FiltersAggregationBuilder createAggregation(ComponentIndexQuery query) {
+ private static HighlightBuilder.Field createHighlighterField() {
+ HighlightBuilder.Field field = new HighlightBuilder.Field(FIELD_NAME);
+ field.highlighterType("fvh");
+ field.matchedFields(
+ Stream.concat(
+ Stream.of(FIELD_NAME),
+ Arrays
+ .stream(NAME_ANALYZERS)
+ .map(a -> a.subField(FIELD_NAME)))
+ .toArray(String[]::new));
+ return field;
+ }
+
+ private static FiltersAggregationBuilder createAggregation(SuggestionQuery query) {
return AggregationBuilders.filters(
FILTERS_AGGREGATION_NAME,
query.getQualifiers().stream().map(q -> new KeyedFilter(q, termQuery(FIELD_QUALIFIER, q))).toArray(KeyedFilter[]::new))
.subAggregation(createSubAggregation(query));
}
- private static TopHitsAggregationBuilder createSubAggregation(ComponentIndexQuery query) {
+ private static TopHitsAggregationBuilder createSubAggregation(SuggestionQuery query) {
return AggregationBuilders.topHits(DOCS_AGGREGATION_NAME)
.highlighter(new HighlightBuilder()
.encoder("html")
.fetchSource(false);
}
- private QueryBuilder createQuery(ComponentIndexQuery query, ComponentTextSearchFeature... features) {
+ private QueryBuilder createQuery(SuggestionQuery query, ComponentTextSearchFeature... features) {
BoolQueryBuilder esQuery = boolQuery();
esQuery.filter(authorizationTypeSupport.createQueryFilter());
ComponentTextSearchQuery componentTextSearchQuery = ComponentTextSearchQuery.builder()
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.component.index;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Objects.requireNonNull;
-
-public class ComponentIndexQuery {
-
- public static final int DEFAULT_LIMIT = 6;
-
- private final String query;
- private final Collection<String> qualifiers;
- private final Set<String> recentlyBrowsedKeys;
- private final Set<String> favoriteKeys;
- private final int skip;
- private final int limit;
-
- private ComponentIndexQuery(Builder builder) {
- this.query = requireNonNull(builder.query);
- this.qualifiers = requireNonNull(builder.qualifiers);
- this.recentlyBrowsedKeys = requireNonNull(builder.recentlyBrowsedKeys);
- this.favoriteKeys = requireNonNull(builder.favoriteKeys);
- this.skip = builder.skip;
- this.limit = builder.limit;
- }
-
- public Collection<String> getQualifiers() {
- return qualifiers;
- }
-
- public String getQuery() {
- return query;
- }
-
- public Set<String> getRecentlyBrowsedKeys() {
- return recentlyBrowsedKeys;
- }
-
- public int getSkip() {
- return skip;
- }
-
- public int getLimit() {
- return limit;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Set<String> getFavoriteKeys() {
- return favoriteKeys;
- }
-
- public static class Builder {
- private String query;
- private Collection<String> qualifiers = Collections.emptyList();
- private Set<String> recentlyBrowsedKeys = Collections.emptySet();
- private Set<String> favoriteKeys = Collections.emptySet();
- private int skip = 0;
- private int limit = DEFAULT_LIMIT;
-
- private Builder() {
- }
-
- public Builder setQuery(String query) {
- checkArgument(query.length() >= 2, "Query must be at least two characters long: %s", query);
- this.query = query;
- return this;
- }
-
- public Builder setQualifiers(Collection<String> qualifiers) {
- this.qualifiers = Collections.unmodifiableCollection(qualifiers);
- return this;
- }
-
- public Builder setRecentlyBrowsedKeys(Set<String> recentlyBrowsedKeys) {
- this.recentlyBrowsedKeys = Collections.unmodifiableSet(recentlyBrowsedKeys);
- return this;
- }
-
- public Builder setFavoriteKeys(Set<String> favoriteKeys) {
- this.favoriteKeys = Collections.unmodifiableSet(favoriteKeys);
- return this;
- }
-
- public Builder setSkip(int skip) {
- checkArgument(limit > 0, "Skip has to be strictly positive: %s", limit);
- this.skip = skip;
- return this;
- }
-
- public Builder setLimit(int limit) {
- checkArgument(limit > 0, "Limit has to be strictly positive: %s", limit);
- this.limit = limit;
- return this;
- }
-
- public ComponentIndexQuery build() {
- return new ComponentIndexQuery(this);
- }
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.component.index;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
+public class SuggestionQuery {
+
+ public static final int DEFAULT_LIMIT = 6;
+
+ private final String query;
+ private final Collection<String> qualifiers;
+ private final Set<String> recentlyBrowsedKeys;
+ private final Set<String> favoriteKeys;
+ private final int skip;
+ private final int limit;
+
+ private SuggestionQuery(Builder builder) {
+ this.query = requireNonNull(builder.query);
+ this.qualifiers = requireNonNull(builder.qualifiers);
+ this.recentlyBrowsedKeys = requireNonNull(builder.recentlyBrowsedKeys);
+ this.favoriteKeys = requireNonNull(builder.favoriteKeys);
+ this.skip = builder.skip;
+ this.limit = builder.limit;
+ }
+
+ public Collection<String> getQualifiers() {
+ return qualifiers;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public Set<String> getRecentlyBrowsedKeys() {
+ return recentlyBrowsedKeys;
+ }
+
+ public int getSkip() {
+ return skip;
+ }
+
+ public int getLimit() {
+ return limit;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public Set<String> getFavoriteKeys() {
+ return favoriteKeys;
+ }
+
+ public static class Builder {
+ private String query;
+ private Collection<String> qualifiers = Collections.emptyList();
+ private Set<String> recentlyBrowsedKeys = Collections.emptySet();
+ private Set<String> favoriteKeys = Collections.emptySet();
+ private int skip = 0;
+ private int limit = DEFAULT_LIMIT;
+
+ private Builder() {
+ }
+
+ public Builder setQuery(String query) {
+ checkArgument(query.length() >= 2, "Query must be at least two characters long: %s", query);
+ this.query = query;
+ return this;
+ }
+
+ public Builder setQualifiers(Collection<String> qualifiers) {
+ this.qualifiers = Collections.unmodifiableCollection(qualifiers);
+ return this;
+ }
+
+ public Builder setRecentlyBrowsedKeys(Set<String> recentlyBrowsedKeys) {
+ this.recentlyBrowsedKeys = Collections.unmodifiableSet(recentlyBrowsedKeys);
+ return this;
+ }
+
+ public Builder setFavoriteKeys(Set<String> favoriteKeys) {
+ this.favoriteKeys = Collections.unmodifiableSet(favoriteKeys);
+ return this;
+ }
+
+ public Builder setSkip(int skip) {
+ checkArgument(limit > 0, "Skip has to be strictly positive: %s", limit);
+ this.skip = skip;
+ return this;
+ }
+
+ public Builder setLimit(int limit) {
+ checkArgument(limit > 0, "Limit has to be strictly positive: %s", limit);
+ this.limit = limit;
+ return this;
+ }
+
+ public SuggestionQuery build() {
+ return new SuggestionQuery(this);
+ }
+ }
+}
import org.sonar.server.component.index.ComponentHit;
import org.sonar.server.component.index.ComponentHitsPerQualifier;
import org.sonar.server.component.index.ComponentIndex;
-import org.sonar.server.component.index.ComponentIndexQuery;
+import org.sonar.server.component.index.SuggestionQuery;
import org.sonar.server.component.index.ComponentIndexResults;
import org.sonar.server.es.DefaultIndexSettings;
import org.sonar.server.favorite.FavoriteFinder;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
-import static org.sonar.server.component.index.ComponentIndexQuery.DEFAULT_LIMIT;
+import static org.sonar.server.component.index.SuggestionQuery.DEFAULT_LIMIT;
import static org.sonar.server.es.DefaultIndexSettings.MINIMUM_NGRAM_LENGTH;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.WsComponents.SuggestionsWsResponse.Organization;
List<ComponentDto> favorites = favoriteFinder.list();
Set<String> favoriteKeys = favorites.stream().map(ComponentDto::getDbKey).collect(MoreCollectors.toSet(favorites.size()));
- ComponentIndexQuery.Builder queryBuilder = ComponentIndexQuery.builder()
+ SuggestionQuery.Builder queryBuilder = SuggestionQuery.builder()
.setQuery(query)
.setRecentlyBrowsedKeys(recentlyBrowsedKeys)
.setFavoriteKeys(favoriteKeys)
.collect(MoreCollectors.uniqueIndex(OrganizationDto::getUuid));
}
- private ComponentIndexResults searchInIndex(ComponentIndexQuery componentIndexQuery) {
- return index.search(componentIndexQuery);
+ private ComponentIndexResults searchInIndex(SuggestionQuery suggestionQuery) {
+ return index.searchSuggestions(suggestionQuery);
}
private static SuggestionsWsResponse.Builder toResponse(ComponentIndexResults componentsPerQualifiers, Set<String> recentlyBrowsedKeys, Set<String> favoriteUuids,
public void return_empty_list_if_no_fields_match_query() {
indexProject("struts", "Apache Struts");
- assertThat(index.search(ComponentIndexQuery.builder().setQuery("missing").build()).isEmpty()).isTrue();
+ assertThat(index.searchSuggestions(SuggestionQuery.builder().setQuery("missing").build()).isEmpty()).isTrue();
}
@Test
ComponentDto project = indexProject("struts", "Apache Struts");
indexFile(project, "src/main/java/StrutsManager.java", "StrutsManager.java");
- assertSearchResults(ComponentIndexQuery.builder().setQuery("struts").setQualifiers(singletonList(Qualifiers.PROJECT)).build(), project);
+ assertSearchResults(SuggestionQuery.builder().setQuery("struts").setQualifiers(singletonList(Qualifiers.PROJECT)).build(), project);
}
@Test
public void should_limit_the_number_of_results() {
IntStream.rangeClosed(0, 10).forEach(i -> indexProject("sonarqube" + i, "SonarQube" + i));
- assertSearch(ComponentIndexQuery.builder().setQuery("sonarqube").setLimit(5).setQualifiers(singletonList(Qualifiers.PROJECT)).build()).hasSize(5);
+ assertSearch(SuggestionQuery.builder().setQuery("sonarqube").setLimit(5).setQualifiers(singletonList(Qualifiers.PROJECT)).build()).hasSize(5);
}
@Test
ComponentDto project1 = indexProject("project1", "LongNameLongNameLongNameLongNameSonarQube");
ComponentDto project2 = indexProject("project2", "LongNameLongNameLongNameLongNameSonarQubeX");
- ComponentIndexQuery query1 = ComponentIndexQuery.builder()
+ SuggestionQuery query1 = SuggestionQuery.builder()
.setQuery("LongNameLongNameLongNameLongNameSonarQube")
.setQualifiers(Collections.singletonList(PROJECT))
.build();
ComponentDto project1 = indexProject("sonarqube", "SonarQube");
ComponentDto project2 = indexProject("recent", "SonarQube Recently");
- ComponentIndexQuery query1 = ComponentIndexQuery.builder()
+ SuggestionQuery query1 = SuggestionQuery.builder()
.setQuery("SonarQube")
.setQualifiers(singletonList(PROJECT))
.setFavoriteKeys(of(project1.getDbKey()))
.build();
assertSearch(query1).containsExactly(uuids(project1, project2));
- ComponentIndexQuery query2 = ComponentIndexQuery.builder()
+ SuggestionQuery query2 = SuggestionQuery.builder()
.setQuery("SonarQube")
.setQualifiers(singletonList(PROJECT))
.setFavoriteKeys(of(project2.getDbKey()))
features.set(q -> termQuery(FIELD_KEY, "non-existing-value"), ComponentTextSearchFeatureRepertoire.FAVORITE);
ComponentDto project1 = indexProject("foo", "foo");
- ComponentIndexQuery query1 = ComponentIndexQuery.builder()
+ SuggestionQuery query1 = SuggestionQuery.builder()
.setQuery("bar")
.setQualifiers(singletonList(PROJECT))
.setFavoriteKeys(of(project1.getDbKey()))
ComponentDto project1 = indexProject("sonarqube", "SonarQube");
ComponentDto project2 = indexProject("recent", "SonarQube Recently");
- ComponentIndexQuery query1 = ComponentIndexQuery.builder()
+ SuggestionQuery query1 = SuggestionQuery.builder()
.setQuery("SonarQube")
.setQualifiers(Collections.singletonList(PROJECT))
.setRecentlyBrowsedKeys(of(project1.getDbKey()))
.build();
assertSearch(query1).containsExactly(uuids(project1, project2));
- ComponentIndexQuery query2 = ComponentIndexQuery.builder()
+ SuggestionQuery query2 = SuggestionQuery.builder()
.setQuery("SonarQube")
.setQualifiers(Collections.singletonList(PROJECT))
.setRecentlyBrowsedKeys(of(project2.getDbKey()))
private void assertHighlighting(String fileName, String search, String expectedHighlighting) {
indexFile(fileName);
- ComponentIndexQuery query = ComponentIndexQuery.builder()
+ SuggestionQuery query = SuggestionQuery.builder()
.setQuery(search)
.setQualifiers(Collections.singletonList(Qualifiers.FILE))
.build();
- Stream<ComponentHitsPerQualifier> results = index.search(query, features.get()).getQualifiers();
+ Stream<ComponentHitsPerQualifier> results = index.searchSuggestions(query, features.get()).getQualifiers();
assertThat(results).flatExtracting(ComponentHitsPerQualifier::getHits)
.extracting(ComponentHit::getHighlightedText)
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.component.index;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ComponentIndexQueryTest {
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Test
- public void should_fail_with_IAE_if_query_is_empty() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Query must be at least two characters long");
-
- ComponentIndexQuery.builder().setQuery("");
- }
-
- @Test
- public void should_fail_with_IAE_if_query_is_one_character_long() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Query must be at least two characters long");
-
- ComponentIndexQuery.builder().setQuery("a");
- }
-
- @Test
- public void should_support_query_with_two_characters_long() {
- ComponentIndexQuery query = ComponentIndexQuery.builder().setQuery("ab").build();
-
- assertThat(query.getQuery()).isEqualTo("ab");
- }
-
- @Test
- public void should_fail_with_IAE_if_limit_is_negative() {
- ComponentIndexQuery.Builder query = ComponentIndexQuery.builder().setQuery("ab");
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Limit has to be strictly positive");
-
- query.setLimit(-1);
- }
-
- @Test
- public void should_fail_with_IAE_if_limit_is_zero() {
- ComponentIndexQuery.Builder query = ComponentIndexQuery.builder().setQuery("ab");
-
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Limit has to be strictly positive");
-
- query.setLimit(0);
- }
-
- @Test
- public void should_support_positive_limit() {
- ComponentIndexQuery query = ComponentIndexQuery.builder().setQuery("ab")
- .setLimit(1).build();
-
- assertThat(query.getLimit()).isEqualTo(1);
- }
-}
ComponentDto file2 = db.components().insertPrivateProject(c -> c.setName("File2"));
index(file2);
- assertSearch(ComponentIndexQuery.builder()
+ assertSearch(SuggestionQuery.builder()
.setQuery("File")
.setQualifiers(asList(PROJECT, MODULE, FILE))
.setRecentlyBrowsedKeys(ImmutableSet.of(file1.getDbKey()))
.setFavoriteKeys(ImmutableSet.of(file2.getDbKey()))
.build()).containsExactly(uuids(file2, file1));
- assertSearch(ComponentIndexQuery.builder()
+ assertSearch(SuggestionQuery.builder()
.setQuery("File")
.setQualifiers(asList(PROJECT, MODULE, FILE))
.setRecentlyBrowsedKeys(ImmutableSet.of(file2.getDbKey()))
}
protected AbstractListAssert<?, ? extends List<? extends String>, String> assertSearch(String query) {
- return assertSearch(ComponentIndexQuery.builder().setQuery(query).setQualifiers(asList(PROJECT, MODULE, FILE)).build());
+ return assertSearch(SuggestionQuery.builder().setQuery(query).setQualifiers(asList(PROJECT, MODULE, FILE)).build());
}
- protected AbstractListAssert<?, ? extends List<? extends String>, String> assertSearch(ComponentIndexQuery query) {
- return assertThat(index.search(query, features.get()).getQualifiers())
+ protected AbstractListAssert<?, ? extends List<? extends String>, String> assertSearch(SuggestionQuery query) {
+ return assertThat(index.searchSuggestions(query, features.get()).getQualifiers())
.flatExtracting(ComponentHitsPerQualifier::getHits)
.extracting(ComponentHit::getUuid);
}
protected void assertSearchResults(String query, ComponentDto... expectedComponents) {
- assertSearchResults(ComponentIndexQuery.builder().setQuery(query).setQualifiers(asList(PROJECT, MODULE, FILE)).build(), expectedComponents);
+ assertSearchResults(SuggestionQuery.builder().setQuery(query).setQualifiers(asList(PROJECT, MODULE, FILE)).build(), expectedComponents);
}
- protected void assertSearchResults(ComponentIndexQuery query, ComponentDto... expectedComponents) {
+ protected void assertSearchResults(SuggestionQuery query, ComponentDto... expectedComponents) {
assertSearch(query).containsOnly(uuids(expectedComponents));
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.component.index;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SuggestionQueryTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void should_fail_with_IAE_if_query_is_empty() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Query must be at least two characters long");
+
+ SuggestionQuery.builder().setQuery("");
+ }
+
+ @Test
+ public void should_fail_with_IAE_if_query_is_one_character_long() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Query must be at least two characters long");
+
+ SuggestionQuery.builder().setQuery("a");
+ }
+
+ @Test
+ public void should_support_query_with_two_characters_long() {
+ SuggestionQuery query = SuggestionQuery.builder().setQuery("ab").build();
+
+ assertThat(query.getQuery()).isEqualTo("ab");
+ }
+
+ @Test
+ public void should_fail_with_IAE_if_limit_is_negative() {
+ SuggestionQuery.Builder query = SuggestionQuery.builder().setQuery("ab");
+
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Limit has to be strictly positive");
+
+ query.setLimit(-1);
+ }
+
+ @Test
+ public void should_fail_with_IAE_if_limit_is_zero() {
+ SuggestionQuery.Builder query = SuggestionQuery.builder().setQuery("ab");
+
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Limit has to be strictly positive");
+
+ query.setLimit(0);
+ }
+
+ @Test
+ public void should_support_positive_limit() {
+ SuggestionQuery query = SuggestionQuery.builder().setQuery("ab")
+ .setLimit(1).build();
+
+ assertThat(query.getLimit()).isEqualTo(1);
+ }
+}