aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-07-03 09:29:40 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-07-17 17:43:32 +0200
commita080f6f35834dc47d80474b5b0cc5fa5f50ec1fc (patch)
tree233c43333c63b4c2f46751be2112a9eb8cc771ab
parent7664f184eb4778d7ff83a1dd9505a18295db85ef (diff)
downloadsonarqube-a080f6f35834dc47d80474b5b0cc5fa5f50ec1fc.tar.gz
sonarqube-a080f6f35834dc47d80474b5b0cc5fa5f50ec1fc.zip
SONAR-6693 Create a new WS to list issue filters
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/filter/AppAction.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/filter/FavoritesAction.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterJsonWriter.java (renamed from server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWriter.java)22
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWs.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsAction.java27
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsModule.java39
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/filter/SearchAction.java73
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/filter/ShowAction.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java14
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/issue/filter/search-example-show.json25
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/AppActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterJsonWriterTest.java (renamed from server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java)6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsModuleTest.java35
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/SearchActionTest.java87
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/ShowActionTest.java4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/filter/SearchActionTest/logged_in_page_with_favorites.json18
18 files changed, 354 insertions, 58 deletions
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
index d79b0e74a7f..8facc8d02de 100644
--- 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
@@ -23,26 +23,26 @@ package org.sonar.server.issue.filter;
import com.google.common.io.Resources;
import java.util.List;
import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
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 AppAction implements RequestHandler {
+public class AppAction implements IssueFilterWsAction {
private final IssueFilterService service;
- private final IssueFilterWriter issueFilterWriter;
+ private final IssueFilterJsonWriter issueFilterJsonWriter;
private final UserSession userSession;
- public AppAction(IssueFilterService service, IssueFilterWriter issueFilterWriter, UserSession userSession) {
+ public AppAction(IssueFilterService service, IssueFilterJsonWriter issueFilterJsonWriter, UserSession userSession) {
this.service = service;
- this.issueFilterWriter = issueFilterWriter;
+ this.issueFilterJsonWriter = issueFilterJsonWriter;
this.userSession = userSession;
}
- void define(WebService.NewController controller) {
+ @Override
+ public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("app");
action
.setDescription("Data required for rendering the page 'Issues'")
@@ -72,7 +72,7 @@ public class AppAction implements RequestHandler {
// Selected filter
if (filter != null) {
- issueFilterWriter.write(userSession, filter, json);
+ issueFilterJsonWriter.writeWithName(json, filter, userSession);
}
// Favorite filters, if logged in
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
index c542fc41aed..baa23775e27 100644
--- 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
@@ -21,14 +21,13 @@
package org.sonar.server.issue.filter;
import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
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 RequestHandler {
+public class FavoritesAction implements IssueFilterWsAction {
private final IssueFilterService service;
private final UserSession userSession;
@@ -38,7 +37,8 @@ public class FavoritesAction implements RequestHandler {
this.userSession = userSession;
}
- void define(WebService.NewController controller) {
+ @Override
+ public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("favorites");
action
.setDescription("The issue filters marked as favorite by request user")
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWriter.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterJsonWriter.java
index a27cc6cc789..b4f3bac141e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWriter.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterJsonWriter.java
@@ -23,28 +23,34 @@ package org.sonar.server.issue.filter;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.db.issue.IssueFilterDto;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.issue.IssueFilterDto;
import org.sonar.server.user.UserSession;
@ServerSide
-public class IssueFilterWriter {
+public class IssueFilterJsonWriter {
+
+ void writeWithName(JsonWriter json, IssueFilterDto filter, UserSession userSession) {
+ json.name("filter");
+ write(json, filter, userSession);
+ }
- void write(UserSession session, IssueFilterDto filter, JsonWriter json) {
- json.name("filter").beginObject()
+ void write(JsonWriter json, IssueFilterDto filter, UserSession userSession) {
+ json
+ .beginObject()
.prop("id", filter.getId())
.prop("name", filter.getName())
.prop("description", filter.getDescription())
.prop("user", filter.getUserLogin())
.prop("shared", filter.isShared())
.prop("query", filter.getData())
- .prop("canModify", canModifyFilter(session, filter))
+ .prop("canModify", canModifyFilter(userSession, filter))
.endObject();
}
- private boolean canModifyFilter(UserSession session, IssueFilterDto filter) {
- return session.isLoggedIn() &&
- (StringUtils.equals(filter.getUserLogin(), session.getLogin()) || session.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN));
+ private boolean canModifyFilter(UserSession userSession, IssueFilterDto filter) {
+ return userSession.isLoggedIn() &&
+ (StringUtils.equals(filter.getUserLogin(), userSession.getLogin()) || userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN));
}
}
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
index e9569badf4b..f9c1b74d528 100644
--- 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
@@ -23,14 +23,10 @@ import org.sonar.api.server.ws.WebService;
public class IssueFilterWs implements WebService {
- private final AppAction appAction;
- private final ShowAction showAction;
- private final FavoritesAction favoritesAction;
+ private final IssueFilterWsAction[] actions;
- public IssueFilterWs(AppAction appAction, ShowAction showAction, FavoritesAction favoritesAction) {
- this.appAction = appAction;
- this.showAction = showAction;
- this.favoritesAction = favoritesAction;
+ public IssueFilterWs(IssueFilterWsAction... actions) {
+ this.actions = actions;
}
@Override
@@ -38,9 +34,9 @@ public class IssueFilterWs implements WebService {
NewController controller = context.createController("api/issue_filters")
.setSince("4.2")
.setDescription("Issue Filters management");
- appAction.define(controller);
- showAction.define(controller);
- favoritesAction.define(controller);
+ 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
new file mode 100644
index 00000000000..f8ad9b2a7ad
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsAction.java
@@ -0,0 +1,27 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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
new file mode 100644
index 00000000000..6571e68c41c
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterWsModule.java
@@ -0,0 +1,39 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/SearchAction.java
new file mode 100644
index 00000000000..f7e5ab9e205
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/SearchAction.java
@@ -0,0 +1,73 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 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;
+
+public class SearchAction implements IssueFilterWsAction {
+
+ private final IssueFilterService service;
+ private final IssueFilterJsonWriter issueFilterJsonWriter;
+ private final UserSession userSession;
+
+ public SearchAction(IssueFilterService service, IssueFilterJsonWriter issueFilterJsonWriter, UserSession userSession) {
+ this.service = service;
+ this.issueFilterJsonWriter = issueFilterJsonWriter;
+ this.userSession = userSession;
+ }
+
+ @Override
+ public void define(WebService.NewController controller) {
+ WebService.NewAction action = controller.createAction("search");
+ action
+ .setDescription("Get the list of favorite issue filters.")
+ .setInternal(false)
+ .setHandler(this)
+ .setSince("5.2")
+ .setResponseExample(Resources.getResource(this.getClass(), "search-example-show.json"));
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ JsonWriter json = response.newJsonWriter();
+ json.beginObject();
+
+ // Favorite filters, if logged in
+ if (userSession.isLoggedIn()) {
+ List<IssueFilterDto> favorites = service.findFavoriteFilters(userSession);
+ json.name("favorites").beginArray();
+ for (IssueFilterDto favorite : favorites) {
+ issueFilterJsonWriter.write(json, favorite, userSession);
+ }
+ json.endArray();
+ }
+
+ json.endObject();
+ json.close();
+ }
+}
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
index 4d8c5f4b54c..b9fdfe884fc 100644
--- 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
@@ -22,26 +22,26 @@ 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.RequestHandler;
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 ShowAction implements RequestHandler {
+public class ShowAction implements IssueFilterWsAction {
private final IssueFilterService service;
- private final IssueFilterWriter issueFilterWriter;
+ private final IssueFilterJsonWriter issueFilterJsonWriter;
private final UserSession userSession;
- public ShowAction(IssueFilterService service, IssueFilterWriter issueFilterWriter, UserSession userSession) {
+ public ShowAction(IssueFilterService service, IssueFilterJsonWriter issueFilterJsonWriter, UserSession userSession) {
this.service = service;
- this.issueFilterWriter = issueFilterWriter;
+ this.issueFilterJsonWriter = issueFilterJsonWriter;
this.userSession = userSession;
}
- void define(WebService.NewController controller) {
+ @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")
@@ -59,7 +59,7 @@ public class ShowAction implements RequestHandler {
JsonWriter json = response.newJsonWriter();
json.beginObject();
- issueFilterWriter.write(userSession, filter, json);
+ issueFilterJsonWriter.writeWithName(json, filter, userSession);
json.endObject();
json.close();
}
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 d5a674cc6ea..fff0cd3c1f4 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
@@ -139,10 +139,7 @@ import org.sonar.server.issue.SetSeverityAction;
import org.sonar.server.issue.TransitionAction;
import org.sonar.server.issue.actionplan.ActionPlanService;
import org.sonar.server.issue.actionplan.ActionPlanWs;
-import org.sonar.server.issue.filter.IssueFilterSerializer;
-import org.sonar.server.issue.filter.IssueFilterService;
-import org.sonar.server.issue.filter.IssueFilterWriter;
-import org.sonar.server.issue.filter.IssueFilterWs;
+import org.sonar.server.issue.filter.IssueFilterWsModule;
import org.sonar.server.issue.index.IssueAuthorizationIndexer;
import org.sonar.server.issue.index.IssueIndexDefinition;
import org.sonar.server.issue.index.IssueIndexer;
@@ -622,14 +619,7 @@ public class PlatformLevel4 extends PlatformLevel {
EmailNotificationChannel.class,
AlertsEmailTemplate.class,
- // issue filters
- IssueFilterService.class,
- IssueFilterSerializer.class,
- IssueFilterWs.class,
- IssueFilterWriter.class,
- org.sonar.server.issue.filter.AppAction.class,
- org.sonar.server.issue.filter.ShowAction.class,
- org.sonar.server.issue.filter.FavoritesAction.class,
+ IssueFilterWsModule.class,
// action plan
ActionPlanWs.class,
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/search-example-show.json b/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/search-example-show.json
new file mode 100644
index 00000000000..dbf2ac8b8d1
--- /dev/null
+++ b/server/sonar-server/src/main/resources/org/sonar/server/issue/filter/search-example-show.json
@@ -0,0 +1,25 @@
+{
+ "favorites": [
+ {
+ "id": 3,
+ "name": "My Unresolved Issues",
+ "shared": true,
+ "query": "resolved=false|assignees=__me__",
+ "canModify": true
+ },
+ {
+ "id": 2,
+ "name": "False Positive and Won't Fix Issues",
+ "shared": true,
+ "query": "resolutions=FALSE-POSITIVE,WONTFIX",
+ "canModify": true
+ },
+ {
+ "id": 1,
+ "name": "Unresolved Issues",
+ "shared": true,
+ "query": "resolved=false",
+ "canModify": true
+ }
+ ]
+}
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
index c82918b71ed..aacca7a8d28 100644
--- 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
@@ -42,7 +42,7 @@ public class AppActionTest {
@Mock
IssueFilterService service;
- IssueFilterWriter writer = new IssueFilterWriter();
+ IssueFilterJsonWriter writer = new IssueFilterJsonWriter();
AppAction action;
@@ -51,7 +51,7 @@ public class AppActionTest {
@Before
public void setUp() {
action = new AppAction(service, writer, userSessionRule);
- tester = new WsTester(new IssueFilterWs(action, mock(ShowAction.class), mock(FavoritesAction.class)));
+ tester = new WsTester(new IssueFilterWs(action, mock(ShowAction.class), mock(SearchAction.class), mock(FavoritesAction.class)));
}
@Test
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
index c46ffa1f68f..3346cbadb3b 100644
--- 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
@@ -43,7 +43,7 @@ public class FavoritesActionTest {
IssueFilterService service;
@Mock
- IssueFilterWriter writer;
+ IssueFilterJsonWriter writer;
FavoritesAction action;
@@ -52,7 +52,7 @@ public class FavoritesActionTest {
@Before
public void setUp() {
action = new FavoritesAction(service, userSessionRule);
- tester = new WsTester(new IssueFilterWs(mock(AppAction.class), mock(ShowAction.class), action));
+ tester = new WsTester(new IssueFilterWs(mock(AppAction.class), mock(ShowAction.class), mock(SearchAction.class), action));
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterJsonWriterTest.java
index 8fda234c3ee..cbda9f431e8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterJsonWriterTest.java
@@ -32,9 +32,9 @@ import java.io.StringWriter;
import static org.sonar.test.JsonAssert.assertJson;
-public class IssueFilterWriterTest {
+public class IssueFilterJsonWriterTest {
- IssueFilterWriter writer = new IssueFilterWriter();
+ IssueFilterJsonWriter writer = new IssueFilterJsonWriter();
@Test
public void write_filter() {
@@ -104,7 +104,7 @@ public class IssueFilterWriterTest {
StringWriter output = new StringWriter();
JsonWriter jsonWriter = JsonWriter.of(output);
jsonWriter.beginObject();
- writer.write(userSession, filter, jsonWriter);
+ writer.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/IssueFilterWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsModuleTest.java
new file mode 100644
index 00000000000..793881393c0
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsModuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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
index 322945d463c..1e9e082df35 100644
--- 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
@@ -40,7 +40,7 @@ public class IssueFilterWsTest {
IssueFilterService service;
@Mock
- IssueFilterWriter issueFilterWriter;
+ IssueFilterJsonWriter issueFilterJsonWriter;
IssueFilterWs ws;
@@ -48,7 +48,7 @@ public class IssueFilterWsTest {
@Before
public void setUp() {
- ws = new IssueFilterWs(new AppAction(service, issueFilterWriter, userSessionRule), new ShowAction(service, issueFilterWriter, userSessionRule), new FavoritesAction(service, userSessionRule));
+ ws = new IssueFilterWs(new AppAction(service, issueFilterJsonWriter, userSessionRule), new ShowAction(service, issueFilterJsonWriter, userSessionRule), new SearchAction(service, issueFilterJsonWriter, userSessionRule), new FavoritesAction(service, userSessionRule));
tester = new WsTester(ws);
}
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
new file mode 100644
index 00000000000..1d9c0b57698
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/SearchActionTest.java
@@ -0,0 +1,87 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.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;
+import static org.sonar.test.JsonAssert.assertJson;
+
+public class SearchActionTest {
+ static final String EMPTY_JSON = "{}";
+ static final String EMPTY_FAVORITES_JSON = "{" +
+ " \"favorites\": []" +
+ "}";
+
+ @Rule
+ public UserSessionRule userSessionRule = UserSessionRule.standalone();
+
+ IssueFilterService service = mock(IssueFilterService.class);
+ IssueFilterJsonWriter writer = new IssueFilterJsonWriter();
+ WsTester ws;
+
+ @Before
+ public void setUp() {
+ ws = new WsTester(new IssueFilterWs(new SearchAction(service, writer, userSessionRule)));
+ }
+
+ @Test
+ public void anonymous_app() throws Exception {
+ userSessionRule.anonymous();
+ WsTester.Result result = ws.newGetRequest("api/issue_filters", "search").execute();
+
+ assertJson(result.outputAsString()).isSimilarTo(EMPTY_JSON);
+ }
+
+ @Test
+ public void logged_in_app() throws Exception {
+ userSessionRule.login("eric").setUserId(123);
+ WsTester.Result result = ws.newGetRequest("api/issue_filters", "search").execute();
+
+ assertJson(result.outputAsString()).isSimilarTo(EMPTY_FAVORITES_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(3L)
+ .setName("My Unresolved Issues")
+ .setShared(true)
+ .setData("resolved=false|assignees=__me__"),
+ new IssueFilterDto()
+ .setId(2L)
+ .setName("False Positive and Won't Fix Issues")
+ .setShared(false)
+ .setData("resolutions=FALSE-POSITIVE,WONTFIX")
+ ));
+ ws.newGetRequest("api/issue_filters", "search").execute()
+ .assertJson(getClass(), "logged_in_page_with_favorites.json");
+ }
+}
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
index 69030f44484..48a21771108 100644
--- 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
@@ -44,7 +44,7 @@ public class ShowActionTest {
@Mock
IssueFilterService service;
- IssueFilterWriter writer = new IssueFilterWriter();
+ IssueFilterJsonWriter writer = new IssueFilterJsonWriter();
ShowAction action;
@@ -53,7 +53,7 @@ public class ShowActionTest {
@Before
public void setUp() {
action = new ShowAction(service, writer, userSessionRule);
- tester = new WsTester(new IssueFilterWs(mock(AppAction.class), action, mock(FavoritesAction.class)));
+ tester = new WsTester(new IssueFilterWs(mock(AppAction.class), action, mock(SearchAction.class), mock(FavoritesAction.class)));
}
@Test
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/SearchActionTest/logged_in_page_with_favorites.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/SearchActionTest/logged_in_page_with_favorites.json
new file mode 100644
index 00000000000..bbaa677e0fa
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/filter/SearchActionTest/logged_in_page_with_favorites.json
@@ -0,0 +1,18 @@
+{
+ "favorites": [
+ {
+ "id": 3,
+ "name": "My Unresolved Issues",
+ "shared": true,
+ "query": "resolved=false|assignees=__me__",
+ "canModify": false
+ },
+ {
+ "id": 2,
+ "name": "False Positive and Won't Fix Issues",
+ "shared": false,
+ "query": "resolutions=FALSE-POSITIVE,WONTFIX",
+ "canModify": false
+ }
+ ]
+}