*/
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
*/
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
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;
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;
--- /dev/null
+/*
+ * 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.
+ * <p/>
+ * 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<Integer, Widget> 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<Widget> getWidgets() {
+ return widgetsByColumn.values();
+ }
+
+ public List<Widget> 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.
+ * <p/>
+ * 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<String, String> 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<String, String> 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;
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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();
+
+}
+++ /dev/null
-/*
- * 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.
- * <p/>
- * 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<Integer, Widget> 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<Widget> getWidgets() {
- return widgetsByColumn.values();
- }
-
- public List<Widget> 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.
- * <p/>
- * 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<String, String> 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<String, String> 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;
- }
- }
-
-}
+++ /dev/null
-/*
- * 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;
- }
-
-}
+++ /dev/null
-/*
- * 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();
-
-}
--- /dev/null
+/*
+ * 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"));
+ }
+}
+++ /dev/null
-/*
- * 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"));
- }
-}
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;
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;