From cdc1c25040fccdf84b46250fa5ad84bb1dde252a Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 15 Feb 2017 12:54:21 +0100 Subject: SONAR-8647 Correctly detect isFavorite in filter --- .../server/component/ws/ProjectMeasuresQueryFactory.java | 3 ++- .../org/sonar/server/component/ws/SearchProjectsAction.java | 4 ++-- .../component/ws/ProjectMeasuresQueryFactoryTest.java | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'server/sonar-server/src') diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java index 54b610e6453..0be862b3473 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java @@ -51,10 +51,11 @@ class ProjectMeasuresQueryFactory { return StreamSupport.stream(CRITERIA_SPLITTER.split(filter).spliterator(), false) .filter(Objects::nonNull) .filter(criterion -> !criterion.isEmpty()) + .map(String::trim) .collect(Collectors.toList()); } - static boolean hasIsFavouriteCriterion(List criteria) { + static boolean hasIsFavoriteCriterion(List criteria) { return criteria.stream().anyMatch(IS_FAVORITE_CRITERION::equalsIgnoreCase); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 8785138925a..ab18e47eca5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -60,7 +60,7 @@ import org.sonarqube.ws.client.component.SearchProjectsRequest; import static com.google.common.base.MoreObjects.firstNonNull; import static java.lang.String.format; import static org.sonar.core.util.stream.Collectors.toSet; -import static org.sonar.server.component.ws.ProjectMeasuresQueryFactory.hasIsFavouriteCriterion; +import static org.sonar.server.component.ws.ProjectMeasuresQueryFactory.hasIsFavoriteCriterion; import static org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery; import static org.sonar.server.component.ws.ProjectMeasuresQueryFactory.toCriteria; import static org.sonar.server.measure.index.ProjectMeasuresIndex.SUPPORTED_FACETS; @@ -193,7 +193,7 @@ public class SearchProjectsAction implements ComponentsWsAction { @CheckForNull private Set buildFilterOnFavoriteProjectUuids(List criteria, Set favoriteProjectUuids) { - if (hasIsFavouriteCriterion(criteria)) { + if (hasIsFavoriteCriterion(criteria)) { return favoriteProjectUuids; } return null; diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactoryTest.java index 80679803f8e..582d23acb2c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactoryTest.java @@ -218,4 +218,17 @@ public class ProjectMeasuresQueryFactoryTest { expectedException.expectMessage("Invalid criterion 'ncloc >='"); newProjectMeasuresQuery(toCriteria("ncloc >="), emptySet()); } + + @Test + public void test_hasIsFavouriteCriterion() throws Exception { + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("isFavorite"))).isTrue(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("isFavorite "))).isTrue(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria(" isFavorite "))).isTrue(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("isFavorite and reliability_rating = 1"))).isTrue(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria(" isFavorite and reliability_rating = 1"))).isTrue(); + + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("ncloc > 10"))).isFalse(); + assertThat(ProjectMeasuresQueryFactory.hasIsFavoriteCriterion(toCriteria("ncloc > 10 and coverage <= 80"))).isFalse(); + } + } -- cgit v1.2.3