aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-12-13 15:40:00 +0100
committerFabrice Bellingard <bellingard@gmail.com>2011-12-13 15:40:56 +0100
commit65cb425e561a1789beee8baa12e6b1aace140c15 (patch)
tree49d124ea6a553209ab540b3089b0c63f69699362 /sonar-plugin-api/src
parent2ad595f71d67e104768d34d5ee0118820681cb25 (diff)
downloadsonarqube-65cb425e561a1789beee8baa12e6b1aace140c15.tar.gz
sonarqube-65cb425e561a1789beee8baa12e6b1aace140c15.zip
SONAR-1929 Modify the new DashboardTemplate API
- Replace the annotation-based one with a POJO one - Fix some issues based on Simon's feedback
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/AbstractDashboard.java75
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java53
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardWidget.java65
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardWidgets.java43
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetProperty.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Dashboard.java164
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardLayouts.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardLayouts.java)26
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardTemplate.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/web/Template.java)19
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Widget.java94
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/DashboardTest.java65
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/WidgetTest.java48
11 files changed, 405 insertions, 250 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/AbstractDashboard.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/AbstractDashboard.java
deleted file mode 100644
index d127c7c533c..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/AbstractDashboard.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;
-
-/**
- * Class that every plugin predefined dashboard should extend (as long as implement the {@link Dashboard} interface).
- *
- * @since 2.13
- */
-public abstract class AbstractDashboard {
-
- private static final String TEMPLATE_TYPE = "DASHBOARD";
-
- /**
- * Returns the identifier of this template.
- *
- * @see Template#getId()
- * @return
- */
- public abstract String getId();
-
- /**
- * Returns the name of the dashboard.
- *
- * @return the name
- */
- public abstract String getName();
-
- /**
- * Returns the description of the dashboard.
- *
- * @return the description
- */
- public String getDescription() {
- return "";
- }
-
- /**
- * Returns the layout for the dashboard.
- *
- * @see DashboardLayouts for the possible values.
- * @return the layout
- */
- public String getLayout() {
- return DashboardLayouts.TWO_COLUMNS;
- }
-
- /**
- * Returns the kind of template.
- *
- * @see Template#getType()
- * @return the type
- */
- public final String getType() {
- return TEMPLATE_TYPE;
- }
-
-}
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
deleted file mode 100644
index 4472dc08b08..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java
+++ /dev/null
@@ -1,53 +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;
-
-/**
- * A dashboard is a set of predefined and potentially parameterized widgets.
- *
- * As a "Template" extension, a dashboard will get created in the DB only once, when its plugin executes for the first time.
- *
- * @since 2.13
- */
-public interface Dashboard extends Template {
-
- /**
- * Returns the name of the dashboard.
- *
- * @return the name
- */
- String getName();
-
- /**
- * Returns the description of the dashboard.
- *
- * @return the description
- */
- String getDescription();
-
- /**
- * Returns the layout for the dashboard.
- *
- * @see DashboardLayouts for the possible values.
- * @return the layout
- */
- String getLayout();
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardWidget.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardWidget.java
deleted file mode 100644
index 7c7085c2f9f..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardWidget.java
+++ /dev/null
@@ -1,65 +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;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation used to specify a widget associated to a dashboard template. It must be nested inside a {@link DashboardWidgets} annotation.
- * It can contain {@link WidgetProperties} annotation to modify the widget default parameters.
- *
- * @since 2.13
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.ANNOTATION_TYPE)
-public @interface DashboardWidget {
-
- /**
- * ID of the widget.
- *
- * @return the id
- */
- String id();
-
- /**
- * The index of the column for this widget.
- *
- * @return the column index
- */
- int columnIndex();
-
- /**
- * The index of the row for this widget.
- *
- * @return the row index
- */
- int rowIndex();
-
- /**
- * The widget specific properties.
- *
- * @return the widget properties
- */
- WidgetProperty[] properties() default {};
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardWidgets.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardWidgets.java
deleted file mode 100644
index c9680521e2c..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardWidgets.java
+++ /dev/null
@@ -1,43 +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;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation used to specify the list of widgets associated to a dashboard template.
- *
- * @see AbstractDashboard
- * @since 2.13
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface DashboardWidgets {
-
- /**
- * List of {@link DashboardWidget} definitions.
- *
- * @return
- */
- DashboardWidget[] value() default {};
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetProperty.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetProperty.java
index 484d3b374fc..b1b4b6a8b05 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetProperty.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetProperty.java
@@ -19,10 +19,13 @@
*/
package org.sonar.api.web;
+import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
public @interface WidgetProperty {
String key();
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
new file mode 100644
index 00000000000..4843418eb04
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Dashboard.java
@@ -0,0 +1,164 @@
+/*
+ * 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 java.util.Collection;
+
+import com.google.common.collect.Lists;
+
+/**
+ *
+ * Definition of a dashboard.
+ *
+ * Its name and description can be retrieved using the i18n mechanism, using the keys "dashboard.&lt;id&gt;.name" and
+ * "dashboard.&lt;id&gt;.description".
+ *
+ * @since 2.13
+ */
+public final class Dashboard {
+
+ private String id;
+ private String name;
+ private String description;
+ private String layout;
+ private Collection<Widget> widgets;
+
+ private Dashboard() {
+ widgets = Lists.newArrayList();
+ }
+
+ /**
+ * Creates a new {@link Dashboard}. See {@link DashboardLayouts} for the layout parameter.
+ *
+ * @param id
+ * the id
+ * @param name
+ * the name
+ * @param layout
+ * the layout
+ */
+ public static Dashboard createDashboard(String id, String name, String layout) {
+ Dashboard dashboard = new Dashboard();
+ dashboard.setId(id);
+ dashboard.setName(name);
+ dashboard.setDescription("");
+ dashboard.setLayout(layout);
+ return dashboard;
+ }
+
+ /**
+ * Add a widget with the given parameters, and return the newly created {@link Widget} object if one wants to add parameters to it.
+ *
+ * @param id
+ * the id of the widget
+ * @param columnId
+ * the column for the widget
+ * @param rowId
+ * the row for the widget
+ * @return the new widget
+ */
+ public Widget addWidget(String id, int columnId, int rowId) {
+ Widget widget = new Widget(id, columnId, rowId);
+ widgets.add(widget);
+ return widget;
+ }
+
+ /**
+ * Returns the list of widgets.
+ *
+ * @return the widgets of this dashboard
+ */
+ public Collection<Widget> getWidgets() {
+ return widgets;
+ }
+
+ /**
+ * Returns the identifier of the dashboard.
+ *
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id
+ * the id to set
+ */
+ private void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Returns the name of the dashboard.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name
+ * the name to set
+ */
+ private void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * 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 void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Returns the layout of the dashboard.
+ *
+ * @return the layout
+ */
+ public String getLayout() {
+ return layout;
+ }
+
+ /**
+ * @param layout
+ * the layout to set
+ */
+ private void setLayout(String layout) {
+ this.layout = layout;
+ }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardLayouts.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardLayouts.java
index 5aa79ce4055..186a16f5b4c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardLayouts.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardLayouts.java
@@ -17,19 +17,41 @@
* 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;
+package org.sonar.api.web.dashboard;
/**
* Possible layouts for a dashboard.
*
* @since 2.13
*/
-public class DashboardLayouts {
+public final class DashboardLayouts {
+ private DashboardLayouts() {
+ }
+
+ /**
+ * Only 1 column that take all the page
+ */
public static final String ONE_COLUMN = "100%";
+
+ /**
+ * 2 columns of the same width
+ */
public static final String TWO_COLUMNS = "50%-50%";
+
+ /**
+ * 2 columns with the first one smaller than the second
+ */
public static final String TWO_COLUMNS_30_70 = "30%-70%";
+
+ /**
+ * 2 columns with the first one bigger than the second
+ */
public static final String TWO_COLUMNS_70_30 = "70%-30%";
+
+ /**
+ * 3 columns of the same width
+ */
public static final String TREE_COLUMNS = "33%-33%-33%";
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/Template.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardTemplate.java
index c8eec915ed1..17412997c68 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/web/Template.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/DashboardTemplate.java
@@ -17,28 +17,23 @@
* 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;
+package org.sonar.api.web.dashboard;
import org.sonar.api.ServerExtension;
/**
- * A template defines a server extension that will be run only once to initialize and store some data in the database.
+ *
+ * This extension point must be implemented to define a new dashboard.
*
* @since 2.13
*/
-public interface Template extends ServerExtension {
+public abstract class DashboardTemplate implements ServerExtension {
/**
- * Returns the identifier of this template.
+ * Returns the {@link Dashboard} object that represents the dashboard to use.
*
- * @return the id
+ * @return the dashboard
*/
- String getId();
+ public abstract Dashboard createDashboard();
- /**
- * Returns the kind of template.
- *
- * @return the type
- */
- String getType();
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Widget.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Widget.java
new file mode 100644
index 00000000000..8929f4f60f9
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Widget.java
@@ -0,0 +1,94 @@
+/*
+ * 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 java.util.Map;
+
+import com.google.common.collect.Maps;
+
+/**
+ *
+ * Definition of a widget inside a dashboard.
+ *
+ * @since 2.13
+ */
+public final class Widget {
+
+ private String id;
+ private int columnIndex;
+ private int rowIndex;
+ private Map<String, String> properties;
+
+ Widget(String id, int columnIndex, int rowIndex) {
+ this.id = id;
+ this.columnIndex = columnIndex;
+ this.rowIndex = rowIndex;
+ this.properties = Maps.newHashMap();
+ }
+
+ /**
+ * Adds a property to this widget.
+ *
+ * @param key
+ * the id of the property
+ * @param value
+ * the value of the property
+ */
+ public void addProperty(String key, String value) {
+ properties.put(key, value);
+ }
+
+ /**
+ * Returns the properties of this widget.
+ *
+ * @return the properties
+ */
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ /**
+ * Returns the identifier of this widget.
+ *
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Returns the column index of this widget.
+ *
+ * @return the columnIndex
+ */
+ public int getColumnIndex() {
+ return columnIndex;
+ }
+
+ /**
+ * Returns the row index of this widget.
+ *
+ * @return the rowIndex
+ */
+ public int getRowIndex() {
+ return rowIndex;
+ }
+
+}
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
new file mode 100644
index 00000000000..bcac4887a06
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/DashboardTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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 static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.junit.Test;
+
+public class DashboardTest {
+
+ @Test
+ public void shouldCreateDashboardAndWidget() throws Exception {
+ Dashboard dashboard = Dashboard.createDashboard("fake-dashboard", "Fake", "30%-70%");
+ assertThat(dashboard.getId(), is("fake-dashboard"));
+ assertThat(dashboard.getName(), is("Fake"));
+ assertThat(dashboard.getLayout(), is("30%-70%"));
+ assertThat(dashboard.getDescription(), is(""));
+
+ Widget widget = dashboard.addWidget("fake-widget", 12, 13);
+ assertThat(widget.getId(), is("fake-widget"));
+ assertThat(widget.getColumnIndex(), is(12));
+ assertThat(widget.getRowIndex(), is(13));
+
+ widget.addProperty("fake-property", "fake_metric");
+ Set<Entry<String, String>> properties = widget.getProperties().entrySet();
+ assertThat(properties.size(), is(1));
+ Entry<String, String> property = properties.iterator().next();
+ assertThat(property.getKey(), is("fake-property"));
+ assertThat(property.getValue(), is("fake_metric"));
+ }
+
+ @Test
+ public void shouldAddWidget() throws Exception {
+ Dashboard dashboard = Dashboard.createDashboard("fake-dashboard", "Fake", "30%-70%");
+ dashboard.addWidget("fake-widget", 12, 13);
+
+ Widget widget = dashboard.getWidgets().iterator().next();
+
+ assertThat(widget.getId(), is("fake-widget"));
+ assertThat(widget.getColumnIndex(), is(12));
+ assertThat(widget.getRowIndex(), is(13));
+ }
+
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/WidgetTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/WidgetTest.java
new file mode 100644
index 00000000000..199d83cd9ef
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/WidgetTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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 static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.junit.Test;
+
+public class WidgetTest {
+
+ @Test
+ public void shouldCreateWidgetWithProperties() throws Exception {
+ Dashboard dashboard = Dashboard.createDashboard("fake-dashboard", "Fake", "30%-70%");
+ Widget widget = dashboard.addWidget("fake-widget", 12, 13);
+ assertThat(widget.getId(), is("fake-widget"));
+ assertThat(widget.getColumnIndex(), is(12));
+ assertThat(widget.getRowIndex(), is(13));
+
+ widget.addProperty("fake-property", "fake_metric");
+ Set<Entry<String, String>> properties = widget.getProperties().entrySet();
+ assertThat(properties.size(), is(1));
+ Entry<String, String> property = properties.iterator().next();
+ assertThat(property.getKey(), is("fake-property"));
+ assertThat(property.getValue(), is("fake_metric"));
+ }
+
+}