From: Simon Brandhof Date: Fri, 16 Dec 2011 08:01:02 +0000 (+0100) Subject: SONAR-1929 move the package org.sonar.api.web.dashboard to org.sonar.api.web X-Git-Tag: 2.13~94 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=610fa9790673efac003b22b3f0e0b7e22fd733c1;p=sonarqube.git SONAR-1929 move the package org.sonar.api.web.dashboard to org.sonar.api.web No need anymore of a dedicated package --- diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/DefaultDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/DefaultDashboard.java index 85f331b914a..7b935de8a70 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/DefaultDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/DefaultDashboard.java @@ -19,9 +19,9 @@ */ package org.sonar.plugins.core.dashboards; -import org.sonar.api.web.dashboard.Dashboard; -import org.sonar.api.web.dashboard.DashboardLayout; -import org.sonar.api.web.dashboard.DashboardTemplate; +import org.sonar.api.web.Dashboard; +import org.sonar.api.web.DashboardLayout; +import org.sonar.api.web.DashboardTemplate; /** * Default dashboard diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java index c8b9a4fb648..0def3bd740b 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java @@ -19,9 +19,9 @@ */ package org.sonar.plugins.core.dashboards; -import org.sonar.api.web.dashboard.Dashboard; -import org.sonar.api.web.dashboard.DashboardLayout; -import org.sonar.api.web.dashboard.DashboardTemplate; +import org.sonar.api.web.Dashboard; +import org.sonar.api.web.DashboardLayout; +import org.sonar.api.web.DashboardTemplate; /** * Hotspot dashboard for Sonar diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java index d5148fa1767..bd4c5bd895b 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java @@ -21,8 +21,8 @@ package org.sonar.plugins.core.dashboards; import org.hamcrest.core.Is; import org.junit.Test; -import org.sonar.api.web.dashboard.Dashboard; -import org.sonar.api.web.dashboard.DashboardLayout; +import org.sonar.api.web.Dashboard; +import org.sonar.api.web.DashboardLayout; import static org.junit.Assert.assertThat; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java index 1057e9a5c96..83042ef59fc 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java @@ -21,8 +21,8 @@ package org.sonar.plugins.core.dashboards; import org.hamcrest.core.Is; import org.junit.Test; -import org.sonar.api.web.dashboard.Dashboard; -import org.sonar.api.web.dashboard.DashboardLayout; +import org.sonar.api.web.Dashboard; +import org.sonar.api.web.DashboardLayout; import static org.junit.Assert.assertThat; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java new file mode 100644 index 00000000000..8e709bd8e4b --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java @@ -0,0 +1,208 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.api.web; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; +import com.google.common.collect.Maps; +import org.apache.commons.lang.StringUtils; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * Definition of a dashboard. + *

+ * Its name and description can be retrieved using the i18n mechanism, using the keys "dashboard.<id>.name" and + * "dashboard.<id>.description". + * + * @since 2.13 + */ +public final class Dashboard { + + private String id; + private String name; + private String description; + private DashboardLayout layout = DashboardLayout.TWO_COLUMNS; + private ListMultimap widgetsByColumn = ArrayListMultimap.create(); + + private Dashboard() { + } + + /** + * Creates a new {@link Dashboard}. + */ + public static Dashboard create(String id, String name) { + return new Dashboard() + .setId(id) + .setName(name); + } + + /** + * The id is deduced from the name. + */ + public static Dashboard createByName(String name) { + String id = StringUtils.trimToEmpty(name); + id = StringUtils.lowerCase(id); + id = StringUtils.replaceChars(id, ' ', '_'); + return new Dashboard() + .setId(id) + .setName(name); + } + + /** + * Add a widget with the given parameters, and return the newly created {@link Widget} object if one wants to add parameters to it. + * + * @param widgetId id of an existing widget + * @param columnId column starts with 1. The widget is ignored if the column id does not match the layout. + */ + public Widget addWidget(String widgetId, int columnId) { + if (columnId < 1) { + throw new IllegalArgumentException("Widget column starts with 1"); + } + + Widget widget = new Widget(widgetId); + widgetsByColumn.put(columnId, widget); + return widget; + } + + public Collection getWidgets() { + return widgetsByColumn.values(); + } + + public List getWidgetsOfColumn(int columnId) { + return widgetsByColumn.get(columnId); + } + + /** + * Returns the identifier of the dashboard. + * + * @return the id + */ + public String getId() { + return id; + } + + private Dashboard setId(String id) { + if (StringUtils.isBlank(id)) { + throw new IllegalArgumentException("Dashboard id can not be blank"); + } + this.id = id; + return this; + } + + /** + * Returns the name of the dashboard. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + private Dashboard setName(String name) { + this.name = name; + return this; + } + + /** + * Returns the description of the dashboard. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Sets the description of the dashboard. + *

+ * Note: you should use the i18n mechanism for the description. + * + * @param description the description to set + */ + public Dashboard setDescription(String description) { + this.description = description; + return this; + } + + /** + * Returns the layout. Default value is the 2 columns mode with width 50%/50%. + * + * @return the layout + */ + public DashboardLayout getLayout() { + return layout; + } + + public Dashboard setLayout(DashboardLayout dl) { + if (dl == null) { + throw new IllegalArgumentException("The layout of the dashboard '" + getId() + "' can not be null"); + } + this.layout = dl; + return this; + } + + + /** + * Note that this class is an inner class to avoid confusion with the extension point org.sonar.api.web.Widget. + */ + public static final class Widget { + private String id; + private Map properties; + + Widget(String id) { + this.id = id; + this.properties = Maps.newHashMap(); + } + + public Widget setProperty(String key, String value) { + properties.put(key, value); + return this; + } + + /** + * Returns the properties of this widget. + * + * @return the properties + */ + public Map getProperties() { + return properties; + } + + public String getProperty(String key) { + return properties.get(key); + } + + /** + * Returns the identifier of this widget. + * + * @return the id + */ + public String getId() { + return id; + } + } + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardLayout.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardLayout.java new file mode 100644 index 00000000000..daa0ded2bb4 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardLayout.java @@ -0,0 +1,75 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.api.web; + +/** + * Possible layouts for a dashboard. + * + * @since 2.13 + */ +public enum DashboardLayout { + + /** + * Only 1 column that take all the page + */ + ONE_COLUMN("100%", 1), + + /** + * 2 columns of the same width + */ + TWO_COLUMNS("50%-50%", 2), + + /** + * 2 columns with the first one smaller than the second + */ + TWO_COLUMNS_30_70("30%-70%", 2), + + /** + * 2 columns with the first one bigger than the second + */ + TWO_COLUMNS_70_30("70%-30%", 2), + + /** + * 3 columns of the same width + */ + TREE_COLUMNS("33%-33%-33%", 3); + + private String code; + private int columns; + + private DashboardLayout(String code, int columns) { + this.code = code; + this.columns = columns; + } + + public String getCode() { + return code; + } + + public int getColumns() { + return columns; + } + + @Override + public String toString() { + return code; + } + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardTemplate.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardTemplate.java new file mode 100644 index 00000000000..ead4a5223df --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardTemplate.java @@ -0,0 +1,38 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.api.web; + +import org.sonar.api.ServerExtension; + +/** + * This extension point must be implemented to define a new dashboard. + * + * @since 2.13 + */ +public abstract class DashboardTemplate implements ServerExtension { + + /** + * Returns the {@link Dashboard} object that represents the dashboard to use. + * + * @return the dashboard + */ + public abstract Dashboard createDashboard(); + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Dashboard.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Dashboard.java deleted file mode 100644 index e1fa4b1df3b..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Dashboard.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.api.web.dashboard; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Maps; -import org.apache.commons.lang.StringUtils; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -/** - * Definition of a dashboard. - *

- * Its name and description can be retrieved using the i18n mechanism, using the keys "dashboard.<id>.name" and - * "dashboard.<id>.description". - * - * @since 2.13 - */ -public final class Dashboard { - - private String id; - private String name; - private String description; - private DashboardLayout layout = DashboardLayout.TWO_COLUMNS; - private ListMultimap widgetsByColumn = ArrayListMultimap.create(); - - private Dashboard() { - } - - /** - * Creates a new {@link Dashboard}. - */ - public static Dashboard create(String id, String name) { - return new Dashboard() - .setId(id) - .setName(name); - } - - /** - * The id is deduced from the name. - */ - public static Dashboard createByName(String name) { - String id = StringUtils.trimToEmpty(name); - id = StringUtils.lowerCase(id); - id = StringUtils.replaceChars(id, ' ', '_'); - return new Dashboard() - .setId(id) - .setName(name); - } - - /** - * Add a widget with the given parameters, and return the newly created {@link Widget} object if one wants to add parameters to it. - * - * @param widgetId id of an existing widget - * @param columnId column starts with 1. The widget is ignored if the column id does not match the layout. - */ - public Widget addWidget(String widgetId, int columnId) { - if (columnId < 1) { - throw new IllegalArgumentException("Widget column starts with 1"); - } - - Widget widget = new Widget(widgetId); - widgetsByColumn.put(columnId, widget); - return widget; - } - - public Collection getWidgets() { - return widgetsByColumn.values(); - } - - public List getWidgetsOfColumn(int columnId) { - return widgetsByColumn.get(columnId); - } - - /** - * Returns the identifier of the dashboard. - * - * @return the id - */ - public String getId() { - return id; - } - - private Dashboard setId(String id) { - if (StringUtils.isBlank(id)) { - throw new IllegalArgumentException("Dashboard id can not be blank"); - } - this.id = id; - return this; - } - - /** - * Returns the name of the dashboard. - * - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - private Dashboard setName(String name) { - this.name = name; - return this; - } - - /** - * Returns the description of the dashboard. - * - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * Sets the description of the dashboard. - *

- * Note: you should use the i18n mechanism for the description. - * - * @param description the description to set - */ - public Dashboard setDescription(String description) { - this.description = description; - return this; - } - - /** - * Returns the layout. Default value is the 2 columns mode with width 50%/50%. - * - * @return the layout - */ - public DashboardLayout getLayout() { - return layout; - } - - public Dashboard setLayout(DashboardLayout dl) { - if (dl == null) { - throw new IllegalArgumentException("The layout of the dashboard '" + getId() + "' can not be null"); - } - this.layout = dl; - return this; - } - - - /** - * Note that this class is an inner class to avoid confusion with the extension point org.sonar.api.web.Widget. - */ - public static final class Widget { - private String id; - private Map properties; - - Widget(String id) { - this.id = id; - this.properties = Maps.newHashMap(); - } - - public Widget setProperty(String key, String value) { - properties.put(key, value); - return this; - } - - /** - * Returns the properties of this widget. - * - * @return the properties - */ - public Map getProperties() { - return properties; - } - - public String getProperty(String key) { - return properties.get(key); - } - - /** - * Returns the identifier of this widget. - * - * @return the id - */ - public String getId() { - return id; - } - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardLayout.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardLayout.java deleted file mode 100644 index 3b698476dc7..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardLayout.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.api.web.dashboard; - -/** - * Possible layouts for a dashboard. - * - * @since 2.13 - */ -public enum DashboardLayout { - - /** - * Only 1 column that take all the page - */ - ONE_COLUMN("100%", 1), - - /** - * 2 columns of the same width - */ - TWO_COLUMNS("50%-50%", 2), - - /** - * 2 columns with the first one smaller than the second - */ - TWO_COLUMNS_30_70("30%-70%", 2), - - /** - * 2 columns with the first one bigger than the second - */ - TWO_COLUMNS_70_30("70%-30%", 2), - - /** - * 3 columns of the same width - */ - TREE_COLUMNS("33%-33%-33%", 3); - - private String code; - private int columns; - - private DashboardLayout(String code, int columns) { - this.code = code; - this.columns = columns; - } - - public String getCode() { - return code; - } - - public int getColumns() { - return columns; - } - - @Override - public String toString() { - return code; - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardTemplate.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardTemplate.java deleted file mode 100644 index 17412997c68..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardTemplate.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.api.web.dashboard; - -import org.sonar.api.ServerExtension; - -/** - * - * This extension point must be implemented to define a new dashboard. - * - * @since 2.13 - */ -public abstract class DashboardTemplate implements ServerExtension { - - /** - * Returns the {@link Dashboard} object that represents the dashboard to use. - * - * @return the dashboard - */ - public abstract Dashboard createDashboard(); - -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/DashboardTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/DashboardTest.java new file mode 100644 index 00000000000..ecc09898b8c --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/DashboardTest.java @@ -0,0 +1,107 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.api.web; + +import org.hamcrest.core.Is; +import org.junit.Test; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +public class DashboardTest { + + @Test + public void shouldCreateDashboard() { + Dashboard dashboard = Dashboard.create("fake-dashboard", "Fake"); + assertThat(dashboard.getId(), is("fake-dashboard")); + assertThat(dashboard.getName(), is("Fake")); + assertThat(dashboard.getLayout(), is(DashboardLayout.TWO_COLUMNS)); + assertThat(dashboard.getDescription(), nullValue()); + } + + @Test + public void shouldAddWidgets() { + Dashboard dashboard = Dashboard.createByName("Fake"); + Dashboard.Widget mostViolatedRules = dashboard.addWidget("most_violated_rules", 1); + assertThat(mostViolatedRules.getId(), is("most_violated_rules")); + assertThat(dashboard.getWidgets().size(), is(1)); + assertThat(dashboard.getWidgetsOfColumn(1).size(), is(1)); + + dashboard.addWidget("hotspots", 1); + assertThat(dashboard.getWidgets().size(), is(2)); + assertThat(dashboard.getWidgetsOfColumn(1).size(), is(2)); + + // widgets are sorted by order of insertion + assertThat(dashboard.getWidgetsOfColumn(1).get(1).getId(), is("hotspots")); + } + + @Test + public void shouldAddWidgetsOnDifferentColumns() { + Dashboard dashboard = Dashboard.createByName("Fake"); + + dashboard.addWidget("most_violated_rules", 1); + assertThat(dashboard.getWidgets().size(), is(1)); + assertThat(dashboard.getWidgetsOfColumn(1).size(), is(1)); + + dashboard.addWidget("hotspots", 2); + assertThat(dashboard.getWidgets().size(), is(2)); + assertThat(dashboard.getWidgetsOfColumn(2).size(), is(1)); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldFailIfBlankId() { + Dashboard.create(" ", "Fake"); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldFailToDeduceIdFromName() { + Dashboard.createByName(" "); + } + + @Test + public void shouldCreateByName() { + Dashboard dashboard = Dashboard.createByName("Fake"); + assertThat(dashboard.getId(), Is.is("fake")); + + dashboard = Dashboard.createByName(" Fake You "); + assertThat(dashboard.getId(), Is.is("fake_you")); + } + + @Test + public void shouldAddSeveralTimesTheSameWidget() { + Dashboard dashboard = Dashboard.createByName("Fake"); + dashboard.addWidget("most_violated_rules", 1); + dashboard.addWidget("most_violated_rules", 1).setProperty("foo", "bar"); + + assertThat(dashboard.getWidgets().size(), is(2)); + assertThat(dashboard.getWidgetsOfColumn(1).get(0).getProperties().size(), is(0)); + assertThat(dashboard.getWidgetsOfColumn(1).get(1).getProperty("foo"), is("bar")); + } + + @Test + public void shouldSetWidgetProperty() { + Dashboard dashboard = Dashboard.createByName("Fake"); + Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1); + widget.setProperty("foo", "bar"); + + assertThat(widget.getProperties().get("foo"), is("bar")); + } +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/DashboardTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/DashboardTest.java deleted file mode 100644 index 08c1b535cae..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/DashboardTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.api.web.dashboard; - -import org.hamcrest.core.Is; -import org.junit.Test; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - -public class DashboardTest { - - @Test - public void shouldCreateDashboard() { - Dashboard dashboard = Dashboard.create("fake-dashboard", "Fake"); - assertThat(dashboard.getId(), is("fake-dashboard")); - assertThat(dashboard.getName(), is("Fake")); - assertThat(dashboard.getLayout(), is(DashboardLayout.TWO_COLUMNS)); - assertThat(dashboard.getDescription(), nullValue()); - } - - @Test - public void shouldAddWidgets() { - Dashboard dashboard = Dashboard.createByName("Fake"); - Dashboard.Widget mostViolatedRules = dashboard.addWidget("most_violated_rules", 1); - assertThat(mostViolatedRules.getId(), is("most_violated_rules")); - assertThat(dashboard.getWidgets().size(), is(1)); - assertThat(dashboard.getWidgetsOfColumn(1).size(), is(1)); - - dashboard.addWidget("hotspots", 1); - assertThat(dashboard.getWidgets().size(), is(2)); - assertThat(dashboard.getWidgetsOfColumn(1).size(), is(2)); - - // widgets are sorted by order of insertion - assertThat(dashboard.getWidgetsOfColumn(1).get(1).getId(), is("hotspots")); - } - - @Test - public void shouldAddWidgetsOnDifferentColumns() { - Dashboard dashboard = Dashboard.createByName("Fake"); - - dashboard.addWidget("most_violated_rules", 1); - assertThat(dashboard.getWidgets().size(), is(1)); - assertThat(dashboard.getWidgetsOfColumn(1).size(), is(1)); - - dashboard.addWidget("hotspots", 2); - assertThat(dashboard.getWidgets().size(), is(2)); - assertThat(dashboard.getWidgetsOfColumn(2).size(), is(1)); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailIfBlankId() { - Dashboard.create(" ", "Fake"); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailToDeduceIdFromName() { - Dashboard.createByName(" "); - } - - @Test - public void shouldCreateByName() { - Dashboard dashboard = Dashboard.createByName("Fake"); - assertThat(dashboard.getId(), Is.is("fake")); - - dashboard = Dashboard.createByName(" Fake You "); - assertThat(dashboard.getId(), Is.is("fake_you")); - } - - @Test - public void shouldAddSeveralTimesTheSameWidget() { - Dashboard dashboard = Dashboard.createByName("Fake"); - dashboard.addWidget("most_violated_rules", 1); - dashboard.addWidget("most_violated_rules", 1).setProperty("foo", "bar"); - - assertThat(dashboard.getWidgets().size(), is(2)); - assertThat(dashboard.getWidgetsOfColumn(1).get(0).getProperties().size(), is(0)); - assertThat(dashboard.getWidgetsOfColumn(1).get(1).getProperty("foo"), is("bar")); - } - - @Test - public void shouldSetWidgetProperty() { - Dashboard dashboard = Dashboard.createByName("Fake"); - Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1); - widget.setProperty("foo", "bar"); - - assertThat(widget.getProperties().get("foo"), is("bar")); - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java index 7add3b89c7d..c8cc09c9a03 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java @@ -23,8 +23,8 @@ import com.google.common.collect.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.utils.TimeProfiler; -import org.sonar.api.web.dashboard.Dashboard; -import org.sonar.api.web.dashboard.DashboardTemplate; +import org.sonar.api.web.Dashboard; +import org.sonar.api.web.DashboardTemplate; import org.sonar.persistence.dashboard.*; import org.sonar.persistence.template.LoadedTemplateDao; import org.sonar.persistence.template.LoadedTemplateDto; diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java index d41719808d3..ae51e4b9701 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java @@ -22,9 +22,9 @@ package org.sonar.server.startup; import com.google.common.collect.Lists; import org.junit.Before; import org.junit.Test; -import org.sonar.api.web.dashboard.Dashboard; -import org.sonar.api.web.dashboard.DashboardLayout; -import org.sonar.api.web.dashboard.DashboardTemplate; +import org.sonar.api.web.Dashboard; +import org.sonar.api.web.DashboardLayout; +import org.sonar.api.web.DashboardTemplate; import org.sonar.persistence.dashboard.*; import org.sonar.persistence.template.LoadedTemplateDao; import org.sonar.persistence.template.LoadedTemplateDto;