]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5148 Allow selection of periods 4 and 5 for quality gate conditions
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 23 Apr 2014 14:57:30 +0000 (16:57 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 23 Apr 2014 15:33:11 +0000 (17:33 +0200)
sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java
sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java
sonar-core/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee
sonar-server/src/main/hbs/quality-gates/quality-gate-detail-condition.hbs
sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java
sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java
sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java

index f2e5b36bbe24588fd2eec1e1d03d1e35cdefc33e..7515efc5b5a87ab78b49c729bd061add8822ba09 100644 (file)
@@ -188,6 +188,10 @@ class ConditionUtils {
       return measure.getVariation2();
     } else if (period == 3) {
       return measure.getVariation3();
+    } else if (period == 4) {
+      return measure.getVariation4();
+    } else if (period == 5) {
+      return measure.getVariation5();
     } else {
       throw new IllegalStateException("Following index period is not allowed : " + Double.toString(period));
     }
index 21a0550c6ff1654c86355dd88cbe93f4bac5ba5d..1a4be071193c55ef41860972d54b3e89f9bfe559 100644 (file)
@@ -302,8 +302,8 @@ public class QualityGateVerifierTest {
     verify(context).saveMeasure(argThat(hasLevel(measureRatingMetric, Metric.Level.OK)));
   }
 
-  @Test(expected = IllegalStateException.class)
-  public void shouldAllowOnlyVariationPeriodOneGlobalPeriods() {
+  @Test
+  public void shouldAllowVariationPeriodOnAllPeriods() {
     measureClasses.setVariation4(40d);
 
     ArrayList<ResolvedCondition> conditions = Lists.newArrayList(
@@ -312,6 +312,9 @@ public class QualityGateVerifierTest {
     when(qualityGate.conditions()).thenReturn(conditions);
 
     verifier.decorate(project, context);
+
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, null)));
+    verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.WARN)));
   }
 
   @Test(expected = NotImplementedException.class)
index fc43b1470e4e46567a9e7b998f8edce3d12a04a1..e9f2973f509cd347501c2a90f0495b35a5ef760a 100644 (file)
@@ -1662,6 +1662,7 @@ quality_gates.delete.confirm.message=Are you sure you want to delete the "{0}" q
 quality_gates.delete.confirm.default=Are you sure you want to delete the "{0}" quality gate, which is the default quality gate?
 quality_gates.delete_condition=Delete Condition
 quality_gates.delete_condition.confirm.message=Are you sure you want to delete the "{0}" condition?
+quality_gates.project_period=over period {0} - defined at project level
 
 
 #------------------------------------------------------------------------------
index e73343ac80b143154fc84578eb53a581818308eb..bf5af58c8e93547772b3ea7155179901e2ca3346 100644 (file)
@@ -59,7 +59,7 @@ define [
       @ui.periodSelect.select2
         allowClear: false
         minimumResultsForSearch: 999
-        width: '200px'
+        width: '100%'
 
       @ui.operatorSelect.select2
         allowClear: false
index 6ec2c6200f1015a687bf763d8b9d06428b68527e..7acd9800f2a80058ce7de6ae3a85b5923f7df5e9 100644 (file)
@@ -4,9 +4,9 @@
     <span class="deprecated">{{t 'deprecated'}}</span>
   {{/if}}
 </td>
-<td width="10%" nowrap>
+<td width="20%" nowrap>
   {{#if canEdit}}
-    <select name="period">
+    <select name="period" style="width: 100%">
       {{#unless isDiffMetric}}<option value="0">{{t 'value'}}</option>{{/unless}}
       {{#each periods}}<option value="{{key}}">&Delta; {{text}}</option>{{/each}}
     </select>
index c0682042c09236c1c4ab0935728c09195710b573..4d5b8b2a6496fe5e475561eeddf9014d0b3a4b72 100644 (file)
@@ -261,8 +261,8 @@ public class QualityGates {
       if (metric.getKey().startsWith("new_")) {
         validationMessages.add(Message.of("A period must be selected for differential metrics."));
       }
-    } else if (period < 1 || period > 3) {
-      validationMessages.add(Message.of("Valid periods are 1, 2 and 3."));
+    } else if (period < 1 || period > 5) {
+      validationMessages.add(Message.of("Valid periods are integers between 1 and 5 (included)."));
     }
   }
 
index bef4810027320b1f928638fd09014fa1357e53e6..a6734e39b67726d5dd00d098df2a2f4756815cb3 100644 (file)
@@ -78,6 +78,7 @@ public class QgateAppHandler implements RequestHandler {
       "quality_gates.delete.confirm.message",
       "quality_gates.delete.confirm.default",
       "quality_gates.delete_condition.confirm.message",
+      "quality_gates.project_period",
       "rename",
       "save",
       "set_as_default",
@@ -120,9 +121,17 @@ public class QgateAppHandler implements RequestHandler {
     for (int i=0; i < 3; i ++) {
       writer.beginObject().prop("key", i + 1).prop("text", periods.label(i + 1)).endObject();
     }
+    addProjectPeriod(4, writer);
+    addProjectPeriod(5, writer);
     writer.endArray();
   }
 
+  private void addProjectPeriod(int periodIndex, JsonWriter writer) {
+    writer.beginObject().prop("key", periodIndex).prop("text",
+      i18n.message(Locale.getDefault(), "quality_gates.project_period", "Period " + periodIndex, periodIndex)
+    ).endObject();
+  }
+
   private void addMessages(JsonWriter writer) {
     writer.name("messages").beginObject();
     for (String message: MESSAGE_KEYS) {
index 435ed2c0a26d72f67a54dbb1e6e83509e3a63814..4688136979c780915051f60141570f11f2192afd 100644 (file)
@@ -420,7 +420,7 @@ public class QualityGatesTest {
     when(metric.getType()).thenReturn(ValueType.BOOL);
     when(metricFinder.findByKey(anyString())).thenReturn(metric);
     when(dao.selectById(qGateId)).thenReturn(new QualityGateDto().setId(qGateId));
-    qGates.createCondition(qGateId, "alert_status", "EQ", null, "90", 4);
+    qGates.createCondition(qGateId, "alert_status", "EQ", null, "90", 6);
   }
 
   @Test
index bc0334256ed01fab77633612c740ae969a8de2c0..1e6baad3415403d5dcf5c03733a480e53040e95c 100644 (file)
@@ -87,9 +87,9 @@ public class QgateAppHandlerTest {
     Map responseJson = (Map) JSONValue.parse(json);
     assertThat((Boolean) responseJson.get("edit")).isFalse();
     Collection<Map> periods = (Collection<Map>) responseJson.get("periods");
-    assertThat(periods).hasSize(3);
+    assertThat(periods).hasSize(5);
     Map messages = (Map) responseJson.get("messages");
-    assertThat(messages).isNotNull().isNotEmpty().hasSize(53);
+    assertThat(messages).isNotNull().isNotEmpty().hasSize(54);
     for (Entry message: (Set<Entry>) messages.entrySet()) {
       assertThat(message.getKey()).isEqualTo(message.getValue());
     }