aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-12-15 17:00:18 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2011-12-15 17:00:18 +0100
commitb84f33030464fcc3e6e70affb1680381516a19e6 (patch)
tree46dcb237e52cd36760f8e1435cb220af10b56fb6 /sonar-plugin-api/src
parentf149f41b21b5d630bdaf98eaa80f15e47ef990e9 (diff)
downloadsonarqube-b84f33030464fcc3e6e70affb1680381516a19e6.tar.gz
sonarqube-b84f33030464fcc3e6e70affb1680381516a19e6.zip
SONAR-1929 refactoring of the extension point Dashboard
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Dashboard.java80
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/DashboardTest.java15
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/WidgetTest.java8
3 files changed, 42 insertions, 61 deletions
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
index 1396b1a22fa..5e91fa7f8b0 100644
--- 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
@@ -19,17 +19,16 @@
*/
package org.sonar.api.web.dashboard;
-import java.util.Collection;
-
import com.google.common.collect.Lists;
+import java.util.Collection;
+
/**
- *
* Definition of a dashboard.
- *
+ * <p/>
* 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 {
@@ -37,42 +36,23 @@ public final class Dashboard {
private String id;
private String name;
private String description;
- private DashboardLayout layout;
- private Collection<Widget> widgets;
+ private DashboardLayout layout = DashboardLayout.TWO_COLUMNS;
+ private Collection<Widget> widgets = Lists.newArrayList();
private Dashboard() {
- widgets = Lists.newArrayList();
}
/**
- * Creates a new {@link Dashboard}. See {@link DashboardLayout} for the layout parameter.
- *
- * @param id
- * the id
- * @param name
- * the name
- * @param layout
- * the layout
+ * Creates a new {@link Dashboard}-
*/
- public static Dashboard createDashboard(String id, String name, DashboardLayout layout) {
- Dashboard dashboard = new Dashboard();
- dashboard.setId(id);
- dashboard.setName(name);
- dashboard.setDescription("");
- dashboard.setLayout(layout);
- return dashboard;
+ public static Dashboard create(String id, String name) {
+ 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 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);
@@ -82,7 +62,7 @@ public final class Dashboard {
/**
* Returns the list of widgets.
- *
+ *
* @return the widgets of this dashboard
*/
public Collection<Widget> getWidgets() {
@@ -91,7 +71,7 @@ public final class Dashboard {
/**
* Returns the identifier of the dashboard.
- *
+ *
* @return the id
*/
public String getId() {
@@ -99,16 +79,16 @@ public final class Dashboard {
}
/**
- * @param id
- * the id to set
+ * @param id the id to set
*/
- private void setId(String id) {
+ private Dashboard setId(String id) {
this.id = id;
+ return this;
}
/**
* Returns the name of the dashboard.
- *
+ *
* @return the name
*/
public String getName() {
@@ -116,16 +96,16 @@ public final class Dashboard {
}
/**
- * @param name
- * the name to set
+ * @param name the name to set
*/
- private void setName(String name) {
+ private Dashboard setName(String name) {
this.name = name;
+ return this;
}
/**
* Returns the description of the dashboard.
- *
+ *
* @return the description
*/
public String getDescription() {
@@ -134,19 +114,19 @@ public final class Dashboard {
/**
* Sets the description of the dashboard.
- *
+ * <p/>
* Note: you should use the i18n mechanism for the description.
- *
- * @param description
- * the description to set
+ *
+ * @param description the description to set
*/
- public void setDescription(String description) {
+ public Dashboard setDescription(String description) {
this.description = description;
+ return this;
}
/**
* Returns the layout of the dashboard.
- *
+ *
* @return the layout
*/
public DashboardLayout getLayout() {
@@ -154,11 +134,11 @@ public final class Dashboard {
}
/**
- * @param layout
- * the layout to set
+ * @param layout the layout to set
*/
- private void setLayout(DashboardLayout layout) {
+ public Dashboard setLayout(DashboardLayout layout) {
this.layout = layout;
+ return this;
}
}
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
index 6c60e47be21..3555d786c4e 100644
--- 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
@@ -19,23 +19,24 @@
*/
package org.sonar.api.web.dashboard;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import org.junit.Test;
import java.util.Map.Entry;
import java.util.Set;
-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 shouldCreateDashboardAndWidget() throws Exception {
- Dashboard dashboard = Dashboard.createDashboard("fake-dashboard", "Fake", DashboardLayout.TWO_COLUMNS_30_70);
+ 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_30_70));
- assertThat(dashboard.getDescription(), is(""));
+ assertThat(dashboard.getLayout(), is(DashboardLayout.TWO_COLUMNS));
+ assertThat(dashboard.getDescription(), nullValue());
Widget widget = dashboard.addWidget("fake-widget", 12, 13);
assertThat(widget.getId(), is("fake-widget"));
@@ -52,7 +53,7 @@ public class DashboardTest {
@Test
public void shouldAddWidget() throws Exception {
- Dashboard dashboard = Dashboard.createDashboard("fake-dashboard", "Fake", DashboardLayout.TWO_COLUMNS_30_70);
+ Dashboard dashboard = Dashboard.create("fake-dashboard", "Fake");
dashboard.addWidget("fake-widget", 12, 13);
Widget widget = dashboard.getWidgets().iterator().next();
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
index 2d6fe2fc41b..a463fc81bf9 100644
--- 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
@@ -19,19 +19,19 @@
*/
package org.sonar.api.web.dashboard;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import org.junit.Test;
import java.util.Map.Entry;
import java.util.Set;
-import org.junit.Test;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
public class WidgetTest {
@Test
public void shouldCreateWidgetWithProperties() throws Exception {
- Dashboard dashboard = Dashboard.createDashboard("fake-dashboard", "Fake", DashboardLayout.TWO_COLUMNS_30_70);
+ Dashboard dashboard = Dashboard.create("fake-dashboard", "Fake");
Widget widget = dashboard.addWidget("fake-widget", 12, 13);
assertThat(widget.getId(), is("fake-widget"));
assertThat(widget.getColumnIndex(), is(12));