summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-01 10:23:27 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-01 10:23:27 +0000
commit632c88629c99be66b63e04d8c5498c3d2ef23cf6 (patch)
tree2a5c33ebdf2538fc8ab05d04d74fe4ea3df84f58 /sonar-server
parent4e8a23e0d25305990324c1ddf31f2bdd097c95da (diff)
downloadsonarqube-632c88629c99be66b63e04d8c5498c3d2ef23cf6.tar.gz
sonarqube-632c88629c99be66b63e04d8c5498c3d2ef23cf6.zip
SONAR-1643 widgets require to be configured only if it has mandatory properties without default value
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java54
3 files changed, 62 insertions, 5 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java
index 8a7e569dc10..0f15f3ad8ae 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java
@@ -20,6 +20,7 @@
package org.sonar.server.ui;
import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
@@ -153,6 +154,16 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
return !ArrayUtils.isEmpty(properties);
}
+ public boolean hasRequiredProperties() {
+ boolean requires = false;
+ for (WidgetProperty property : properties) {
+ if (!property.optional() && StringUtils.isEmpty(property.defaultValue())) {
+ requires = true;
+ }
+ }
+ return requires;
+ }
+
@Override
public int hashCode() {
return getId().hashCode();
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
index 3811e1c6b83..5fc5729aba6 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
@@ -93,7 +93,7 @@ class DashboardController < ApplicationController
:name => definition.getTitle(),
:column_index => dashboard.number_of_columns,
:row_index => dashboard.column_size(dashboard.number_of_columns) + 1,
- :configured => !definition.isEditable())
+ :configured => !definition.hasRequiredProperties())
widget_id=new_widget.id
end
end
diff --git a/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java b/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java
index 410b2897f18..52eb5197aa7 100644
--- a/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java
@@ -20,10 +20,7 @@
package org.sonar.server.ui;
import org.junit.Test;
-import org.sonar.api.web.DefaultTab;
-import org.sonar.api.web.NavigationSection;
-import org.sonar.api.web.UserRole;
-import org.sonar.api.web.View;
+import org.sonar.api.web.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.lessThan;
@@ -117,6 +114,25 @@ public class ViewProxyTest {
assertThat(proxy.isDefaultTab(), is(false));
assertThat(proxy.getDefaultTabForMetrics(), is(new String[]{"ncloc", "coverage"}));
}
+
+ @Test
+ public void widgetShouldBeEditable() {
+ ViewProxy proxy = new ViewProxy<Widget>(new EditableWidget());
+ assertThat(proxy.isEditable(), is(true));
+ assertThat(proxy.getProperties().length, is(2));
+ }
+
+ @Test
+ public void widgetShouldRequireMandatoryProperties() {
+ ViewProxy proxy = new ViewProxy<Widget>(new EditableWidget());
+ assertThat(proxy.hasRequiredProperties(), is(true));
+ }
+
+ @Test
+ public void widgetShouldDefineOnlyOptionalProperties() {
+ ViewProxy proxy = new ViewProxy<Widget>(new WidgetWithOptionalProperties());
+ assertThat(proxy.hasRequiredProperties(), is(false));
+ }
}
class FakeView implements View {
@@ -135,3 +151,33 @@ class FakeView implements View {
return id;
}
}
+
+@WidgetProperties({
+ @WidgetProperty(key="foo", optional = false),
+ @WidgetProperty(key="bar", defaultValue = "30", type = "INTEGER")
+})
+class EditableWidget implements Widget {
+
+ public String getId() {
+ return "w1";
+ }
+
+ public String getTitle() {
+ return "W1";
+ }
+}
+
+@WidgetProperties({
+ @WidgetProperty(key="foo"),
+ @WidgetProperty(key="bar")
+})
+class WidgetWithOptionalProperties implements Widget {
+
+ public String getId() {
+ return "w2";
+ }
+
+ public String getTitle() {
+ return "W2";
+ }
+}