aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-03-09 18:13:19 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-03-10 15:49:22 +0100
commit93e3a0990b80453252bf442ecf0fb52b3f95a971 (patch)
tree9b6ecaf9cb34c0f8a917adeea99a64cdefe608cc /plugins
parent4411bd57b286b519f13017d061539b9789ae0f83 (diff)
downloadsonarqube-93e3a0990b80453252bf442ecf0fb52b3f95a971.tar.gz
sonarqube-93e3a0990b80453252bf442ecf0fb52b3f95a971.zip
SONAR-6236 Put back widgets on default "Issues" dashboard, based on new issue filter widget
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboard.java48
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest.java29
-rw-r--r--plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest/filters.xml33
3 files changed, 100 insertions, 10 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboard.java
index 295e62a67a8..32c23a27545 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboard.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboard.java
@@ -19,9 +19,12 @@
*/
package org.sonar.plugins.core.dashboards;
+import com.google.common.base.Preconditions;
import org.sonar.api.web.Dashboard;
import org.sonar.api.web.DashboardLayout;
import org.sonar.api.web.DashboardTemplate;
+import org.sonar.core.issue.db.IssueFilterDao;
+import org.sonar.core.issue.db.IssueFilterDto;
/**
* Issues dashboard for Sonar
@@ -30,6 +33,12 @@ import org.sonar.api.web.DashboardTemplate;
*/
public final class ProjectIssuesDashboard extends DashboardTemplate {
+ private final IssueFilterDao issueFilterDao;
+
+ public ProjectIssuesDashboard(IssueFilterDao issueFilterDao) {
+ this.issueFilterDao = issueFilterDao;
+ }
+
@Override
public String getName() {
return "Issues";
@@ -39,20 +48,43 @@ public final class ProjectIssuesDashboard extends DashboardTemplate {
public Dashboard createDashboard() {
Dashboard dashboard = Dashboard.create();
dashboard.setLayout(DashboardLayout.TWO_COLUMNS);
- addFirstColumn(dashboard);
- addSecondColumn();
+
+ IssueFilterDto unresolvedIssues = getIssueFilterByName("Unresolved Issues");
+ IssueFilterDto hiddenDebt = getIssueFilterByName("False Positive and Won't Fix Issues");
+ IssueFilterDto myUnresolvedIssues = getIssueFilterByName("My Unresolved Issues");
+
+ addFirstColumn(dashboard, unresolvedIssues);
+ addSecondColumn(dashboard, unresolvedIssues, hiddenDebt, myUnresolvedIssues);
return dashboard;
}
- private void addFirstColumn(Dashboard dashboard) {
- // TODO: + unresolved issues by status
+ private IssueFilterDto getIssueFilterByName(String name) {
+ IssueFilterDto filter = issueFilterDao.selectProvidedFilterByName(name);
+ Preconditions.checkState(filter != null, String.format("Could not find a provided issue filter with name '%s'", name));
+ return filter;
+ }
+
+ private void addFirstColumn(Dashboard dashboard, IssueFilterDto unresolvedIssues) {
+ // Unresolved issues by status
+ dashboard.addWidget("project_issue_filter", 1)
+ .setProperty("filter", Long.toString(unresolvedIssues.getId()))
+ .setProperty("distributionAxis", "statuses");
+ // Action plans
dashboard.addWidget("action_plans", 1);
}
- private void addSecondColumn() {
- // TODO: + unresolved issues by assignee
- // TODO: + my unresolved issues
- // TODO: + false positive and won't fix issues
+ private void addSecondColumn(Dashboard dashboard, IssueFilterDto unresolvedIssues, IssueFilterDto hiddenDebt, IssueFilterDto myUnresolvedIssues) {
+ // Unresolved issues by assignee
+ dashboard.addWidget("project_issue_filter", 2)
+ .setProperty("filter", Long.toString(unresolvedIssues.getId()))
+ .setProperty("distributionAxis", "assignees");
+ // My unresolved issues
+ dashboard.addWidget("project_issue_filter", 2)
+ .setProperty("filter", Long.toString(myUnresolvedIssues.getId()));
+ // False positive and won't fix issues by resolution
+ dashboard.addWidget("project_issue_filter", 2)
+ .setProperty("filter", Long.toString(hiddenDebt.getId()))
+ .setProperty("distributionAxis", "resolutions");
}
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest.java
index 7aa7d11bae0..28924a13293 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest.java
@@ -20,16 +20,32 @@
package org.sonar.plugins.core.dashboards;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.sonar.api.web.Dashboard;
import org.sonar.api.web.DashboardLayout;
+import org.sonar.core.issue.db.IssueFilterDao;
+import org.sonar.core.persistence.DbTester;
import org.sonar.plugins.core.CorePlugin;
+import org.sonar.test.DbTests;
import static org.assertj.core.api.Assertions.assertThat;
+@Category(DbTests.class)
public class ProjectIssuesDashboardTest {
- ProjectIssuesDashboard template = new ProjectIssuesDashboard();
+ @ClassRule
+ public static final DbTester dbTester = new DbTester();
+
+ ProjectIssuesDashboard template;
+
+ @Before
+ public void setUp() throws Exception {
+ IssueFilterDao issueFilterDao = new IssueFilterDao(dbTester.myBatis());
+ template = new ProjectIssuesDashboard(issueFilterDao);
+ }
@Test
public void should_have_a_name() {
@@ -43,10 +59,19 @@ public class ProjectIssuesDashboardTest {
@Test
public void should_create_dashboard() {
+ dbTester.prepareDbUnit(getClass(), "filters.xml");
Dashboard dashboard = template.createDashboard();
assertThat(dashboard.getLayout()).isEqualTo(DashboardLayout.TWO_COLUMNS);
- assertThat(dashboard.getWidgets()).hasSize(1);
+ assertThat(dashboard.getWidgets()).hasSize(5);
}
+ @Test
+ public void should_provide_clean_error_message_on_failure() {
+ try {
+ template.createDashboard();
+ } catch (IllegalStateException illegalState) {
+ assertThat(illegalState).hasMessage("Could not find a provided issue filter with name 'Unresolved Issues'");
+ }
+ }
}
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest/filters.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest/filters.xml
new file mode 100644
index 00000000000..8ec92ddcdbf
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/dashboards/ProjectIssuesDashboardTest/filters.xml
@@ -0,0 +1,33 @@
+<dataset>
+
+ <issue_filters
+ id="1"
+ name="Unresolved Issues"
+ user_login="[null]"
+ shared="[true]"
+ description="[null]"
+ data="resolved=false"
+ created_at="2011-04-25 01:15:00"
+ updated_at="2011-04-25 01:15:00" />
+
+ <issue_filters
+ id="2"
+ name="False Positive and Won't Fix Issues"
+ user_login="[null]"
+ shared="[true]"
+ description="[null]"
+ data="resolutions=FALSE-POSITIVE,WONTFIX"
+ created_at="2011-04-25 01:15:00"
+ updated_at="2011-04-25 01:15:00" />
+
+ <issue_filters
+ id="3"
+ name="My Unresolved Issues"
+ user_login="[null]"
+ shared="[true]"
+ description="[null]"
+ data="resolved=false|assignees=__me__"
+ created_at="2011-04-25 01:15:00"
+ updated_at="2011-04-25 01:15:00" />
+
+</dataset>