From 39338ec2574ab8c019a4baa0385a7dbc795c988c Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 10 Nov 2016 08:30:05 +0100 Subject: [PATCH] SONAR-8377 Remove WS / startup registration on issue filters --- .../issue/InternalRubyIssueService.java | 199 +---- .../sonar/server/issue/filter/AppAction.java | 95 --- .../server/issue/filter/FavoritesAction.java | 67 -- .../issue/filter/IssueFilterJsonWriter.java | 65 -- .../issue/filter/IssueFilterSerializer.java | 102 --- .../issue/filter/IssueFilterService.java | 373 ---------- .../issue/filter/IssueFilterWithFavorite.java | 42 -- .../server/issue/filter/IssueFilterWs.java | 43 -- .../issue/filter/IssueFilterWsAction.java | 26 - .../issue/filter/IssueFilterWsModule.java | 38 - .../issue/filter/RegisterIssueFilters.java | 97 --- .../server/issue/filter/SearchAction.java | 125 ---- .../sonar/server/issue/filter/ShowAction.java | 65 -- .../server/issue/filter/package-info.java | 23 - .../platformlevel/PlatformLevel4.java | 3 - .../platformlevel/PlatformLevelStartup.java | 2 - .../server/issue/filter/example-app.json | 23 - .../server/issue/filter/example-show.json | 10 - .../issue/filter/favorites-example.json | 19 - .../server/issue/filter/search-example.json | 40 - .../issue/InternalRubyIssueServiceTest.java | 268 +------ .../server/issue/filter/AppActionTest.java | 100 --- .../issue/filter/FavoritesActionTest.java | 76 -- .../filter/IssueFilterJsonWriterTest.java | 110 --- .../filter/IssueFilterSerializerTest.java | 85 --- .../issue/filter/IssueFilterServiceTest.java | 699 ------------------ .../issue/filter/IssueFilterWsModuleTest.java | 34 - .../issue/filter/IssueFilterWsTest.java | 77 -- .../filter/RegisterIssueFiltersTest.java | 72 -- .../server/issue/filter/SearchActionTest.java | 120 --- .../server/issue/filter/ShowActionTest.java | 81 -- .../filter/AppActionTest/anonymous_page.json | 4 - .../filter/AppActionTest/logged_in_page.json | 5 - .../logged_in_page_with_favorites.json | 14 - .../logged_in_page_with_selected_filter.json | 14 - .../selected_filter_can_not_be_modified.json | 14 - .../do_nothing-result.xml | 18 - .../RegisterIssueFiltersTest/do_nothing.xml | 18 - .../filter/RegisterIssueFiltersTest/empty.xml | 3 - .../register-result.xml | 48 -- .../issue/filter/SearchActionTest/search.json | 36 - .../filter/ShowActionTest/show_filter.json | 11 - .../app/controllers/issues_controller.rb | 6 +- 43 files changed, 14 insertions(+), 3356 deletions(-) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/AppAction.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/FavoritesAction.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterJsonWriter.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterSerializer.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterService.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWithFavorite.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWs.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsAction.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsModule.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/RegisterIssueFilters.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/SearchAction.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/ShowAction.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/issue/filter/package-info.java delete mode 100644 server/sonar-server/src/main/resources/org/sonar/server/issue/filter/example-app.json delete mode 100644 server/sonar-server/src/main/resources/org/sonar/server/issue/filter/example-show.json delete mode 100644 server/sonar-server/src/main/resources/org/sonar/server/issue/filter/favorites-example.json delete mode 100644 server/sonar-server/src/main/resources/org/sonar/server/issue/filter/search-example.json delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/AppActionTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterJsonWriterTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterSerializerTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterServiceTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsModuleTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/RegisterIssueFiltersTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/SearchActionTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/issue/filter/ShowActionTest.java delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/anonymous_page.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page_with_favorites.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page_with_selected_filter.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/selected_filter_can_not_be_modified.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/do_nothing-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/do_nothing.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/empty.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/register-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/SearchActionTest/search.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/filter/ShowActionTest/show_filter.json diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java index df3afc34089..8d915a682e7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java @@ -20,29 +20,23 @@ package org.sonar.server.issue; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Predicate; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.util.Collection; import java.util.List; import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; import org.sonar.api.issue.Issue; import org.sonar.api.issue.IssueComment; import org.sonar.api.server.ServerSide; import org.sonar.api.web.UserRole; import org.sonar.core.issue.DefaultIssueComment; -import org.sonar.db.issue.IssueFilterDto; import org.sonar.server.es.SearchOptions; -import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.issue.filter.IssueFilterService; +import org.sonar.server.issue.index.IssueDoc; +import org.sonar.server.issue.index.IssueIndex; import org.sonar.server.issue.workflow.Transition; import org.sonar.server.search.QueryContext; import org.sonar.server.user.UserSession; import org.sonar.server.util.RubyUtils; -import org.sonar.server.util.Validation; import org.sonarqube.ws.client.issue.IssueFilterParameters; /** @@ -55,32 +49,27 @@ import org.sonarqube.ws.client.issue.IssueFilterParameters; @ServerSide public class InternalRubyIssueService { - private static final String ID_PARAM = "id"; - private static final String NAME_PARAM = "name"; - private static final String DESCRIPTION_PARAM = "description"; - private static final String USER_PARAM = "user"; - + private final IssueIndex issueIndex; private final IssueService issueService; private final IssueQueryService issueQueryService; private final IssueCommentService commentService; private final IssueChangelogService changelogService; - private final IssueFilterService issueFilterService; private final IssueBulkChangeService issueBulkChangeService; private final ActionService actionService; private final UserSession userSession; public InternalRubyIssueService( - IssueService issueService, + IssueIndex issueIndex, IssueService issueService, IssueQueryService issueQueryService, IssueCommentService commentService, IssueChangelogService changelogService, - IssueFilterService issueFilterService, IssueBulkChangeService issueBulkChangeService, + IssueBulkChangeService issueBulkChangeService, ActionService actionService, UserSession userSession) { + this.issueIndex = issueIndex; this.issueService = issueService; this.issueQueryService = issueQueryService; this.commentService = commentService; this.changelogService = changelogService; - this.issueFilterService = issueFilterService; this.issueBulkChangeService = issueBulkChangeService; this.actionService = actionService; this.userSession = userSession; @@ -154,169 +143,11 @@ public class InternalRubyIssueService { return issueQueryService.createFromMap(Maps.newHashMap()); } - @CheckForNull - public IssueFilterDto findIssueFilterById(Long id) { - return issueFilterService.findById(id); - } - - /** - * Return the issue filter if the user has the right to see it - * Never return null - */ - public IssueFilterDto findIssueFilter(Long id) { - return issueFilterService.find(id, userSession); - } - - public boolean isUserAuthorized(IssueFilterDto issueFilter) { - try { - String user = issueFilterService.getLoggedLogin(userSession); - issueFilterService.verifyCurrentUserCanReadFilter(issueFilter, user); - return true; - } catch (Exception e) { - return false; - } - } - - public boolean canUserShareIssueFilter() { - return issueFilterService.canShareFilter(userSession); - } - - public String serializeFilterQuery(Map filterQuery) { - return issueFilterService.serializeFilterQuery(filterQuery); - } - - public Map deserializeFilterQuery(IssueFilterDto issueFilter) { - return issueFilterService.deserializeIssueFilterQuery(issueFilter); - } - - public Map sanitizeFilterQuery(Map filterQuery) { - return Maps.filterEntries(filterQuery, MatchIssueFilterParameters.INSTANCE); - } - /** * Execute issue filter from parameters */ - public IssueFilterService.IssueFilterResult execute(Map props) { - return issueFilterService.execute(issueQueryService.createFromMap(props), toSearchOptions(props)); - } - - /** - * Execute issue filter from existing filter with optional overridable parameters - */ - public IssueFilterService.IssueFilterResult execute(Long issueFilterId, Map overrideProps) { - IssueFilterDto issueFilter = issueFilterService.find(issueFilterId, userSession); - Map props = issueFilterService.deserializeIssueFilterQuery(issueFilter); - overrideProps(props, overrideProps); - return execute(props); - } - - private static void overrideProps(Map props, Map overrideProps) { - for (Map.Entry entry : overrideProps.entrySet()) { - props.put(entry.getKey(), entry.getValue()); - } - } - - /** - * List user issue filter - */ - public List findIssueFiltersForCurrentUser() { - return issueFilterService.findByUser(userSession); - } - - /** - * Create issue filter - */ - public IssueFilterDto createIssueFilter(Map parameters) { - IssueFilterDto result = createIssueFilterResultForNew(parameters); - return issueFilterService.save(result, userSession); - } - - /** - * Update issue filter - */ - public IssueFilterDto updateIssueFilter(Map parameters) { - IssueFilterDto result = createIssueFilterResultForUpdate(parameters); - return issueFilterService.update(result, userSession); - } - - /** - * Update issue filter data - */ - public IssueFilterDto updateIssueFilterQuery(Long issueFilterId, Map data) { - return issueFilterService.updateFilterQuery(issueFilterId, data, userSession); - } - - /** - * Delete issue filter - */ - public void deleteIssueFilter(Long issueFilterId) { - issueFilterService.delete(issueFilterId, userSession); - } - - /** - * Copy issue filter - */ - public IssueFilterDto copyIssueFilter(Long issueFilterIdToCopy, Map parameters) { - IssueFilterDto result = createIssueFilterResultForCopy(parameters); - return issueFilterService.copy(issueFilterIdToCopy, result, userSession); - } - - @VisibleForTesting - IssueFilterDto createIssueFilterResultForNew(Map params) { - return createIssueFilterResult(params, false, false); - } - - @VisibleForTesting - IssueFilterDto createIssueFilterResultForUpdate(Map params) { - return createIssueFilterResult(params, true, true); - } - - @VisibleForTesting - IssueFilterDto createIssueFilterResultForCopy(Map params) { - return createIssueFilterResult(params, false, false); - } - - @VisibleForTesting - IssueFilterDto createIssueFilterResult(Map params, boolean checkId, boolean checkUser) { - String id = params.get(ID_PARAM); - String name = params.get(NAME_PARAM); - String description = params.get(DESCRIPTION_PARAM); - String data = params.get("data"); - String user = params.get(USER_PARAM); - Boolean sharedParam = RubyUtils.toBoolean(params.get("shared")); - boolean shared = sharedParam != null ? sharedParam : false; - - if (checkId) { - Validation.checkMandatoryParameter(id, ID_PARAM); - } - if (checkUser) { - Validation.checkMandatoryParameter(user, USER_PARAM); - } - Validation.checkMandatorySizeParameter(name, NAME_PARAM, 100); - checkOptionalSizeParameter(description, DESCRIPTION_PARAM, 4000); - - IssueFilterDto issueFilterDto = new IssueFilterDto() - .setName(name) - .setDescription(description) - .setShared(shared) - .setUserLogin(user) - .setData(data); - if (!Strings.isNullOrEmpty(id)) { - issueFilterDto.setId(Long.valueOf(id)); - } - return issueFilterDto; - } - - public List findSharedFiltersForCurrentUser() { - return issueFilterService.findSharedFiltersWithoutUserFilters(userSession); - } - - public List findFavouriteIssueFiltersForCurrentUser() { - return issueFilterService.findFavoriteFilters(userSession); - } - - public boolean toggleFavouriteIssueFilter(Long issueFilterId) { - return issueFilterService.toggleFavouriteIssueFilter(issueFilterId, userSession); + public List execute(Map props) { + return issueIndex.search(issueQueryService.createFromMap(props), toSearchOptions(props)).getDocs(); } /** @@ -327,12 +158,6 @@ public class InternalRubyIssueService { return issueBulkChangeService.execute(issueBulkChangeQuery, userSession); } - private static void checkOptionalSizeParameter(String value, String paramName, Integer size) { - if (!Strings.isNullOrEmpty(value) && value.length() > size) { - throw new BadRequestException(Validation.IS_TOO_LONG_MESSAGE, paramName, size); - } - } - /** * Do not make this method static as it's called by rails */ @@ -369,12 +194,4 @@ public class InternalRubyIssueService { return userSession.hasComponentUuidPermission(UserRole.ISSUE_ADMIN, projectUuid); } - private enum MatchIssueFilterParameters implements Predicate> { - INSTANCE; - - @Override - public boolean apply(@Nonnull Map.Entry input) { - return IssueFilterParameters.ALL.contains(input.getKey()); - } - } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/AppAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/AppAction.java deleted file mode 100644 index d50bb86daf5..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/AppAction.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import java.util.List; -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.server.user.UserSession; - -import static org.sonar.server.issue.filter.IssueFilterJsonWriter.writeWithName; - -public class AppAction implements IssueFilterWsAction { - - private final IssueFilterService service; - private final UserSession userSession; - - public AppAction(IssueFilterService service, UserSession userSession) { - this.service = service; - this.userSession = userSession; - } - - @Override - public void define(WebService.NewController controller) { - WebService.NewAction action = controller.createAction("app"); - action - .setDescription("Get data required for rendering the page 'Issues'.") - .setSince("4.2") - .setInternal(true) - .setHandler(this) - .setResponseExample(getClass().getResource("example-app.json")); - action - .createParam("id") - .setDescription("Optionally, the ID of the current filter"); - } - - @Override - public void handle(Request request, Response response) throws Exception { - JsonWriter json = response.newJsonWriter(); - json.beginObject(); - - // Current filter (optional) - Integer filterId = request.paramAsInt("id"); - IssueFilterDto filter = null; - if (filterId != null && filterId >= 0) { - filter = service.find((long) filterId, userSession); - } - - // Permissions - json.prop("canManageFilters", userSession.isLoggedIn()); - json.prop("canBulkChange", userSession.isLoggedIn()); - - // Selected filter - if (filter != null) { - writeWithName(json, filter, userSession); - } - - // Favorite filters, if logged in - if (userSession.isLoggedIn()) { - List favorites = service.findFavoriteFilters(userSession); - json.name("favorites").beginArray(); - for (IssueFilterDto favorite : favorites) { - json - .beginObject() - .prop("id", favorite.getId()) - .prop("name", favorite.getName()) - .endObject(); - } - json.endArray(); - } - - json.endObject(); - json.close(); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/FavoritesAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/FavoritesAction.java deleted file mode 100644 index e81417b7133..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/FavoritesAction.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.server.user.UserSession; - -public class FavoritesAction implements IssueFilterWsAction { - - private final IssueFilterService service; - private final UserSession userSession; - - public FavoritesAction(IssueFilterService service, UserSession userSession) { - this.service = service; - this.userSession = userSession; - } - - @Override - public void define(WebService.NewController controller) { - WebService.NewAction action = controller.createAction("favorites"); - action - .setDescription("List issue filters marked as favorite by request user.") - .setResponseExample(getClass().getResource("favorites-example.json")) - .setSince("4.2") - .setHandler(this); - } - - @Override - public void handle(Request request, Response response) throws Exception { - JsonWriter json = response.newJsonWriter(); - json.beginObject().name("favoriteFilters").beginArray(); - if (userSession.isLoggedIn()) { - for (IssueFilterDto favorite : service.findFavoriteFilters(userSession)) { - json.beginObject(); - json.prop("id", favorite.getId()); - json.prop("name", favorite.getName()); - json.prop("user", favorite.getUserLogin()); - json.prop("shared", favorite.isShared()); - // no need to export description and query fields - json.endObject(); - } - } - json.endArray().endObject().close(); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterJsonWriter.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterJsonWriter.java deleted file mode 100644 index 31134c8d61b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterJsonWriter.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.core.permission.GlobalPermissions; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.server.user.UserSession; - -import static com.google.common.base.MoreObjects.firstNonNull; - -class IssueFilterJsonWriter { - - private static final String DEFAULT_LOGIN = "[SonarQube]"; - - private IssueFilterJsonWriter() { - // static methods only - } - - static void writeWithName(JsonWriter json, IssueFilterDto filter, UserSession userSession) { - json.name("filter"); - write(json, new IssueFilterWithFavorite(filter, null), userSession); - } - - static void write(JsonWriter json, IssueFilterWithFavorite issueFilterWithFavorite, UserSession userSession) { - IssueFilterDto issueFilter = issueFilterWithFavorite.issueFilter(); - json - .beginObject() - .prop("id", String.valueOf(issueFilter.getId())) - .prop("name", issueFilter.getName()) - .prop("description", issueFilter.getDescription()) - .prop("user", firstNonNull(issueFilter.getUserLogin(), DEFAULT_LOGIN)) - .prop("shared", issueFilter.isShared()) - .prop("query", issueFilter.getData()) - .prop("canModify", canModifyFilter(userSession, issueFilter)); - if (issueFilterWithFavorite.isFavorite() != null) { - json.prop("favorite", issueFilterWithFavorite.isFavorite()); - } - json.endObject(); - } - - private static boolean canModifyFilter(UserSession userSession, IssueFilterDto filter) { - return userSession.isLoggedIn() && - (StringUtils.equals(filter.getUserLogin(), userSession.getLogin()) || userSession.hasPermission(GlobalPermissions.SYSTEM_ADMIN)); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterSerializer.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterSerializer.java deleted file mode 100644 index ac029fde65f..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterSerializer.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import com.google.common.base.Splitter; -import com.google.common.collect.Lists; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.server.ServerSide; - -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newHashMap; - -@ServerSide -public class IssueFilterSerializer { - - public static final String SEPARATOR = "|"; - public static final String KEY_VALUE_SEPARATOR = "="; - public static final String LIST_SEPARATOR = ","; - - public String serialize(Map map) { - StringBuilder stringBuilder = new StringBuilder(); - - for (Map.Entry entries : map.entrySet()) { - String key = entries.getKey(); - Object value = entries.getValue(); - if (value != null) { - List valuesList = newArrayList(); - if (value instanceof List) { - // assume that it contains only strings - valuesList = (List) value; - } else if (value instanceof CharSequence) { - valuesList = Lists.newArrayList(Splitter.on(',').omitEmptyStrings().split((CharSequence) value)); - } else { - stringBuilder.append(key); - stringBuilder.append(IssueFilterSerializer.KEY_VALUE_SEPARATOR); - stringBuilder.append(value); - stringBuilder.append(IssueFilterSerializer.SEPARATOR); - } - if (!valuesList.isEmpty()) { - stringBuilder.append(key); - stringBuilder.append(IssueFilterSerializer.KEY_VALUE_SEPARATOR); - for (Iterator valueListIter = valuesList.iterator(); valueListIter.hasNext();) { - Object valueList = valueListIter.next(); - stringBuilder.append(valueList); - if (valueListIter.hasNext()) { - stringBuilder.append(IssueFilterSerializer.LIST_SEPARATOR); - } - } - stringBuilder.append(IssueFilterSerializer.SEPARATOR); - } - } - } - - if (stringBuilder.length() > 0) { - // Delete useless last separator character - stringBuilder.deleteCharAt(stringBuilder.length() - 1); - } - - return stringBuilder.toString(); - } - - public Map deserialize(String data) { - Map map = newHashMap(); - - Iterable keyValues = Splitter.on(IssueFilterSerializer.SEPARATOR).split(data); - for (String keyValue : keyValues) { - String[] keyValueSplit = StringUtils.split(keyValue, IssueFilterSerializer.KEY_VALUE_SEPARATOR); - if (keyValueSplit.length == 2) { - String key = keyValueSplit[0]; - String value = keyValueSplit[1]; - String[] listValues = StringUtils.split(value, IssueFilterSerializer.LIST_SEPARATOR); - if (listValues.length > 1) { - map.put(key, newArrayList(listValues)); - } else { - map.put(key, value); - } - } - } - return map; - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterService.java deleted file mode 100644 index 73ed72de0f8..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterService.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import java.util.Date; -import java.util.List; -import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import org.sonar.api.server.ServerSide; -import org.sonar.api.utils.Paging; -import org.sonar.core.permission.GlobalPermissions; -import org.sonar.db.DbClient; -import org.sonar.db.issue.IssueFilterDao; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.db.issue.IssueFilterFavouriteDao; -import org.sonar.db.issue.IssueFilterFavouriteDto; -import org.sonar.db.permission.AuthorizationDao; -import org.sonar.server.es.SearchOptions; -import org.sonar.server.es.SearchResult; -import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.exceptions.UnauthorizedException; -import org.sonar.server.issue.IssueQuery; -import org.sonar.server.issue.index.IssueDoc; -import org.sonar.server.issue.index.IssueIndex; -import org.sonar.server.user.UserSession; -import org.sonarqube.ws.client.issue.IssueFilterParameters; - -import static com.google.common.collect.Lists.newArrayList; - -@ServerSide -public class IssueFilterService { - - private final IssueFilterDao filterDao; - private final IssueFilterFavouriteDao favouriteDao; - private final IssueIndex issueIndex; - private final AuthorizationDao authorizationDao; - private final IssueFilterSerializer serializer; - - public IssueFilterService(DbClient dbClient, IssueIndex issueIndex, IssueFilterSerializer serializer) { - this.filterDao = dbClient.issueFilterDao(); - this.favouriteDao = dbClient.issueFilterFavouriteDao(); - this.authorizationDao = dbClient.authorizationDao(); - this.issueIndex = issueIndex; - this.serializer = serializer; - } - - public IssueFilterResult execute(IssueQuery issueQuery, SearchOptions options) { - return createIssueFilterResult(issueIndex.search(issueQuery, options), options); - } - - public IssueFilterDto find(Long id, UserSession userSession) { - return findIssueFilterDto(id, getLoggedLogin(userSession)); - } - - @CheckForNull - public IssueFilterDto findById(Long id) { - IssueFilterDto issueFilterDto = filterDao.selectById(id); - if (issueFilterDto != null) { - return issueFilterDto; - } - return null; - } - - public List findByUser(UserSession userSession) { - return selectUserIssueFilters(getLoggedLogin(userSession)); - } - - public IssueFilterDto save(IssueFilterDto issueFilter, UserSession userSession) { - String user = getLoggedLogin(userSession); - issueFilter.setUserLogin(user); - validateFilter(issueFilter); - return insertIssueFilter(issueFilter, user); - } - - IssueFilterDto save(IssueFilterDto issueFilter) { - return insertIssueFilter(issueFilter); - } - - public IssueFilterDto update(IssueFilterDto issueFilter, UserSession userSession) { - String login = getLoggedLogin(userSession); - IssueFilterDto existingFilterDto = findIssueFilterDto(issueFilter.getId(), login); - verifyCurrentUserCanModifyFilter(existingFilterDto, login); - verifyCurrentUserCanChangeFilterSharingFilter(issueFilter, existingFilterDto, login); - if (!isFilterOwnedByUser(existingFilterDto, issueFilter.getUserLogin())) { - verifyCurrentUserCanChangeFilterOwnership(login); - } - validateFilter(issueFilter); - deleteOtherFavoriteFiltersIfFilterBecomeUnshared(existingFilterDto, issueFilter); - issueFilter.setUpdatedAt(new Date()); - filterDao.update(issueFilter); - return issueFilter; - } - - private void deleteOtherFavoriteFiltersIfFilterBecomeUnshared(IssueFilterDto existingFilterDto, IssueFilterDto issueFilter) { - if (existingFilterDto.isShared() && !issueFilter.isShared()) { - for (IssueFilterFavouriteDto favouriteDto : selectFavouriteFilters(existingFilterDto.getId())) { - if (!favouriteDto.getUserLogin().equals(issueFilter.getUserLogin())) { - deleteFavouriteIssueFilter(favouriteDto); - } - } - } - } - - public IssueFilterDto updateFilterQuery(Long issueFilterId, Map filterQuery, UserSession userSession) { - String login = getLoggedLogin(userSession); - IssueFilterDto issueFilterDto = findIssueFilterDto(issueFilterId, login); - verifyCurrentUserCanModifyFilter(issueFilterDto, login); - - issueFilterDto.setData(serializeFilterQuery(filterQuery)); - issueFilterDto.setUpdatedAt(new Date()); - filterDao.update(issueFilterDto); - return issueFilterDto; - } - - public void delete(Long issueFilterId, UserSession userSession) { - String login = getLoggedLogin(userSession); - IssueFilterDto issueFilterDto = findIssueFilterDto(issueFilterId, login); - verifyCurrentUserCanModifyFilter(issueFilterDto, login); - - deleteFavouriteIssueFilters(issueFilterDto); - filterDao.delete(issueFilterId); - } - - public IssueFilterDto copy(Long issueFilterIdToCopy, IssueFilterDto issueFilter, UserSession userSession) { - String login = getLoggedLogin(userSession); - IssueFilterDto issueFilterDtoToCopy = findIssueFilterDto(issueFilterIdToCopy, login); - // Copy of filter should not be shared - issueFilter.setShared(false); - issueFilter.setUserLogin(login); - issueFilter.setData(issueFilterDtoToCopy.getData()); - validateFilter(issueFilter); - return insertIssueFilter(issueFilter, login); - } - - public List findSharedFiltersWithoutUserFilters(UserSession userSession) { - final String login = getLoggedLogin(userSession); - return newArrayList(Iterables.filter(selectSharedFilters(), new Predicate() { - @Override - public boolean apply(IssueFilterDto input) { - return !isFilterOwnedByUser(input, login); - } - })); - } - - public List findFavoriteFilters(UserSession userSession) { - return filterDao.selectFavoriteFiltersByUser(getLoggedLogin(userSession)); - } - - /** - * Return true if favorite is added, false if favorite is removed - */ - public boolean toggleFavouriteIssueFilter(Long filterId, UserSession userSession) { - String user = getLoggedLogin(userSession); - findIssueFilterDto(filterId, user); - IssueFilterFavouriteDto issueFilterFavouriteDto = selectFavouriteFilterForUser(filterId, user); - if (issueFilterFavouriteDto == null) { - addFavouriteIssueFilter(filterId, user); - return true; - } else { - deleteFavouriteIssueFilter(issueFilterFavouriteDto); - return false; - } - } - - public String serializeFilterQuery(Map filterQuery) { - Map filterQueryFiltered = Maps.filterEntries(filterQuery, MatchIssueFilterParameters.INSTANCE); - return serializer.serialize(filterQueryFiltered); - } - - public Map deserializeIssueFilterQuery(IssueFilterDto issueFilter) { - return serializer.deserialize(issueFilter.getData()); - } - - private IssueFilterDto findIssueFilterDto(Long id, String login) { - IssueFilterDto issueFilterDto = filterDao.selectById(id); - if (issueFilterDto == null) { - throw new NotFoundException("Filter not found: " + id); - } - verifyCurrentUserCanReadFilter(issueFilterDto, login); - return issueFilterDto; - } - - public boolean canShareFilter(UserSession userSession) { - return userSession.isLoggedIn(); - } - - public String getLoggedLogin(UserSession userSession) { - String user = userSession.getLogin(); - if (!userSession.isLoggedIn()) { - throw new UnauthorizedException("User is not logged in"); - } - return user; - } - - public void verifyCurrentUserCanReadFilter(IssueFilterDto issueFilter, String login) { - if (issueFilter.getUserLogin() != null && !issueFilter.getUserLogin().equals(login) && !issueFilter.isShared()) { - throw new ForbiddenException("User is not authorized to read this filter"); - } - } - - private void verifyCurrentUserCanModifyFilter(IssueFilterDto issueFilter, String user) { - if (issueFilter.getUserLogin() != null && !issueFilter.getUserLogin().equals(user) && !isAdmin(user)) { - throw new ForbiddenException("User is not authorized to modify this filter"); - } - } - - private void verifyCurrentUserCanChangeFilterSharingFilter(IssueFilterDto issueFilter, IssueFilterDto existingFilterDto, String login) { - if (existingFilterDto.isShared() != issueFilter.isShared() && !isFilterOwnedByUser(existingFilterDto, login)) { - throw new ForbiddenException("Only owner of a filter can change sharing"); - } - } - - private void verifyCurrentUserCanChangeFilterOwnership(String user) { - if (!isAdmin(user)) { - throw new ForbiddenException("User is not authorized to change the owner of this filter"); - } - } - - private void validateFilter(final IssueFilterDto issueFilter) { - List userFilters = selectUserIssueFilters(issueFilter.getUserLogin()); - IssueFilterDto userFilterSameName = findFilterWithSameName(userFilters, issueFilter.getName()); - if (userFilterSameName != null && !userFilterSameName.getId().equals(issueFilter.getId())) { - throw new BadRequestException("Name already exists"); - } - if (issueFilter.isShared()) { - List sharedFilters = selectSharedFilters(); - IssueFilterDto sharedFilterWithSameName = findFilterWithSameName(sharedFilters, issueFilter.getName()); - if (sharedFilterWithSameName != null && !sharedFilterWithSameName.getId().equals(issueFilter.getId())) { - throw new BadRequestException("Other users already share filters with the same name"); - } - } - } - - @CheckForNull - private IssueFilterFavouriteDto selectFavouriteFilterForUser(Long filterId, final String user) { - return Iterables.find(selectFavouriteFilters(filterId), new IssueFilterFavouriteDtoMatchUser(user), null); - } - - private List selectFavouriteFilters(Long filterId) { - return favouriteDao.selectByFilterId(filterId); - } - - private List selectUserIssueFilters(String user) { - return filterDao.selectByUser(user); - } - - private List selectSharedFilters() { - return filterDao.selectSharedFilters(); - } - - @CheckForNull - private static IssueFilterDto findFilterWithSameName(List dtos, String name) { - return Iterables.find(dtos, new IssueFilterDtoMatchName(name), null); - } - - private void addFavouriteIssueFilter(Long issueFilterId, String user) { - IssueFilterFavouriteDto issueFilterFavouriteDto = new IssueFilterFavouriteDto() - .setIssueFilterId(issueFilterId) - .setUserLogin(user); - favouriteDao.insert(issueFilterFavouriteDto); - } - - private void deleteFavouriteIssueFilter(IssueFilterFavouriteDto issueFilterFavouriteDto) { - favouriteDao.delete(issueFilterFavouriteDto.getId()); - } - - private void deleteFavouriteIssueFilters(IssueFilterDto issueFilterDto) { - favouriteDao.deleteByFilterId(issueFilterDto.getId()); - } - - private IssueFilterDto insertIssueFilter(IssueFilterDto issueFilter, String user) { - filterDao.insert(issueFilter); - addFavouriteIssueFilter(issueFilter.getId(), user); - return issueFilter; - } - - private IssueFilterDto insertIssueFilter(IssueFilterDto issueFilter) { - filterDao.insert(issueFilter); - return issueFilter; - } - - private boolean isAdmin(String user) { - return authorizationDao.selectGlobalPermissions(user).contains(GlobalPermissions.SYSTEM_ADMIN); - } - - private static IssueFilterResult createIssueFilterResult(SearchResult issues, SearchOptions options) { - Paging paging = Paging.forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) issues.getTotal()); - return new IssueFilterResult(issues.getDocs(), paging); - } - - private boolean isFilterOwnedByUser(IssueFilterDto filter, String login) { - String ownerLogin = filter.getUserLogin(); - return ownerLogin != null && ownerLogin.equals(login); - } - - public static class IssueFilterResult { - - private final List issues; - private final Paging paging; - - public IssueFilterResult(List issues, Paging paging) { - this.issues = issues; - this.paging = paging; - } - - public List issues() { - return issues; - } - - public Paging paging() { - return paging; - } - } - - private enum MatchIssueFilterParameters implements Predicate> { - INSTANCE; - - @Override - public boolean apply(@Nonnull Map.Entry input) { - return IssueFilterParameters.ALL_WITHOUT_PAGINATION.contains(input.getKey()); - } - } - - private static class IssueFilterDtoMatchName implements Predicate { - private final String name; - - public IssueFilterDtoMatchName(String name) { - this.name = name; - } - - @Override - public boolean apply(@Nonnull IssueFilterDto input) { - return input.getName().equals(name); - } - } - - private static class IssueFilterFavouriteDtoMatchUser implements Predicate { - private final String user; - - public IssueFilterFavouriteDtoMatchUser(String user) { - this.user = user; - } - - @Override - public boolean apply(@Nonnull IssueFilterFavouriteDto input) { - return input.getUserLogin().equals(user); - } - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWithFavorite.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWithFavorite.java deleted file mode 100644 index eabfafb9b81..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWithFavorite.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import javax.annotation.Nullable; -import org.sonar.db.issue.IssueFilterDto; - -public class IssueFilterWithFavorite { - private final IssueFilterDto issueFilter; - private final Boolean isFavourite; - - public IssueFilterWithFavorite(IssueFilterDto issueFilter, Boolean isFavourite) { - this.issueFilter = issueFilter; - this.isFavourite = isFavourite; - } - - public IssueFilterDto issueFilter() { - return issueFilter; - } - - @Nullable - public Boolean isFavorite() { - return isFavourite; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWs.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWs.java deleted file mode 100644 index fa821d16189..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWs.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.sonar.api.server.ws.WebService; - -public class IssueFilterWs implements WebService { - - private final IssueFilterWsAction[] actions; - - public IssueFilterWs(IssueFilterWsAction... actions) { - this.actions = actions; - } - - @Override - public void define(Context context) { - NewController controller = context.createController("api/issue_filters") - .setSince("4.2") - .setDescription("Get details on existing issue filters/saved issue searches."); - for (IssueFilterWsAction action : actions) { - action.define(controller); - } - controller.done(); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsAction.java deleted file mode 100644 index 68a0615951c..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsAction.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.sonar.server.ws.WsAction; - -public interface IssueFilterWsAction extends WsAction { - // marker interface -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsModule.java deleted file mode 100644 index d0f90e85093..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.sonar.core.platform.Module; - -public class IssueFilterWsModule extends Module { - @Override - protected void configureModule() { - add( - IssueFilterService.class, - IssueFilterSerializer.class, - IssueFilterWs.class, - IssueFilterJsonWriter.class, - org.sonar.server.issue.filter.AppAction.class, - org.sonar.server.issue.filter.ShowAction.class, - org.sonar.server.issue.filter.SearchAction.class, - org.sonar.server.issue.filter.FavoritesAction.class - ); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/RegisterIssueFilters.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/RegisterIssueFilters.java deleted file mode 100644 index 46ae876461f..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/RegisterIssueFilters.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.picocontainer.Startable; -import org.sonar.api.utils.System2; -import org.sonar.db.issue.IssueFilterDao; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.db.loadedtemplate.LoadedTemplateDao; -import org.sonar.db.loadedtemplate.LoadedTemplateDto; - -import java.util.Date; - -public class RegisterIssueFilters implements Startable { - - static final String BUILTIN_ISSUE_FILTER_UNRESOLVED = "Unresolved Issues"; - static final String BUILTIN_ISSUE_FILTER_HIDDEN_DEBT = "False Positive and Won't Fix Issues"; - static final String BUILTIN_ISSUE_FILTER_MY_UNRESOLVED = "My Unresolved Issues"; - - private final IssueFilterDao issueFilterDao; - - private final LoadedTemplateDao loadedTemplateDao; - - private final System2 system; - - public RegisterIssueFilters(IssueFilterDao issueFilterDao, LoadedTemplateDao loadedTemplateDao, System2 system) { - this.issueFilterDao = issueFilterDao; - this.loadedTemplateDao = loadedTemplateDao; - this.system = system; - } - - @Override - public void start() { - if (shouldRegisterBuiltinIssueFilters()) { - createBuiltinIssueFilters(); - registerBuiltinIssueFilters(); - } - } - - @Override - public void stop() { - // do nothing - } - - private boolean shouldRegisterBuiltinIssueFilters() { - return loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.ISSUE_FILTER_TYPE, BUILTIN_ISSUE_FILTER_UNRESOLVED) == 0; - } - - private void createBuiltinIssueFilters() { - Date now = new Date(system.now()); - - IssueFilterDto unresolvedIssueFilter = new IssueFilterDto().setName(BUILTIN_ISSUE_FILTER_UNRESOLVED) - .setShared(true) - .setCreatedAt(now) - .setUpdatedAt(now) - .setData("resolved=false"); - issueFilterDao.insert(unresolvedIssueFilter); - - IssueFilterDto hiddenDebtFilter = new IssueFilterDto().setName(BUILTIN_ISSUE_FILTER_HIDDEN_DEBT) - .setShared(true) - .setCreatedAt(now) - .setUpdatedAt(now) - .setData("resolutions=FALSE-POSITIVE,WONTFIX"); - issueFilterDao.insert(hiddenDebtFilter); - - IssueFilterDto myUnresolvedFilter = new IssueFilterDto().setName(BUILTIN_ISSUE_FILTER_MY_UNRESOLVED) - .setShared(true) - .setCreatedAt(now) - .setUpdatedAt(now) - .setData("resolved=false|assignees=__me__"); - issueFilterDao.insert(myUnresolvedFilter); - - } - - private void registerBuiltinIssueFilters() { - loadedTemplateDao.insert(new LoadedTemplateDto(BUILTIN_ISSUE_FILTER_UNRESOLVED, LoadedTemplateDto.ISSUE_FILTER_TYPE)); - loadedTemplateDao.insert(new LoadedTemplateDto(BUILTIN_ISSUE_FILTER_HIDDEN_DEBT, LoadedTemplateDto.ISSUE_FILTER_TYPE)); - loadedTemplateDao.insert(new LoadedTemplateDto(BUILTIN_ISSUE_FILTER_MY_UNRESOLVED, LoadedTemplateDto.ISSUE_FILTER_TYPE)); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/SearchAction.java deleted file mode 100644 index 12c7b1e9c72..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/SearchAction.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import com.google.common.base.Function; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.Maps; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.annotation.Nonnull; -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.issue.IssueFilterDao; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.db.issue.IssueFilterFavouriteDto; -import org.sonar.server.user.UserSession; - -public class SearchAction implements IssueFilterWsAction { - - private final DbClient dbClient; - private final UserSession userSession; - - public SearchAction(DbClient dbClient, UserSession userSession) { - this.dbClient = dbClient; - this.userSession = userSession; - } - - @Override - public void define(WebService.NewController controller) { - WebService.NewAction action = controller.createAction("search"); - action - .setDescription("List issue filters and shared issue filters of the current user.") - .setHandler(this) - .setSince("5.2") - .setResponseExample(getClass().getResource("search-example.json")); - } - - @Override - public void handle(Request request, Response response) throws Exception { - DbSession dbSession = dbClient.openSession(false); - try { - Set issueFilters = searchIssueFilters(dbSession); - Map userFavouritesByFilterId = searchUserFavouritesByFilterId(dbSession); - writeResponse(response, issueFilters, userFavouritesByFilterId); - } finally { - dbClient.closeSession(dbSession); - } - } - - private void writeResponse(Response response, Set issueFilters, Map userFavouritesByFilterId) { - JsonWriter json = response.newJsonWriter(); - json.beginObject(); - json.name("issueFilters").beginArray(); - for (IssueFilterDto issueFilter : issueFilters) { - IssueFilterJsonWriter.write(json, new IssueFilterWithFavorite(issueFilter, isFavourite(issueFilter, userFavouritesByFilterId)), userSession); - } - json.endArray(); - - json.endObject(); - json.close(); - } - - private static boolean isFavourite(IssueFilterDto issueFilter, Map userFavouritesByFilterId) { - return userFavouritesByFilterId.get(issueFilter.getId()) != null; - } - - /** - * @return all the current user issue filters and all the shared filters - */ - private Set searchIssueFilters(DbSession dbSession) { - IssueFilterDao issueFilterDao = dbClient.issueFilterDao(); - - List filters = issueFilterDao.selectByUser(dbSession, userSession.getLogin()); - List sharedFilters = issueFilterDao.selectSharedFilters(dbSession); - filters.addAll(sharedFilters); - - return FluentIterable.from(filters).toSortedSet(IssueFilterDtoIdComparator.INSTANCE); - } - - private Map searchUserFavouritesByFilterId(DbSession dbSession) { - List favouriteFilters = dbClient.issueFilterFavouriteDao().selectByUser(dbSession, userSession.getLogin()); - return Maps.uniqueIndex(favouriteFilters, IssueFilterFavouriteDToIssueFilterId.INSTANCE); - } - - private enum IssueFilterDtoIdComparator implements Comparator { - INSTANCE; - - @Override - public int compare(IssueFilterDto o1, IssueFilterDto o2) { - return o1.getId().intValue() - o2.getId().intValue(); - } - } - - private enum IssueFilterFavouriteDToIssueFilterId implements Function { - INSTANCE; - - @Override - public Long apply(@Nonnull IssueFilterFavouriteDto filterFavourite) { - return filterFavourite.getIssueFilterId(); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/ShowAction.java deleted file mode 100644 index 374ac2fd1c6..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/ShowAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import com.google.common.io.Resources; -import org.sonar.api.server.ws.Request; -import org.sonar.api.server.ws.Response; -import org.sonar.api.server.ws.WebService; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.server.user.UserSession; - -import static org.sonar.server.issue.filter.IssueFilterJsonWriter.writeWithName; - -public class ShowAction implements IssueFilterWsAction { - - private final IssueFilterService service; - private final UserSession userSession; - - public ShowAction(IssueFilterService service, UserSession userSession) { - this.service = service; - this.userSession = userSession; - } - - @Override - public void define(WebService.NewController controller) { - WebService.NewAction action = controller.createAction("show"); - action - .setDescription("Get detail of an issue filter. Requires to be authenticated") - .setSince("4.2") - .setHandler(this) - .setResponseExample(Resources.getResource(this.getClass(), "example-show.json")); - action.createParam("id") - .setDescription("ID of the issue filter") - .setRequired(true); - } - - @Override - public void handle(Request request, Response response) throws Exception { - IssueFilterDto filter = service.find(request.mandatoryParamAsLong("id"), userSession); - - JsonWriter json = response.newJsonWriter(); - json.beginObject(); - writeWithName(json, filter, userSession); - json.endObject(); - json.close(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/package-info.java deleted file mode 100644 index 3c9bd20092c..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.issue.filter; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index fc4f62b7a2f..f093c2e6d8b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -72,7 +72,6 @@ import org.sonar.server.issue.ServerIssueStorage; import org.sonar.server.issue.SetSeverityAction; import org.sonar.server.issue.SetTypeAction; import org.sonar.server.issue.TransitionAction; -import org.sonar.server.issue.filter.IssueFilterWsModule; import org.sonar.server.issue.index.IssueIndexDefinition; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher; @@ -418,8 +417,6 @@ public class PlatformLevel4 extends PlatformLevel { EmailNotificationChannel.class, AlertsEmailTemplate.class, - IssueFilterWsModule.class, - // issues actions AssignAction.class, SetTypeAction.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java index dd07540d4a3..dd599eb41d6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java @@ -21,7 +21,6 @@ package org.sonar.server.platform.platformlevel; import org.sonar.server.app.ProcessCommandWrapper; import org.sonar.server.es.IndexerStartupTask; -import org.sonar.server.issue.filter.RegisterIssueFilters; import org.sonar.server.organization.DefaultOrganizationEnforcer; import org.sonar.server.platform.ServerLifecycleNotifier; import org.sonar.server.platform.web.RegisterServletFilters; @@ -58,7 +57,6 @@ public class PlatformLevelStartup extends PlatformLevel { RegisterQualityProfiles.class, RegisterPermissionTemplates.class, RenameDeprecatedPropertyKeys.class, - RegisterIssueFilters.class, DisplayLogOnDeprecatedProjects.class, ClearRulesOverloadedDebt.class, DeleteOldAnalysisReportsFromFs.class); diff --git a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/example-app.json b/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/example-app.json deleted file mode 100644 index 995830aa84b..00000000000 --- a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/example-app.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "canManageFilters": true, - "canBulkChange": true, - "filter": { - "id": "8", - "name": "My Issues To Fix", - "description": "", - "user": "john.snow", - "shared": false, - "query": "asc=false|assignees=john.snow|statuses=OPEN,CONFIRMED,REOPENED", - "canModify": true - }, - "favorites": [ - { - "id": "8", - "name": "My Issues To Fix" - }, - { - "id": "22", - "name": "SonarQube Issues" - } - ] -} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/example-show.json b/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/example-show.json deleted file mode 100644 index aba2f2f6670..00000000000 --- a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/example-show.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "filter": { - "id": "1", - "name": "My Filter", - "user": "admin", - "shared": true, - "query": "statuses=OPEN,REOPENED|sort=UPDATE_DATE|asc=false", - "canModify": true - } -} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/favorites-example.json b/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/favorites-example.json deleted file mode 100644 index fa9f7d3eab2..00000000000 --- a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/favorites-example.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "favoriteFilters": [ - { - "id": 1, - "name": "Unresolved Issues", - "shared": true - }, - { - "id": 2, - "name": "False Positive and Won't Fix Issues", - "shared": true - }, - { - "id": 3, - "name": "My Custom Unresolved Issues", - "shared": false - } - ] -} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/search-example.json b/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/search-example.json deleted file mode 100644 index b303d6430ef..00000000000 --- a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/search-example.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "issueFilters": [ - { - "id": "3", - "name": "My Unresolved Issues", - "shared": true, - "query": "resolved=false|assignees=__me__", - "user": "[SonarQube]", - "canModify": false, - "favorite": true - }, - { - "id": "2", - "name": "False Positive and Won't Fix Issues", - "shared": true, - "query": "resolutions=FALSE-POSITIVE,WONTFIX", - "user": "[SonarQube]", - "canModify": false, - "favorite": false - }, - { - "id": "12", - "name": "Unresolved Issues", - "shared": true, - "query": "resolved=false", - "user": "grace.hopper", - "canModify": true, - "favorite": false - }, - { - "id": "54", - "name": "My Custom Filter", - "shared": false, - "query": "resolved=false|statuses=OPEN,REOPENED|assignees=__me__", - "user": "grace.hopper", - "canModify": true, - "favorite": true - } - ] -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java index 0a4c0187a38..30afd9a69f9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java @@ -28,7 +28,6 @@ import java.util.Map; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.mockito.ArgumentCaptor; import org.sonar.api.issue.Issue; import org.sonar.api.user.User; import org.sonar.api.web.UserRole; @@ -37,20 +36,17 @@ import org.sonar.core.issue.FieldDiffs; import org.sonar.db.component.ResourceDao; import org.sonar.db.component.ResourceDto; import org.sonar.db.component.ResourceQuery; -import org.sonar.db.issue.IssueFilterDto; import org.sonar.server.es.SearchOptions; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.Message; -import org.sonar.server.issue.filter.IssueFilterService; +import org.sonar.server.issue.index.IssueIndex; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.ThreadLocalUserSession; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Maps.newHashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -61,6 +57,8 @@ public class InternalRubyIssueServiceTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); + IssueIndex issueIndex = mock(IssueIndex.class); + IssueService issueService; IssueQueryService issueQueryService; @@ -71,8 +69,6 @@ public class InternalRubyIssueServiceTest { ResourceDao resourceDao; - IssueFilterService issueFilterService; - IssueBulkChangeService issueBulkChangeService; ActionService actionService; @@ -86,15 +82,14 @@ public class InternalRubyIssueServiceTest { commentService = mock(IssueCommentService.class); changelogService = mock(IssueChangelogService.class); resourceDao = mock(ResourceDao.class); - issueFilterService = mock(IssueFilterService.class); issueBulkChangeService = mock(IssueBulkChangeService.class); actionService = mock(ActionService.class); ResourceDto project = new ResourceDto().setKey("org.sonar.Sample"); when(resourceDao.selectResource(any(ResourceQuery.class))).thenReturn(project); - service = new InternalRubyIssueService(issueService, issueQueryService, commentService, changelogService, - issueFilterService, issueBulkChangeService, actionService, userSessionRule); + service = new InternalRubyIssueService(issueIndex, issueService, issueQueryService, commentService, changelogService, + issueBulkChangeService, actionService, userSessionRule); } @Test @@ -155,259 +150,6 @@ public class InternalRubyIssueServiceTest { assertThat(result).isSameAs(changelog); } - @Test - public void create_issue_filter() { - Map parameters = newHashMap(); - parameters.put("name", "Long term"); - parameters.put("description", "Long term issues"); - - service.createIssueFilter(parameters); - - ArgumentCaptor issueFilterCaptor = ArgumentCaptor.forClass(IssueFilterDto.class); - verify(issueFilterService).save(issueFilterCaptor.capture(), any(ThreadLocalUserSession.class)); - IssueFilterDto issueFilter = issueFilterCaptor.getValue(); - assertThat(issueFilter.getName()).isEqualTo("Long term"); - assertThat(issueFilter.getDescription()).isEqualTo("Long term issues"); - } - - @Test - public void update_issue_filter() { - Map parameters = newHashMap(); - parameters.put("id", "10"); - parameters.put("name", "Long term"); - parameters.put("description", "Long term issues"); - parameters.put("user", "John"); - - service.updateIssueFilter(parameters); - - ArgumentCaptor issueFilterCaptor = ArgumentCaptor.forClass(IssueFilterDto.class); - verify(issueFilterService).update(issueFilterCaptor.capture(), any(ThreadLocalUserSession.class)); - IssueFilterDto issueFilter = issueFilterCaptor.getValue(); - assertThat(issueFilter.getId()).isEqualTo(10L); - assertThat(issueFilter.getName()).isEqualTo("Long term"); - assertThat(issueFilter.getDescription()).isEqualTo("Long term issues"); - } - - @Test - public void update_data() { - Map data = newHashMap(); - service.updateIssueFilterQuery(10L, data); - verify(issueFilterService).updateFilterQuery(eq(10L), eq(data), any(ThreadLocalUserSession.class)); - } - - @Test - public void delete_issue_filter() { - service.deleteIssueFilter(1L); - verify(issueFilterService).delete(eq(1L), any(ThreadLocalUserSession.class)); - } - - @Test - public void copy_issue_filter() { - Map parameters = newHashMap(); - parameters.put("name", "Copy of Long term"); - parameters.put("description", "Copy of Long term issues"); - - service.copyIssueFilter(1L, parameters); - - ArgumentCaptor issueFilterCaptor = ArgumentCaptor.forClass(IssueFilterDto.class); - verify(issueFilterService).copy(eq(1L), issueFilterCaptor.capture(), any(ThreadLocalUserSession.class)); - IssueFilterDto issueFilter = issueFilterCaptor.getValue(); - assertThat(issueFilter.getName()).isEqualTo("Copy of Long term"); - assertThat(issueFilter.getDescription()).isEqualTo("Copy of Long term issues"); - } - - @Test - public void get_error_on_create_issue_filter_result_when_no_name() { - Map parameters = newHashMap(); - parameters.put("name", ""); - parameters.put("description", "Long term issues"); - parameters.put("user", "John"); - - try { - service.createIssueFilterResultForNew(parameters); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class); - checkBadRequestException(e, "errors.cant_be_empty", "name"); - } - } - - @Test - public void get_error_on_create_issue_filter_result_when_name_is_too_long() { - Map parameters = newHashMap(); - parameters.put("name", createLongString(101)); - parameters.put("description", "Long term issues"); - parameters.put("user", "John"); - - try { - service.createIssueFilterResultForNew(parameters); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class); - checkBadRequestException(e, "errors.is_too_long", "name", 100); - } - } - - @Test - public void get_error_on_create_issue_filter_result_when_description_is_too_long() { - Map parameters = newHashMap(); - parameters.put("name", "Long term"); - parameters.put("description", createLongString(4001)); - parameters.put("user", "John"); - - try { - service.createIssueFilterResultForNew(parameters); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class); - checkBadRequestException(e, "errors.is_too_long", "description", 4000); - } - } - - @Test - public void get_error_on_create_issue_filter_result_when_id_is_null_on_update() { - Map parameters = newHashMap(); - parameters.put("id", null); - parameters.put("name", "Long term"); - parameters.put("description", "Long term issues"); - parameters.put("user", "John"); - - try { - service.createIssueFilterResultForUpdate(parameters); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class); - checkBadRequestException(e, "errors.cant_be_empty", "id"); - } - } - - @Test - public void get_error_on_create_issue_filter_result_when_user_is_null_on_update() { - Map parameters = newHashMap(); - parameters.put("id", "10"); - parameters.put("name", "All Open Issues"); - parameters.put("description", "Long term issues"); - parameters.put("user", null); - - try { - service.createIssueFilterResultForUpdate(parameters); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class); - checkBadRequestException(e, "errors.cant_be_empty", "user"); - } - } - - @Test - public void get_no_error_on_issue_filter_result_when_id_and_user_are_null_on_copy() { - Map parameters = newHashMap(); - parameters.put("id", null); - parameters.put("name", "Long term"); - parameters.put("description", "Long term issues"); - parameters.put("user", null); - - IssueFilterDto result = service.createIssueFilterResultForCopy(parameters); - assertThat(result).isNotNull(); - } - - @Test - public void execute_issue_filter_from_issue_query() { - service.execute(Maps.newHashMap()); - verify(issueFilterService).execute(any(IssueQuery.class), any(SearchOptions.class)); - } - - @Test - public void execute_issue_filter_from_existing_filter() { - Map props = newHashMap(); - props.put("componentRoots", "struts"); - props.put("statuses", "OPEN"); - when(issueFilterService.deserializeIssueFilterQuery(any(IssueFilterDto.class))).thenReturn(props); - - Map overrideProps = newHashMap(); - overrideProps.put("statuses", "CLOSED"); - overrideProps.put("resolved", true); - overrideProps.put("pageSize", 20); - overrideProps.put("pageIndex", 2); - - IssueQuery query = IssueQuery.builder(userSessionRule).build(); - when(issueQueryService.createFromMap(eq(overrideProps))).thenReturn(query); - - service.execute(10L, overrideProps); - - ArgumentCaptor issueQueryArgumentCaptor = ArgumentCaptor.forClass(IssueQuery.class); - ArgumentCaptor contextArgumentCaptor = ArgumentCaptor.forClass(SearchOptions.class); - - verify(issueFilterService).execute(issueQueryArgumentCaptor.capture(), contextArgumentCaptor.capture()); - verify(issueFilterService).find(eq(10L), any(ThreadLocalUserSession.class)); - - SearchOptions searchOptions = contextArgumentCaptor.getValue(); - assertThat(searchOptions.getLimit()).isEqualTo(20); - assertThat(searchOptions.getPage()).isEqualTo(2); - } - - @Test - public void serialize_filter_query() { - Map props = newHashMap(); - props.put("componentRoots", "struts"); - service.serializeFilterQuery(props); - verify(issueFilterService).serializeFilterQuery(props); - } - - @Test - public void deserialize_filter_query() { - IssueFilterDto issueFilter = new IssueFilterDto(); - service.deserializeFilterQuery(issueFilter); - verify(issueFilterService).deserializeIssueFilterQuery(issueFilter); - } - - @Test - public void sanitize_filter_query() { - Map query = newHashMap(); - query.put("statuses", "CLOSED"); - query.put("resolved", true); - query.put("unknown", "john"); - Map result = service.sanitizeFilterQuery(query); - assertThat(result.keySet()).containsOnly("statuses", "resolved"); - } - - @Test - public void find_user_issue_filters() { - service.findIssueFiltersForCurrentUser(); - verify(issueFilterService).findByUser(any(ThreadLocalUserSession.class)); - } - - @Test - public void find_shared_issue_filters() { - service.findSharedFiltersForCurrentUser(); - verify(issueFilterService).findSharedFiltersWithoutUserFilters(any(ThreadLocalUserSession.class)); - } - - @Test - public void find_favourite_issue_filters() { - service.findFavouriteIssueFiltersForCurrentUser(); - verify(issueFilterService).findFavoriteFilters(any(ThreadLocalUserSession.class)); - } - - @Test - public void toggle_favourite_issue_filter() { - service.toggleFavouriteIssueFilter(10L); - verify(issueFilterService).toggleFavouriteIssueFilter(eq(10L), any(ThreadLocalUserSession.class)); - } - - @Test - public void check_if_user_is_authorized_to_see_issue_filter() { - IssueFilterDto issueFilter = new IssueFilterDto(); - service.isUserAuthorized(issueFilter); - verify(issueFilterService).getLoggedLogin(any(ThreadLocalUserSession.class)); - verify(issueFilterService).verifyCurrentUserCanReadFilter(eq(issueFilter), anyString()); - } - - @Test - public void check_if_user_can_share_issue_filter() { - service.canUserShareIssueFilter(); - verify(issueFilterService).canShareFilter(any(ThreadLocalUserSession.class)); - } - @Test public void execute_bulk_change() { Map params = newHashMap(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/AppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/AppActionTest.java deleted file mode 100644 index a47f6d3fadb..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/AppActionTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import java.util.Arrays; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.ws.WsTester; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class AppActionTest { - @Rule - public UserSessionRule userSessionRule = UserSessionRule.standalone(); - - @Mock - IssueFilterService service; - - AppAction underTest; - WsTester ws; - - @Before - public void setUp() { - underTest = new AppAction(service, userSessionRule); - ws = new WsTester(new IssueFilterWs(underTest, mock(ShowAction.class), mock(SearchAction.class), mock(FavoritesAction.class))); - } - - @Test - public void anonymous_app() throws Exception { - userSessionRule.anonymous(); - ws.newGetRequest("api/issue_filters", "app").execute().assertJson(getClass(), "anonymous_page.json"); - } - - @Test - public void logged_in_app() throws Exception { - userSessionRule.login("eric").setUserId(123); - ws.newGetRequest("api/issue_filters", "app").execute() - .assertJson(getClass(), "logged_in_page.json"); - } - - @Test - public void logged_in_app_with_favorites() throws Exception { - userSessionRule.login("eric").setUserId(123); - when(service.findFavoriteFilters(userSessionRule)).thenReturn(Arrays.asList( - new IssueFilterDto().setId(6L).setName("My issues"), - new IssueFilterDto().setId(13L).setName("Blocker issues") - )); - ws.newGetRequest("api/issue_filters", "app").execute() - .assertJson(getClass(), "logged_in_page_with_favorites.json"); - } - - @Test - public void logged_in_app_with_selected_filter() throws Exception { - userSessionRule.login("eric").setUserId(123); - when(service.find(13L, userSessionRule)).thenReturn( - new IssueFilterDto().setId(13L).setName("Blocker issues").setData("severity=BLOCKER").setUserLogin("eric") - ); - - ws.newGetRequest("api/issue_filters", "app").setParam("id", "13").execute() - .assertJson(getClass(), "logged_in_page_with_selected_filter.json"); - } - - @Test - public void app_selected_filter_can_not_be_modified() throws Exception { - // logged-in user is 'eric' but filter is owned by 'simon' - userSessionRule.login("eric").setUserId(123).setGlobalPermissions("none"); - when(service.find(13L, userSessionRule)).thenReturn( - new IssueFilterDto().setId(13L).setName("Blocker issues").setData("severity=BLOCKER").setUserLogin("simon").setShared(true) - ); - - ws.newGetRequest("api/issue_filters", "app").setParam("id", "13").execute() - .assertJson(getClass(), "selected_filter_can_not_be_modified.json"); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java deleted file mode 100644 index 268acebdca6..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import java.util.Arrays; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.ws.WsTester; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class FavoritesActionTest { - @Rule - public UserSessionRule userSessionRule = UserSessionRule.standalone(); - - @Mock - IssueFilterService service; - - @Mock - IssueFilterJsonWriter writer; - - FavoritesAction action; - - WsTester tester; - - @Before - public void setUp() { - action = new FavoritesAction(service, userSessionRule); - tester = new WsTester(new IssueFilterWs(mock(AppAction.class), mock(ShowAction.class), mock(SearchAction.class), action)); - } - - @Test - public void favorites_of_anonymous() throws Exception { - userSessionRule.login(); - - tester.newGetRequest("api/issue_filters", "favorites").execute() - .assertJson("{\"favoriteFilters\": []}"); - } - - @Test - public void favorites_of_logged_in_user() throws Exception { - userSessionRule.login("eric").setUserId(123); - when(service.findFavoriteFilters(userSessionRule)).thenReturn(Arrays.asList( - new IssueFilterDto().setId(13L).setName("Blocker issues").setData("severity=BLOCKER").setUserLogin("simon").setShared(true) - )); - - tester.newGetRequest("api/issue_filters", "favorites").execute() - .assertJson("{\"favoriteFilters\": [{\"id\": 13, \"name\": \"Blocker issues\", \"user\": \"simon\", \"shared\": true}]}"); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterJsonWriterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterJsonWriterTest.java deleted file mode 100644 index 59139799279..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterJsonWriterTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.junit.Test; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.core.permission.GlobalPermissions; -import org.sonar.server.tester.AnonymousMockUserSession; -import org.sonar.server.tester.MockUserSession; -import org.sonar.server.user.UserSession; - -import java.io.StringWriter; - -import static org.sonar.test.JsonAssert.assertJson; - -public class IssueFilterJsonWriterTest { - - @Test - public void write_filter() { - test(new AnonymousMockUserSession(), - new IssueFilterDto() - .setId(13L) - .setName("Blocker issues") - .setDescription("All Blocker Issues") - .setShared(true) - .setUserLogin("simon") - .setData("severity=BLOCKER"), - "{\"filter\":{\n" + - " \"id\":\"13\",\n" + - " \"name\":\"Blocker issues\",\n" + - " \"description\":\"All Blocker Issues\",\n" + - " \"shared\":true,\n" + - " \"query\":\"severity=BLOCKER\",\n" + - " \"user\":\"simon\",\n" + - " \"canModify\":false\n" + - " }}"); - } - - @Test - public void can_modify_if_logged_user_own_filter() { - test(new MockUserSession("simon"), - new IssueFilterDto() - .setId(13L) - .setName("Blocker issues") - .setDescription("All Blocker Issues") - .setShared(true) - .setUserLogin("simon") - .setData("severity=BLOCKER"), - "{\"filter\":{\n" + - " \"id\":\"13\",\n" + - " \"name\":\"Blocker issues\",\n" + - " \"description\":\"All Blocker Issues\",\n" + - " \"shared\":true,\n" + - " \"query\":\"severity=BLOCKER\",\n" + - " \"user\":\"simon\",\n" + - " \"canModify\":true\n" + - " }}"); - } - - @Test - public void can_modify_if_logged_user_has_permission() { - UserSession userSession = new MockUserSession("simon").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); - test(userSession, - new IssueFilterDto() - .setId(13L) - .setName("Blocker issues") - .setDescription("All Blocker Issues") - .setShared(true) - .setUserLogin("julien") - .setData("severity=BLOCKER"), - "{\"filter\":{\n" + - " \"id\":\"13\",\n" + - " \"name\":\"Blocker issues\",\n" + - " \"description\":\"All Blocker Issues\",\n" + - " \"shared\":true,\n" + - " \"query\":\"severity=BLOCKER\",\n" + - " \"user\":\"julien\",\n" + - " \"canModify\":true\n" + - " }}"); - } - - private void test(UserSession userSession, IssueFilterDto filter, String expected) { - StringWriter output = new StringWriter(); - JsonWriter jsonWriter = JsonWriter.of(output); - jsonWriter.beginObject(); - - IssueFilterJsonWriter.writeWithName(jsonWriter, filter, userSession); - - jsonWriter.endObject(); - assertJson(output.toString()).isSimilarTo(expected); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterSerializerTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterSerializerTest.java deleted file mode 100644 index 92fb485bee1..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterSerializerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import java.util.List; -import java.util.Map; -import org.junit.Test; - -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newLinkedHashMap; -import static org.assertj.core.api.Assertions.assertThat; - -public class IssueFilterSerializerTest { - - IssueFilterSerializer issueFilterSerializer = new IssueFilterSerializer(); - - @Test - public void should_serialize() { - Map map = newLinkedHashMap(); - map.put("issues", newArrayList("ABCDE1234")); - map.put("severities", newArrayList("MAJOR", "MINOR")); - map.put("resolved", true); - map.put("pageSize", 10l); - map.put("pageIndex", 50); - - String result = issueFilterSerializer.serialize(map); - - assertThat(result).isEqualTo("issues=ABCDE1234|severities=MAJOR,MINOR|resolved=true|pageSize=10|pageIndex=50"); - } - - @Test - public void should_remove_empty_value_when_serializing() { - Map map = newLinkedHashMap(); - map.put("issues", newArrayList("ABCDE1234")); - map.put("resolved", null); - map.put("pageSize", ""); - - String result = issueFilterSerializer.serialize(map); - - assertThat(result).isEqualTo("issues=ABCDE1234"); - } - - @Test - public void should_deserialize() { - String data = "issues=ABCDE1234|severities=MAJOR,MINOR|resolved=true|pageSize=10|pageIndex=50"; - - Map map = issueFilterSerializer.deserialize(data); - - assertThat(map).hasSize(5); - assertThat(map.get("issues")).isEqualTo("ABCDE1234"); - assertThat(map.get("severities")).isInstanceOf(List.class); - assertThat((List) map.get("severities")).contains("MAJOR", "MINOR"); - assertThat(map.get("resolved")).isEqualTo("true"); - assertThat(map.get("pageSize")).isEqualTo("10"); - assertThat(map.get("pageIndex")).isEqualTo("50"); - } - - @Test - public void should_remove_empty_value_when_deserializing() { - String data = "issues=ABCDE1234|severities="; - - Map map = issueFilterSerializer.deserialize(data); - - assertThat(map).hasSize(1); - assertThat(map.get("issues")).isEqualTo("ABCDE1234"); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterServiceTest.java deleted file mode 100644 index 0072f9fabd2..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterServiceTest.java +++ /dev/null @@ -1,699 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import com.google.common.collect.Lists; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import org.apache.commons.lang.ObjectUtils; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.sonar.api.web.UserRole; -import org.sonar.core.permission.GlobalPermissions; -import org.sonar.db.DbClient; -import org.sonar.db.issue.IssueFilterDao; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.db.issue.IssueFilterFavouriteDao; -import org.sonar.db.issue.IssueFilterFavouriteDto; -import org.sonar.db.permission.AuthorizationDao; -import org.sonar.server.es.SearchOptions; -import org.sonar.server.es.SearchResult; -import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.exceptions.UnauthorizedException; -import org.sonar.server.issue.IssueQuery; -import org.sonar.server.issue.index.IssueDoc; -import org.sonar.server.issue.index.IssueIndex; -import org.sonar.server.tester.AnonymousMockUserSession; -import org.sonar.server.tester.MockUserSession; -import org.sonar.server.user.UserSession; - -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newHashMap; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyLong; -import static org.mockito.Mockito.anyMap; -import static org.mockito.Mockito.argThat; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -public class IssueFilterServiceTest { - - private DbClient dbClient = mock(DbClient.class); - private IssueFilterDao issueFilterDao = mock(IssueFilterDao.class); - private IssueFilterFavouriteDao issueFilterFavouriteDao = mock(IssueFilterFavouriteDao.class); - private AuthorizationDao authorizationDao = mock(AuthorizationDao.class); - private IssueIndex issueIndex = mock(IssueIndex.class); - private IssueFilterSerializer issueFilterSerializer = mock(IssueFilterSerializer.class); - private UserSession userSession = new MockUserSession("john"); - private IssueFilterService underTest; - - @Before - public void setUp() { - when(dbClient.issueFilterDao()).thenReturn(issueFilterDao); - when(dbClient.issueFilterFavouriteDao()).thenReturn(issueFilterFavouriteDao); - when(dbClient.authorizationDao()).thenReturn(authorizationDao); - - underTest = new IssueFilterService(dbClient, issueIndex, issueFilterSerializer); - } - - @Test - public void should_find_by_id() { - IssueFilterDto dto = new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("john"); - when(issueFilterDao.selectById(1L)).thenReturn(dto); - - IssueFilterDto issueFilter = underTest.findById(1L); - assertThat(issueFilter).isNotNull(); - assertThat(issueFilter.getId()).isEqualTo(1L); - } - - @Test - public void should_find_issue_filter() { - IssueFilterDto issueFilterDto = new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("john"); - when(issueFilterDao.selectById(1L)).thenReturn(issueFilterDto); - - IssueFilterDto issueFilter = underTest.find(1L, userSession); - assertThat(issueFilter).isNotNull(); - assertThat(issueFilter.getId()).isEqualTo(1L); - } - - @Test - public void should_find_shared_filter_by_id() { - IssueFilterDto issueFilterDto = new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("arthur").setShared(true); - when(issueFilterDao.selectById(1L)).thenReturn(issueFilterDto); - - IssueFilterDto issueFilter = underTest.find(1L, userSession); - assertThat(issueFilter).isNotNull(); - assertThat(issueFilter.getId()).isEqualTo(1L); - } - - @Test - public void should_not_find_by_id_on_not_existing_issue() { - when(issueFilterDao.selectById(1L)).thenReturn(null); - try { - underTest.find(1L, userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(NotFoundException.class).hasMessage("Filter not found: 1"); - } - } - - @Test - public void should_not_find_by_id_if_not_logged() { - try { - underTest.find(1L, new AnonymousMockUserSession()); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(UnauthorizedException.class).hasMessage("User is not logged in"); - } - verifyZeroInteractions(issueFilterDao); - } - - @Test - public void should_not_find_if_not_shared_and_user_is_not_the_owner_of_filter() { - IssueFilterDto issueFilterDto = new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("eric").setShared(false); - when(issueFilterDao.selectById(1L)).thenReturn(issueFilterDto); - try { - // John is not authorized to see eric filters - underTest.find(1L, userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("User is not authorized to read this filter"); - } - } - - @Test - public void should_find_by_user() { - when(issueFilterDao.selectByUser("john")).thenReturn(newArrayList(new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("john"))); - - List issueFilter = underTest.findByUser(userSession); - assertThat(issueFilter).hasSize(1); - assertThat(issueFilter.get(0).getId()).isEqualTo(1L); - } - - @Test - public void should_not_find_by_user_if_not_logged() { - try { - underTest.findByUser(new AnonymousMockUserSession()); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(UnauthorizedException.class).hasMessage("User is not logged in"); - } - } - - @Test - public void should_save() { - IssueFilterDto issueFilter = new IssueFilterDto().setName("My Issue"); - IssueFilterDto result = underTest.save(issueFilter, userSession); - assertThat(result.getName()).isEqualTo("My Issue"); - assertThat(result.getUserLogin()).isEqualTo("john"); - - verify(issueFilterDao).insert(any(IssueFilterDto.class)); - } - - @Test - public void should_add_favorite_on_save() { - IssueFilterDto issueFilter = new IssueFilterDto().setName("My Issue"); - underTest.save(issueFilter, userSession); - - verify(issueFilterDao).insert(any(IssueFilterDto.class)); - verify(issueFilterFavouriteDao).insert(any(IssueFilterFavouriteDto.class)); - } - - @Test - public void should_not_save_if_not_logged() { - try { - IssueFilterDto issueFilter = new IssueFilterDto().setName("My Issue"); - underTest.save(issueFilter, new AnonymousMockUserSession()); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(UnauthorizedException.class).hasMessage("User is not logged in"); - } - verify(issueFilterDao, never()).insert(any(IssueFilterDto.class)); - } - - @Test - public void should_not_save_if_name_already_used() { - when(issueFilterDao.selectByUser(eq("john"))).thenReturn(newArrayList(new IssueFilterDto().setId(1L).setName("My Issue"))); - try { - IssueFilterDto issueFilter = new IssueFilterDto().setName("My Issue"); - underTest.save(issueFilter, userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("Name already exists"); - } - verify(issueFilterDao, never()).insert(any(IssueFilterDto.class)); - } - - @Test - public void should_not_save_shared_filter_if_name_already_used_by_shared_filter() { - when(issueFilterDao.selectByUser(eq("john"))).thenReturn(Collections.emptyList()); - when(issueFilterDao.selectSharedFilters()).thenReturn(newArrayList(new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("henry").setShared(true))); - IssueFilterDto issueFilter = new IssueFilterDto().setName("My Issue").setShared(true); - try { - underTest.save(issueFilter, userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("Other users already share filters with the same name"); - } - verify(issueFilterDao, never()).insert(any(IssueFilterDto.class)); - } - - @Test - public void should_update() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setUserLogin("john")); - - IssueFilterDto result = underTest.update(new IssueFilterDto().setId(1L).setName("My New Filter").setUserLogin("john"), userSession); - assertThat(result.getName()).isEqualTo("My New Filter"); - - verify(issueFilterDao).update(any(IssueFilterDto.class)); - } - - @Test - public void should_not_share_filter_if_filter_owner_is_platform() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Filter").setShared(false)); - - try { - underTest.update(new IssueFilterDto().setId(1L).setName("My Filter").setShared(true), userSession); - failBecauseExceptionWasNotThrown(ForbiddenException.class); - } catch (Exception e) { - assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("Only owner of a filter can change sharing"); - } - verify(issueFilterDao, never()).update(any(IssueFilterDto.class)); - } - - @Test - public void should_not_update_sharing_if_not_owner() { - // John is admin and want to change arthur filter sharing - when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(GlobalPermissions.SYSTEM_ADMIN)); - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("Arthur Filter").setShared(true).setUserLogin("arthur")); - - try { - underTest.update(new IssueFilterDto().setId(1L).setName("Arthur Filter").setShared(false).setUserLogin("john"), userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("Only owner of a filter can change sharing"); - } - verify(issueFilterDao, never()).update(any(IssueFilterDto.class)); - } - - @Test - public void should_update_own_user_filter_without_changing_anything() { - IssueFilterDto dto = new IssueFilterDto().setId(1L).setName("My Filter").setUserLogin("john"); - when(issueFilterDao.selectById(1L)).thenReturn(dto); - when(issueFilterDao.selectByUser("john")).thenReturn(newArrayList(dto)); - - IssueFilterDto result = underTest.update(new IssueFilterDto().setId(1L).setName("My Filter").setUserLogin("john"), userSession); - assertThat(result.getName()).isEqualTo("My Filter"); - - verify(issueFilterDao).update(any(IssueFilterDto.class)); - } - - @Test - public void should_remove_other_favorite_filters_if_filter_become_unshared() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setUserLogin("john").setShared(true)); - IssueFilterFavouriteDto userFavouriteDto = new IssueFilterFavouriteDto().setId(10L).setUserLogin("john").setIssueFilterId(1L); - IssueFilterFavouriteDto otherFavouriteDto = new IssueFilterFavouriteDto().setId(11L).setUserLogin("arthur").setIssueFilterId(1L); - when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(newArrayList(userFavouriteDto, otherFavouriteDto)); - - IssueFilterDto result = underTest.update(new IssueFilterDto().setId(1L).setName("My New Filter").setUserLogin("john").setShared(false), userSession); - assertThat(result.getName()).isEqualTo("My New Filter"); - - verify(issueFilterDao).update(any(IssueFilterDto.class)); - verify(issueFilterFavouriteDao).delete(11L); - verify(issueFilterFavouriteDao, never()).delete(10L); - } - - @Test - public void should_update_other_shared_filter_if_admin() { - when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(GlobalPermissions.SYSTEM_ADMIN)); - when(issueFilterDao.selectById(1L)) - .thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setDescription("Old description").setUserLogin("arthur").setShared(true)); - - IssueFilterDto result = underTest.update(new IssueFilterDto().setId(1L).setName("My New Filter").setDescription("New description").setShared(true).setUserLogin("arthur"), - userSession); - assertThat(result.getName()).isEqualTo("My New Filter"); - assertThat(result.getDescription()).isEqualTo("New description"); - - verify(issueFilterDao).update(any(IssueFilterDto.class)); - } - - @Test - public void should_not_update_other_shared_filter_if_not_admin() { - when(authorizationDao.selectGlobalPermissions("arthur")).thenReturn(Collections.emptyList()); - when(issueFilterDao.selectById(1L)) - .thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setDescription("Old description").setUserLogin("arthur").setShared(true)); - - try { - underTest.update(new IssueFilterDto().setId(1L).setName("My New Filter").setDescription("New description").setShared(true).setUserLogin("arthur"), userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("User is not authorized to modify this filter"); - } - verify(issueFilterDao, never()).update(any(IssueFilterDto.class)); - } - - @Test - public void should_not_update_if_filter_not_found() { - when(issueFilterDao.selectById(1L)).thenReturn(null); - - try { - underTest.update(new IssueFilterDto().setId(1L).setName("My New Filter"), userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(NotFoundException.class).hasMessage("Filter not found: 1"); - } - verify(issueFilterDao, never()).update(any(IssueFilterDto.class)); - } - - @Test - public void should_not_update_if_shared_and_not_admin() { - when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(UserRole.USER)); - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setUserLogin("arthur").setShared(true)); - - try { - underTest.update(new IssueFilterDto().setId(1L).setName("My New Filter"), userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("User is not authorized to modify this filter"); - } - verify(issueFilterDao, never()).update(any(IssueFilterDto.class)); - } - - @Test - public void should_not_update_if_name_already_used() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setUserLogin("john")); - when(issueFilterDao.selectByUser(eq("john"))).thenReturn(newArrayList(new IssueFilterDto().setId(2L).setName("My Issue"))); - - try { - underTest.update(new IssueFilterDto().setId(1L).setUserLogin("john").setName("My Issue"), userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("Name already exists"); - } - verify(issueFilterDao, never()).update(any(IssueFilterDto.class)); - } - - @Test - public void should_update_data() { - when(issueFilterSerializer.serialize(anyMap())).thenReturn("componentRoots=struts"); - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setUserLogin("john")); - - Map data = newHashMap(); - data.put("componentRoots", "struts"); - - IssueFilterDto result = underTest.updateFilterQuery(1L, data, userSession); - assertThat(result.getData()).isEqualTo("componentRoots=struts"); - - verify(issueFilterDao).update(any(IssueFilterDto.class)); - } - - @Test - public void should_change_shared_filter_ownership_when_admin() { - IssueFilterDto sharedFilter = new IssueFilterDto().setId(1L).setName("My filter").setUserLogin("former.owner").setShared(true); - IssueFilterDto expectedDto = new IssueFilterDto().setName("My filter").setUserLogin("new.owner").setShared(true); - - when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(GlobalPermissions.SYSTEM_ADMIN)); - - when(issueFilterDao.selectById(1L)).thenReturn(sharedFilter); - when(issueFilterDao.selectSharedFilters()).thenReturn(Lists.newArrayList(sharedFilter)); - - IssueFilterDto issueFilter = new IssueFilterDto().setId(1L).setName("My filter").setShared(true).setUserLogin("new.owner"); - underTest.update(issueFilter, userSession); - - verify(issueFilterDao).update(argThat(Matches.filter(expectedDto))); - } - - @Test - public void should_deny_filter_ownership_change_when_not_admin() { - String currentUser = "dave.loper"; - IssueFilterDto sharedFilter = new IssueFilterDto().setId(1L).setName("My filter").setUserLogin(currentUser).setShared(true); - - when(authorizationDao.selectGlobalPermissions(currentUser)).thenReturn(newArrayList(GlobalPermissions.PROVISIONING)); - when(issueFilterDao.selectById(1L)).thenReturn(sharedFilter); - - try { - IssueFilterDto issueFilter = new IssueFilterDto().setId(1L).setName("My filter").setShared(true).setUserLogin("new.owner"); - underTest.update(issueFilter, new MockUserSession(currentUser).setUserId(1)); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("User is not authorized to change the owner of this filter"); - } - - verify(issueFilterDao, never()).update(any(IssueFilterDto.class)); - } - - @Test - public void should_delete() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("john")); - - underTest.delete(1L, userSession); - - verify(issueFilterDao).delete(1L); - } - - @Test - public void should_delete_favorite_filter_on_delete() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("john")); - when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(newArrayList(new IssueFilterFavouriteDto().setId(10L).setUserLogin("john").setIssueFilterId(1L))); - - underTest.delete(1L, userSession); - - verify(issueFilterDao).delete(1L); - verify(issueFilterFavouriteDao).deleteByFilterId(1L); - } - - @Test - public void should_not_delete_if_filter_not_found() { - when(issueFilterDao.selectById(1L)).thenReturn(null); - - try { - underTest.delete(1L, userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(NotFoundException.class).hasMessage("Filter not found: 1"); - } - verify(issueFilterDao, never()).delete(anyLong()); - } - - @Test - public void should_delete_shared_filter_if_user_is_admin() { - when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(GlobalPermissions.SYSTEM_ADMIN)); - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(true)); - - underTest.delete(1L, userSession); - - verify(issueFilterDao).delete(1L); - } - - @Test - public void should_not_delete_not_shared_filter_if_user_is_admin() { - when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(GlobalPermissions.SYSTEM_ADMIN)); - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(false)); - - try { - underTest.delete(1L, userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("User is not authorized to read this filter"); - } - verify(issueFilterDao, never()).delete(anyLong()); - } - - @Test - public void should_not_delete_shared_filter_if_not_admin() { - when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(UserRole.USER)); - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(true)); - - try { - underTest.delete(1L, userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("User is not authorized to modify this filter"); - } - verify(issueFilterDao, never()).delete(anyLong()); - } - - @Test - public void should_copy() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("john").setData("componentRoots=struts")); - IssueFilterDto issueFilter = new IssueFilterDto().setName("Copy Of My Issue"); - - IssueFilterDto result = underTest.copy(1L, issueFilter, userSession); - assertThat(result.getName()).isEqualTo("Copy Of My Issue"); - assertThat(result.getUserLogin()).isEqualTo("john"); - assertThat(result.getData()).isEqualTo("componentRoots=struts"); - - verify(issueFilterDao).insert(any(IssueFilterDto.class)); - } - - @Test - public void should_copy_shared_filter() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(true)); - IssueFilterDto issueFilter = new IssueFilterDto().setName("Copy Of My Issue"); - - IssueFilterDto result = underTest.copy(1L, issueFilter, userSession); - assertThat(result.getName()).isEqualTo("Copy Of My Issue"); - assertThat(result.getUserLogin()).isEqualTo("john"); - assertThat(result.isShared()).isFalse(); - - verify(issueFilterDao).insert(any(IssueFilterDto.class)); - } - - @Test - public void should_add_favorite_on_copy() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("john").setData("componentRoots=struts")); - IssueFilterDto issueFilter = new IssueFilterDto().setName("Copy Of My Issue"); - underTest.copy(1L, issueFilter, userSession); - - verify(issueFilterDao).insert(any(IssueFilterDto.class)); - verify(issueFilterFavouriteDao).insert(any(IssueFilterFavouriteDto.class)); - } - - @Test - public void should_execute_from_issue_query() { - IssueQuery issueQuery = IssueQuery.builder(userSession).build(); - SearchOptions searchOptions = new SearchOptions().setPage(2, 50); - - SearchResult result = mock(SearchResult.class); - when(result.getDocs()).thenReturn(newArrayList((IssueDoc) new IssueDoc())); - when(result.getTotal()).thenReturn(100L); - when(issueIndex.search(issueQuery, searchOptions)).thenReturn(result); - - IssueFilterService.IssueFilterResult issueFilterResult = underTest.execute(issueQuery, searchOptions); - assertThat(issueFilterResult.issues()).hasSize(1); - assertThat(issueFilterResult.paging().total()).isEqualTo(100); - assertThat(issueFilterResult.paging().pageIndex()).isEqualTo(2); - assertThat(issueFilterResult.paging().pageSize()).isEqualTo(50); - } - - @Test - public void should_find_shared_issue_filter() { - when(issueFilterDao.selectSharedFilters()).thenReturn(newArrayList( - new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("john").setShared(true), - new IssueFilterDto().setId(2L).setName("Project Issues").setUserLogin("arthur").setShared(true) - )); - - List results = underTest.findSharedFiltersWithoutUserFilters(userSession); - assertThat(results).hasSize(1); - IssueFilterDto filter = results.get(0); - assertThat(filter.getName()).isEqualTo("Project Issues"); - } - - @Test - public void should_find_favourite_issue_filter() { - when(issueFilterDao.selectFavoriteFiltersByUser("john")).thenReturn(newArrayList(new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("john"))); - - List results = underTest.findFavoriteFilters(userSession); - assertThat(results).hasSize(1); - } - - @Test - public void should_not_find_favourite_issue_filter_if_not_logged() { - try { - underTest.findFavoriteFilters(new AnonymousMockUserSession()); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(UnauthorizedException.class).hasMessage("User is not logged in"); - } - } - - @Test - public void should_add_favourite_issue_filter_id() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("john").setData("componentRoots=struts")); - // The filter is not in the favorite list --> add to favorite - when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(Collections.emptyList()); - - ArgumentCaptor issueFilterFavouriteDtoCaptor = ArgumentCaptor.forClass(IssueFilterFavouriteDto.class); - boolean result = underTest.toggleFavouriteIssueFilter(1L, userSession); - assertThat(result).isTrue(); - verify(issueFilterFavouriteDao).insert(issueFilterFavouriteDtoCaptor.capture()); - - IssueFilterFavouriteDto issueFilterFavouriteDto = issueFilterFavouriteDtoCaptor.getValue(); - assertThat(issueFilterFavouriteDto.getIssueFilterId()).isEqualTo(1L); - assertThat(issueFilterFavouriteDto.getUserLogin()).isEqualTo("john"); - } - - @Test - public void should_add_favourite_on_shared_filter() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(true)); - // The filter is not in the favorite list --> add to favorite - when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(Collections.emptyList()); - - ArgumentCaptor issueFilterFavouriteDtoCaptor = ArgumentCaptor.forClass(IssueFilterFavouriteDto.class); - boolean result = underTest.toggleFavouriteIssueFilter(1L, userSession); - assertThat(result).isTrue(); - verify(issueFilterFavouriteDao).insert(issueFilterFavouriteDtoCaptor.capture()); - - IssueFilterFavouriteDto issueFilterFavouriteDto = issueFilterFavouriteDtoCaptor.getValue(); - assertThat(issueFilterFavouriteDto.getIssueFilterId()).isEqualTo(1L); - assertThat(issueFilterFavouriteDto.getUserLogin()).isEqualTo("john"); - } - - @Test - public void should_delete_favourite_issue_filter_id() { - when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("john").setData("componentRoots=struts")); - // The filter is in the favorite list --> remove favorite - when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(newArrayList(new IssueFilterFavouriteDto().setId(10L).setUserLogin("john").setIssueFilterId(1L))); - - boolean result = underTest.toggleFavouriteIssueFilter(1L, userSession); - assertThat(result).isFalse(); - verify(issueFilterFavouriteDao).delete(10L); - } - - @Test - public void should_not_toggle_favourite_filter_if_filter_not_found() { - when(issueFilterDao.selectById(1L)).thenReturn(null); - try { - underTest.toggleFavouriteIssueFilter(1L, userSession); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(NotFoundException.class).hasMessage("Filter not found: 1"); - } - verify(issueFilterFavouriteDao, never()).delete(anyLong()); - } - - @Test - public void should_serialize_filter_query_ignore_unknown_parameter() { - Map props = newHashMap(); - props.put("componentRoots", "struts"); - props.put("statuses", "OPEN"); - props.put("unkwown", "JOHN"); - underTest.serializeFilterQuery(props); - - Map expected = newHashMap(); - expected.put("componentRoots", "struts"); - expected.put("statuses", "OPEN"); - verify(issueFilterSerializer).serialize(expected); - } - - @Test - public void should_deserialize_filter_query() { - IssueFilterDto issueFilter = new IssueFilterDto().setData("componentRoots=struts"); - underTest.deserializeIssueFilterQuery(issueFilter); - verify(issueFilterSerializer).deserialize("componentRoots=struts"); - } - - @Test - public void user_can_share_filter_if_logged() { - UserSession userSession = new MockUserSession("john"); - assertThat(underTest.canShareFilter(userSession)).isTrue(); - - assertThat(underTest.canShareFilter(new AnonymousMockUserSession())).isFalse(); - } - - @Test - public void should_create_filter_provided_by_platform() { - - ArgumentCaptor filterCaptor = ArgumentCaptor.forClass(IssueFilterDto.class); - - String savedData = "my super filter"; - underTest.save(new IssueFilterDto().setData(savedData)); - - verify(issueFilterDao).insert(filterCaptor.capture()); - - IssueFilterDto persistedFilter = filterCaptor.getValue(); - - assertThat(persistedFilter.getData()).isEqualTo(savedData); - } - - private static class Matches extends BaseMatcher { - - private final IssueFilterDto referenceFilter; - - private Matches(IssueFilterDto reference) { - referenceFilter = reference; - } - - static Matches filter(IssueFilterDto filterDto) { - return new Matches(filterDto); - } - - @Override - public boolean matches(Object o) { - if (o != null && o instanceof IssueFilterDto) { - IssueFilterDto otherFilter = (IssueFilterDto) o; - return ObjectUtils.equals(referenceFilter.isShared(), otherFilter.isShared()) - && ObjectUtils.equals(referenceFilter.getUserLogin(), otherFilter.getUserLogin()) - && ObjectUtils.equals(referenceFilter.getDescription(), otherFilter.getDescription()) - && ObjectUtils.equals(referenceFilter.getName(), otherFilter.getName()) - && ObjectUtils.equals(referenceFilter.getData(), otherFilter.getData()); - } - return false; - } - - @Override - public void describeTo(Description description) { - } - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsModuleTest.java deleted file mode 100644 index cdab24faa8d..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsModuleTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.junit.Test; -import org.sonar.core.platform.ComponentContainer; - -import static org.assertj.core.api.Assertions.assertThat; - -public class IssueFilterWsModuleTest { - @Test - public void verify_count_of_added_components() { - ComponentContainer container = new ComponentContainer(); - new IssueFilterWsModule().configure(container); - assertThat(container.size()).isEqualTo(10); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsTest.java deleted file mode 100644 index 1ac82189664..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.server.ws.WebService; -import org.sonar.db.DbClient; -import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.ws.WsTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -public class IssueFilterWsTest { - @Rule - public UserSessionRule userSession = UserSessionRule.standalone(); - - IssueFilterWs underTest; - WsTester ws; - - @Before - public void setUp() { - IssueFilterService service = mock(IssueFilterService.class); - DbClient dbClient = mock(DbClient.class); - underTest = new IssueFilterWs( - new AppAction(service, userSession), - new ShowAction(service, userSession), - new SearchAction(dbClient, userSession), - new FavoritesAction(service, userSession)); - ws = new WsTester(underTest); - } - - @Test - public void define_ws() { - WebService.Controller controller = ws.controller("api/issue_filters"); - assertThat(controller).isNotNull(); - assertThat(controller.description()).isNotEmpty(); - assertThat(controller.since()).isEqualTo("4.2"); - - WebService.Action app = controller.action("app"); - assertThat(app).isNotNull(); - assertThat(app.params()).hasSize(1); - - WebService.Action show = controller.action("show"); - assertThat(show).isNotNull(); - assertThat(show.responseExampleAsString()).isNotEmpty(); - assertThat(show.params()).hasSize(1); - - WebService.Action favorites = controller.action("favorites"); - assertThat(favorites).isNotNull(); - assertThat(favorites.params()).isEmpty(); - - WebService.Action search = controller.action("search"); - assertThat(search).isNotNull(); - assertThat(search.params()).isEmpty(); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/RegisterIssueFiltersTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/RegisterIssueFiltersTest.java deleted file mode 100644 index f8a9537fbfc..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/RegisterIssueFiltersTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import java.util.Date; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.DateUtils; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; -import org.sonar.db.issue.IssueFilterDao; -import org.sonar.db.loadedtemplate.LoadedTemplateDao; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - - -public class RegisterIssueFiltersTest { - - @Rule - public DbTester db = DbTester.create(System2.INSTANCE); - - RegisterIssueFilters taskUnderTest; - - private System2 system; - - @Before - public void setUp() { - IssueFilterDao issueFilterDao = new IssueFilterDao(db.myBatis()); - LoadedTemplateDao loadedTemplateDao = new LoadedTemplateDao(db.myBatis()); - system = mock(System2.class); - taskUnderTest = new RegisterIssueFilters(issueFilterDao, loadedTemplateDao, system); - } - - @Test - public void should_do_nothing_if_not_needed() { - db.prepareDbUnit(getClass(), "do_nothing.xml"); - taskUnderTest.start(); - taskUnderTest.stop(); - db.assertDbUnit(getClass(), "do_nothing-result.xml", "issue_filters"); - } - - @Test - public void should_register_issue_filters() { - Date now = DateUtils.parseDateTime("2011-04-25T01:15:00+0200"); - when(system.now()).thenReturn(now.getTime()); - - db.prepareDbUnit(getClass(), "empty.xml"); - taskUnderTest.start(); - taskUnderTest.stop(); - db.assertDbUnit(getClass(), "register-result.xml", new String[]{"created_at", "updated_at"}, "issue_filters", "loaded_templates"); - - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/SearchActionTest.java deleted file mode 100644 index 06753364261..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/SearchActionTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.db.issue.IssueFilterFavouriteDto; -import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.ws.TestResponse; -import org.sonar.server.ws.WsActionTester; - -import static org.sonar.test.JsonAssert.assertJson; - - -public class SearchActionTest { - static final String EMPTY_ISSUE_FILTERS_JSON = "{" + - " \"issueFilters\": []" + - "}"; - - @Rule - public DbTester db = DbTester.create(System2.INSTANCE); - @Rule - public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - WsActionTester ws; - DbClient dbClient; - DbSession dbSession; - - @Before - public void setUp() { - dbClient = db.getDbClient(); - dbSession = db.getSession(); - userSession.anonymous(); - - ws = new WsActionTester(new SearchAction(dbClient, userSession)); - } - - @Test - public void empty_response() throws Exception { - TestResponse result = newRequest(); - - assertJson(result.getInput()).isSimilarTo(EMPTY_ISSUE_FILTERS_JSON); - } - - @Test - public void issue_filter_with_all_cases() { - userSession.login("grace.hopper"); - IssueFilterDto myUnresolvedIssues = insertIssueFilter(new IssueFilterDto() - .setName("My Unresolved Issues") - .setShared(true) - .setData("resolved=false|assignees=__me__")); - IssueFilterDto falsePositiveAndWontFixIssues = insertIssueFilter(new IssueFilterDto() - .setName("False Positive and Won't Fix Issues") - .setShared(true) - .setData("resolutions=FALSE-POSITIVE,WONTFIX")); - IssueFilterDto unresolvedIssues = insertIssueFilter(new IssueFilterDto() - .setName("Unresolved Issues") - .setShared(true) - .setUserLogin("grace.hopper") - .setData("resolved=false")); - IssueFilterDto myCustomFilter = insertIssueFilter(new IssueFilterDto() - .setName("My Custom Filter") - .setShared(false) - .setUserLogin("grace.hopper") - .setData("resolved=false|statuses=OPEN,REOPENED|assignees=__me__")); - linkFilterToUser(myUnresolvedIssues.getId(), "grace.hopper"); - linkFilterToUser(myCustomFilter.getId(), "grace.hopper"); - linkFilterToUser(falsePositiveAndWontFixIssues.getId(), "another-login"); - linkFilterToUser(unresolvedIssues.getId(), "yet-another-login"); - commit(); - - TestResponse result = newRequest(); - - assertJson(result.getInput()).isSimilarTo(getClass().getResource("SearchActionTest/search.json")); - } - - private TestResponse newRequest() { - return ws.newRequest().execute(); - } - - private void linkFilterToUser(long filterId, String userLogin) { - dbClient.issueFilterFavouriteDao().insert(dbSession, new IssueFilterFavouriteDto() - .setIssueFilterId(filterId) - .setUserLogin(userLogin)); - } - - private IssueFilterDto insertIssueFilter(IssueFilterDto issueFilter) { - return dbClient.issueFilterDao().insert(dbSession, issueFilter); - } - - private void commit() { - dbSession.commit(); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/ShowActionTest.java deleted file mode 100644 index bbafbb62f3b..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/ShowActionTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.issue.filter; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.ws.WsTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class ShowActionTest { - @Rule - public UserSessionRule userSessionRule = UserSessionRule.standalone(); - - @Mock - IssueFilterService service; - - ShowAction action; - - WsTester tester; - - @Before - public void setUp() { - action = new ShowAction(service, userSessionRule); - tester = new WsTester(new IssueFilterWs(mock(AppAction.class), action, mock(SearchAction.class), mock(FavoritesAction.class))); - } - - @Test - public void show_filter() throws Exception { - // logged-in user is 'eric' but filter is owned by 'simon' - userSessionRule.login("eric").setUserId(123).setGlobalPermissions("none"); - when(service.find(13L, userSessionRule)).thenReturn( - new IssueFilterDto().setId(13L).setName("Blocker issues").setDescription("All Blocker Issues").setData("severity=BLOCKER").setUserLogin("simon").setShared(true) - ); - - tester.newGetRequest("api/issue_filters", "show").setParam("id", "13").execute() - .assertJson(getClass(), "show_filter.json"); - } - - @Test - public void show_unknown_filter() throws Exception { - userSessionRule.login("eric").setUserId(123).setGlobalPermissions("none"); - when(service.find(42L, userSessionRule)).thenThrow(new NotFoundException("Filter 42 does not exist")); - - try { - tester.newGetRequest("api/issue_filters", "show").setParam("id", "42").execute(); - fail(); - } catch (NotFoundException e) { - assertThat(e).hasMessage("Filter 42 does not exist"); - } - } - -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/anonymous_page.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/anonymous_page.json deleted file mode 100644 index 6a97863e116..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/anonymous_page.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "canManageFilters": false, - "canBulkChange": false -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page.json deleted file mode 100644 index 3a9d984361e..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "canManageFilters": true, - "canBulkChange": true, - "favorites": [] -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page_with_favorites.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page_with_favorites.json deleted file mode 100644 index 62f43b22021..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page_with_favorites.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "canManageFilters": true, - "canBulkChange": true, - "favorites": [ - { - "id": 6, - "name": "My issues" - }, - { - "id": 13, - "name": "Blocker issues" - } - ] -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page_with_selected_filter.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page_with_selected_filter.json deleted file mode 100644 index 0497cbd9eaa..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/logged_in_page_with_selected_filter.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "canManageFilters": true, - "canBulkChange": true, - "filter": { - "id": "13", - "name": "Blocker issues", - "shared": false, - "query": "severity=BLOCKER", - "user": "eric", - "canModify": true - }, - "favorites": [ - ] -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/selected_filter_can_not_be_modified.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/selected_filter_can_not_be_modified.json deleted file mode 100644 index ce741bedc35..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/AppActionTest/selected_filter_can_not_be_modified.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "canManageFilters": true, - "canBulkChange": true, - "filter": { - "id": "13", - "name": "Blocker issues", - "shared": true, - "query": "severity=BLOCKER", - "user": "simon", - "canModify": false - }, - "favorites": [ - ] -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/do_nothing-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/do_nothing-result.xml deleted file mode 100644 index 9ff915156a6..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/do_nothing-result.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/do_nothing.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/do_nothing.xml deleted file mode 100644 index 9ff915156a6..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/do_nothing.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/empty.xml deleted file mode 100644 index 871dedcb5e9..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/empty.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/register-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/register-result.xml deleted file mode 100644 index 4124c7a057a..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/RegisterIssueFiltersTest/register-result.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/SearchActionTest/search.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/SearchActionTest/search.json deleted file mode 100644 index 7bbcb909081..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/SearchActionTest/search.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "issueFilters": [ - { - "name": "My Unresolved Issues", - "shared": true, - "query": "resolved=false|assignees=__me__", - "user": "[SonarQube]", - "canModify": false, - "favorite": true - }, - { - "name": "False Positive and Won't Fix Issues", - "shared": true, - "query": "resolutions=FALSE-POSITIVE,WONTFIX", - "user": "[SonarQube]", - "canModify": false, - "favorite": false - }, - { - "name": "Unresolved Issues", - "shared": true, - "query": "resolved=false", - "user": "grace.hopper", - "canModify": true, - "favorite": false - }, - { - "name": "My Custom Filter", - "shared": false, - "query": "resolved=false|statuses=OPEN,REOPENED|assignees=__me__", - "user": "grace.hopper", - "canModify": true, - "favorite": true - } - ] -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/ShowActionTest/show_filter.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/ShowActionTest/show_filter.json deleted file mode 100644 index f0428f8d494..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/ShowActionTest/show_filter.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "filter": { - "id": "13", - "name": "Blocker issues", - "description": "All Blocker Issues", - "shared": true, - "query": "severity=BLOCKER", - "user": "simon", - "canModify": false - } -} diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb index 8385def1ca3..558c09d65e9 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb @@ -45,11 +45,7 @@ class IssuesController < ApplicationController issues_query_params = criteria_params.clone.merge({'pageSize' => -1}) # SONAR-4654 pagination parameters should be remove when loading issues for bulk change issues_query_params.delete('pageIndex') - if params[:id] - @issues = Internal.issues.execute(params[:id].to_i, issues_query_params).issues() - else - @issues = Internal.issues.execute(issues_query_params).issues() - end + @issues = Internal.issues.execute(issues_query_params) @projectUuids = Set.new(@issues.map {|issue| issue.projectUuid()}) @tags = Internal.issues.listTags() -- 2.39.5