]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2983 Unable to define an alert for a boolean metric
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 5 Apr 2012 14:24:23 +0000 (16:24 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 5 Apr 2012 14:24:23 +0000 (16:24 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AlertUtilsTest.java
sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb

index c9ab1e5d2169ef7e109b89e03364de325dcdbe62..5faddcff8212d92a981ef166fb783a9124a1030e 100644 (file)
@@ -84,7 +84,7 @@ public final class AlertUtils {
       return value;
     }
     if (metric.getType() == Metric.ValueType.BOOL) {
-      return Boolean.valueOf(value);
+      return Integer.parseInt(value);
     }
     if (metric.getType() == Metric.ValueType.RATING) {
       return Double.parseDouble(value);
@@ -106,7 +106,7 @@ public final class AlertUtils {
       return measure.getData();
     }
     if (metric.getType() == Metric.ValueType.BOOL) {
-      return measure.getValue() == 0d ? Boolean.FALSE : Boolean.TRUE;
+      return measure.getValue().intValue();
     }
     if (metric.getType() == Metric.ValueType.RATING) {
       return measure.getValue();
index f7eda8eb909b14f634aeb2b784fc594bef149cf4..dfc6eafd2b09b3e7f6133bb1fb990f5041650199 100644 (file)
@@ -218,17 +218,17 @@ public class AlertUtilsTest {
     alert.setOperator(Alert.OPERATOR_EQUALS);
     alert.setMetric(metric);
 
-    alert.setValueError("true");
+    alert.setValueError("1");
     Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
 
-    alert.setValueError("false");
+    alert.setValueError("0");
     Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
 
     alert.setOperator(Alert.OPERATOR_NOT_EQUALS);
-    alert.setValueError("true");
+    alert.setValueError("1");
     Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
 
-    alert.setValueError("false");
+    alert.setValueError("0");
     Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
   }
 
index 4a97fba3452ce829371c09375a37c2e57ffd8e49..87355bd7c946d134addaf9ede2a72d94259ab816 100644 (file)
@@ -76,13 +76,13 @@ module AlertsHelper
       text_field_tag fieldname, value, :size => 5
 
     elsif alert.metric.val_type==Metric::VALUE_TYPE_BOOLEAN
-      select_tag fieldname, {'' => '', 'Yes' => '1', 'No' => '0'}
+      select_tag fieldname, options_for_select([['', ''], ['Yes', '1'], ['No', '0']], value)
 
     elsif alert.metric.val_type==Metric::VALUE_TYPE_STRING
       text_field_tag fieldname, value, :size => 5
 
     elsif alert.metric.val_type==Metric::VALUE_TYPE_LEVEL
-      select_tag fieldname, {'' => '', 'OK' => Metric::TYPE_LEVEL_OK, 'Error' => Metric::TYPE_LEVEL_ERROR, 'Warning' => Metric::TYPE_LEVEL_WARN}
+      select_tag fieldname, options_for_select([['', ''], ['OK', Metric::TYPE_LEVEL_OK], ['Error', Metric::TYPE_LEVEL_ERROR], ['Warning', Metric::TYPE_LEVEL_WARN]], value)
     else
       hidden_field_tag fieldname, value
     end