aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-12-16 08:32:48 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2011-12-16 08:33:01 +0100
commitc4d46ddae98dfcd7dbf34cdc1acd2416c0baef4d (patch)
tree403b67e5557f294c781b77f9e64d83a9af57c400 /sonar-plugin-api
parent9b2c7a304e54de416063bebca448663bfb515fa0 (diff)
downloadsonarqube-c4d46ddae98dfcd7dbf34cdc1acd2416c0baef4d.tar.gz
sonarqube-c4d46ddae98dfcd7dbf34cdc1acd2416c0baef4d.zip
SONAR-1929 minor refactoring + add some tests
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/dashboard/Dashboard.java14
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/DashboardTest.java17
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/WidgetTest.java48
3 files changed, 25 insertions, 54 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 9f56b90eab6..e1fa4b1df3b 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
@@ -48,7 +48,7 @@ public final class Dashboard {
}
/**
- * Creates a new {@link Dashboard}-
+ * Creates a new {@link Dashboard}.
*/
public static Dashboard create(String id, String name) {
return new Dashboard()
@@ -70,6 +70,9 @@ public final class 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 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) {
@@ -98,9 +101,6 @@ public final class Dashboard {
return id;
}
- /**
- * @param id the id to set
- */
private Dashboard setId(String id) {
if (StringUtils.isBlank(id)) {
throw new IllegalArgumentException("Dashboard id can not be blank");
@@ -148,7 +148,7 @@ public final class Dashboard {
}
/**
- * Returns the layout of the dashboard.
+ * Returns the layout. Default value is the 2 columns mode with width 50%/50%.
*
* @return the layout
*/
@@ -191,6 +191,10 @@ public final class Dashboard {
return properties;
}
+ public String getProperty(String key) {
+ return properties.get(key);
+ }
+
/**
* Returns the identifier of this widget.
*
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 b35a740c2ea..08c1b535cae 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
@@ -87,6 +87,21 @@ public class DashboardTest {
@Test
public void shouldAddSeveralTimesTheSameWidget() {
- // TODO
+ 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/WidgetTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/WidgetTest.java
deleted file mode 100644
index 95af6699d0f..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/web/dashboard/WidgetTest.java
+++ /dev/null
@@ -1,48 +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.junit.Test;
-
-import java.util.Map.Entry;
-import java.util.Set;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class WidgetTest {
-
- @Test
- public void shouldCreateWidget() {
- Dashboard dashboard = Dashboard.createByName("Fake");
- Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
- assertThat(widget.getId(), is("fake-widget"));
- }
-
- @Test
- public void shouldSetProperty() {
- Dashboard dashboard = Dashboard.createByName("Fake");
- Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
- widget.setProperty("foo", "bar");
-
- assertThat(widget.getProperties().get("foo"), is("bar"));
- }
-
-}