From d28a121fe58d6155048ba244e92a36540cba9990 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 7 Dec 2015 17:35:03 +0100 Subject: SONAR-7030 Update widgets from Custom dashboard --- .../dashboard/template/ProjectCustomDashboard.java | 79 ++++++++++++++++++++++ .../template/ProjectDefaultDashboard.java | 76 --------------------- .../platform/platformlevel/PlatformLevel4.java | 4 +- .../template/ProjectCustomDashboardTest.java | 71 +++++++++++++++++++ .../template/ProjectDefaultDashboardTest.java | 71 ------------------- .../ProjectCustomDashboardTest/filters.xml | 33 +++++++++ .../ProjectDefaultDashboardTest/filters.xml | 33 --------- 7 files changed, 185 insertions(+), 182 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/dashboard/template/ProjectCustomDashboard.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/dashboard/template/ProjectDefaultDashboard.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectCustomDashboardTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectDefaultDashboardTest.java create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/dashboard/template/ProjectCustomDashboardTest/filters.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/dashboard/template/ProjectDefaultDashboardTest/filters.xml diff --git a/server/sonar-server/src/main/java/org/sonar/server/dashboard/template/ProjectCustomDashboard.java b/server/sonar-server/src/main/java/org/sonar/server/dashboard/template/ProjectCustomDashboard.java new file mode 100644 index 00000000000..bb24d96305b --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/dashboard/template/ProjectCustomDashboard.java @@ -0,0 +1,79 @@ +/* + * 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.dashboard.template; + +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.db.issue.IssueFilterDao; +import org.sonar.db.issue.IssueFilterDto; +import org.sonar.server.dashboard.widget.ProjectIssueFilterWidget; + +/** + * Custom dashboard + * + * @since 2.13 + */ +public final class ProjectCustomDashboard extends DashboardTemplate { + + private final IssueFilterDao issueFilterDao; + + public ProjectCustomDashboard(IssueFilterDao issueFilterDao) { + this.issueFilterDao = issueFilterDao; + } + + @Override + public String getName() { + return "Custom"; + } + + @Override + public Dashboard createDashboard() { + Dashboard dashboard = Dashboard.create(); + dashboard.setLayout(DashboardLayout.TWO_COLUMNS); + addFirstColumn(dashboard); + addSecondColumn(dashboard); + return dashboard; + } + + private void addFirstColumn(Dashboard dashboard) { + dashboard.addWidget("size", 1); + dashboard.addWidget("code_coverage", 1); + dashboard.addWidget("duplications", 1); + dashboard.addWidget("documentation_comments", 1); + } + + private void addSecondColumn(Dashboard dashboard) { + dashboard.addWidget("rules", 2); + dashboard.addWidget("timeline", 2); + IssueFilterDto unresolvedIssues = getIssueFilterByName("Unresolved Issues"); + dashboard.addWidget(ProjectIssueFilterWidget.ID, 2) + .setProperty(ProjectIssueFilterWidget.FILTER_PROPERTY, Long.toString(unresolvedIssues.getId())) + .setProperty(ProjectIssueFilterWidget.DISTRIBUTION_AXIS_PROPERTY, "createdAt"); + } + + 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; + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/dashboard/template/ProjectDefaultDashboard.java b/server/sonar-server/src/main/java/org/sonar/server/dashboard/template/ProjectDefaultDashboard.java deleted file mode 100644 index 3803fb2db63..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/dashboard/template/ProjectDefaultDashboard.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.dashboard.template; - -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.db.issue.IssueFilterDao; -import org.sonar.db.issue.IssueFilterDto; -import org.sonar.server.dashboard.widget.ProjectIssueFilterWidget; - -/** - * Default dashboard - * - * @since 2.13 - */ -public final class ProjectDefaultDashboard extends DashboardTemplate { - - private final IssueFilterDao issueFilterDao; - - public ProjectDefaultDashboard(IssueFilterDao issueFilterDao) { - this.issueFilterDao = issueFilterDao; - } - - @Override - public String getName() { - return "Dashboard"; - } - - @Override - public Dashboard createDashboard() { - Dashboard dashboard = Dashboard.create(); - dashboard.setLayout(DashboardLayout.TWO_COLUMNS); - addFirstColumn(dashboard); - addSecondColumn(dashboard); - return dashboard; - } - - private void addFirstColumn(Dashboard dashboard) { - dashboard.addWidget("technical_debt_pyramid", 1); - } - - private void addSecondColumn(Dashboard dashboard) { - IssueFilterDto unresolvedIssues = getIssueFilterByName("Unresolved Issues"); - - dashboard.addWidget(ProjectIssueFilterWidget.ID, 2) - .setProperty(ProjectIssueFilterWidget.FILTER_PROPERTY, Long.toString(unresolvedIssues.getId())) - .setProperty(ProjectIssueFilterWidget.DISTRIBUTION_AXIS_PROPERTY, "severities") - .setProperty(ProjectIssueFilterWidget.DISPLAY_MODE, "debt"); - } - - 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; - } - -} 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 de74d22e9fe..53b153bb349 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 @@ -66,7 +66,7 @@ import org.sonar.server.computation.taskprocessor.CeTaskProcessorModule; import org.sonar.server.computation.ws.CeWsModule; import org.sonar.server.config.ws.PropertiesWs; import org.sonar.server.dashboard.template.GlobalDefaultDashboard; -import org.sonar.server.dashboard.template.ProjectDefaultDashboard; +import org.sonar.server.dashboard.template.ProjectCustomDashboard; import org.sonar.server.dashboard.widget.ActionPlansWidget; import org.sonar.server.dashboard.widget.AlertsWidget; import org.sonar.server.dashboard.widget.BubbleChartWidget; @@ -352,7 +352,7 @@ public class PlatformLevel4 extends PlatformLevel { // Dashboard DashboardsWs.class, org.sonar.server.dashboard.ws.ShowAction.class, - ProjectDefaultDashboard.class, + ProjectCustomDashboard.class, GlobalDefaultDashboard.class, AlertsWidget.class, CoverageWidget.class, diff --git a/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectCustomDashboardTest.java b/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectCustomDashboardTest.java new file mode 100644 index 00000000000..b2b44a0c7f4 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectCustomDashboardTest.java @@ -0,0 +1,71 @@ +/* + * 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.dashboard.template; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.sonar.api.utils.System2; +import org.sonar.api.web.Dashboard; +import org.sonar.api.web.DashboardLayout; +import org.sonar.db.DbTester; +import org.sonar.db.issue.IssueFilterDao; +import org.sonar.test.DbTests; + +import static org.assertj.core.api.Assertions.assertThat; + +@Category(DbTests.class) +public class ProjectCustomDashboardTest { + + @Rule + public DbTester dbTester = DbTester.create(System2.INSTANCE); + + ProjectCustomDashboard template; + + @Before + public void setUp() { + IssueFilterDao issueFilterDao = new IssueFilterDao(dbTester.myBatis()); + template = new ProjectCustomDashboard(issueFilterDao); + } + + @Test + public void should_have_a_name() { + assertThat(template.getName()).isEqualTo("Custom"); + } + + @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(7); + } + + @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/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectDefaultDashboardTest.java b/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectDefaultDashboardTest.java deleted file mode 100644 index 55d1b2120f3..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/dashboard/template/ProjectDefaultDashboardTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.dashboard.template; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.sonar.api.utils.System2; -import org.sonar.api.web.Dashboard; -import org.sonar.api.web.DashboardLayout; -import org.sonar.db.DbTester; -import org.sonar.db.issue.IssueFilterDao; -import org.sonar.test.DbTests; - -import static org.assertj.core.api.Assertions.assertThat; - -@Category(DbTests.class) -public class ProjectDefaultDashboardTest { - - @Rule - public DbTester dbTester = DbTester.create(System2.INSTANCE); - - ProjectDefaultDashboard template; - - @Before - public void setUp() { - IssueFilterDao issueFilterDao = new IssueFilterDao(dbTester.myBatis()); - template = new ProjectDefaultDashboard(issueFilterDao); - } - - @Test - public void should_have_a_name() { - assertThat(template.getName()).isEqualTo("Dashboard"); - } - - @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(2); - } - - @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/server/sonar-server/src/test/resources/org/sonar/server/dashboard/template/ProjectCustomDashboardTest/filters.xml b/server/sonar-server/src/test/resources/org/sonar/server/dashboard/template/ProjectCustomDashboardTest/filters.xml new file mode 100644 index 00000000000..8ec92ddcdbf --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/dashboard/template/ProjectCustomDashboardTest/filters.xml @@ -0,0 +1,33 @@ + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/dashboard/template/ProjectDefaultDashboardTest/filters.xml b/server/sonar-server/src/test/resources/org/sonar/server/dashboard/template/ProjectDefaultDashboardTest/filters.xml deleted file mode 100644 index 8ec92ddcdbf..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/dashboard/template/ProjectDefaultDashboardTest/filters.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - -- cgit v1.2.3