]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11571 Drop warning treshold from QG web services
authorBenoît Gianinetti <benoit.gianinetti@sonarsource.com>
Tue, 11 Dec 2018 14:57:05 +0000 (15:57 +0100)
committerSonarTech <sonartech@sonarsource.com>
Tue, 8 Jan 2019 19:21:07 +0000 (20:21 +0100)
92 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/ConditionImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/ConditionToCondition.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsData.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/Condition.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluator.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionStatus.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateStatus.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/webhook/WebhookPostTask.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ConditionImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ConditionToConditionTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/EvaluatedConditionTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SmallChangesetQualityGateSpecialCaseTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/webhook/WebhookPostTaskTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDbTester.java
server/sonar-db-dao/src/test/resources/org/sonar/db/qualitygate/QualityGateConditionDaoTest/update-result.xml
server/sonar-server-common/src/main/java/org/sonar/server/measure/index/ProjectMeasuresDoc.java
server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/Condition.java
server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java
server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/EvaluatedCondition.java
server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/QualityGateEvaluatorImpl.java
server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ShortLivingBranchQualityGate.java
server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java
server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java
server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionTest.java
server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedConditionTest.java
server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedQualityGateTest.java
server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateTest.java
server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ShortLivingBranchQualityGateTest.java
server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java
server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java
server/sonar-server/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
server/sonar-server/src/main/java/org/sonar/server/badge/ws/SvgGenerator.java
server/sonar-server/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateConverter.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsParameters.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java
server/sonar-server/src/main/java/org/sonar/server/util/MetricLevelTypeValidation.java
server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/project_status-example.json
server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/show-example.json
server/sonar-server/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java
server/sonar-server/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/badge/ws/SvgGeneratorTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CustomMeasureValidatorTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java
server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/qualitygate/ws/ProjectStatusActionTest/measure_data.json
server/sonar-server/src/test/resources/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest/non_leak_period.json
sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTaskTester.java
sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/QualityGate.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
sonar-plugin-api/src/test/java/org/sonar/api/ce/posttask/ConditionBuilder_PostProjectAnalysisTaskTesterTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/CreateConditionRequest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java
sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/UpdateConditionRequest.java
sonar-ws/src/main/protobuf/ws-qualitygates.proto

index 3871e10e93c2fd6010edefaa833852e2e770d647..dde8c0b2535cee7a3f18aa1d466b083b1ae0f4b2 100644 (file)
@@ -33,10 +33,7 @@ class ConditionImpl implements QualityGate.Condition {
   private final QualityGate.EvaluationStatus status;
   private final String metricKey;
   private final QualityGate.Operator operator;
-  @CheckForNull
   private final String errorThreshold;
-  @CheckForNull
-  private final String warningThreshold;
   private final boolean onLeakPeriod;
   @CheckForNull
   private final String value;
@@ -45,24 +42,17 @@ class ConditionImpl implements QualityGate.Condition {
     requireNonNull(builder.status, "status can not be null");
     requireNonNull(builder.metricKey, "metricKey can not be null");
     requireNonNull(builder.operator, "operator can not be null");
-    verifyThresholds(builder);
+    requireNonNull(builder.errorThreshold, "errorThreshold can not be null");
     verifyValue(builder);
 
     this.status = builder.status;
     this.metricKey = builder.metricKey;
     this.operator = builder.operator;
     this.errorThreshold = builder.errorThreshold;
-    this.warningThreshold = builder.warningThreshold;
     this.onLeakPeriod = builder.metricKey.startsWith("new_");
     this.value = builder.value;
   }
 
-  private static void verifyThresholds(Builder builder) {
-    checkArgument(
-      builder.errorThreshold != null || builder.warningThreshold != null,
-      "At least one of errorThreshold and warningThreshold must be non null");
-  }
-
   private static void verifyValue(Builder builder) {
     if (builder.status == NO_VALUE) {
       checkArgument(builder.value == null, "value must be null when status is %s", NO_VALUE);
@@ -78,11 +68,8 @@ class ConditionImpl implements QualityGate.Condition {
   public static class Builder {
     private String metricKey;
     private QualityGate.Operator operator;
-    @CheckForNull
     private String errorThreshold;
     @CheckForNull
-    private String warningThreshold;
-    @CheckForNull
     private String value;
     private QualityGate.EvaluationStatus status;
 
@@ -105,8 +92,11 @@ class ConditionImpl implements QualityGate.Condition {
       return this;
     }
 
+    /**
+     * @deprecated in 7.6. This method has no longer any effect.
+     */
+    @Deprecated
     public Builder setWarningThreshold(String warningThreshold) {
-      this.warningThreshold = warningThreshold;
       return this;
     }
 
@@ -153,9 +143,10 @@ class ConditionImpl implements QualityGate.Condition {
     return errorThreshold;
   }
 
+  @Deprecated
   @Override
   public String getWarningThreshold() {
-    return warningThreshold;
+    return null;
   }
 
   /**
@@ -181,7 +172,6 @@ class ConditionImpl implements QualityGate.Condition {
       ", metricKey='" + metricKey + '\'' +
       ", operator=" + operator +
       ", errorThreshold='" + errorThreshold + '\'' +
-      ", warningThreshold='" + warningThreshold + '\'' +
       ", value='" + value + '\'' +
       '}';
   }
index acc0297c63f5433cd218daf4f6ef8da94c009d52..2226440dbcc9c7b249df03340f51a9a18707783f 100644 (file)
@@ -52,7 +52,6 @@ class ConditionToCondition implements Function<Condition, QualityGate.Condition>
       .setMetricKey(metricKey)
       .setOperator(convert(input.getOperator()))
       .setErrorThreshold(input.getErrorThreshold())
-      .setWarningThreshold(input.getWarningThreshold())
       .setValue(conditionStatus.getValue())
       .build();
   }
@@ -63,8 +62,6 @@ class ConditionToCondition implements Function<Condition, QualityGate.Condition>
         return QualityGate.EvaluationStatus.NO_VALUE;
       case OK:
         return QualityGate.EvaluationStatus.OK;
-      case WARN:
-        return QualityGate.EvaluationStatus.WARN;
       case ERROR:
         return QualityGate.EvaluationStatus.ERROR;
       default:
index 4e14bc38d18a2ac511f6ef0e1da01c4381d1822d..574695e1223973713973e2b25fcd6ea304c2bdd6 100644 (file)
@@ -195,8 +195,6 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor
     switch (status) {
       case OK:
         return QualityGate.Status.OK;
-      case WARN:
-        return QualityGate.Status.WARN;
       case ERROR:
         return QualityGate.Status.ERROR;
       default:
index e8d534d3ff36adf4095d74f0f18879b143c1ba75..672517a0315eacbb1ab54aad1d04dbff252ed9d1 100644 (file)
@@ -40,7 +40,6 @@ public final class Measure {
 
   public enum Level {
     OK("Green"),
-    WARN("Orange"),
     ERROR("Red");
 
     private final String colorName;
@@ -125,7 +124,7 @@ public final class Measure {
     }
 
     public Measure create(boolean value, @Nullable String data) {
-      return new Measure(ValueType.BOOLEAN, developer, value ? 1.0d : 0.0d, data, null, qualityGateStatus, variation);
+      return new Measure(ValueType.BOOLEAN, developer, value ? 1.0D : 0.0D, data, null, qualityGateStatus, variation);
     }
 
     public Measure create(boolean value) {
@@ -239,7 +238,7 @@ public final class Measure {
    */
   public boolean getBooleanValue() {
     checkValueType(ValueType.BOOLEAN);
-    return value == 1.0d;
+    return value == 1.0D;
   }
 
   /**
index 8ed3865cff40953fa50caf93e14656d41b12f9f1..5c0071af71639a85bb8b42a7b5fa7034bcdc4bd3 100644 (file)
@@ -67,12 +67,7 @@ public class QualityGateDetailsData {
       // the actual value in the QG failure reason
       result.addProperty("period", 1);
     }
-    if (condition.getWarningThreshold() != null) {
-      result.addProperty("warning", condition.getWarningThreshold());
-    }
-    if (condition.getErrorThreshold() != null) {
-      result.addProperty("error", condition.getErrorThreshold());
-    }
+    result.addProperty("error", condition.getErrorThreshold());
     result.addProperty("actual", evaluatedCondition.getActualValue());
     result.addProperty(FIELD_LEVEL, evaluatedCondition.getLevel().name());
     return result;
index 8ee946eb63bb4035c6fd4a499a6ca31ac949251e..9aa090afc39148a2eabbf146461fb6dcb02f15b9 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.ce.task.projectanalysis.qualitygate;
 
 import com.google.common.base.MoreObjects;
-import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.ce.task.projectanalysis.metric.Metric;
@@ -47,19 +46,14 @@ public class Condition {
 
   private final Metric metric;
   private final Operator operator;
-  @CheckForNull
-  private final String warningThreshold;
-  @CheckForNull
   private final String errorThreshold;
   private final boolean useVariation;
 
-  public Condition(Metric metric, String operator,
-    @Nullable String errorThreshold, @Nullable String warningThreshold) {
+  public Condition(Metric metric, String operator, String errorThreshold) {
     this.metric = requireNonNull(metric);
     this.operator = parseFromDbValue(requireNonNull(operator));
     this.useVariation = metric.getKey().startsWith("new_");
     this.errorThreshold = errorThreshold;
-    this.warningThreshold = warningThreshold;
   }
 
   private static Operator parseFromDbValue(String str) {
@@ -83,12 +77,6 @@ public class Condition {
     return operator;
   }
 
-  @CheckForNull
-  public String getWarningThreshold() {
-    return warningThreshold;
-  }
-
-  @CheckForNull
   public String getErrorThreshold() {
     return errorThreshold;
   }
@@ -115,7 +103,6 @@ public class Condition {
     return MoreObjects.toStringHelper(this)
       .add("metric", metric)
       .add("operator", operator)
-      .add("warningThreshold", warningThreshold)
       .add("errorThreshold", errorThreshold)
       .toString();
   }
index 99633200d9fe0fa79b6595966fdf08c5fa8f6a64..2f5b44d83b80ea046fb9e1da26a87974814e7051 100644 (file)
@@ -21,9 +21,8 @@ package org.sonar.ce.task.projectanalysis.qualitygate;
 
 import java.util.Optional;
 import javax.annotation.CheckForNull;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.ce.task.projectanalysis.metric.Metric;
 import org.sonar.ce.task.projectanalysis.measure.Measure;
+import org.sonar.ce.task.projectanalysis.metric.Metric;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Optional.of;
@@ -41,37 +40,21 @@ public final class ConditionEvaluator {
       return new EvaluationResult(Measure.Level.OK, null);
     }
 
-    return evaluateCondition(condition, measureComparable, Measure.Level.ERROR)
-      .orElseGet(() -> evaluateCondition(condition, measureComparable, Measure.Level.WARN)
-        .orElseGet(() -> new EvaluationResult(Measure.Level.OK, measureComparable)));
+    return evaluateCondition(condition, measureComparable)
+      .orElseGet(() -> new EvaluationResult(Measure.Level.OK, measureComparable));
   }
 
-  private static Optional<EvaluationResult> evaluateCondition(Condition condition, Comparable<?> measureComparable, Measure.Level alertLevel) {
-    String conditionValue = getValueToEval(condition, alertLevel);
-    if (StringUtils.isEmpty(conditionValue)) {
-      return Optional.empty();
-    }
-
+  private static Optional<EvaluationResult> evaluateCondition(Condition condition, Comparable<?> measureComparable) {
     try {
-      Comparable conditionComparable = parseConditionValue(condition.getMetric(), conditionValue);
+      Comparable conditionComparable = parseConditionValue(condition.getMetric(), condition.getErrorThreshold());
       if (doesReachThresholds(measureComparable, conditionComparable, condition)) {
-        return of(new EvaluationResult(alertLevel, measureComparable));
+        return of(new EvaluationResult(Measure.Level.ERROR, measureComparable));
       }
       return Optional.empty();
     } catch (NumberFormatException badValueFormat) {
       throw new IllegalArgumentException(String.format(
         "Quality Gate: Unable to parse value '%s' to compare against %s",
-        conditionValue, condition.getMetric().getName()));
-    }
-  }
-
-  private static String getValueToEval(Condition condition, Measure.Level alertLevel) {
-    if (Measure.Level.ERROR.equals(alertLevel)) {
-      return condition.getErrorThreshold();
-    } else if (Measure.Level.WARN.equals(alertLevel)) {
-      return condition.getWarningThreshold();
-    } else {
-      throw new IllegalStateException(alertLevel.toString());
+        condition.getErrorThreshold(), condition.getMetric().getName()));
     }
   }
 
index 35adc5529a492758b5c3570cc0fe991ef4d1e5d4..4bb8911286a3a7616b91612793b24d2d92a2615c 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.ce.task.projectanalysis.measure.Measure;
 import org.sonar.ce.task.projectanalysis.metric.Metric;
 
 import static java.util.Objects.requireNonNull;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
 
 public final class EvaluationResultTextConverterImpl implements EvaluationResultTextConverter {
   private static final Map<Condition.Operator, String> OPERATOR_LABELS = ImmutableMap.of(
@@ -54,10 +53,10 @@ public final class EvaluationResultTextConverterImpl implements EvaluationResult
     if (evaluationResult.getLevel() == Measure.Level.OK) {
       return null;
     }
-    return getAlertLabel(condition, evaluationResult.getLevel());
+    return getAlertLabel(condition);
   }
 
-  private String getAlertLabel(Condition condition, Measure.Level level) {
+  private String getAlertLabel(Condition condition) {
     String metric = i18n.message(Locale.ENGLISH, "metric." + condition.getMetric().getKey() + ".name", condition.getMetric().getName());
 
     StringBuilder stringBuilder = new StringBuilder();
@@ -65,17 +64,16 @@ public final class EvaluationResultTextConverterImpl implements EvaluationResult
 
     stringBuilder
       .append(" ").append(OPERATOR_LABELS.get(condition.getOperator())).append(" ")
-      .append(alertValue(condition, level));
+      .append(alertValue(condition));
 
     return stringBuilder.toString();
   }
 
-  private String alertValue(Condition condition, Measure.Level level) {
-    String value = level == ERROR ? condition.getErrorThreshold() : condition.getWarningThreshold();
+  private String alertValue(Condition condition) {
     if (condition.getMetric().getType() == Metric.MetricType.WORK_DUR) {
-      return formatDuration(value);
+      return formatDuration(condition.getErrorThreshold());
     }
-    return value;
+    return condition.getErrorThreshold();
   }
 
   private String formatDuration(String value) {
index a2f75161f4d7eb9d73f6d738b742cfa0d7864a26..96ef3e0bd09b672d64af81f2dcd5beb407f1d27b 100644 (file)
@@ -72,7 +72,7 @@ public class QualityGateServiceImpl implements QualityGateService {
 
     Iterable<Condition> conditions = dtos.stream()
       .map(input -> metricRepository.getOptionalById(input.getMetricId())
-        .map(metric -> new Condition(metric, input.getOperator(), input.getErrorThreshold(), input.getWarningThreshold()))
+        .map(metric -> new Condition(metric, input.getOperator(), input.getErrorThreshold()))
         .orElse(null))
       .filter(Objects::nonNull)
       .collect(toList(dtos.size()));
@@ -85,7 +85,7 @@ public class QualityGateServiceImpl implements QualityGateService {
       ShortLivingBranchQualityGate.ID,
       ShortLivingBranchQualityGate.NAME,
       ShortLivingBranchQualityGate.CONDITIONS.stream()
-        .map(c -> new Condition(metricRepository.getByKey(c.getMetricKey()), c.getOperator(), c.getErrorThreshold(), c.getWarnThreshold()))
+        .map(c -> new Condition(metricRepository.getByKey(c.getMetricKey()), c.getOperator(), c.getErrorThreshold()))
         .collect(toList(ShortLivingBranchQualityGate.CONDITIONS.size())));
   }
 
index 3f87e33b04fe6d1da83f7ad9348447a53400a2f6..b7e696576b1496ef4d36456184d28d6a8346fee4 100644 (file)
@@ -124,8 +124,8 @@ public class QualityGateEventsStep implements ComputationStep {
   }
 
   /**
-   * @param label "Red (was Orange)"
-   * @param rawStatus OK, WARN or ERROR + optional text
+   * @param label "Red (was Green)"
+   * @param rawStatus OK or ERROR + optional text
    */
   private void notifyUsers(Component project, String label, QualityGateStatus rawStatus, boolean isNewAlert) {
     Notification notification = new Notification("alerts")
index 2c7925176a95cac6afd77311381c8dcfc06b52c4..772b10e8b09837c11b52fb44659505d9b237887b 100644 (file)
@@ -125,8 +125,6 @@ public class QualityGateMeasuresStep implements ComputationStep {
     switch (globalLevel) {
       case OK:
         return ConditionStatus.EvaluationStatus.OK;
-      case WARN:
-        return ConditionStatus.EvaluationStatus.WARN;
       case ERROR:
         return ConditionStatus.EvaluationStatus.ERROR;
       default:
@@ -140,8 +138,6 @@ public class QualityGateMeasuresStep implements ComputationStep {
     switch (globalLevel) {
       case OK:
         return org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatus.OK;
-      case WARN:
-        return org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatus.WARN;
       case ERROR:
         return org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatus.ERROR;
       default:
@@ -251,10 +247,7 @@ public class QualityGateMeasuresStep implements ComputationStep {
 
     public void addEvaluatedCondition(MetricEvaluationResult metricEvaluationResult) {
       Measure.Level level = metricEvaluationResult.evaluationResult.getLevel();
-      if (Measure.Level.WARN == level && this.globalLevel != Measure.Level.ERROR) {
-        globalLevel = Measure.Level.WARN;
-
-      } else if (Measure.Level.ERROR == level) {
+      if (Measure.Level.ERROR == level) {
         globalLevel = Measure.Level.ERROR;
       }
       evaluatedConditions.add(
index 91f426782ed8c2bc6e3955dfd5044051ee312b94..cea109218f169469204ca40b679a9d89411ee9a3 100644 (file)
@@ -64,8 +64,7 @@ public class WebhookPostTask implements PostProjectAnalysisTask {
         EvaluatedQualityGate.Builder builder = EvaluatedQualityGate.newBuilder();
         Set<Condition> conditions = qg.getConditions().stream()
           .map(q -> {
-            Condition condition = new Condition(q.getMetricKey(), Condition.Operator.valueOf(q.getOperator().name()),
-              q.getErrorThreshold(), q.getWarningThreshold());
+            Condition condition = new Condition(q.getMetricKey(), Condition.Operator.valueOf(q.getOperator().name()), q.getErrorThreshold());
             builder.addCondition(condition,
               EvaluatedCondition.EvaluationStatus.valueOf(q.getStatus().name()),
               q.getStatus() == org.sonar.api.ce.posttask.QualityGate.EvaluationStatus.NO_VALUE ? null : q.getValue());
index 190a16e3215bd3893142f823d313d2ab04057baa..0438f014b972f53207bdf05f571d781aff652672 100644 (file)
@@ -34,7 +34,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class ConditionImplTest {
   private static final String METRIC_KEY = "metricKey";
   private static final String ERROR_THRESHOLD = "error threshold";
-  private static final String WARN_THRESHOLD = "warn threshold";
   private static final String VALUE = "value";
 
   @Rule
@@ -45,7 +44,6 @@ public class ConditionImplTest {
     .setMetricKey(METRIC_KEY)
     .setOperator(QualityGate.Operator.GREATER_THAN)
     .setErrorThreshold(ERROR_THRESHOLD)
-    .setWarningThreshold(WARN_THRESHOLD)
     .setValue(VALUE);
 
   @Test
@@ -79,12 +77,11 @@ public class ConditionImplTest {
   }
 
   @Test
-  public void build_throws_IAE_if_both_thresholds_are_null() {
-    builder.setWarningThreshold(null)
-      .setErrorThreshold(null);
+  public void build_throws_NPE_if_error_threshold_is_null() {
+    builder.setErrorThreshold(null);
 
-    expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("At least one of errorThreshold and warningThreshold must be non null");
+    expectedException.expect(NullPointerException.class);
+    expectedException.expectMessage("errorThreshold can not be null");
 
     builder.build();
   }
@@ -139,7 +136,7 @@ public class ConditionImplTest {
   public void toString_ConditionImpl_of_type_different_from_NO_VALUE() {
     assertThat(builder.build().toString())
       .isEqualTo(
-        "ConditionImpl{status=OK, metricKey='metricKey', operator=GREATER_THAN, errorThreshold='error threshold', warningThreshold='warn threshold', value='value'}");
+        "ConditionImpl{status=OK, metricKey='metricKey', operator=GREATER_THAN, errorThreshold='error threshold', value='value'}");
   }
 
   @Test
@@ -149,7 +146,7 @@ public class ConditionImplTest {
 
     assertThat(builder.build().toString())
       .isEqualTo(
-        "ConditionImpl{status=NO_VALUE, metricKey='metricKey', operator=GREATER_THAN, errorThreshold='error threshold', warningThreshold='warn threshold', value='null'}");
+        "ConditionImpl{status=NO_VALUE, metricKey='metricKey', operator=GREATER_THAN, errorThreshold='error threshold', value='null'}");
   }
 
   @Test
@@ -160,7 +157,6 @@ public class ConditionImplTest {
     assertThat(underTest.getMetricKey()).isEqualTo(METRIC_KEY);
     assertThat(underTest.getOperator()).isEqualTo(QualityGate.Operator.GREATER_THAN);
     assertThat(underTest.getErrorThreshold()).isEqualTo(ERROR_THRESHOLD);
-    assertThat(underTest.getWarningThreshold()).isEqualTo(WARN_THRESHOLD);
     assertThat(underTest.getValue()).isEqualTo(VALUE);
   }
 }
index b78da1eb6689d58b90f72e62bb47767c7733a8c6..3fd169ee0ca002b8539e9efcab324aba0cdcd60f 100644 (file)
@@ -42,12 +42,10 @@ import static org.mockito.Mockito.when;
 public class ConditionToConditionTest {
   private static final String METRIC_KEY = "metricKey";
   private static final String ERROR_THRESHOLD = "error threshold";
-  private static final String WARN_THRESHOLD = "warn threshold";
   private static final Map<Condition, ConditionStatus> NO_STATUS_PER_CONDITIONS = Collections.emptyMap();
   private static final String SOME_VALUE = "some value";
   private static final ConditionStatus SOME_CONDITION_STATUS = ConditionStatus.create(ConditionStatus.EvaluationStatus.OK, SOME_VALUE);
-  private static final Condition SOME_CONDITION = new Condition(newMetric(METRIC_KEY), Condition.Operator.EQUALS.getDbValue(), ERROR_THRESHOLD, WARN_THRESHOLD);
-
+  private static final Condition SOME_CONDITION = new Condition(newMetric(METRIC_KEY), Condition.Operator.EQUALS.getDbValue(), ERROR_THRESHOLD);
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
@@ -92,13 +90,12 @@ public class ConditionToConditionTest {
     ConditionToCondition underTest = new ConditionToCondition(of(SOME_CONDITION, SOME_CONDITION_STATUS));
 
     assertThat(underTest.apply(SOME_CONDITION).getErrorThreshold()).isEqualTo(ERROR_THRESHOLD);
-    assertThat(underTest.apply(SOME_CONDITION).getWarningThreshold()).isEqualTo(WARN_THRESHOLD);
   }
 
   @Test
   @UseDataProvider("allOperatorValues")
   public void apply_converts_all_values_of_operator(Condition.Operator operator) {
-    Condition condition = new Condition(newMetric(METRIC_KEY), operator.getDbValue(), ERROR_THRESHOLD, WARN_THRESHOLD);
+    Condition condition = new Condition(newMetric(METRIC_KEY), operator.getDbValue(), ERROR_THRESHOLD);
     ConditionToCondition underTest = new ConditionToCondition(of(condition, SOME_CONDITION_STATUS));
 
     assertThat(underTest.apply(condition).getOperator().name()).isEqualTo(operator.name());
@@ -106,7 +103,7 @@ public class ConditionToConditionTest {
 
   @Test
   public void apply_copies_value() {
-    Condition otherCondition = new Condition(newMetric(METRIC_KEY), Condition.Operator.NOT_EQUALS.getDbValue(), ERROR_THRESHOLD, WARN_THRESHOLD);
+    Condition otherCondition = new Condition(newMetric(METRIC_KEY), Condition.Operator.NOT_EQUALS.getDbValue(), ERROR_THRESHOLD);
     ConditionToCondition underTest = new ConditionToCondition(of(
       SOME_CONDITION, SOME_CONDITION_STATUS,
       otherCondition, ConditionStatus.NO_VALUE_STATUS));
index 737791816d2ee791e7831250c40447a515d3abc9..6a460d59425228b52f393ddc8975a5050a55c02b 100644 (file)
@@ -391,7 +391,7 @@ public class PostProjectAnalysisTasksExecutorTest {
   private static Condition createCondition(String metricKey) {
     Metric metric = mock(Metric.class);
     when(metric.getKey()).thenReturn(metricKey);
-    return new Condition(metric, Condition.Operator.EQUALS.getDbValue(), "error threshold", "warn threshold");
+    return new Condition(metric, Condition.Operator.EQUALS.getDbValue(), "error threshold");
   }
 
 }
index 2532c59cff25f40fea09f923761184d450e79814..8e85b43bb05121246d06302111b972c8354c3dca 100644 (file)
@@ -34,7 +34,7 @@ public class EvaluatedConditionTest {
   static {
     when(SOME_METRIC.getKey()).thenReturn("dummy key");
   }
-  private static final Condition SOME_CONDITION = new Condition(SOME_METRIC, Condition.Operator.EQUALS.getDbValue(), "1", null);
+  private static final Condition SOME_CONDITION = new Condition(SOME_METRIC, Condition.Operator.EQUALS.getDbValue(), "1");
   private static final Measure.Level SOME_LEVEL = Measure.Level.OK;
   private static final String SOME_VALUE = "some value";
 
index 86c431bdacec3ac31258b6a53764f6e756854b59..5a91b986a0231cccda28802688abbb73a2136872 100644 (file)
@@ -52,10 +52,9 @@ public class QualityGateDetailsDataTest {
   @Test
   public void verify_json_for_each_type_of_condition() {
     String value = "actualValue";
-    Condition condition = new Condition(new MetricImpl(1, "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh", "warnTh");
+    Condition condition = new Condition(new MetricImpl(1, "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
     ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(
       new EvaluatedCondition(condition, Measure.Level.OK, value),
-      new EvaluatedCondition(condition, Measure.Level.WARN, value),
       new EvaluatedCondition(condition, Measure.Level.ERROR, value));
     String actualJson = new QualityGateDetailsData(Measure.Level.OK, evaluatedConditions, false).toJson();
 
@@ -65,7 +64,6 @@ public class QualityGateDetailsDataTest {
       "  {" +
       "    \"metric\":\"key1\"," +
       "    \"op\":\"GT\"," +
-      "    \"warning\":\"warnTh\"," +
       "    \"error\":\"errorTh\"," +
       "    \"actual\":\"actualValue\"," +
       "    \"level\":\"OK\"" +
@@ -73,15 +71,6 @@ public class QualityGateDetailsDataTest {
       "  {" +
       "    \"metric\":\"key1\"," +
       "    \"op\":\"GT\"," +
-      "    \"warning\":\"warnTh\"," +
-      "    \"error\":\"errorTh\"," +
-      "    \"actual\":\"actualValue\"," +
-      "    \"level\":\"WARN\"" +
-      "  }," +
-      "  {" +
-      "    \"metric\":\"key1\"," +
-      "    \"op\":\"GT\"," +
-      "    \"warning\":\"warnTh\"," +
       "    \"error\":\"errorTh\"," +
       "    \"actual\":\"actualValue\"," +
       "    \"level\":\"ERROR\"" +
index b08cc2f14edeabac6b9203c905e20164eeb24b61..d8d2f9de383548ed176687e39bd6abd4d99a841c 100644 (file)
@@ -238,15 +238,15 @@ public class ConditionEvaluatorTest {
   }
 
   @Test
-  public void testErrorAndWarningLevel() {
+  public void testErrorLevel() {
     Metric metric = createMetric(FLOAT);
     Measure measure = newMeasureBuilder().create(10.2d, 1, null);
 
     assertThat(underTest.evaluate(createErrorCondition(metric, EQUALS, "10.2"), measure)).hasLevel(ERROR);
     assertThat(underTest.evaluate(createErrorCondition(metric, EQUALS, "10.1"), measure)).hasLevel(OK);
 
-    assertThat(underTest.evaluate(new Condition(metric, EQUALS.getDbValue(), "10.3", "10.2"), measure)).hasLevel(Measure.Level.WARN);
-    assertThat(underTest.evaluate(new Condition(metric, LESS_THAN.getDbValue(), "10.3", "10.2"), measure)).hasLevel(Measure.Level.ERROR);
+    assertThat(underTest.evaluate(new Condition(metric, EQUALS.getDbValue(), "10.3"), measure)).hasLevel(Measure.Level.OK);
+    assertThat(underTest.evaluate(new Condition(metric, LESS_THAN.getDbValue(), "10.3"), measure)).hasLevel(Measure.Level.ERROR);
   }
 
   @Test
@@ -276,8 +276,8 @@ public class ConditionEvaluatorTest {
     Metric metric = createNewMetric(metricType);
     Measure measure = newMeasureBuilder().setVariation(3d).createNoValue();
 
-    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3", null), measure)).hasLevel(OK);
-    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2", null), measure)).hasLevel(ERROR);
+    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3"), measure)).hasLevel(OK);
+    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2"), measure)).hasLevel(ERROR);
   }
 
   @Test
@@ -286,7 +286,7 @@ public class ConditionEvaluatorTest {
     Metric metric = createNewMetric(metricType);
     Measure measure = newMeasureBuilder().createNoValue();
 
-    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3", null), measure)).hasLevel(OK).hasValue(null);
+    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3"), measure)).hasLevel(OK).hasValue(null);
   }
 
   @DataProvider
@@ -307,7 +307,7 @@ public class ConditionEvaluatorTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Unsupported metric type " + metricType);
 
-    underTest.evaluate(new Condition(metric, EQUALS.getDbValue(), "3", null), measure);
+    underTest.evaluate(new Condition(metric, EQUALS.getDbValue(), "3"), measure);
   }
 
   @DataProvider
@@ -323,12 +323,12 @@ public class ConditionEvaluatorTest {
     Metric metric = createMetric(RATING);
     Measure measure = newMeasureBuilder().create(4, "D");
 
-    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "4", null), measure)).hasLevel(OK).hasValue(4);
-    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2", null), measure)).hasLevel(ERROR).hasValue(4);
+    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "4"), measure)).hasLevel(OK).hasValue(4);
+    assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2"), measure)).hasLevel(ERROR).hasValue(4);
   }
 
   private static Condition createErrorCondition(Metric metric, Condition.Operator operator, String errorThreshold) {
-    return new Condition(metric, operator.getDbValue(), errorThreshold, null);
+    return new Condition(metric, operator.getDbValue(), errorThreshold);
   }
 
   private static MetricImpl createMetric(MetricType metricType) {
index e10977223cb7fbb389d131d969cfc1cc0e8cefe7..e6acb186e2ea4e32406e64207b9cbeadb31f4c50 100644 (file)
@@ -44,12 +44,12 @@ public class ConditionTest {
 
   @Test(expected = NullPointerException.class)
   public void constructor_throws_NPE_for_null_metric_argument() {
-    new Condition(null, SOME_OPERATOR, null, null);
+    new Condition(null, SOME_OPERATOR, null);
   }
 
   @Test(expected = NullPointerException.class)
   public void constructor_throws_NPE_for_null_operator_argument() {
-    new Condition(SOME_METRIC, null, null, null);
+    new Condition(SOME_METRIC, null, null);
   }
 
   @Test
@@ -57,27 +57,26 @@ public class ConditionTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Unsupported operator value: 'troloto'");
 
-    new Condition(SOME_METRIC, "troloto", null, null);
+    new Condition(SOME_METRIC, "troloto", null);
   }
 
   @Test
   public void verify_getters() {
     String error = "error threshold";
-    String warning = "warning threshold";
 
-    Condition condition = new Condition(SOME_METRIC, SOME_OPERATOR, error, warning);
+    Condition condition = new Condition(SOME_METRIC, SOME_OPERATOR, error);
 
     assertThat(condition.getMetric()).isSameAs(SOME_METRIC);
     assertThat(condition.getOperator()).isSameAs(Condition.Operator.EQUALS);
     assertThat(condition.getErrorThreshold()).isEqualTo(error);
-    assertThat(condition.getWarningThreshold()).isEqualTo(warning);
   }
 
   @Test
   public void all_fields_are_displayed_in_toString() {
     when(SOME_METRIC.toString()).thenReturn("metric1");
 
-    assertThat(new Condition(SOME_METRIC, SOME_OPERATOR, "error_l", "warn").toString())
-      .isEqualTo("Condition{metric=metric1, operator=EQUALS, warningThreshold=warn, errorThreshold=error_l}");
+    assertThat(new Condition(SOME_METRIC, SOME_OPERATOR, "error_l").toString())
+      .isEqualTo("Condition{metric=metric1, operator=EQUALS, errorThreshold=error_l}");
+
   }
 }
index a4f62144b9bdc9d99469184742c1a25b7216e3fc..5a9213c5255c2b3382ee7bdcdf0d9b07a6c1bace 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.ce.task.projectanalysis.qualitygate;
 
-import com.google.common.collect.ImmutableList;
 import com.tngtech.java.junit.dataprovider.DataProvider;
 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import com.tngtech.java.junit.dataprovider.UseDataProvider;
@@ -38,18 +37,14 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.WARN;
 
 @RunWith(DataProviderRunner.class)
 public class EvaluationResultTextConverterTest {
   private static final Metric INT_METRIC = new MetricImpl(1, "key", "int_metric_name", Metric.MetricType.INT);
   private static final Metric SOME_VARIATION_METRIC = new MetricImpl(2, "new_variation_of_trololo", "variation_of_trololo_name", Metric.MetricType.INT);
-  private static final Condition EQ_10_CONDITION = new Condition(INT_METRIC, Condition.Operator.EQUALS.getDbValue(), "10", null);
+  private static final Condition EQ_10_CONDITION = new Condition(INT_METRIC, Condition.Operator.EQUALS.getDbValue(), "10");
   private static final EvaluationResult OK_EVALUATION_RESULT = new EvaluationResult(Measure.Level.OK, null);
   private static final String ERROR_THRESHOLD = "error_threshold";
-  private static final String WARNING_THRESHOLD = "warning_threshold";
-  private static final String SOME_MODE = "mode";
-  private static final String SOME_ANALYSIS_UUID = "u1";
 
   private I18n i18n = mock(I18n.class);
   private Durations durations = mock(Durations.class);
@@ -71,46 +66,40 @@ public class EvaluationResultTextConverterTest {
   }
 
   @DataProvider
-  public static Object[][] all_operators_for_error_warning_levels() {
+  public static Object[][] all_operators_for_error_levels() {
     List<Object[]> res = new ArrayList<>();
     for (Condition.Operator operator : Condition.Operator.values()) {
-      for (Measure.Level level : ImmutableList.of(ERROR, WARN)) {
-        res.add(new Object[] {operator, level});
-      }
+      res.add(new Object[] {operator, ERROR});
     }
     return res.toArray(new Object[res.size()][2]);
   }
 
   @Test
-  @UseDataProvider("all_operators_for_error_warning_levels")
+  @UseDataProvider("all_operators_for_error_levels")
   public void evaluate_returns_msg_of_metric_plus_operator_plus_threshold_for_level_argument(Condition.Operator operator, Measure.Level level) {
     String metricMsg = "int_metric_msg";
 
     when(i18n.message(Locale.ENGLISH, "metric." + INT_METRIC.getKey() + ".name", INT_METRIC.getName()))
       .thenReturn(metricMsg);
 
-    Condition condition = new Condition(INT_METRIC, operator.getDbValue(), ERROR_THRESHOLD, WARNING_THRESHOLD);
+    Condition condition = new Condition(INT_METRIC, operator.getDbValue(), ERROR_THRESHOLD);
 
     assertThat(underTest.asText(condition, new EvaluationResult(level, null)))
-      .isEqualTo(metricMsg + " " + toSign(operator) + " " + getThreshold(level));
-  }
-
-  private String getThreshold(Measure.Level level) {
-    return level == ERROR ? ERROR_THRESHOLD : WARNING_THRESHOLD;
+      .isEqualTo(metricMsg + " " + toSign(operator) + " " + ERROR_THRESHOLD);
   }
 
   @Test
-  @UseDataProvider("all_operators_for_error_warning_levels")
+  @UseDataProvider("all_operators_for_error_levels")
   public void evaluate_does_not_add_variation_if_metric_starts_with_variation_prefix_but_period_is_null(Condition.Operator operator, Measure.Level level) {
     String metricMsg = "trololo_metric_msg";
 
     when(i18n.message(Locale.ENGLISH, "metric." + SOME_VARIATION_METRIC.getKey() + ".name", SOME_VARIATION_METRIC.getName()))
       .thenReturn(metricMsg);
 
-    Condition condition = new Condition(SOME_VARIATION_METRIC, operator.getDbValue(), ERROR_THRESHOLD, WARNING_THRESHOLD);
+    Condition condition = new Condition(SOME_VARIATION_METRIC, operator.getDbValue(), ERROR_THRESHOLD);
 
     assertThat(underTest.asText(condition, new EvaluationResult(level, null)))
-      .isEqualTo(metricMsg + " " + toSign(operator) + " " + getThreshold(level));
+      .isEqualTo(metricMsg + " " + toSign(operator) + " " + ERROR_THRESHOLD);
   }
 
   private static String toSign(Condition.Operator operator) {
index efe75abe831ddf94895bc2c1b05b12b0c366c70c..efcf5054b3033eb25a91f9eef5568db7b1bf6e19 100644 (file)
@@ -54,8 +54,8 @@ public class QualityGateServiceImplTest {
   private static final Metric METRIC_1 = mock(Metric.class);
   private static final Metric METRIC_2 = mock(Metric.class);
   private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setId(321).setMetricId(METRIC_ID_1).setOperator("EQ")
-    .setWarningThreshold("warnin_th").setErrorThreshold("error_th");
-  private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setId(456).setMetricId(METRIC_ID_2).setOperator("NE");
+    .setErrorThreshold("error_th");
+  private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setId(456).setMetricId(METRIC_ID_2).setOperator("NE").setErrorThreshold("error_th");
 
   private QualityGateDao qualityGateDao = mock(QualityGateDao.class);
   private QualityGateConditionDao qualityGateConditionDao = mock(QualityGateConditionDao.class);
@@ -104,8 +104,8 @@ public class QualityGateServiceImplTest {
     assertThat(res.get().getId()).isEqualTo(SOME_ID);
     assertThat(res.get().getName()).isEqualTo(SOME_NAME);
     assertThat(res.get().getConditions()).containsOnly(
-      new Condition(METRIC_1, CONDITION_1.getOperator(), CONDITION_1.getErrorThreshold(), CONDITION_1.getWarningThreshold()),
-      new Condition(METRIC_2, CONDITION_2.getOperator(), CONDITION_2.getErrorThreshold(), CONDITION_2.getWarningThreshold()));
+      new Condition(METRIC_1, CONDITION_1.getOperator(), CONDITION_1.getErrorThreshold()),
+      new Condition(METRIC_2, CONDITION_2.getOperator(), CONDITION_2.getErrorThreshold()));
   }
 
   @Test
@@ -122,7 +122,7 @@ public class QualityGateServiceImplTest {
     assertThat(res.get().getId()).isEqualTo(SOME_ID);
     assertThat(res.get().getName()).isEqualTo(SOME_NAME);
     assertThat(res.get().getConditions()).containsOnly(
-      new Condition(METRIC_2, CONDITION_2.getOperator(), CONDITION_2.getErrorThreshold(), CONDITION_2.getWarningThreshold()));
+      new Condition(METRIC_2, CONDITION_2.getOperator(), CONDITION_2.getErrorThreshold()));
   }
 
   @Test
@@ -140,10 +140,10 @@ public class QualityGateServiceImplTest {
     assertThat(qualityGate.getId()).isEqualTo(ShortLivingBranchQualityGate.ID);
     assertThat(qualityGate.getName()).isEqualTo("Hardcoded short living branch quality gate");
     assertThat(qualityGate.getConditions())
-      .extracting(Condition::getMetric, Condition::getOperator, Condition::getErrorThreshold, Condition::getWarningThreshold)
+      .extracting(Condition::getMetric, Condition::getOperator, Condition::getErrorThreshold)
       .containsOnly(
-        tuple(openedIssueMetric, GREATER_THAN, "0", null),
-        tuple(reOpenedIssueMetric, GREATER_THAN, "0", null));
+        tuple(openedIssueMetric, GREATER_THAN, "0"),
+        tuple(reOpenedIssueMetric, GREATER_THAN, "0"));
   }
 
   private MetricImpl mockMetricInRepository(String metricKey) {
index 09be7e4e29763f83ea678baa2ed4738ca210e66d..0b0787fec0225fed6c16c58788fe2106b08c8f8d 100644 (file)
@@ -56,7 +56,6 @@ import static org.mockito.Mockito.when;
 import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.WARN;
 
 public class QualityGateEventsStepTest {
   private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1)
@@ -68,7 +67,6 @@ public class QualityGateEventsStepTest {
   private static final String INVALID_ALERT_STATUS = "trololo";
   private static final String ALERT_TEXT = "alert text";
   private static final QualityGateStatus OK_QUALITY_GATE_STATUS = new QualityGateStatus(OK, ALERT_TEXT);
-  private static final QualityGateStatus WARN_QUALITY_GATE_STATUS = new QualityGateStatus(WARN, ALERT_TEXT);
   private static final QualityGateStatus ERROR_QUALITY_GATE_STATUS = new QualityGateStatus(ERROR, ALERT_TEXT);
 
   @Rule
@@ -146,36 +144,16 @@ public class QualityGateEventsStepTest {
     verifyNoMoreInteractions(measureRepository, eventRepository);
   }
 
-  @Test
-  public void event_created_if_no_base_ALERT_STATUS_and_raw_is_WARN() {
-    verify_event_created_if_no_base_ALERT_STATUS_measure(WARN, "Orange");
-  }
-
-  @Test
-  public void event_created_if_base_ALERT_STATUS_and_raw_is_ERROR() {
-    verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Red");
-  }
-
   @Test
   public void event_created_if_base_ALERT_STATUS_has_no_alertStatus_and_raw_is_ERROR() {
     verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Red");
   }
 
-  @Test
-  public void event_created_if_base_ALERT_STATUS_has_no_alertStatus_and_raw_is_WARN() {
-    verify_event_created_if_no_base_ALERT_STATUS_measure(WARN, "Orange");
-  }
-
   @Test
   public void event_created_if_base_ALERT_STATUS_has_invalid_alertStatus_and_raw_is_ERROR() {
     verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Red");
   }
 
-  @Test
-  public void event_created_if_base_ALERT_STATUS_has_invalid_alertStatus_and_raw_is_WARN() {
-    verify_event_created_if_no_base_ALERT_STATUS_measure(WARN, "Orange");
-  }
-
   private void verify_event_created_if_no_base_ALERT_STATUS_measure(Measure.Level rawAlterStatus, String expectedLabel) {
     QualityGateStatus someQGStatus = new QualityGateStatus(rawAlterStatus, ALERT_TEXT);
 
@@ -222,12 +200,8 @@ public class QualityGateEventsStepTest {
 
   @Test
   public void event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed() {
-    verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(OK, WARN_QUALITY_GATE_STATUS, "Orange (was Green)");
     verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(OK, ERROR_QUALITY_GATE_STATUS, "Red (was Green)");
-    verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(WARN, OK_QUALITY_GATE_STATUS, "Green (was Orange)");
-    verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(WARN, ERROR_QUALITY_GATE_STATUS, "Red (was Orange)");
     verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(ERROR, OK_QUALITY_GATE_STATUS, "Green (was Red)");
-    verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(ERROR, WARN_QUALITY_GATE_STATUS, "Orange (was Red)");
   }
 
   private void verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(Measure.Level previousAlertStatus,
@@ -274,7 +248,7 @@ public class QualityGateEventsStepTest {
     });
 
     when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric))
-      .thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(WARN_QUALITY_GATE_STATUS).createNoValue()));
+      .thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(OK_QUALITY_GATE_STATUS).createNoValue()));
     when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(
       of(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(ERROR)).createNoValue()));
 
@@ -296,7 +270,7 @@ public class QualityGateEventsStepTest {
     analysisMetadataHolder.setBranch(new DefaultBranchImpl());
 
     when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric))
-      .thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(WARN_QUALITY_GATE_STATUS).createNoValue()));
+      .thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(OK_QUALITY_GATE_STATUS).createNoValue()));
     when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(
       of(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(ERROR)).createNoValue()));
 
index 8b39421392e4f4564ba45e595fd240b0845ae3ab..eddec0e70519498ff191caa6bd330f0079b6ac71 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Optional;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import javax.annotation.Nullable;
 import org.assertj.core.api.AbstractAssert;
 import org.junit.Before;
@@ -58,10 +59,9 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.WARN;
+import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
 import static org.sonar.ce.task.projectanalysis.measure.MeasureAssert.assertThat;
 
 public class QualityGateMeasuresStepTest {
@@ -150,7 +150,7 @@ public class QualityGateMeasuresStepTest {
 
   @Test
   public void new_measures_are_created_even_if_there_is_no_rawMeasure_for_metric_of_condition() {
-    Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", null);
+    Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2");
     qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition)));
 
     underTest.execute(new TestComputationStepContext());
@@ -173,7 +173,7 @@ public class QualityGateMeasuresStepTest {
   @Test
   public void rawMeasure_is_updated_if_present_and_new_measures_are_created_if_project_has_measure_for_metric_of_condition() {
     int rawValue = 1;
-    Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", null);
+    Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2");
     Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
 
     qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition)));
@@ -201,11 +201,11 @@ public class QualityGateMeasuresStepTest {
   @Test
   public void new_measures_have_ERROR_level_if_at_least_one_updated_measure_has_ERROR_level() {
     int rawValue = 1;
-    Condition equals1ErrorCondition = createEqualsCondition(INT_METRIC_1, "1", null);
-    Condition equals1WarningCondition = createEqualsCondition(INT_METRIC_2, null, "1");
+    Condition equalsOneErrorCondition = createEqualsCondition(INT_METRIC_1, "1");
+    Condition equalsOneOkCondition = createEqualsCondition(INT_METRIC_2, "2");
     Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
 
-    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals1ErrorCondition, equals1WarningCondition)));
+    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equalsOneErrorCondition, equalsOneOkCondition)));
     measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
     measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure);
 
@@ -216,69 +216,31 @@ public class QualityGateMeasuresStepTest {
 
     assertThat(rawMeasure1.get())
       .hasQualityGateLevel(ERROR)
-      .hasQualityGateText(dumbResultTextAnswer(equals1ErrorCondition, ERROR, rawValue));
+      .hasQualityGateText(dumbResultTextAnswer(equalsOneErrorCondition, ERROR, rawValue));
     assertThat(rawMeasure2.get())
-      .hasQualityGateLevel(WARN)
-      .hasQualityGateText(dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
+      .hasQualityGateLevel(OK)
+      .hasQualityGateText(dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
     assertThat(getAlertStatusMeasure())
       .hasQualityGateLevel(ERROR)
-      .hasQualityGateText(dumbResultTextAnswer(equals1ErrorCondition, ERROR, rawValue) + ", "
-        + dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
+      .hasQualityGateText(dumbResultTextAnswer(equalsOneErrorCondition, ERROR, rawValue) + ", "
+        + dumbResultTextAnswer(equalsOneOkCondition, OK, rawValue));
     assertThat(getQGDetailsMeasure())
       .hasValue(new QualityGateDetailsData(ERROR, of(
-        new EvaluatedCondition(equals1ErrorCondition, ERROR, rawValue),
-        new EvaluatedCondition(equals1WarningCondition, WARN, rawValue)), false).toJson());
+        new EvaluatedCondition(equalsOneErrorCondition, ERROR, rawValue),
+        new EvaluatedCondition(equalsOneOkCondition, OK, rawValue)), false).toJson());
 
     QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder)
       .hasStatus(QualityGateStatus.ERROR)
       .hasConditionCount(2)
-      .hasCondition(equals1ErrorCondition, ConditionStatus.EvaluationStatus.ERROR, String.valueOf(rawValue))
-      .hasCondition(equals1WarningCondition, ConditionStatus.EvaluationStatus.WARN, String.valueOf(rawValue));
-  }
-
-  @Test
-  public void new_measures_have_WARNING_level_if_no_updated_measure_has_ERROR_level() {
-    int rawValue = 1;
-    Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", null);
-    Condition equals1WarningCondition = createEqualsCondition(INT_METRIC_2, null, "1");
-    Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
-
-    qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition, equals1WarningCondition)));
-    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
-    measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure);
-
-    underTest.execute(new TestComputationStepContext());
-
-    Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
-    Optional<Measure> rawMeasure2 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_2_KEY);
-
-    assertThat(rawMeasure1.get())
-      .hasQualityGateLevel(OK)
-      .hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
-    assertThat(rawMeasure2.get())
-      .hasQualityGateLevel(WARN)
-      .hasQualityGateText(dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
-    assertThat(getAlertStatusMeasure())
-      .hasQualityGateLevel(WARN)
-      .hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue) + ", "
-        + dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
-    assertThat(getQGDetailsMeasure())
-      .hasValue(new QualityGateDetailsData(WARN, of(
-        new EvaluatedCondition(equals2Condition, OK, rawValue),
-        new EvaluatedCondition(equals1WarningCondition, WARN, rawValue)), false).toJson());
-
-    QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder)
-      .hasStatus(QualityGateStatus.WARN)
-      .hasConditionCount(2)
-      .hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue))
-      .hasCondition(equals1WarningCondition, ConditionStatus.EvaluationStatus.WARN, String.valueOf(rawValue));
+      .hasCondition(equalsOneErrorCondition, ConditionStatus.EvaluationStatus.ERROR, String.valueOf(rawValue))
+      .hasCondition(equalsOneOkCondition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue));
   }
 
   @Test
   public void new_measure_has_ERROR_level_of_all_conditions_for_a_specific_metric_if_its_the_worst() {
     int rawValue = 1;
-    Condition fixedCondition = createEqualsCondition(INT_METRIC_1, "1", null);
-    Condition periodCondition = createEqualsCondition(INT_METRIC_1, null, "2");
+    Condition fixedCondition = createEqualsCondition(INT_METRIC_1, "1");
+    Condition periodCondition = createEqualsCondition(INT_METRIC_1, "2");
 
     qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(fixedCondition, periodCondition)));
     Measure measure = newMeasureBuilder().create(rawValue, null);
@@ -295,8 +257,8 @@ public class QualityGateMeasuresStepTest {
   @Test
   public void new_measure_has_condition_on_leak_period_when_all_conditions_on_specific_metric_has_same_QG_level() {
     int rawValue = 1;
-    Condition fixedCondition = createEqualsCondition(INT_METRIC_1, "1", null);
-    Condition periodCondition = createEqualsCondition(INT_METRIC_1, "1", null);
+    Condition fixedCondition = createEqualsCondition(INT_METRIC_1, "1");
+    Condition periodCondition = createEqualsCondition(INT_METRIC_1, "1");
 
     qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(fixedCondition, periodCondition)));
     Measure measure = newMeasureBuilder()
@@ -320,8 +282,8 @@ public class QualityGateMeasuresStepTest {
     return measureRepository.getAddedRawMeasure(PROJECT_REF, CoreMetrics.QUALITY_GATE_DETAILS_KEY);
   }
 
-  private static Condition createEqualsCondition(Metric metric, @Nullable String errorThreshold, @Nullable String warningThreshold) {
-    return new Condition(metric, Condition.Operator.EQUALS.getDbValue(), errorThreshold, warningThreshold);
+  private static Condition createEqualsCondition(Metric metric, String errorThreshold) {
+    return new Condition(metric, Condition.Operator.EQUALS.getDbValue(), errorThreshold);
   }
 
   private static MetricImpl createIntMetric(int index) {
index 9a491a421dc5d2e2a465273bf73410178fe27572..b37f22f6a864540ebef92450bbadfe9e2d98082b 100644 (file)
@@ -39,7 +39,6 @@ import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builde
 import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.WARN;
 
 public class SmallChangesetQualityGateSpecialCaseTest {
 
@@ -66,17 +65,6 @@ public class SmallChangesetQualityGateSpecialCaseTest {
     assertThat(result).isTrue();
   }
 
-  @Test
-  public void ignore_warnings_about_new_coverage_for_small_changesets() {
-    QualityGateMeasuresStep.MetricEvaluationResult metricEvaluationResult = generateEvaluationResult(NEW_COVERAGE_KEY, WARN);
-    Component project = generateNewRootProject();
-    measureRepository.addRawMeasure(PROJECT_REF, CoreMetrics.NEW_LINES_KEY, newMeasureBuilder().setVariation(19).create(1000));
-
-    boolean result = underTest.appliesTo(project, metricEvaluationResult);
-
-    assertThat(result).isTrue();
-  }
-
   @Test
   public void should_not_change_for_bigger_changesets() {
     QualityGateMeasuresStep.MetricEvaluationResult metricEvaluationResult = generateEvaluationResult(NEW_COVERAGE_KEY, ERROR);
@@ -149,7 +137,7 @@ public class SmallChangesetQualityGateSpecialCaseTest {
 
   private QualityGateMeasuresStep.MetricEvaluationResult generateEvaluationResult(String metric, Measure.Level level) {
     Metric newCoverageMetric = metricRepository.getByKey(metric);
-    Condition condition = new Condition(newCoverageMetric, "LT", "80", "90");
+    Condition condition = new Condition(newCoverageMetric, "LT", "80");
     EvaluationResult evaluationResult = new EvaluationResult(level, mock(Comparable.class));
     return new QualityGateMeasuresStep.MetricEvaluationResult(evaluationResult, condition);
   }
index 6c0d726222d2f5d30c285c5a84c9ea7a13f9dd50..e967a56a6f2b5efaadbddd396cdff450ca666583 100644 (file)
@@ -87,7 +87,6 @@ public class WebhookPostTaskTest {
       .setMetricKey(randomAlphanumeric(96))
       .setOperator(QualityGate.Operator.values()[random.nextInt(QualityGate.Operator.values().length)])
       .setErrorThreshold(randomAlphanumeric(22))
-      .setWarningThreshold(randomAlphanumeric(23))
       .setOnLeakPeriod(random.nextBoolean())
       .build(QualityGate.EvaluationStatus.OK, randomAlphanumeric(33));
     QualityGate qualityGate = newQualityGateBuilder()
@@ -147,9 +146,7 @@ public class WebhookPostTaskTest {
       Condition qgCondition = new Condition(
         condition.getMetricKey(),
         Condition.Operator.valueOf(condition.getOperator().name()),
-        condition.getErrorThreshold(),
-        condition.getWarningThreshold()
-      );
+        condition.getErrorThreshold());
       webQualityGate = EvaluatedQualityGate.newBuilder()
         .setQualityGate(new org.sonar.server.qualitygate.QualityGate(qualityGate.getId(), qualityGate.getName(), Collections.singleton(qgCondition)))
         .setStatus(Metric.Level.valueOf(qualityGate.getStatus().name()))
index 396cae5453bd973802df285159390b7bd2341415..853cfe174c811d40119551d9cf128662c0c21389 100644 (file)
@@ -93,8 +93,6 @@ public class QualityGateConditionDto {
 
   private String operator;
 
-  private String warningThreshold;
-
   private String errorThreshold;
 
   private Date createdAt;
@@ -147,20 +145,11 @@ public class QualityGateConditionDto {
     return this;
   }
 
-  public String getWarningThreshold() {
-    return warningThreshold;
-  }
-
-  public QualityGateConditionDto setWarningThreshold(@Nullable String warningThreshold) {
-    this.warningThreshold = warningThreshold;
-    return this;
-  }
-
   public String getErrorThreshold() {
     return errorThreshold;
   }
 
-  public QualityGateConditionDto setErrorThreshold(@Nullable String errorThreshold) {
+  public QualityGateConditionDto setErrorThreshold(String errorThreshold) {
     this.errorThreshold = errorThreshold;
     return this;
   }
index 51421b1597b6db1184df1a95b3374e30b9bde50b..8cb7a614c8291998896083ac78a8e2f883bc3ff1 100644 (file)
@@ -4,15 +4,12 @@
 <mapper namespace="org.sonar.db.qualitygate.QualityGateConditionMapper">
 
   <insert id="insert" parameterType="QualityGateCondition" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    insert into quality_gate_conditions (qgate_id, metric_id, operator, value_error, value_warning, created_at,
-    updated_at)
-    values (#{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{warningThreshold}, #{createdAt},
-    #{updatedAt})
+    insert into quality_gate_conditions (qgate_id, metric_id, operator, value_error, created_at, updated_at)
+    values (#{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt})
   </insert>
 
   <sql id="conditionColumns">
-    id, qgate_id as qualityGateId, metric_id as metricId, operator, value_warning as warningThreshold, value_error as
-    errorThreshold,
+    id, qgate_id as qualityGateId, metric_id as metricId, operator, value_error as errorThreshold,
     created_at as createdAt, updated_at as updatedAt
   </sql>
 
@@ -37,7 +34,6 @@
     update quality_gate_conditions set
     metric_id=#{metricId},
     operator=#{operator},
-    value_warning=#{warningThreshold},
     value_error=#{errorThreshold},
     updated_at=#{updatedAt}
     where id=#{id}
index e5ddcfcfacb5314d4f01aa5894fca38b1ff35928..afc418a59a3dff7f5988fc14752e53b3eee68c21 100644 (file)
@@ -40,7 +40,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.entry;
 import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.api.measures.Metric.Level.OK;
-import static org.sonar.api.measures.Metric.Level.WARN;
 import static org.sonar.api.measures.Metric.ValueType.DATA;
 import static org.sonar.api.measures.Metric.ValueType.DISTRIB;
 import static org.sonar.api.measures.Metric.ValueType.INT;
@@ -101,13 +100,11 @@ public class ProjectMeasuresIndexerIteratorTest {
     ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
     ComponentDto project3 = dbTester.components().insertPrivateProject(organization);
     MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status"));
-    dbTester.measures().insertLiveMeasure(project1, metric, m -> m.setValue(null).setData(WARN.name()));
     dbTester.measures().insertLiveMeasure(project2, metric, m -> m.setValue(null).setData(OK.name()));
     dbTester.measures().insertLiveMeasure(project3, metric, m -> m.setValue(null).setData(ERROR.name()));
 
     Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
 
-    assertThat(docsById.get(project1.uuid()).getMeasures().getQualityGateStatus()).isEqualTo("WARN");
     assertThat(docsById.get(project2.uuid()).getMeasures().getQualityGateStatus()).isEqualTo("OK");
     assertThat(docsById.get(project3.uuid()).getMeasures().getQualityGateStatus()).isEqualTo("ERROR");
   }
index 25056c0749b81b55247257e2f52aa6d695201739..e43d063aa789b2053058a5bd7c611f4438a56f1d 100644 (file)
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class QualityGateConditionDaoTest {
 
   private static final String[] COLUMNS_WITHOUT_TIMESTAMPS = {
-    "id", "qgate_id", "metric_id", "operator", "value_warning", "value_error"
+    "id", "qgate_id", "metric_id", "operator", "value_error"
   };
 
   @Rule
@@ -43,12 +43,12 @@ public class QualityGateConditionDaoTest {
   public void testInsert() {
     dbTester.prepareDbUnit(getClass(), "insert.xml");
     QualityGateConditionDto newCondition = new QualityGateConditionDto()
-      .setQualityGateId(1L).setMetricId(2L).setOperator("GT").setWarningThreshold("10").setErrorThreshold("20");
+      .setQualityGateId(1L).setMetricId(2L).setOperator("GT").setErrorThreshold("20");
 
     underTest.insert(newCondition, dbTester.getSession());
     dbTester.commit();
 
-    dbTester.assertDbUnitTable(getClass(), "insert-result.xml", "quality_gate_conditions", "metric_id", "operator", "error_value", "warning_value");
+    dbTester.assertDbUnitTable(getClass(), "insert-result.xml", "quality_gate_conditions", "metric_id", "operator", "error_value");
     assertThat(newCondition.getId()).isNotNull();
   }
 
@@ -68,7 +68,6 @@ public class QualityGateConditionDaoTest {
     assertThat(selectById.getMetricId()).isEqualTo(2L);
     assertThat(selectById.getOperator()).isEqualTo("<");
     assertThat(selectById.getQualityGateId()).isEqualTo(1L);
-    assertThat(selectById.getWarningThreshold()).isEqualTo("10");
     assertThat(selectById.getErrorThreshold()).isEqualTo("20");
     assertThat(underTest.selectById(42L, dbSession)).isNull();
   }
@@ -87,7 +86,7 @@ public class QualityGateConditionDaoTest {
   public void testUpdate() {
     dbTester.prepareDbUnit(getClass(), "selectForQualityGate.xml");
 
-    underTest.update(new QualityGateConditionDto().setId(1L).setMetricId(7L).setOperator(">").setWarningThreshold("50").setErrorThreshold("80"), dbSession);
+    underTest.update(new QualityGateConditionDto().setId(1L).setMetricId(7L).setOperator(">").setErrorThreshold("80"), dbSession);
     dbSession.commit();
 
     dbTester.assertDbUnitTable(getClass(), "update-result.xml", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS);
index 694ab3fe346de5d52532bac3bd01f07e26f54a65..872e495e950142a4b6d42039e8992de9bc5ffe3e 100644 (file)
@@ -99,7 +99,6 @@ public class QualityGateDbTester {
     QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId())
       .setMetricId(metric.getId())
       .setOperator("GT")
-      .setWarningThreshold(randomNumeric(10))
       .setErrorThreshold(randomNumeric(10));
     Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(condition));
     dbClient.gateConditionDao().insert(condition, dbSession);
index f34db17b6a863ee6f68078bb6e77a29b8615933c..e22a05872ff9eb5558b91a020b8b7f34930aecba 100644 (file)
@@ -1,9 +1,7 @@
 <dataset>
-
-  <quality_gate_conditions id="1" qgate_id="1" metric_id="7" operator="&gt;" value_warning="50" value_error="80"/>
-  <quality_gate_conditions id="2" qgate_id="1" metric_id="3" operator="&lt;" value_warning="10" value_error="20"/>
-  <quality_gate_conditions id="3" qgate_id="1" metric_id="4" operator="&lt;" value_warning="10" value_error="[null]"/>
-  <quality_gate_conditions id="4" qgate_id="2" metric_id="5" operator="&lt;" value_warning="[null]" value_error="20"/>
-  <quality_gate_conditions id="5" qgate_id="2" metric_id="6" operator="&lt;" value_warning="[null]" value_error="20"/>
-
+  <quality_gate_conditions id="1" qgate_id="1" metric_id="7" operator="&gt;" value_error="80" />
+  <quality_gate_conditions id="2" qgate_id="1" metric_id="3" operator="&lt;" value_error="20" />
+  <quality_gate_conditions id="3" qgate_id="1" metric_id="4" operator="&lt;" value_error="[null]" />
+  <quality_gate_conditions id="4" qgate_id="2" metric_id="5" operator="&lt;" value_error="20"  />
+  <quality_gate_conditions id="5" qgate_id="2" metric_id="6" operator="&lt;" value_error="20" />
 </dataset>
index de4ded099825cfbf9e0401571ec7c1b5cd6246ee..b1f2e22df872275f017735f2289fb957254faa91 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.server.es.BaseDoc;
 
 import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.api.measures.Metric.Level.OK;
-import static org.sonar.api.measures.Metric.Level.WARN;
 import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_ANALYSED_AT;
 import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_DISTRIB_LANGUAGE;
 import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_DISTRIB_NCLOC;
@@ -50,7 +49,7 @@ import static org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIEL
 
 public class ProjectMeasuresDoc extends BaseDoc {
 
-  public static final Map<String, Integer> QUALITY_GATE_STATUS = ImmutableMap.of(OK.name(), 1, WARN.name(), 2, ERROR.name(), 3);
+  public static final Map<String, Integer> QUALITY_GATE_STATUS = ImmutableMap.of(OK.name(), 1, ERROR.name(), 2);
 
   public ProjectMeasuresDoc() {
     super(new HashMap<>(8));
index 1efc974fe6cf3908494aed8ab8b868bc418b170b..7dd515f6d0351418cf92ff50b869f4c19fb41ed6 100644 (file)
 package org.sonar.server.qualitygate;
 
 import java.util.Objects;
-import java.util.Optional;
 import java.util.stream.Stream;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.db.qualitygate.QualityGateConditionDto;
 
-import static com.google.common.base.Strings.emptyToNull;
 import static java.util.Objects.requireNonNull;
 
 @Immutable
@@ -35,19 +31,14 @@ public class Condition {
 
   private final String metricKey;
   private final Operator operator;
-  @CheckForNull
-  private final String warningThreshold;
-  @CheckForNull
   private final String errorThreshold;
   private final boolean onLeakPeriod;
 
-  public Condition(String metricKey, Operator operator,
-    @Nullable String errorThreshold, @Nullable String warningThreshold) {
+  public Condition(String metricKey, Operator operator, String errorThreshold) {
     this.metricKey = requireNonNull(metricKey, "metricKey can't be null");
     this.operator = requireNonNull(operator, "operator can't be null");
+    this.errorThreshold = requireNonNull(errorThreshold, "errorThreshold can't be null");
     this.onLeakPeriod = metricKey.startsWith("new_");
-    this.errorThreshold = emptyToNull(errorThreshold);
-    this.warningThreshold = emptyToNull(warningThreshold);
   }
 
   public String getMetricKey() {
@@ -62,12 +53,8 @@ public class Condition {
     return operator;
   }
 
-  public Optional<String> getWarningThreshold() {
-    return Optional.ofNullable(warningThreshold);
-  }
-
-  public Optional<String> getErrorThreshold() {
-    return Optional.ofNullable(errorThreshold);
+  public String getErrorThreshold() {
+    return errorThreshold;
   }
 
   @Override
@@ -81,13 +68,12 @@ public class Condition {
     Condition condition = (Condition) o;
     return Objects.equals(metricKey, condition.metricKey) &&
       operator == condition.operator &&
-      Objects.equals(warningThreshold, condition.warningThreshold) &&
       Objects.equals(errorThreshold, condition.errorThreshold);
   }
 
   @Override
   public int hashCode() {
-    return Objects.hash(metricKey, operator, warningThreshold, errorThreshold);
+    return Objects.hash(metricKey, operator, errorThreshold);
   }
 
   @Override
@@ -95,15 +81,11 @@ public class Condition {
     return "Condition{" +
       "metricKey='" + metricKey + '\'' +
       ", operator=" + operator +
-      ", warningThreshold=" + toString(warningThreshold) +
       ", errorThreshold=" + toString(errorThreshold) +
       '}';
   }
 
-  private static String toString(@Nullable String errorThreshold) {
-    if (errorThreshold == null) {
-      return null;
-    }
+  private static String toString(String errorThreshold) {
     return '\'' + errorThreshold + '\'';
   }
 
index f386e2bc1b25feaabf1ced510f48b173d617e410..8775bd62444177c731e635b823b14eabbc77419f 100644 (file)
@@ -58,54 +58,48 @@ class ConditionEvaluator {
     }
 
     ValueType type = measure.get().getType();
-    return evaluateCondition(condition, type, value.get(), true)
-      .orElseGet(() -> evaluateCondition(condition, type, value.get(), false)
+    return evaluateCondition(condition, type, value.get())
+      .orElseGet(() -> evaluateCondition(condition, type, value.get())
         .orElseGet(() -> new EvaluatedCondition(condition, EvaluationStatus.OK, value.get().toString())));
   }
 
   /**
-   * Evaluates the error or warning condition. Returns empty if threshold or measure value is not defined.
+   * Evaluates the error condition. Returns empty if threshold or measure value is not defined.
    */
-  private static Optional<EvaluatedCondition> evaluateCondition(Condition condition, ValueType type, Comparable value, boolean error) {
-    Optional<Comparable> threshold = getThreshold(condition, type, error);
-    if (!threshold.isPresent()) {
-      return Optional.empty();
-    }
+  private static Optional<EvaluatedCondition> evaluateCondition(Condition condition, ValueType type, Comparable value) {
+    Comparable threshold = getThreshold(condition, type);
 
-    if (reachThreshold(value, threshold.get(), condition)) {
-      EvaluationStatus status = error ? EvaluationStatus.ERROR : EvaluationStatus.WARN;
-      return of(new EvaluatedCondition(condition, status, value.toString()));
+    if (reachThreshold(value, threshold, condition)) {
+      return of(new EvaluatedCondition(condition, EvaluationStatus.ERROR, value.toString()));
     }
     return Optional.empty();
   }
 
-  private static Optional<Comparable> getThreshold(Condition condition, ValueType valueType, boolean error) {
-    Optional<String> valString = error ? condition.getErrorThreshold() : condition.getWarningThreshold();
-    return valString.map(s -> {
-      try {
-        switch (valueType) {
-          case BOOL:
-            return parseInteger(s) == 1;
-          case INT:
-          case RATING:
-            return parseInteger(s);
-          case MILLISEC:
-          case WORK_DUR:
-            return Long.parseLong(s);
-          case FLOAT:
-          case PERCENT:
-            return Double.parseDouble(s);
-          case STRING:
-          case LEVEL:
-            return s;
-          default:
-            throw new IllegalArgumentException(String.format("Unsupported value type %s. Cannot convert condition value", valueType));
-        }
-      } catch (NumberFormatException badValueFormat) {
-        throw new IllegalArgumentException(String.format(
-          "Quality Gate: unable to parse threshold '%s' to compare against %s", s, condition.getMetricKey()));
+  private static Comparable getThreshold(Condition condition, ValueType valueType) {
+    String valString = condition.getErrorThreshold();
+    try {
+      switch (valueType) {
+        case BOOL:
+          return parseInteger(valString) == 1;
+        case INT:
+        case RATING:
+          return parseInteger(valString);
+        case MILLISEC:
+        case WORK_DUR:
+          return Long.parseLong(valString);
+        case FLOAT:
+        case PERCENT:
+          return Double.parseDouble(valString);
+        case STRING:
+        case LEVEL:
+          return valueType;
+        default:
+          throw new IllegalArgumentException(String.format("Unsupported value type %s. Cannot convert condition value", valueType));
       }
-    });
+    } catch (NumberFormatException badValueFormat) {
+      throw new IllegalArgumentException(String.format(
+        "Quality Gate: unable to parse threshold '%s' to compare against %s", valString, condition.getMetricKey()));
+    }
   }
 
   private static Optional<Comparable> getMeasureValue(Condition condition, QualityGateEvaluator.Measure measure) {
index d3731191406378bacd8b15283932023edae4f052..b4115edee1fb3626b595040d698d534063c24e80 100644 (file)
@@ -89,15 +89,11 @@ public class EvaluatedCondition {
      */
     NO_VALUE,
     /**
-     * Condition evaluated as OK, neither error nor warning thresholds have been reached.
+     * Condition evaluated as OK, error thresholds hasn't been reached.
      */
     OK,
     /**
-     * Condition evaluated as WARN, only warning thresholds has been reached.
-     */
-    WARN,
-    /**
-     * Condition evaluated as ERROR, error thresholds has been reached (and most likely warning thresholds too).
+     * Condition evaluated as ERROR, error thresholds has been reached.
      */
     ERROR
   }
index 6eeb5df5cf91c9b1f92b38239a558e5e7c4b6889..9420450295a76fb09a9976f16bb62013be6cd913 100644 (file)
@@ -91,9 +91,6 @@ public class QualityGateEvaluatorImpl implements QualityGateEvaluator {
     if (statuses.contains(EvaluationStatus.ERROR)) {
       return Level.ERROR;
     }
-    if (statuses.contains(EvaluationStatus.WARN)) {
-      return Level.WARN;
-    }
     return Level.OK;
   }
 }
index 002e0ce8d7b3d3d195ef070c3228c49b5347d2f5..389e7f008d419e9f73a0df1c79857fb5adfa3503 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.qualitygate;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.util.List;
-import javax.annotation.CheckForNull;
 import org.sonar.api.measures.CoreMetrics;
 
 import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_GREATER_THAN;
@@ -38,8 +37,8 @@ public final class ShortLivingBranchQualityGate {
     new Condition(CoreMetrics.REOPENED_ISSUES_KEY, OPERATOR_GREATER_THAN, "0"));
 
   public static final QualityGate GATE = new QualityGate(String.valueOf(ID), NAME, ImmutableSet.of(
-    new org.sonar.server.qualitygate.Condition(CoreMetrics.OPEN_ISSUES_KEY, org.sonar.server.qualitygate.Condition.Operator.GREATER_THAN, "0", null),
-    new org.sonar.server.qualitygate.Condition(CoreMetrics.REOPENED_ISSUES_KEY, org.sonar.server.qualitygate.Condition.Operator.GREATER_THAN, "0", null)));
+    new org.sonar.server.qualitygate.Condition(CoreMetrics.OPEN_ISSUES_KEY, org.sonar.server.qualitygate.Condition.Operator.GREATER_THAN, "0"),
+    new org.sonar.server.qualitygate.Condition(CoreMetrics.REOPENED_ISSUES_KEY, org.sonar.server.qualitygate.Condition.Operator.GREATER_THAN, "0")));
 
   private ShortLivingBranchQualityGate() {
     // prevents instantiation
@@ -67,10 +66,5 @@ public final class ShortLivingBranchQualityGate {
     public String getErrorThreshold() {
       return errorThreshold;
     }
-
-    @CheckForNull
-    public String getWarnThreshold() {
-      return null;
-    }
   }
 }
index 67fd97b2196ecaad9e2f57c83b5647db42c473ec..2a683181b5195ab611d4234ff73f78c845667d93 100644 (file)
@@ -154,8 +154,7 @@ public class WebhookPayloadFactoryImpl implements WebhookPayloadFactory {
       evaluatedCondition.getValue().ifPresent(t -> writer.prop("value", t));
       writer
         .prop(PROPERTY_STATUS, evaluatedCondition.getStatus().name())
-        .prop("errorThreshold", condition.getErrorThreshold().orElse(null))
-        .prop("warningThreshold", condition.getWarningThreshold().orElse(null))
+        .prop("errorThreshold", condition.getErrorThreshold())
         .endObject();
     }
     writer
index b55cc6c31bf357d965bd86437076f67997b9ee07..01a25df60c3e089a4a2ead973ad8f6ebad602c28 100644 (file)
@@ -110,6 +110,15 @@ public class ConditionEvaluatorTest {
     testOnLeak(newFakeMeasureOnLeak(10), Condition.Operator.LESS_THAN, "11", EvaluatedCondition.EvaluationStatus.ERROR, "10");
   }
 
+  @Test
+  public void evaluate_throws_IAE_if_fail_to_parse_threshold() {
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("Quality Gate: unable to parse threshold '9bar' to compare against foo");
+
+    test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "9bar", EvaluatedCondition.EvaluationStatus.ERROR, "10da");
+  }
+
   @Test
   public void no_value_present() {
     test(new FakeMeasure((Integer) null), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, null);
@@ -118,19 +127,13 @@ public class ConditionEvaluatorTest {
 
   @Test
   public void empty_warning_condition() {
-    test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "9", null, EvaluatedCondition.EvaluationStatus.OK, "10");
-    test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "9", "", EvaluatedCondition.EvaluationStatus.OK, "10");
-    test(new FakeMeasure(3), Condition.Operator.LESS_THAN, "9", "", EvaluatedCondition.EvaluationStatus.ERROR, "3");
-  }
-
-  private void test(@Nullable QualityGateEvaluator.Measure measure, Condition.Operator operator, String errorThreshold, EvaluatedCondition.EvaluationStatus expectedStatus,
-    @Nullable String expectedValue) {
-    test(measure, operator, errorThreshold, null, expectedStatus, expectedValue);
+    test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, "10");
+    test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, "10");
+    test(new FakeMeasure(3), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.ERROR, "3");
   }
 
-  private void test(@Nullable QualityGateEvaluator.Measure measure, Condition.Operator operator, String errorThreshold, @Nullable String warningThreshold,
-    EvaluatedCondition.EvaluationStatus expectedStatus, @Nullable String expectedValue) {
-    Condition condition = new Condition("foo", operator, errorThreshold, warningThreshold);
+  private void test(@Nullable QualityGateEvaluator.Measure measure, Condition.Operator operator, String errorThreshold, EvaluatedCondition.EvaluationStatus expectedStatus, @Nullable String expectedValue) {
+    Condition condition = new Condition("foo", operator, errorThreshold);
 
     EvaluatedCondition result = ConditionEvaluator.evaluate(condition, new FakeMeasures(measure));
 
@@ -144,7 +147,7 @@ public class ConditionEvaluatorTest {
 
   private void testOnLeak(QualityGateEvaluator.Measure measure, Condition.Operator operator, String errorThreshold, EvaluatedCondition.EvaluationStatus expectedStatus,
     @Nullable String expectedValue) {
-    Condition condition = new Condition("new_foo", operator, errorThreshold, null);
+    Condition condition = new Condition("new_foo", operator, errorThreshold);
 
     EvaluatedCondition result = ConditionEvaluator.evaluate(condition, new FakeMeasures(measure));
 
index 01f227bde6e6345e910801f2b427e8b6d21d4346..0799b033a62cbc9a2d75510b7ce8513b555f1662 100644 (file)
@@ -30,19 +30,18 @@ public class ConditionTest {
   private static final String METRIC_KEY = "metric_key";
   private static final Condition.Operator OPERATOR = Condition.Operator.EQUALS;
   private static final String ERROR_THRESHOLD = "2";
-  private static final String WARN_THRESHOLD = "4";
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private Condition underTest = new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD, WARN_THRESHOLD);
+  private Condition underTest = new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD);
 
   @Test
   public void constructor_throws_NPE_if_metricKey_is_null() {
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("metricKey can't be null");
 
-    new Condition(null, OPERATOR, ERROR_THRESHOLD, WARN_THRESHOLD);
+    new Condition(null, OPERATOR, ERROR_THRESHOLD);
   }
 
   @Test
@@ -50,21 +49,15 @@ public class ConditionTest {
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("operator can't be null");
 
-    new Condition(METRIC_KEY, null, ERROR_THRESHOLD, WARN_THRESHOLD);
+    new Condition(METRIC_KEY, null, ERROR_THRESHOLD);
   }
 
   @Test
-  public void errorThreshold_can_be_null() {
-    Condition underTest = new Condition(METRIC_KEY, OPERATOR, null, WARN_THRESHOLD);
-
-    assertThat(underTest.getErrorThreshold()).isEmpty();
-  }
-
-  @Test
-  public void warnThreshold_can_be_null() {
-    Condition underTest = new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD, null);
+  public void constructor_throws_NPE_if_errorThreshold_is_null() {
+    expectedException.expect(NullPointerException.class);
+    expectedException.expectMessage("errorThreshold can't be null");
 
-    assertThat(underTest.getWarningThreshold()).isEmpty();
+    new Condition(METRIC_KEY, OPERATOR, null);
   }
 
   @Test
@@ -72,20 +65,12 @@ public class ConditionTest {
     assertThat(underTest.getMetricKey()).isEqualTo(METRIC_KEY);
     assertThat(underTest.getOperator()).isEqualTo(OPERATOR);
     assertThat(underTest.getErrorThreshold()).contains(ERROR_THRESHOLD);
-    assertThat(underTest.getWarningThreshold()).contains(WARN_THRESHOLD);
   }
 
   @Test
   public void toString_is_override() {
     assertThat(underTest.toString())
-      .isEqualTo("Condition{metricKey='metric_key', operator=EQUALS, warningThreshold='4', errorThreshold='2'}");
-  }
-
-  @Test
-  public void toString_does_not_quote_nulls() {
-    Condition withNulls = new Condition("metric_key", Condition.Operator.LESS_THAN, null, null);
-    assertThat(withNulls.toString())
-      .isEqualTo("Condition{metricKey='metric_key', operator=LESS_THAN, warningThreshold=null, errorThreshold=null}");
+      .isEqualTo("Condition{metricKey='metric_key', operator=EQUALS, errorThreshold='2'}");
   }
 
   @Test
@@ -93,16 +78,13 @@ public class ConditionTest {
     assertThat(underTest).isEqualTo(underTest);
     assertThat(underTest).isNotEqualTo(null);
     assertThat(underTest).isNotEqualTo(new Object());
-    assertThat(underTest).isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD, WARN_THRESHOLD));
-    assertThat(underTest).isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD, WARN_THRESHOLD));
+    assertThat(underTest).isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD));
+    assertThat(underTest).isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD));
     Arrays.stream(Condition.Operator.values())
         .filter(s -> !OPERATOR.equals(s))
         .forEach(otherOperator ->  assertThat(underTest)
-            .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD, WARN_THRESHOLD)));
-    assertThat(underTest).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, null, WARN_THRESHOLD));
-    assertThat(underTest).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, "other_error_threshold", WARN_THRESHOLD));
-    assertThat(underTest).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD, null));
-    assertThat(underTest).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD, "other_warn_threshold"));
+            .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD)));
+    assertThat(underTest).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, "other_error_threshold"));
   }
 
   @Test
@@ -110,15 +92,12 @@ public class ConditionTest {
     assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode());
     assertThat(underTest.hashCode()).isNotEqualTo(null);
     assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode());
-    assertThat(underTest.hashCode()).isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD, WARN_THRESHOLD).hashCode());
-    assertThat(underTest.hashCode()).isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD, WARN_THRESHOLD).hashCode());
+    assertThat(underTest.hashCode()).isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD).hashCode());
+    assertThat(underTest.hashCode()).isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD).hashCode());
     Arrays.stream(Condition.Operator.values())
         .filter(s -> !OPERATOR.equals(s))
         .forEach(otherOperator ->  assertThat(underTest.hashCode())
-            .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD, WARN_THRESHOLD).hashCode()));
-    assertThat(underTest.hashCode()).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, null, WARN_THRESHOLD).hashCode());
-    assertThat(underTest.hashCode()).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, "other_error_threshold", WARN_THRESHOLD).hashCode());
-    assertThat(underTest.hashCode()).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD, null).hashCode());
-    assertThat(underTest.hashCode()).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD, "other_warn_threshold").hashCode());
+            .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD).hashCode()));
+    assertThat(underTest.hashCode()).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, "other_error_threshold").hashCode());
   }
 }
index 9444ed758f92807b69ff8bc2bd77e9cce3710f95..1806aa823687d9afaf4a81dd93171d57fa53c454 100644 (file)
@@ -25,23 +25,23 @@ import org.junit.rules.ExpectedException;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.server.qualitygate.Condition.Operator.EQUALS;
+import static org.sonar.server.qualitygate.EvaluatedCondition.EvaluationStatus.ERROR;
 import static org.sonar.server.qualitygate.EvaluatedCondition.EvaluationStatus.OK;
-import static org.sonar.server.qualitygate.EvaluatedCondition.EvaluationStatus.WARN;
 
 public class EvaluatedConditionTest {
-  private static final Condition CONDITION_1 = new Condition("metricKey", EQUALS, "2", "4");
+  private static final Condition CONDITION_1 = new Condition("metricKey", EQUALS, "2");
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, WARN, "value");
+  private EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, ERROR, "value");
 
   @Test
   public void constructor_throws_NPE_if_condition_is_null() {
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("condition can't be null");
 
-    new EvaluatedCondition(null, WARN, "value");
+    new EvaluatedCondition(null, ERROR, "value");
   }
 
   @Test
@@ -54,57 +54,57 @@ public class EvaluatedConditionTest {
 
   @Test
   public void constructor_accepts_null_value() {
-    EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, WARN, null);
+    EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, ERROR, null);
 
     assertThat(underTest.getValue()).isEmpty();
   }
 
   @Test
   public void verify_getters() {
-    EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, WARN, "value");
+    EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, ERROR, "value");
 
     assertThat(underTest.getCondition()).isEqualTo(CONDITION_1);
-    assertThat(underTest.getStatus()).isEqualTo(WARN);
+    assertThat(underTest.getStatus()).isEqualTo(ERROR);
     assertThat(underTest.getValue()).contains("value");
   }
 
   @Test
   public void override_toString() {
     assertThat(underTest.toString()).isEqualTo("EvaluatedCondition{condition=" +
-      "Condition{metricKey='metricKey', operator=EQUALS, warningThreshold='4', errorThreshold='2'}, " +
-      "status=WARN, value='value'}");
+      "Condition{metricKey='metricKey', operator=EQUALS, errorThreshold='2'}, " +
+      "status=ERROR, value='value'}");
   }
 
   @Test
   public void toString_does_not_quote_null_value() {
-    EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, WARN, null);
+    EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, ERROR, null);
 
     assertThat(underTest.toString()).isEqualTo("EvaluatedCondition{condition=" +
-      "Condition{metricKey='metricKey', operator=EQUALS, warningThreshold='4', errorThreshold='2'}, " +
-      "status=WARN, value=null}");
+      "Condition{metricKey='metricKey', operator=EQUALS, errorThreshold='2'}, " +
+      "status=ERROR, value=null}");
   }
 
   @Test
   public void equals_is_based_on_all_fields() {
     assertThat(underTest).isEqualTo(underTest);
-    assertThat(underTest).isEqualTo(new EvaluatedCondition(CONDITION_1, WARN, "value"));
+    assertThat(underTest).isEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "value"));
     assertThat(underTest).isNotEqualTo(null);
     assertThat(underTest).isNotEqualTo(new Object());
-    assertThat(underTest).isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", EQUALS, "a", "b"), WARN, "value"));
+    assertThat(underTest).isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", EQUALS, "a"), ERROR, "value"));
     assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, OK, "value"));
-    assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, WARN, null));
-    assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, WARN, "other_value"));
+    assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, null));
+    assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "other_value"));
   }
 
   @Test
   public void hashcode_is_based_on_all_fields() {
     assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode());
-    assertThat(underTest.hashCode()).isEqualTo(new EvaluatedCondition(CONDITION_1, WARN, "value").hashCode());
+    assertThat(underTest.hashCode()).isEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "value").hashCode());
     assertThat(underTest.hashCode()).isNotEqualTo(null);
     assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode());
-    assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", EQUALS, "a", "b"), WARN, "value").hashCode());
+    assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", EQUALS, "a"), ERROR, "value").hashCode());
     assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(CONDITION_1, OK, "value").hashCode());
-    assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(CONDITION_1, WARN, null).hashCode());
-    assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(CONDITION_1, WARN, "other_value").hashCode());
+    assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, null).hashCode());
+    assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "other_value").hashCode());
   }
 }
index 04509c451a157d0e1ac16d7b8d0d2dd30d9ba9b9..03ed5e410b164b3f0afa402aea6e4d0144c12a95 100644 (file)
@@ -36,8 +36,8 @@ public class EvaluatedQualityGateTest {
   private static final String QUALITY_GATE_ID = "qg_id";
   private static final String QUALITY_GATE_NAME = "qg_name";
   private static final QualityGate NO_CONDITION_QUALITY_GATE = new QualityGate(QUALITY_GATE_ID, QUALITY_GATE_NAME, emptySet());
-  private static final Condition CONDITION_1 = new Condition("metric_key", Condition.Operator.LESS_THAN, "2", "4");
-  private static final Condition CONDITION_2 = new Condition("metric_key_2", Condition.Operator.GREATER_THAN, "6", "12");
+  private static final Condition CONDITION_1 = new Condition("metric_key", Condition.Operator.LESS_THAN, "2");
+  private static final Condition CONDITION_2 = new Condition("metric_key_2", Condition.Operator.GREATER_THAN, "6");
   private static final QualityGate ONE_CONDITION_QUALITY_GATE = new QualityGate(QUALITY_GATE_ID, QUALITY_GATE_NAME, singleton(CONDITION_1));
 
   @Rule
@@ -66,7 +66,7 @@ public class EvaluatedQualityGateTest {
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("condition can't be null");
 
-    builder.addCondition(null, EvaluatedCondition.EvaluationStatus.WARN, "a_value");
+    builder.addCondition(null, EvaluatedCondition.EvaluationStatus.ERROR, "a_value");
   }
 
   @Test
@@ -74,7 +74,7 @@ public class EvaluatedQualityGateTest {
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("status can't be null");
 
-    builder.addCondition(new Condition("metric_key", Condition.Operator.LESS_THAN, "2", "4"), null, "a_value");
+    builder.addCondition(new Condition("metric_key", Condition.Operator.LESS_THAN, "2"), null, "a_value");
   }
 
   @Test
@@ -146,22 +146,22 @@ public class EvaluatedQualityGateTest {
       .setQualityGate(qualityGate)
       .setStatus(randomStatus)
       .addCondition(CONDITION_1, randomEvaluationStatus, randomValue)
-      .addCondition(CONDITION_2, EvaluatedCondition.EvaluationStatus.WARN, "bad")
+      .addCondition(CONDITION_2, EvaluatedCondition.EvaluationStatus.ERROR, "bad")
       .build();
 
     assertThat(underTest.getQualityGate()).isEqualTo(qualityGate);
     assertThat(underTest.getStatus()).isEqualTo(randomStatus);
     assertThat(underTest.getEvaluatedConditions()).containsOnly(
       new EvaluatedCondition(CONDITION_1, randomEvaluationStatus, randomValue),
-      new EvaluatedCondition(CONDITION_2, EvaluatedCondition.EvaluationStatus.WARN, "bad"));
+      new EvaluatedCondition(CONDITION_2, EvaluatedCondition.EvaluationStatus.ERROR, "bad"));
   }
 
   @Test
   public void equals_is_based_on_all_fields() {
     EvaluatedQualityGate.Builder builder = this.builder
       .setQualityGate(ONE_CONDITION_QUALITY_GATE)
-      .setStatus(Level.WARN)
-      .addCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.WARN, "foo");
+      .setStatus(Level.ERROR)
+      .addCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.ERROR, "foo");
 
     EvaluatedQualityGate underTest = builder.build();
     assertThat(underTest).isEqualTo(builder.build());
@@ -172,7 +172,7 @@ public class EvaluatedQualityGateTest {
     assertThat(underTest).isNotEqualTo(builder.setQualityGate(ONE_CONDITION_QUALITY_GATE).setStatus(Level.OK).build());
     assertThat(underTest).isNotEqualTo(newBuilder()
       .setQualityGate(ONE_CONDITION_QUALITY_GATE)
-      .setStatus(Level.WARN)
+      .setStatus(Level.ERROR)
       .addCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.OK, "foo")
       .build());
   }
@@ -181,8 +181,8 @@ public class EvaluatedQualityGateTest {
   public void hashcode_is_based_on_all_fields() {
     EvaluatedQualityGate.Builder builder = this.builder
       .setQualityGate(ONE_CONDITION_QUALITY_GATE)
-      .setStatus(Level.WARN)
-      .addCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.WARN, "foo");
+      .setStatus(Level.ERROR)
+      .addCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.ERROR, "foo");
 
     EvaluatedQualityGate underTest = builder.build();
     assertThat(underTest.hashCode()).isEqualTo(builder.build().hashCode());
@@ -193,7 +193,7 @@ public class EvaluatedQualityGateTest {
     assertThat(underTest.hashCode()).isNotEqualTo(builder.setQualityGate(ONE_CONDITION_QUALITY_GATE).setStatus(Level.OK).build().hashCode());
     assertThat(underTest.hashCode()).isNotEqualTo(newBuilder()
       .setQualityGate(ONE_CONDITION_QUALITY_GATE)
-      .setStatus(Level.WARN)
+      .setStatus(Level.ERROR)
       .addCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.OK, "foo")
       .build().hashCode());
   }
index aa16cbeba94ec832e488ca5ed91f4258991e01cb..19cd6cdacca2c7ac7005634daf7bb8e88a071e95 100644 (file)
@@ -35,8 +35,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class QualityGateTest {
   private static final String QUALIGATE_ID = "qg_id";
   private static final String QUALIGATE_NAME = "qg_name";
-  private static final Condition CONDITION_1 = new Condition("m1", Condition.Operator.EQUALS, "1", "2");
-  private static final Condition CONDITION_2 = new Condition("m2", Condition.Operator.LESS_THAN, "2", "4");
+  private static final Condition CONDITION_1 = new Condition("m1", Condition.Operator.EQUALS, "1");
+  private static final Condition CONDITION_2 = new Condition("m2", Condition.Operator.LESS_THAN, "2");
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
@@ -74,10 +74,10 @@ public class QualityGateTest {
     Random random = new Random();
     Set<Condition> conditions = Stream.of(
       IntStream.range(0, random.nextInt(5))
-        .mapToObj(i -> new Condition("m_before_" + i, Condition.Operator.EQUALS, null, null)),
+        .mapToObj(i -> new Condition("m_before_" + i, Condition.Operator.EQUALS, "10")),
       Stream.of((Condition) null),
       IntStream.range(0, random.nextInt(5))
-        .mapToObj(i -> new Condition("m_after_" + i, Condition.Operator.EQUALS, null, null)))
+        .mapToObj(i -> new Condition("m_after_" + i, Condition.Operator.EQUALS, "10")))
       .flatMap(s -> s)
       .collect(Collectors.toSet());
 
@@ -99,7 +99,7 @@ public class QualityGateTest {
     QualityGate underTest = new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2));
 
     assertThat(underTest.toString()).isEqualTo("QualityGate{id=qg_id, name='qg_name', conditions=[" +
-      "Condition{metricKey='m2', operator=LESS_THAN, warningThreshold='4', errorThreshold='2'}" +
+      "Condition{metricKey='m2', operator=LESS_THAN, errorThreshold='2'}" +
       "]}");
   }
 
@@ -115,7 +115,7 @@ public class QualityGateTest {
     assertThat(underTest).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1)));
     assertThat(underTest).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2)));
     assertThat(underTest).isNotEqualTo(
-      new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1, CONDITION_2, new Condition("new", Condition.Operator.GREATER_THAN, "a", "b"))));
+      new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1, CONDITION_2, new Condition("new", Condition.Operator.GREATER_THAN, "a"))));
   }
 
   @Test
@@ -130,6 +130,6 @@ public class QualityGateTest {
     assertThat(underTest.hashCode()).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1)).hashCode());
     assertThat(underTest.hashCode()).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2)).hashCode());
     assertThat(underTest.hashCode()).isNotEqualTo(
-      new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1, CONDITION_2, new Condition("new", Condition.Operator.GREATER_THAN, "a", "b"))).hashCode());
+      new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1, CONDITION_2, new Condition("new", Condition.Operator.GREATER_THAN, "a"))).hashCode());
   }
 }
index 14b1c338b55c76fcd3ee6e88629b4cf86e3ba1f7..a1d9805f440ccbc93c9086af1d350bb20f2120cb 100644 (file)
@@ -31,10 +31,10 @@ public class ShortLivingBranchQualityGateTest {
   @Test
   public void defines_short_living_branches_hardcoded_quality_gate_conditions() {
     assertThat(ShortLivingBranchQualityGate.CONDITIONS)
-      .extracting(Condition::getMetricKey, Condition::getOperator, Condition::getErrorThreshold, Condition::getWarnThreshold)
+      .extracting(Condition::getMetricKey, Condition::getOperator, Condition::getErrorThreshold)
       .containsExactly(
-        tuple(CoreMetrics.OPEN_ISSUES_KEY, "GT", "0", null),
-        tuple(CoreMetrics.REOPENED_ISSUES_KEY, "GT", "0", null));
+        tuple(CoreMetrics.OPEN_ISSUES_KEY, "GT", "0"),
+        tuple(CoreMetrics.REOPENED_ISSUES_KEY, "GT", "0"));
   }
 
 }
index fc1d12dd63bbad82688ca4cb4b147bad56a4e3a3..6cb28a0b0f344127c04e3ca5a586d43b7176335d 100644 (file)
@@ -42,7 +42,7 @@ public class ProjectAnalysisTest {
   private final Branch branch = new Branch(true, "name", Branch.Type.SHORT);
   private final EvaluatedQualityGate qualityGate = EvaluatedQualityGate.newBuilder()
     .setQualityGate(new QualityGate("id", "name", emptySet()))
-    .setStatus(Metric.Level.WARN)
+    .setStatus(Metric.Level.ERROR)
     .build();
   private final Map<String, String> properties = ImmutableMap.of("a", "b");
   private ProjectAnalysis underTest = new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, properties);
@@ -109,7 +109,7 @@ public class ProjectAnalysisTest {
     assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, null, 1L, properties));
     EvaluatedQualityGate otherQualityGate = EvaluatedQualityGate.newBuilder()
       .setQualityGate(new QualityGate("A", "B", emptySet()))
-      .setStatus(Metric.Level.WARN)
+      .setStatus(Metric.Level.ERROR)
       .build();
     assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, otherQualityGate, 1L, properties));
     assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, null, properties));
@@ -135,7 +135,7 @@ public class ProjectAnalysisTest {
     assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, null, 1L, properties).hashCode());
     EvaluatedQualityGate otherQualityGate = EvaluatedQualityGate.newBuilder()
       .setQualityGate(new QualityGate("A", "B", emptySet()))
-      .setStatus(Metric.Level.WARN)
+      .setStatus(Metric.Level.ERROR)
       .build();
     assertThat(underTest.hashCode())
       .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, otherQualityGate, 1L, properties).hashCode());
@@ -148,6 +148,6 @@ public class ProjectAnalysisTest {
   @Test
   public void verify_toString() {
     assertThat(underTest.toString()).isEqualTo(
-      "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=SHORT}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=WARN, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500}}");
+      "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=SHORT}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=ERROR, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500}}");
   }
 }
index 02812a4adb07011a1a217291b0ebb9569933a83e..04ed254c9f39ac29c097dca1d5d6f03d53e8f6dc 100644 (file)
@@ -57,11 +57,11 @@ public class WebhookPayloadFactoryImplTest {
   @Test
   public void create_payload_for_successful_analysis() {
     CeTask task = new CeTask("#1", CeTask.Status.SUCCESS);
-    Condition condition = new Condition("coverage", Condition.Operator.GREATER_THAN, "70.0", "75.0");
+    Condition condition = new Condition("coverage", Condition.Operator.GREATER_THAN, "70.0");
     EvaluatedQualityGate gate = EvaluatedQualityGate.newBuilder()
       .setQualityGate(new QualityGate("G1", "Gate One", singleton(condition)))
-      .setStatus(Metric.Level.WARN)
-      .addCondition(condition, EvaluatedCondition.EvaluationStatus.WARN, "74.0")
+      .setStatus(Metric.Level.ERROR)
+      .addCondition(condition, EvaluatedCondition.EvaluationStatus.ERROR, "74.0")
       .build();
     ProjectAnalysis analysis = newAnalysis(task, gate, null, 1_500_000_000_000L, emptyMap());
 
@@ -81,15 +81,14 @@ public class WebhookPayloadFactoryImplTest {
         "  }," +
         "  \"qualityGate\": {" +
         "    \"name\": \"Gate One\"," +
-        "    \"status\": \"WARN\"," +
+        "    \"status\": \"ERROR\"," +
         "    \"conditions\": [" +
         "      {" +
         "        \"metric\": \"coverage\"," +
         "        \"operator\": \"GREATER_THAN\"," +
         "        \"value\": \"74.0\"," +
-        "        \"status\": \"WARN\"," +
-        "        \"errorThreshold\": \"70.0\"," +
-        "        \"warningThreshold\": \"75.0\"" +
+        "        \"status\": \"ERROR\"," +
+        "        \"errorThreshold\": \"70.0\"" +
         "      }" +
         "    ]" +
         "  }," +
@@ -102,10 +101,10 @@ public class WebhookPayloadFactoryImplTest {
   public void create_payload_with_gate_conditions_without_value() {
     CeTask task = new CeTask("#1", CeTask.Status.SUCCESS);
 
-    Condition condition = new Condition("coverage", Condition.Operator.GREATER_THAN, "70.0", "75.0");
+    Condition condition = new Condition("coverage", Condition.Operator.GREATER_THAN, "70.0");
     EvaluatedQualityGate gate = EvaluatedQualityGate.newBuilder()
       .setQualityGate(new QualityGate("G1", "Gate One", singleton(condition)))
-      .setStatus(Metric.Level.WARN)
+      .setStatus(Metric.Level.ERROR)
       .addCondition(condition, EvaluatedCondition.EvaluationStatus.NO_VALUE, null)
       .build();
     ProjectAnalysis analysis = newAnalysis(task, gate, null, 1_500_000_000_000L, emptyMap());
@@ -126,14 +125,13 @@ public class WebhookPayloadFactoryImplTest {
         "  }," +
         "  \"qualityGate\": {" +
         "    \"name\": \"Gate One\"," +
-        "    \"status\": \"WARN\"," +
+        "    \"status\": \"ERROR\"," +
         "    \"conditions\": [" +
         "      {" +
         "        \"metric\": \"coverage\"," +
         "        \"operator\": \"GREATER_THAN\"," +
         "        \"status\": \"NO_VALUE\"," +
-        "        \"errorThreshold\": \"70.0\"," +
-        "        \"warningThreshold\": \"75.0\"" +
+        "        \"errorThreshold\": \"70.0\"" +
         "      }" +
         "    ]" +
         "  }" +
@@ -145,7 +143,7 @@ public class WebhookPayloadFactoryImplTest {
     CeTask task = new CeTask("#1", CeTask.Status.SUCCESS);
     EvaluatedQualityGate gate = EvaluatedQualityGate.newBuilder()
       .setQualityGate(new QualityGate("G1", "Gate One", emptySet()))
-      .setStatus(Metric.Level.WARN)
+      .setStatus(Metric.Level.ERROR)
       .build();
     Map<String, String> scannerProperties = ImmutableMap.of(
       "sonar.analysis.revision", "ab45d24",
@@ -169,7 +167,7 @@ public class WebhookPayloadFactoryImplTest {
         "  }," +
         "  \"qualityGate\": {" +
         "    \"name\": \"Gate One\"," +
-        "    \"status\": \"WARN\"," +
+        "    \"status\": \"ERROR\"," +
         "    \"conditions\": [" +
         "    ]" +
         "  }," +
index 50e0637aef90620e177c73e11a25b6cd3c8c01fd..e02d92762422c030f7337a72ebe97a7cb55089d5 100644 (file)
@@ -60,7 +60,6 @@ import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY;
 import static org.sonar.api.measures.Metric.Level;
 import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.api.measures.Metric.Level.OK;
-import static org.sonar.api.measures.Metric.Level.WARN;
 import static org.sonar.api.measures.Metric.ValueType;
 import static org.sonar.server.badge.ws.ETagUtils.RFC1123_DATE;
 import static org.sonar.server.badge.ws.ETagUtils.getETag;
@@ -95,12 +94,10 @@ public class MeasureAction implements ProjectBadgesWsAction {
 
   private static final Map<Level, String> QUALITY_GATE_MESSAGE_BY_STATUS = new EnumMap<>(ImmutableMap.of(
     OK, "passed",
-    WARN, "warning",
     ERROR, "failed"));
 
   private static final Map<Level, Color> COLOR_BY_QUALITY_GATE_STATUS = new EnumMap<>(ImmutableMap.of(
     OK, Color.QUALITY_GATE_OK,
-    WARN, Color.QUALITY_GATE_WARN,
     ERROR, Color.QUALITY_GATE_ERROR));
 
   private static final Map<Rating, Color> COLOR_BY_RATING = new EnumMap<>(ImmutableMap.of(
index b9d86844a0bfcb46e15816cf66e692a13441fb65..e21bb66c8b4512e3f63c25061749dbc2566cfe31 100644 (file)
@@ -33,7 +33,6 @@ import static java.lang.String.valueOf;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.api.measures.Metric.Level.OK;
-import static org.sonar.api.measures.Metric.Level.WARN;
 import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED;
 
 @ServerSide
@@ -137,7 +136,6 @@ public class SvgGenerator {
     this.badgeTemplate = readTemplate(templatePath + "/badge.svg");
     this.qualityGateTemplates = ImmutableMap.of(
       OK, readTemplate(templatePath + "/quality_gate_passed.svg"),
-      WARN, readTemplate(templatePath + "/quality_gate_warn.svg"),
       ERROR, readTemplate(templatePath + "/quality_gate_failed.svg"));
   }
 
@@ -195,7 +193,6 @@ public class SvgGenerator {
   static class Color {
     static final Color DEFAULT = new Color("#999");
     static final Color QUALITY_GATE_OK = new Color("#4c1");
-    static final Color QUALITY_GATE_WARN = new Color("#ed7d20");
     static final Color QUALITY_GATE_ERROR = new Color("#d4333f");
     static final Color RATING_A = new Color("#00aa00");
     static final Color RATING_B = new Color("#b0d513");
index 1675f7a6f39b99d1d9265a97bb8ffc2ad51dcef2..2f6740305a247ca695da7a878590f0eda23364a1 100644 (file)
@@ -80,7 +80,7 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer {
     Set<Condition> conditions = conditionDtos.stream().map(conditionDto -> {
       String metricKey = metricsById.get((int) conditionDto.getMetricId()).getKey();
       Condition.Operator operator = Condition.Operator.fromDbValue(conditionDto.getOperator());
-      return new Condition(metricKey, operator, conditionDto.getErrorThreshold(), conditionDto.getWarningThreshold());
+      return new Condition(metricKey, operator, conditionDto.getErrorThreshold());
     }).collect(toHashSet(conditionDtos.size()));
 
     return new QualityGate(String.valueOf(gateDto.getId()), gateDto.getName(), conditions);
index 831df17ec6df4d6036d5db219240d0a10b350cfb..42126a88fbded7dff3088fef9bd079529d2b47b6 100644 (file)
@@ -42,6 +42,7 @@ import static java.lang.Integer.parseInt;
 import static java.lang.Long.parseLong;
 import static java.lang.String.format;
 import static java.util.Arrays.stream;
+import static java.util.Objects.requireNonNull;
 import static org.sonar.api.measures.Metric.ValueType.RATING;
 import static org.sonar.api.measures.Metric.ValueType.valueOf;
 import static org.sonar.db.qualitygate.QualityGateConditionDto.isOperatorAllowed;
@@ -60,30 +61,28 @@ public class QualityGateConditionsUpdater {
   }
 
   public QualityGateConditionDto createCondition(DbSession dbSession, QualityGateDto qualityGate, String metricKey, String operator,
-    @Nullable String warningThreshold, @Nullable String errorThreshold) {
+    String errorThreshold) {
     MetricDto metric = getNonNullMetric(dbSession, metricKey);
-    validateCondition(metric, operator, warningThreshold, errorThreshold);
+    validateCondition(metric, operator, errorThreshold);
     checkConditionDoesNotExistOnSameMetric(getConditions(dbSession, qualityGate.getId()), metric);
 
     QualityGateConditionDto newCondition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId())
       .setMetricId(metric.getId()).setMetricKey(metric.getKey())
       .setOperator(operator)
-      .setWarningThreshold(warningThreshold)
       .setErrorThreshold(errorThreshold);
     dbClient.gateConditionDao().insert(newCondition, dbSession);
     return newCondition;
   }
 
   public QualityGateConditionDto updateCondition(DbSession dbSession, QualityGateConditionDto condition, String metricKey, String operator,
-    @Nullable String warningThreshold, @Nullable String errorThreshold) {
+    String errorThreshold) {
     MetricDto metric = getNonNullMetric(dbSession, metricKey);
-    validateCondition(metric, operator, warningThreshold, errorThreshold);
+    validateCondition(metric, operator, errorThreshold);
 
     condition
       .setMetricId(metric.getId())
       .setMetricKey(metric.getKey())
       .setOperator(operator)
-      .setWarningThreshold(warningThreshold)
       .setErrorThreshold(errorThreshold);
     dbClient.gateConditionDao().update(condition, dbSession);
     return condition;
@@ -101,15 +100,12 @@ public class QualityGateConditionsUpdater {
     return dbClient.gateConditionDao().selectForQualityGate(dbSession, qGateId);
   }
 
-  private static void validateCondition(MetricDto metric, String operator, @Nullable String warningThreshold, @Nullable String errorThreshold) {
+  private static void validateCondition(MetricDto metric, String operator, String errorThreshold) {
     List<String> errors = new ArrayList<>();
     validateMetric(metric, errors);
     checkOperator(metric, operator, errors);
-    checkThresholds(warningThreshold, errorThreshold, errors);
-
-    validateThresholdValues(metric, warningThreshold, errors);
-    validateThresholdValues(metric, errorThreshold, errors);
-    checkRatingMetric(metric, warningThreshold, errorThreshold, errors);
+    checkErrorThreshold(metric, errorThreshold, errors);
+    checkRatingMetric(metric, errorThreshold, errors);
     checkRequest(errors.isEmpty(), errors);
   }
 
@@ -130,8 +126,9 @@ public class QualityGateConditionsUpdater {
     check(isOperatorAllowed(operator, valueType), errors, "Operator %s is not allowed for metric type %s.", operator, metric.getValueType());
   }
 
-  private static void checkThresholds(@Nullable String warningThreshold, @Nullable String errorThreshold, List<String> errors) {
-    check(warningThreshold != null || errorThreshold != null, errors, "At least one threshold (warning, error) must be set.");
+  private static void checkErrorThreshold(MetricDto metric, String errorThreshold, List<String> errors) {
+    requireNonNull(errorThreshold, "errorThreshold can not be null");
+    validateErrorThresholdValue(metric, errorThreshold, errors);
   }
 
   private static void checkConditionDoesNotExistOnSameMetric(Collection<QualityGateConditionDto> conditions, MetricDto metric) {
@@ -143,25 +140,22 @@ public class QualityGateConditionsUpdater {
     checkRequest(!conditionExists, format("Condition on metric '%s' already exists.", metric.getShortName()));
   }
 
-  private static void validateThresholdValues(MetricDto metric, @Nullable String value, List<String> errors) {
-    if (value == null) {
-      return;
-    }
+  private static void validateErrorThresholdValue(MetricDto metric, String errorThreshold, List<String> errors) {
     try {
       ValueType valueType = ValueType.valueOf(metric.getValueType());
       switch (valueType) {
         case BOOL:
         case INT:
         case RATING:
-          parseInt(value);
+          parseInt(errorThreshold);
           return;
         case MILLISEC:
         case WORK_DUR:
-          parseLong(value);
+          parseLong(errorThreshold);
           return;
         case FLOAT:
         case PERCENT:
-          parseDouble(value);
+          parseDouble(errorThreshold);
           return;
         case STRING:
         case LEVEL:
@@ -170,26 +164,21 @@ public class QualityGateConditionsUpdater {
           throw new IllegalArgumentException(format("Unsupported value type %s. Cannot convert condition value", valueType));
       }
     } catch (Exception e) {
-      errors.add(format("Invalid value '%s' for metric '%s'", value, metric.getShortName()));
+      errors.add(format("Invalid value '%s' for metric '%s'", errorThreshold, metric.getShortName()));
     }
   }
 
-  private static void checkRatingMetric(MetricDto metric, @Nullable String warningThreshold, @Nullable String errorThreshold, List<String> errors) {
+  private static void checkRatingMetric(MetricDto metric, String errorThreshold, List<String> errors) {
     if (!metric.getValueType().equals(RATING.name())) {
       return;
     }
     if (!isCoreRatingMetric(metric.getKey())) {
       errors.add(format("The metric '%s' cannot be used", metric.getShortName()));
     }
-    if (!isValidRating(warningThreshold)) {
-      addInvalidRatingError(warningThreshold, errors);
-      return;
-    }
     if (!isValidRating(errorThreshold)) {
       addInvalidRatingError(errorThreshold, errors);
       return;
     }
-    checkRatingGreaterThanOperator(warningThreshold, errors);
     checkRatingGreaterThanOperator(errorThreshold, errors);
   }
 
index 32dd6f61918573ddd008b93e94d4a776e1924dee..402c9bfed54b802808669abb760fc416eef8ead8 100644 (file)
@@ -49,8 +49,7 @@ public class QualityGateConverter {
     JsonObject result = new JsonObject();
     result.addProperty("metric", condition.getMetricKey());
     result.addProperty("op", condition.getOperator().getDbValue());
-    condition.getWarningThreshold().ifPresent(t -> result.addProperty("warning", t));
-    condition.getErrorThreshold().ifPresent(t -> result.addProperty("error", t));
+    result.addProperty("error", condition.getErrorThreshold());
     evaluatedCondition.getValue().ifPresent(v -> result.addProperty("actual", v));
     result.addProperty(FIELD_LEVEL, evaluatedCondition.getStatus().name());
     return result;
index d139e06eae8026562a58f3e1d16cd7379658c58c..8fa1bc6846485f3f975c98f17961cc7141888107 100644 (file)
@@ -58,9 +58,11 @@ public class QualityGateUpdater {
     QualityGateDto destinationGate = create(dbSession, organizationDto, destinationName);
 
     for (QualityGateConditionDto sourceCondition : dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId())) {
-      dbClient.gateConditionDao().insert(new QualityGateConditionDto().setQualityGateId(destinationGate.getId())
-        .setMetricId(sourceCondition.getMetricId()).setOperator(sourceCondition.getOperator())
-        .setWarningThreshold(sourceCondition.getWarningThreshold()).setErrorThreshold(sourceCondition.getErrorThreshold()),
+      dbClient.gateConditionDao().insert(new QualityGateConditionDto()
+          .setQualityGateId(destinationGate.getId())
+          .setMetricId(sourceCondition.getMetricId())
+          .setOperator(sourceCondition.getOperator())
+          .setErrorThreshold(sourceCondition.getErrorThreshold()),
         dbSession);
     }
 
index 618972c73017d65b4255612d1bd5c71a2d7ab3b8..35e0af5fff2af165f78257b18c351c9229ef7593 100644 (file)
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
 import org.picocontainer.Startable;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.Logger;
@@ -129,7 +128,7 @@ public class RegisterQualityGates implements Startable {
     List<QualityGateCondition> qgConditionsToBeCreated = new ArrayList<>(QUALITY_GATE_CONDITIONS);
     qgConditionsToBeCreated.removeAll(qualityGateConditions);
     qgConditionsToBeCreated
-      .forEach(qgc -> qualityGateConditionsUpdater.createCondition(dbSession, builtin, qgc.getMetricKey(), qgc.getOperator(), qgc.getWarningThreshold(),
+      .forEach(qgc -> qualityGateConditionsUpdater.createCondition(dbSession, builtin, qgc.getMetricKey(), qgc.getOperator(),
         qgc.getErrorThreshold()));
 
     if (!qgConditionsToBeCreated.isEmpty() || !qgConditionsToBeDeleted.isEmpty()) {
@@ -155,7 +154,6 @@ public class RegisterQualityGates implements Startable {
     private Long id;
     private String metricKey;
     private String operator;
-    private String warningThreshold;
     private String errorThreshold;
 
     public static QualityGateCondition from(QualityGateConditionDto qualityGateConditionDto, Map<Long, String> mapping) {
@@ -163,8 +161,7 @@ public class RegisterQualityGates implements Startable {
         .setId(qualityGateConditionDto.getId())
         .setMetricKey(mapping.get(qualityGateConditionDto.getMetricId()))
         .setOperator(qualityGateConditionDto.getOperator())
-        .setErrorThreshold(qualityGateConditionDto.getErrorThreshold())
-        .setWarningThreshold(qualityGateConditionDto.getWarningThreshold());
+        .setErrorThreshold(qualityGateConditionDto.getErrorThreshold());
     }
 
     @CheckForNull
@@ -195,22 +192,11 @@ public class RegisterQualityGates implements Startable {
       return this;
     }
 
-    @CheckForNull
-    public String getWarningThreshold() {
-      return warningThreshold;
-    }
-
-    public QualityGateCondition setWarningThreshold(@Nullable String warningThreshold) {
-      this.warningThreshold = warningThreshold;
-      return this;
-    }
-
-    @CheckForNull
     public String getErrorThreshold() {
       return errorThreshold;
     }
 
-    public QualityGateCondition setErrorThreshold(@Nullable String errorThreshold) {
+    public QualityGateCondition setErrorThreshold(String errorThreshold) {
       this.errorThreshold = errorThreshold;
       return this;
     }
@@ -221,7 +207,6 @@ public class RegisterQualityGates implements Startable {
         .setMetricKey(metricKey)
         .setOperator(operator)
         .setErrorThreshold(errorThreshold)
-        .setWarningThreshold(warningThreshold)
         .setQualityGateId(qualityGateId);
     }
 
@@ -237,14 +222,13 @@ public class RegisterQualityGates implements Startable {
       QualityGateCondition that = (QualityGateCondition) o;
       return Objects.equals(metricKey, that.metricKey) &&
         Objects.equals(operator, that.operator) &&
-        Objects.equals(warningThreshold, that.warningThreshold) &&
         Objects.equals(errorThreshold, that.errorThreshold);
     }
 
     // id does not belongs to hashcode to be able to be compared with builtin
     @Override
     public int hashCode() {
-      return Objects.hash(metricKey, operator, warningThreshold, errorThreshold);
+      return Objects.hash(metricKey, operator, errorThreshold);
     }
   }
 }
index e7b33e6502912bd38f80796c03ac4381e00d3de0..39e8cb5c9024e81392cbc273738e254c71eeeb27 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.qualitygate.ws;
 
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -38,7 +39,6 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ERR
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GATE_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_METRIC;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_OPERATOR;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_WARNING;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class CreateConditionAction implements QualityGatesWsAction {
@@ -61,6 +61,10 @@ public class CreateConditionAction implements QualityGatesWsAction {
         "Requires the 'Administer Quality Gates' permission.")
       .setSince("4.3")
       .setResponseExample(getClass().getResource("create-condition-example.json"))
+      .setChangelog(
+        new Change("7.6", "Removed optional 'warning' and 'period' parameters"),
+        new Change("7.6", "Made 'error' parameter mandatory"),
+        new Change("7.6", "Reduced the possible values of 'op' parameter to LT and GT"))
       .setHandler(this);
 
     createCondition
@@ -78,20 +82,18 @@ public class CreateConditionAction implements QualityGatesWsAction {
     int gateId = request.mandatoryParamAsInt(PARAM_GATE_ID);
     String metric = request.mandatoryParam(PARAM_METRIC);
     String operator = request.mandatoryParam(PARAM_OPERATOR);
-    String warning = request.param(PARAM_WARNING);
-    String error = request.param(PARAM_ERROR);
+    String error = request.mandatoryParam(PARAM_ERROR);
 
     try (DbSession dbSession = dbClient.openSession(false)) {
       OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
       QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, gateId);
       wsSupport.checkCanEdit(qualityGate);
-      QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, qualityGate, metric, operator, emptyToNull(warning), emptyToNull(error));
+      QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, qualityGate, metric, operator, error);
       CreateConditionResponse.Builder createConditionResponse = CreateConditionResponse.newBuilder()
         .setId(condition.getId())
         .setMetric(condition.getMetricKey())
+        .setError(condition.getErrorThreshold())
         .setOp(condition.getOperator());
-      setNullable(condition.getWarningThreshold(), createConditionResponse::setWarning);
-      setNullable(condition.getErrorThreshold(), createConditionResponse::setError);
       writeProtobuf(createConditionResponse.build(), request, response);
       dbSession.commit();
     }
index ebb87894ae3fc38286d2783627a11c5e2728d7bb..0284864ba8ac25ed7a17ebb90718a476d57d9d37 100644 (file)
@@ -87,6 +87,7 @@ public class ProjectStatusAction implements QualityGatesWsAction {
       .setSince("5.3")
       .setHandler(this)
       .setChangelog(
+        new Change("7.6", "The field 'warning' is deprecated from the response"),
         new Change("6.4", "The field 'ignoredConditions' is added to the response"));
 
     action.createParam(PARAM_ANALYSIS_ID)
index db59f7e7bb346757bbd1cf86f0e6ae560f9d7e7c..456c5c4b8cf2cfe0646b909a02d1f9e5d7fd274d 100644 (file)
@@ -30,7 +30,7 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.CONTROLLE
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ERROR;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_METRIC;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_OPERATOR;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_WARNING;
+
 
 public class QualityGatesWs implements WebService {
 
@@ -84,14 +84,10 @@ public class QualityGatesWs implements WebService {
       .setExampleValue(QualityGateConditionDto.OPERATOR_EQUALS)
       .setPossibleValues(QualityGateConditionDto.ALL_OPERATORS);
 
-    action.createParam(PARAM_WARNING)
-      .setMaximumLength(CONDITION_MAX_LENGTH)
-      .setDescription("Condition warning threshold")
-      .setExampleValue("5");
-
     action.createParam(PARAM_ERROR)
       .setMaximumLength(CONDITION_MAX_LENGTH)
       .setDescription("Condition error threshold")
+      .setRequired(true)
       .setExampleValue("10");
   }
 
index fd903ae892176ea236dd82a1531948f13a89dd36..f5d763635fb37e80df2b00f5db8dfb334772bd7f 100644 (file)
@@ -39,7 +39,6 @@ public class QualityGatesWsParameters {
   public static final String PARAM_QUERY = "query";
   public static final String PARAM_NAME = "name";
   public static final String PARAM_ERROR = "error";
-  public static final String PARAM_WARNING = "warning";
   public static final String PARAM_OPERATOR = "op";
   public static final String PARAM_METRIC = "metric";
   public static final String PARAM_GATE_ID = "gateId";
index 67971cf1259cdd6b27669bcc5361398d6e84cc89..ac20ac8c1d46ff8e46b27d3fef1e3fb027e2866e 100644 (file)
@@ -68,6 +68,7 @@ public class ShowAction implements QualityGatesWsAction {
       .setSince("4.3")
       .setResponseExample(Resources.getResource(this.getClass(), "show-example.json"))
       .setChangelog(
+        new Change("7.6", "'period' and 'warning' fields of conditions are removed from the response"),
         new Change("7.0", "'isBuiltIn' field is added to the response"),
         new Change("7.0", "'actions' field is added in the response"))
       .setHandler(this);
@@ -143,7 +144,6 @@ public class ShowAction implements QualityGatesWsAction {
         .setMetric(metric.getKey())
         .setOp(condition.getOperator());
       setNullable(condition.getErrorThreshold(), builder::setError);
-      setNullable(condition.getWarningThreshold(), builder::setWarning);
       return builder.build();
     };
   }
index fea9a68f4751221e764d24ec41a8c94591d03c70..0c51ba994288b0388e30ad795b8dc86bc6c1d657 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.qualitygate.ws;
 
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -39,7 +40,6 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ERR
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_METRIC;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_OPERATOR;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_WARNING;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class UpdateConditionAction implements QualityGatesWsAction {
@@ -61,6 +61,10 @@ public class UpdateConditionAction implements QualityGatesWsAction {
         "Requires the 'Administer Quality Gates' permission.")
       .setPost(true)
       .setSince("4.3")
+      .setChangelog(
+        new Change("7.6", "Removed optional 'warning' and 'period' parameters"),
+        new Change("7.6", "Made 'error' parameter mandatory"),
+        new Change("7.6", "Reduced the possible values of 'op' parameter to LT and GT"))
       .setHandler(this);
 
     createCondition
@@ -78,8 +82,7 @@ public class UpdateConditionAction implements QualityGatesWsAction {
     int id = request.mandatoryParamAsInt(PARAM_ID);
     String metric = request.mandatoryParam(PARAM_METRIC);
     String operator = request.mandatoryParam(PARAM_OPERATOR);
-    String warning = request.param(PARAM_WARNING);
-    String error = request.param(PARAM_ERROR);
+    String error = request.mandatoryParam(PARAM_ERROR);
 
     try (DbSession dbSession = dbClient.openSession(false)) {
       OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
@@ -87,14 +90,12 @@ public class UpdateConditionAction implements QualityGatesWsAction {
       QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, condition.getQualityGateId());
       checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", id, condition.getQualityGateId());
       wsSupport.checkCanEdit(qualityGateDto);
-      QualityGateConditionDto updatedCondition = qualityGateConditionsUpdater.updateCondition(dbSession, condition, metric, operator,
-        emptyToNull(warning), emptyToNull(error));
+      QualityGateConditionDto updatedCondition = qualityGateConditionsUpdater.updateCondition(dbSession, condition, metric, operator, error);
       UpdateConditionResponse.Builder updateConditionResponse = UpdateConditionResponse.newBuilder()
         .setId(updatedCondition.getId())
         .setMetric(updatedCondition.getMetricKey())
+        .setError(updatedCondition.getErrorThreshold())
         .setOp(updatedCondition.getOperator());
-      setNullable(updatedCondition.getWarningThreshold(), updateConditionResponse::setWarning);
-      setNullable(updatedCondition.getErrorThreshold(), updateConditionResponse::setError);
       writeProtobuf(updateConditionResponse.build(), request, response);
       dbSession.commit();
     }
index 28879a2a687ebc32da1ec3584f3a7fc6962433b7..ba8598a7786d8ddee44b784449669cb72ed46c6e 100644 (file)
@@ -38,7 +38,7 @@ public class MetricLevelTypeValidation implements TypeValidation {
     try {
       Metric.Level.valueOf(value);
     } catch (IllegalArgumentException e) {
-      throw BadRequestException.create(format("Value '%s' must be one of \"OK\", \"WARN\", \"ERROR\".", value));
+      throw BadRequestException.create(format("Value '%s' must be one of \"OK\", \"ERROR\".", value));
     }
   }
 }
index 946f9c4fdb38d207bc080278d8f1e4ec1cf3369d..e5c5610b29dc275c8911706b2385a9018112d898 100644 (file)
         "metricKey": "reopened_issues",
         "comparator": "GT",
         "periodIndex": 1,
-        "warningThreshold": "0",
         "actualValue": "0"
       },
       {
-        "status": "WARN",
+        "status": "ERROR",
         "metricKey": "open_issues",
         "comparator": "GT",
         "periodIndex": 1,
-        "warningThreshold": "0",
         "actualValue": "17"
       },
       {
@@ -56,7 +54,6 @@
         "metricKey": "skipped_tests",
         "comparator": "GT",
         "periodIndex": 1,
-        "warningThreshold": "0",
         "actualValue": "0"
       }
     ],
index 6b9d436343e76228f36d97b839acada073ae82fc..0e2b63cc310a159b84469260bff9e047595412bb 100644 (file)
@@ -10,9 +10,9 @@
     },
     {
       "id": 3,
-      "metric": "critical_violations",
+      "metric": "tests",
       "op": "LT",
-      "warning": "0"
+      "error": "10"
     }
   ],
   "isBuiltIn": false,
index a4b62766680f12b45b81ec693c895fd20137db05..b730b064e488393b20d5d1b9a6fca6d744af3f77 100644 (file)
@@ -57,7 +57,6 @@ import static org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY;
 import static org.sonar.api.measures.CoreMetrics.TECHNICAL_DEBT_KEY;
 import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.api.measures.Metric.Level.OK;
-import static org.sonar.api.measures.Metric.Level.WARN;
 import static org.sonar.api.measures.Metric.ValueType.INT;
 import static org.sonar.api.measures.Metric.ValueType.LEVEL;
 import static org.sonar.api.measures.Metric.ValueType.PERCENT;
@@ -69,7 +68,6 @@ import static org.sonar.db.component.BranchType.SHORT;
 import static org.sonar.server.badge.ws.SvgGenerator.Color.DEFAULT;
 import static org.sonar.server.badge.ws.SvgGenerator.Color.QUALITY_GATE_ERROR;
 import static org.sonar.server.badge.ws.SvgGenerator.Color.QUALITY_GATE_OK;
-import static org.sonar.server.badge.ws.SvgGenerator.Color.QUALITY_GATE_WARN;
 
 @RunWith(DataProviderRunner.class)
 public class MeasureActionTest {
@@ -177,7 +175,6 @@ public class MeasureActionTest {
   public static Object[][] qualityGates() {
     return new Object[][] {
       {OK, "passed", QUALITY_GATE_OK},
-      {WARN, "warning", QUALITY_GATE_WARN},
       {ERROR, "failed", QUALITY_GATE_ERROR}
     };
   }
index 2e76b6362672e3f84d7b942181593660235d79d4..d189746349364fccac815d4701af1896b6cc77f4 100644 (file)
@@ -48,7 +48,6 @@ import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
 import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.api.measures.Metric.Level.OK;
-import static org.sonar.api.measures.Metric.Level.WARN;
 import static org.sonar.api.measures.Metric.ValueType.LEVEL;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.db.component.BranchType.LONG;
@@ -84,20 +83,6 @@ public class QualityGateActionTest {
     checkResponse(response, OK);
   }
 
-  @Test
-  public void quality_gate_warn() {
-    ComponentDto project = db.components().insertPublicProject();
-    userSession.registerComponents(project);
-    MetricDto metric = createQualityGateMetric();
-    db.measures().insertLiveMeasure(project, metric, m -> m.setData(WARN.name()));
-
-    TestResponse response = ws.newRequest()
-      .setParam("project", project.getKey())
-      .execute();
-
-    checkResponse(response, WARN);
-  }
-
   @Test
   public void quality_gate_failed() {
     ComponentDto project = db.components().insertPublicProject();
@@ -124,16 +109,6 @@ public class QualityGateActionTest {
       .execute();
     String eTagOK = response.getHeader("ETag");
 
-    liveMeasure.setData(WARN.name());
-    db.getDbClient().liveMeasureDao().insertOrUpdate(db.getSession(), liveMeasure);
-    db.commit();
-
-    response = ws.newRequest()
-      .setParam("project", project.getKey())
-      .execute();
-
-    String eTagWARN = response.getHeader("ETag");
-
     liveMeasure.setData(ERROR.name());
     db.getDbClient().liveMeasureDao().insertOrUpdate(db.getSession(), liveMeasure);
     db.commit();
@@ -144,7 +119,7 @@ public class QualityGateActionTest {
 
     String eTagERROR = response.getHeader("ETag");
 
-    assertThat(Arrays.asList(eTagOK, eTagWARN, eTagERROR))
+    assertThat(Arrays.asList(eTagOK, eTagERROR))
       .doesNotContainNull()
       .doesNotHaveDuplicates();
   }
@@ -177,14 +152,14 @@ public class QualityGateActionTest {
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
     ComponentDto longBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(LONG));
-    db.measures().insertLiveMeasure(longBranch, metric, m -> m.setData(WARN.name()));
+    db.measures().insertLiveMeasure(longBranch, metric, m -> m.setData(ERROR.name()));
 
     TestResponse response = ws.newRequest()
       .setParam("project", longBranch.getKey())
       .setParam("branch", longBranch.getBranch())
       .execute();
 
-    checkResponse(response, WARN);
+    checkResponse(response, ERROR);
   }
 
   @Test
@@ -193,13 +168,13 @@ public class QualityGateActionTest {
     ComponentDto application = db.components().insertPublicApplication(organization);
     userSession.registerComponents(application);
     MetricDto metric = createQualityGateMetric();
-    db.measures().insertLiveMeasure(application, metric, m -> m.setData(WARN.name()));
+    db.measures().insertLiveMeasure(application, metric, m -> m.setData(ERROR.name()));
 
     TestResponse response = ws.newRequest()
       .setParam("project", application.getKey())
       .execute();
 
-    checkResponse(response, WARN);
+    checkResponse(response, ERROR);
   }
 
   @Test
@@ -356,9 +331,6 @@ public class QualityGateActionTest {
       case OK:
         assertThat(response.getInput()).contains("<!-- SONARQUBE QUALITY GATE PASS -->");
         break;
-      case WARN:
-        assertThat(response.getInput()).contains("<!-- SONARQUBE QUALITY GATE WARN -->");
-        break;
       case ERROR:
         assertThat(response.getInput()).contains("<!-- SONARQUBE QUALITY GATE FAIL -->");
         break;
index a0261f079b34b541a3d3d00717ee9f6efc875b30..2cae011851e837a70b0ba41a5533642d1ecf6e67 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.server.tester.UserSessionRule;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.api.measures.Metric.Level.WARN;
+import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.server.badge.ws.SvgGenerator.Color.DEFAULT;
 
 public class SvgGeneratorTest {
@@ -62,9 +62,9 @@ public class SvgGeneratorTest {
     mapSettings.setProperty("sonar.sonarcloud.enabled", false);
     initSvgGenerator();
 
-    String result = underTest.generateQualityGate(WARN);
+    String result = underTest.generateQualityGate(ERROR);
 
-    checkQualityGate(result, WARN);
+    checkQualityGate(result, ERROR);
   }
 
   @Test
@@ -103,9 +103,6 @@ public class SvgGeneratorTest {
       case OK:
         assertThat(response).isEqualTo(readTemplate("quality_gate_passed.svg"));
         break;
-      case WARN:
-        assertThat(response).isEqualTo(readTemplate("quality_gate_warn.svg"));
-        break;
       case ERROR:
         assertThat(response).isEqualTo(readTemplate("quality_gate_failed.svg"));
         break;
index 43f67a31909350b6b90f4a3048f87f9824f0956f..21507e936b0b01eee7501f9d062fbe64e2304573 100644 (file)
@@ -970,14 +970,14 @@ public class SearchProjectsActionTest {
     OrganizationDto organization = db.organizations().insert();
     MetricDto qualityGateStatus = db.measures().insertMetric(c -> c.setKey(QUALITY_GATE_STATUS).setValueType(LEVEL.name()));
     ComponentDto project1 = insertProject(organization, c -> c.setName("Sonar Java"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("ERROR")));
-    ComponentDto project2 = insertProject(organization, c -> c.setName("Sonar Groovy"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("WARN")));
+    ComponentDto project2 = insertProject(organization, c -> c.setName("Sonar Groovy"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("ERROR")));
     ComponentDto project3 = insertProject(organization, c -> c.setName("Sonar Markdown"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK")));
     ComponentDto project4 = insertProject(organization, c -> c.setName("Sonar Qube"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK")));
 
     assertThat(call(request.setSort(QUALITY_GATE_STATUS).setAsc(true)).getComponentsList()).extracting(Component::getKey)
       .containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey());
     assertThat(call(request.setSort(QUALITY_GATE_STATUS).setAsc(false)).getComponentsList()).extracting(Component::getKey)
-      .containsExactly(project1.getDbKey(), project2.getDbKey(), project3.getDbKey(), project4.getDbKey());
+      .containsExactly(project2.getDbKey(), project1.getDbKey(), project3.getDbKey(), project4.getDbKey());
   }
 
   @Test
index caef2d96e77f14ce7e41fe89cc98996309747c1f..26a42f9fad17b3d742a05a04c91dbeda325a50d1 100644 (file)
@@ -206,12 +206,12 @@ public class CreateActionTest {
     ws.newRequest()
       .setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
       .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
-      .setParam(CreateAction.PARAM_VALUE, Metric.Level.WARN.name())
+      .setParam(CreateAction.PARAM_VALUE, Metric.Level.ERROR.name())
       .execute();
 
     assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
       .extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
-      .containsExactlyInAnyOrder(tuple(null, Metric.Level.WARN.name(), 0d, project.uuid()));
+      .containsExactlyInAnyOrder(tuple(null, Metric.Level.ERROR.name(), 0d, project.uuid()));
   }
 
   @Test
index 6c3094a98076e69fbf0825bf9f31d896f5eeac91..d9d8b8fe7eaf5a489b2e40315e6f30238ba9a67b 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.db.measure.custom.CustomMeasureTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.api.measures.Metric.Level.WARN;
+import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.api.measures.Metric.ValueType.BOOL;
 import static org.sonar.api.measures.Metric.ValueType.FLOAT;
 import static org.sonar.api.measures.Metric.ValueType.INT;
@@ -82,9 +82,9 @@ public class CustomMeasureValidatorTest {
 
   @Test
   public void set_level_value() {
-    underTest.setMeasureValue(customMeasure, WARN.name(), newMetricDto().setValueType(LEVEL.name()));
+    underTest.setMeasureValue(customMeasure, ERROR.name(), newMetricDto().setValueType(LEVEL.name()));
 
-    assertThat(customMeasure.getTextValue()).isEqualTo(WARN.name());
+    assertThat(customMeasure.getTextValue()).isEqualTo(ERROR.name());
   }
 
   @Test
index cd5272a9ddbf4f88519a2ef9d38556b029626694..639bdaff95229d5e6d2c74fecc82c392f140ad80 100644 (file)
@@ -62,7 +62,6 @@ import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
 import static org.sonar.api.measures.CoreMetrics.COVERAGE_KEY;
 import static org.sonar.api.measures.Metric.Level.ERROR;
 import static org.sonar.api.measures.Metric.Level.OK;
-import static org.sonar.api.measures.Metric.Level.WARN;
 import static org.sonar.api.resources.Qualifiers.PROJECT;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
@@ -173,11 +172,10 @@ public class ProjectMeasuresIndexTest {
     index(
       newDoc(PROJECT1).setQualityGateStatus(OK.name()),
       newDoc(PROJECT2).setQualityGateStatus(ERROR.name()),
-      newDoc(PROJECT3).setQualityGateStatus(WARN.name()),
       newDoc(project4).setQualityGateStatus(OK.name()));
 
-    assertResults(new ProjectMeasuresQuery().setSort("alert_status").setAsc(true), PROJECT1, project4, PROJECT3, PROJECT2);
-    assertResults(new ProjectMeasuresQuery().setSort("alert_status").setAsc(false), PROJECT2, PROJECT3, PROJECT1, project4);
+    assertResults(new ProjectMeasuresQuery().setSort("alert_status").setAsc(true), PROJECT1, project4, PROJECT2);
+    assertResults(new ProjectMeasuresQuery().setSort("alert_status").setAsc(false), PROJECT2, PROJECT1, project4);
   }
 
   @Test
@@ -187,7 +185,7 @@ public class ProjectMeasuresIndexTest {
     ComponentDto apache1 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-1").setName("Apache").setDbKey("project3");
     ComponentDto apache2 = ComponentTesting.newPrivateProjectDto(ORG).setUuid("apache-2").setName("Apache").setDbKey("project4");
     index(
-      newDoc(windows).setQualityGateStatus(WARN.name()),
+      newDoc(windows).setQualityGateStatus(ERROR.name()),
       newDoc(apachee).setQualityGateStatus(OK.name()),
       newDoc(apache1).setQualityGateStatus(OK.name()),
       newDoc(apache2).setQualityGateStatus(OK.name()));
@@ -335,7 +333,7 @@ public class ProjectMeasuresIndexTest {
     index(
       newDoc(PROJECT1).setQualityGateStatus(OK.name()),
       newDoc(PROJECT2).setQualityGateStatus(OK.name()),
-      newDoc(PROJECT3).setQualityGateStatus(WARN.name()));
+      newDoc(PROJECT3).setQualityGateStatus(ERROR.name()));
 
     ProjectMeasuresQuery query = new ProjectMeasuresQuery().setQualityGateStatus(OK);
     assertResults(query, PROJECT1, PROJECT2);
@@ -1041,10 +1039,6 @@ public class ProjectMeasuresIndexTest {
       // 2 docs with QG OK
       newDoc().setQualityGateStatus(OK.name()),
       newDoc().setQualityGateStatus(OK.name()),
-      // 3 docs with QG WARN
-      newDoc().setQualityGateStatus(WARN.name()),
-      newDoc().setQualityGateStatus(WARN.name()),
-      newDoc().setQualityGateStatus(WARN.name()),
       // 4 docs with QG ERROR
       newDoc().setQualityGateStatus(ERROR.name()),
       newDoc().setQualityGateStatus(ERROR.name()),
@@ -1055,7 +1049,6 @@ public class ProjectMeasuresIndexTest {
 
     assertThat(result).containsOnly(
       entry(ERROR.name(), 4L),
-      entry(WARN.name(), 3L),
       entry(OK.name(), 2L));
   }
 
@@ -1065,10 +1058,6 @@ public class ProjectMeasuresIndexTest {
       // 2 docs with QG OK
       newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGateStatus(OK.name()),
       newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGateStatus(OK.name()),
-      // 3 docs with QG WARN
-      newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()),
-      newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()),
-      newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()),
       // 4 docs with QG ERROR
       newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(ERROR.name()),
       newDoc(NCLOC, 5000d, COVERAGE, 40d).setQualityGateStatus(ERROR.name()),
@@ -1083,7 +1072,6 @@ public class ProjectMeasuresIndexTest {
     // Sticky facet on quality gate does not take into account quality gate filter
     assertThat(facets.get(ALERT_STATUS_KEY)).containsOnly(
       entry(OK.name(), 2L),
-      entry(WARN.name(), 3L),
       entry(ERROR.name(), 3L));
     // But facet on ncloc does well take into into filters
     assertThat(facets.get(NCLOC)).containsExactly(
@@ -1100,11 +1088,7 @@ public class ProjectMeasuresIndexTest {
     indexForUser(USER1,
       // 2 docs with QG OK
       newDoc().setQualityGateStatus(OK.name()),
-      newDoc().setQualityGateStatus(OK.name()),
-      // 3 docs with QG WARN
-      newDoc().setQualityGateStatus(WARN.name()),
-      newDoc().setQualityGateStatus(WARN.name()),
-      newDoc().setQualityGateStatus(WARN.name()));
+      newDoc().setQualityGateStatus(OK.name()));
 
     // User cannot see these projects
     indexForUser(USER2,
@@ -1119,7 +1103,6 @@ public class ProjectMeasuresIndexTest {
 
     assertThat(result).containsOnly(
       entry(ERROR.name(), 0L),
-      entry(WARN.name(), 3L),
       entry(OK.name(), 2L));
   }
 
@@ -1252,7 +1235,7 @@ public class ProjectMeasuresIndexTest {
     index(
       newDoc().setTags(newArrayList("finance")).setQualityGateStatus(OK.name()),
       newDoc().setTags(newArrayList("finance")).setQualityGateStatus(ERROR.name()),
-      newDoc().setTags(newArrayList("cpp")).setQualityGateStatus(WARN.name()));
+      newDoc().setTags(newArrayList("cpp")).setQualityGateStatus(ERROR.name()));
 
     Facets facets = underTest.search(
       new ProjectMeasuresQuery().setTags(newHashSet("cpp")),
@@ -1264,8 +1247,7 @@ public class ProjectMeasuresIndexTest {
       entry("cpp", 1L));
     assertThat(facets.get(ALERT_STATUS_KEY)).containsOnly(
       entry(OK.name(), 0L),
-      entry(ERROR.name(), 0L),
-      entry(WARN.name(), 1L));
+      entry(ERROR.name(), 1L));
   }
 
   @Test
index f04b8fc0db09f580352438c64ae62e6ea9c91602..be254749f57d1f9acfe346317cd40f722302da21 100644 (file)
@@ -330,7 +330,7 @@ public class LiveMeasureComputerImplTest {
   @Test
   public void event_contains_newQualityGate_computed_by_LiveQualityGateComputer() {
     markProjectAsAnalyzed(project);
-    db.measures().insertLiveMeasure(project, alertStatusMetric, m -> m.setData(Metric.Level.WARN.name()));
+    db.measures().insertLiveMeasure(project, alertStatusMetric, m -> m.setData(Metric.Level.ERROR.name()));
     db.measures().insertLiveMeasure(project, intMetric, m -> m.setVariation(42.0).setValue(null));
     BranchDto branch = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), project.projectUuid(), "master")
       .orElseThrow(() -> new IllegalStateException("Can't find master branch"));
index 158b38f942c6c144600f61af4498fd4a7cfe4522..5e96dc1444693e531140f4d64bbaed458f9582ea 100644 (file)
@@ -107,14 +107,14 @@ public class LiveQualityGateComputerImplTest {
 
     assertThat(result.getId()).isEqualTo("" + gate.getId());
     assertThat(result.getConditions())
-      .extracting(Condition::getMetricKey, Condition::getOperator, c -> c.getErrorThreshold().get(), c -> c.getWarningThreshold().get())
+      .extracting(Condition::getMetricKey, Condition::getOperator, Condition::getErrorThreshold)
       .containsExactlyInAnyOrder(
-        tuple(metric.getKey(), Condition.Operator.fromDbValue(condition.getOperator()), condition.getErrorThreshold(), condition.getWarningThreshold()));
+        tuple(metric.getKey(), Condition.Operator.fromDbValue(condition.getOperator()), condition.getErrorThreshold()));
   }
 
   @Test
   public void getMetricsRelatedTo() {
-    Condition condition = new Condition("metric1", Condition.Operator.EQUALS, "10", null);
+    Condition condition = new Condition("metric1", Condition.Operator.EQUALS, "10");
     QualityGate gate = new QualityGate("1", "foo", ImmutableSet.of(condition));
 
     Set<String> result = underTest.getMetricsRelatedTo(gate);
@@ -132,7 +132,7 @@ public class LiveQualityGateComputerImplTest {
     MetricDto conditionMetric = newMetricDto();
     MetricDto statusMetric = newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY);
     MetricDto detailsMetric = newMetricDto().setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
-    Condition condition = new Condition(conditionMetric.getKey(), Condition.Operator.GREATER_THAN, "10", null);
+    Condition condition = new Condition(conditionMetric.getKey(), Condition.Operator.GREATER_THAN, "10");
     QualityGate gate = new QualityGate("1", "foo", ImmutableSet.of(condition));
     MeasureMatrix matrix = new MeasureMatrix(singleton(project), asList(conditionMetric, statusMetric, detailsMetric), emptyList());
 
index 8f179406c6056bb24576e472226694216582f202..4bcc338208d9d6153111da8f27cb68b7fb08d5dc 100644 (file)
@@ -154,19 +154,17 @@ public class ComponentTreeSortTest {
   public void sort_by_alert_status_ascending() {
     components = newArrayList(
       newComponentWithoutSnapshotId("PROJECT OK 1", Qualifiers.PROJECT, "PROJECT_OK_PATH_1"),
-      newComponentWithoutSnapshotId("PROJECT WARN 1", Qualifiers.PROJECT, "PROJECT_WARN_PATH_1"),
       newComponentWithoutSnapshotId("PROJECT ERROR 1", Qualifiers.PROJECT, "PROJECT_ERROR_PATH_1"),
       newComponentWithoutSnapshotId("PROJECT OK 2", Qualifiers.PROJECT, "PROJECT_OK_PATH_2"),
-      newComponentWithoutSnapshotId("PROJECT WARN 2", Qualifiers.PROJECT, "PROJECT_WARN_PATH_2"),
       newComponentWithoutSnapshotId("PROJECT ERROR 2", Qualifiers.PROJECT, "PROJECT_ERROR_PATH_2"));
     metrics = singletonList(newMetricDto()
       .setKey(CoreMetrics.ALERT_STATUS_KEY)
       .setValueType(ValueType.LEVEL.name()));
     measuresByComponentUuidAndMetric = HashBasedTable.create();
-    List<String> statuses = newArrayList("OK", "WARN", "ERROR");
+    List<String> statuses = newArrayList("OK", "ERROR");
     for (int i = 0; i < components.size(); i++) {
       ComponentDto component = components.get(i);
-      String alertStatus = statuses.get(i % 3);
+      String alertStatus = statuses.get(i % 2);
       measuresByComponentUuidAndMetric.put(component.uuid(), metrics.get(0), createFromMeasureDto(new LiveMeasureDto().setData(alertStatus)));
     }
     ComponentTreeRequest wsRequest = newRequest(newArrayList(METRIC_SORT, NAME_SORT), true, CoreMetrics.ALERT_STATUS_KEY);
@@ -175,7 +173,6 @@ public class ComponentTreeSortTest {
 
     assertThat(result).extracting("name").containsExactly(
       "PROJECT ERROR 1", "PROJECT ERROR 2",
-      "PROJECT WARN 1", "PROJECT WARN 2",
       "PROJECT OK 1", "PROJECT OK 2");
   }
 
index 93b72ff7d02c4f64b87879d922e443836cf65529..164abbbaf7253c628a9a2847637c3e422aaa78f8 100644 (file)
@@ -51,7 +51,7 @@ public class AlertsEmailTemplateTest {
 
   @Test
   public void shouldFormatAlertWithSeveralMessages() {
-    Notification notification = createNotification("Orange (was Red)", "violations > 4, coverage < 75%", "WARN", "false");
+    Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "false");
 
     EmailMessage message = template.format(notification);
     assertThat(message.getMessageId(), is("alerts/45"));
@@ -59,7 +59,7 @@ public class AlertsEmailTemplateTest {
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Orange (was Red)\n" +
+      "Quality gate status: Red (was Green)\n" +
       "\n" +
       "Quality gate thresholds:\n" +
       "  - violations > 4\n" +
@@ -70,7 +70,7 @@ public class AlertsEmailTemplateTest {
 
   @Test
   public void shouldFormatAlertWithSeveralMessagesOnBranch() {
-    Notification notification = createNotification("Orange (was Red)", "violations > 4, coverage < 75%", "WARN", "false")
+    Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "false")
         .setFieldValue("branch", "feature");
 
     EmailMessage message = template.format(notification);
@@ -80,7 +80,7 @@ public class AlertsEmailTemplateTest {
       "Project: Foo\n" +
       "Branch: feature\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Orange (was Red)\n" +
+      "Quality gate status: Red (was Green)\n" +
       "\n" +
       "Quality gate thresholds:\n" +
       "  - violations > 4\n" +
@@ -91,7 +91,7 @@ public class AlertsEmailTemplateTest {
 
   @Test
   public void shouldFormatNewAlertWithSeveralMessages() {
-    Notification notification = createNotification("Orange (was Red)", "violations > 4, coverage < 75%", "WARN", "true");
+    Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "true");
 
     EmailMessage message = template.format(notification);
     assertThat(message.getMessageId(), is("alerts/45"));
@@ -99,7 +99,7 @@ public class AlertsEmailTemplateTest {
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Orange (was Red)\n" +
+      "Quality gate status: Red (was Green)\n" +
       "\n" +
       "New quality gate thresholds:\n" +
       "  - violations > 4\n" +
@@ -110,7 +110,7 @@ public class AlertsEmailTemplateTest {
 
   @Test
   public void shouldFormatNewAlertWithOneMessage() {
-    Notification notification = createNotification("Orange (was Red)", "violations > 4", "WARN", "true");
+    Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true");
 
     EmailMessage message = template.format(notification);
     assertThat(message.getMessageId(), is("alerts/45"));
@@ -118,7 +118,7 @@ public class AlertsEmailTemplateTest {
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Orange (was Red)\n" +
+      "Quality gate status: Red (was Green)\n" +
       "\n" +
       "New quality gate threshold: violations > 4\n" +
       "\n" +
@@ -127,7 +127,7 @@ public class AlertsEmailTemplateTest {
 
   @Test
   public void shouldFormatNewAlertWithoutVersion() {
-    Notification notification = createNotification("Orange (was Red)", "violations > 4", "WARN", "true")
+    Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true")
         .setFieldValue("projectVersion", null);
 
     EmailMessage message = template.format(notification);
@@ -135,7 +135,7 @@ public class AlertsEmailTemplateTest {
     assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
-      "Quality gate status: Orange (was Red)\n" +
+      "Quality gate status: Red (was Green)\n" +
       "\n" +
       "New quality gate threshold: violations > 4\n" +
       "\n" +
@@ -144,7 +144,7 @@ public class AlertsEmailTemplateTest {
 
   @Test
   public void shouldFormatNewAlertWithOneMessageOnBranch() {
-    Notification notification = createNotification("Orange (was Red)", "violations > 4", "WARN", "true")
+    Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true")
       .setFieldValue("branch", "feature");
 
     EmailMessage message = template.format(notification);
@@ -154,7 +154,7 @@ public class AlertsEmailTemplateTest {
       "Project: Foo\n" +
       "Branch: feature\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Orange (was Red)\n" +
+      "Quality gate status: Red (was Green)\n" +
       "\n" +
       "New quality gate threshold: violations > 4\n" +
       "\n" +
index bd2dc92bb51be3f84910ae9c70a3ecac0856e506..2269165109d65e2329d83e64b733701ba88e0ca5 100644 (file)
@@ -65,9 +65,20 @@ public class QualityGateConditionsUpdaterTest {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey("new_coverage").setValueType(INT.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
 
-    QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "LT", null, "80");
+    QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "LT", "80");
 
-    verifyCondition(result, qualityGate, metric, "LT", null, "80");
+    verifyCondition(result, qualityGate, metric, "LT", "80");
+  }
+
+  @Test
+  public void create_condition_throws_NPE_if_errorThreshold_is_null() {
+    MetricDto metric = db.measures().insertMetric(m -> m.setKey(SQALE_RATING_KEY).setValueType(RATING.name()).setHidden(false));
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+
+    expectedException.expect(NullPointerException.class);
+    expectedException.expectMessage("errorThreshold can not be null");
+
+    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", null);
   }
 
   @Test
@@ -79,7 +90,7 @@ public class QualityGateConditionsUpdaterTest {
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("Condition on metric '%s' already exists.", metric.getShortName()));
 
-    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "LT", "90", null);
+    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "LT", "90");
   }
 
   @Test
@@ -89,7 +100,7 @@ public class QualityGateConditionsUpdaterTest {
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("There is no metric with key=new_coverage");
 
-    underTest.createCondition(db.getSession(), qualityGate, "new_coverage", "LT", null, "80");
+    underTest.createCondition(db.getSession(), qualityGate, "new_coverage", "LT", "80");
   }
 
   @Test
@@ -101,7 +112,7 @@ public class QualityGateConditionsUpdaterTest {
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("Metric '%s' cannot be used to define a condition.", metric.getKey()));
 
-    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "EQ", null, "80");
+    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "EQ", "80");
   }
 
   @Test
@@ -112,7 +123,7 @@ public class QualityGateConditionsUpdaterTest {
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("Operator UNKNOWN is not allowed for metric type PERCENT.");
 
-    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "UNKNOWN", null, "80");
+    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "UNKNOWN", "90");
   }
 
   @Test
@@ -120,20 +131,9 @@ public class QualityGateConditionsUpdaterTest {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(SQALE_RATING_KEY).setValueType(RATING.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
 
-    QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", null, "3");
+    QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", "3");
 
-    verifyCondition(result, qualityGate, metric, "GT", null, "3");
-  }
-
-  @Test
-  public void fail_to_create_warning_condition_on_invalid_rating_metric() {
-    MetricDto metric = db.measures().insertMetric(m -> m.setKey(SQALE_RATING_KEY).setValueType(RATING.name()).setHidden(false));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-
-    expectedException.expect(BadRequestException.class);
-    expectedException.expectMessage("'6' is not a valid rating");
-
-    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", "6", null);
+    verifyCondition(result, qualityGate, metric, "GT", "3");
   }
 
   @Test
@@ -144,7 +144,7 @@ public class QualityGateConditionsUpdaterTest {
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("'80' is not a valid rating");
 
-    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", null, "80");
+    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", "80");
   }
 
   @Test
@@ -155,18 +155,7 @@ public class QualityGateConditionsUpdaterTest {
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage("There's no worse rating than E (5)");
 
-    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", "5", null);
-  }
-
-  @Test
-  @UseDataProvider("valid_values")
-  public void create_warning_condition(Metric.ValueType valueType, String value) {
-    MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-
-    QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "EQ", value, null);
-
-    verifyCondition(result, qualityGate, metric, "EQ", value, null);
+    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", "5");
   }
 
   @Test
@@ -175,45 +164,46 @@ public class QualityGateConditionsUpdaterTest {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
 
-    QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "EQ", null, value);
+    QualityGateConditionDto result = underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "EQ", value);
 
-    verifyCondition(result, qualityGate, metric, "EQ", null, value);
+    verifyCondition(result, qualityGate, metric, "EQ", value);
   }
 
   @Test
   @UseDataProvider("invalid_values")
-  public void fail_to_create_warning_INT_condition_when_value_is_not_an_integer(Metric.ValueType valueType, String value) {
+  public void fail_to_create_error_INT_condition_when_value_is_not_an_integer(Metric.ValueType valueType, String value) {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("Invalid value '%s' for metric '%s'", value, metric.getShortName()));
 
-    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "EQ", value, null);
+    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "EQ", value);
   }
 
   @Test
-  @UseDataProvider("invalid_values")
-  public void fail_to_create_error_INT_condition_when_value_is_not_an_integer(Metric.ValueType valueType, String value) {
-    MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false));
+  public void update_condition() {
+    MetricDto metric = db.measures().insertMetric(m -> m.setValueType(PERCENT.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
+    QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
+      c -> c.setOperator("LT").setErrorThreshold("80"));
 
-    expectedException.expect(BadRequestException.class);
-    expectedException.expectMessage(format("Invalid value '%s' for metric '%s'", value, metric.getShortName()));
+    QualityGateConditionDto result = underTest.updateCondition(db.getSession(), condition, metric.getKey(), "LT", "80");
 
-    underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "EQ", null, value);
+    verifyCondition(result, qualityGate, metric, "LT", "80");
   }
 
   @Test
-  public void update_condition() {
+  public void update_condition_throws_NPE_if_errorThreshold_is_null() {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(PERCENT.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("LT").setWarningThreshold(null).setErrorThreshold("80"));
+      c -> c.setOperator("LT").setErrorThreshold("80"));
 
-    QualityGateConditionDto result = underTest.updateCondition(db.getSession(), condition, metric.getKey(), "GT", "60", null);
+    expectedException.expect(NullPointerException.class);
+    expectedException.expectMessage("errorThreshold can not be null");
 
-    verifyCondition(result, qualityGate, metric, "GT", "60", null);
+    underTest.updateCondition(db.getSession(), condition, metric.getKey(), "GT", null);
   }
 
   @Test
@@ -221,11 +211,11 @@ public class QualityGateConditionsUpdaterTest {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(SQALE_RATING_KEY).setValueType(RATING.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("LT").setWarningThreshold("80").setErrorThreshold(null));
+      c -> c.setOperator("LT").setErrorThreshold("80"));
 
-    QualityGateConditionDto result = underTest.updateCondition(db.getSession(), condition, metric.getKey(), "GT", "4", null);
+    QualityGateConditionDto result = underTest.updateCondition(db.getSession(), condition, metric.getKey(), "GT", "4");
 
-    verifyCondition(result, qualityGate, metric, "GT", "4", null);
+    verifyCondition(result, qualityGate, metric, "GT", "4");
   }
 
   @Test
@@ -233,12 +223,12 @@ public class QualityGateConditionsUpdaterTest {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey("not_core_rating_metric").setValueType(RATING.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("LT").setWarningThreshold(null).setErrorThreshold("3"));
+      c -> c.setOperator("LT").setErrorThreshold("3"));
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("The metric '%s' cannot be used", metric.getShortName()));
 
-    underTest.updateCondition(db.getSession(), condition, metric.getKey(), "GT", "4", null);
+    underTest.updateCondition(db.getSession(), condition, metric.getKey(), "GT", "4");
   }
 
   @Test
@@ -247,25 +237,12 @@ public class QualityGateConditionsUpdaterTest {
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(metricKey).setValueType(valueType.name()).setHidden(hidden));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("LT").setWarningThreshold(null).setErrorThreshold("80"));
+      c -> c.setOperator("LT").setErrorThreshold("80"));
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("Metric '%s' cannot be used to define a condition.", metric.getKey()));
 
-    underTest.updateCondition(db.getSession(), condition, metric.getKey(), "GT", "60", null);
-  }
-
-  @Test
-  @UseDataProvider("valid_values")
-  public void update_warning_condition(Metric.ValueType valueType, String value) {
-    MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-    QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("LT").setWarningThreshold(null).setErrorThreshold("80"));
-
-    QualityGateConditionDto result = underTest.updateCondition(db.getSession(), condition, metric.getKey(), "EQ", value, null);
-
-    verifyCondition(result, qualityGate, metric, "EQ", value, null);
+    underTest.updateCondition(db.getSession(), condition, metric.getKey(), "GT", "60");
   }
 
   @Test
@@ -274,25 +251,11 @@ public class QualityGateConditionsUpdaterTest {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("LT").setWarningThreshold(null).setErrorThreshold("80"));
+      c -> c.setOperator("LT").setErrorThreshold("80"));
 
-    QualityGateConditionDto result = underTest.updateCondition(db.getSession(), condition, metric.getKey(), "EQ", null, value);
-
-    verifyCondition(result, qualityGate, metric, "EQ", null, value);
-  }
-
-  @Test
-  @UseDataProvider("invalid_values")
-  public void fail_to_update_warning_INT_condition_when_value_is_not_an_integer(Metric.ValueType valueType, String value) {
-    MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false));
-    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
-    QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("LT").setWarningThreshold(null).setErrorThreshold("80"));
-
-    expectedException.expect(BadRequestException.class);
-    expectedException.expectMessage(format("Invalid value '%s' for metric '%s'", value, metric.getShortName()));
+    QualityGateConditionDto result = underTest.updateCondition(db.getSession(), condition, metric.getKey(), "EQ", value);
 
-    underTest.updateCondition(db.getSession(), condition, metric.getKey(), "EQ", value, null);
+    verifyCondition(result, qualityGate, metric, "EQ", value);
   }
 
   @Test
@@ -301,12 +264,12 @@ public class QualityGateConditionsUpdaterTest {
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType(valueType.name()).setHidden(false));
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization());
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("LT").setWarningThreshold(null).setErrorThreshold("80"));
+      c -> c.setOperator("LT").setErrorThreshold("80"));
 
     expectedException.expect(BadRequestException.class);
     expectedException.expectMessage(format("Invalid value '%s' for metric '%s'", value, metric.getShortName()));
 
-    underTest.updateCondition(db.getSession(), condition, metric.getKey(), "EQ", null, value);
+    underTest.updateCondition(db.getSession(), condition, metric.getKey(), "EQ", value);
   }
 
   @DataProvider
@@ -342,18 +305,16 @@ public class QualityGateConditionsUpdaterTest {
     };
   }
 
-  private void verifyCondition(QualityGateConditionDto dto, QualityGateDto qualityGate, MetricDto metric, String operator, @Nullable String warning, @Nullable String error) {
+  private void verifyCondition(QualityGateConditionDto dto, QualityGateDto qualityGate, MetricDto metric, String operator, String error) {
     QualityGateConditionDto reloaded = db.getDbClient().gateConditionDao().selectById(dto.getId(), db.getSession());
     assertThat(reloaded.getQualityGateId()).isEqualTo(qualityGate.getId());
     assertThat(reloaded.getMetricId()).isEqualTo(metric.getId().longValue());
     assertThat(reloaded.getOperator()).isEqualTo(operator);
-    assertThat(reloaded.getWarningThreshold()).isEqualTo(warning);
     assertThat(reloaded.getErrorThreshold()).isEqualTo(error);
 
     assertThat(dto.getQualityGateId()).isEqualTo(qualityGate.getId());
     assertThat(dto.getMetricId()).isEqualTo(metric.getId().longValue());
     assertThat(dto.getOperator()).isEqualTo(operator);
-    assertThat(dto.getWarningThreshold()).isEqualTo(warning);
     assertThat(dto.getErrorThreshold()).isEqualTo(error);
   }
 
index 481e4f36bbbc3e52c4702866a8d1a5fecf351af1..ce299186f24bfed30afb04710d847f2e8187b127 100644 (file)
@@ -107,7 +107,7 @@ public class RegisterQualityGatesTest {
     createBuiltInConditions(builtInQualityGate);
     // Add another condition
     qualityGateConditionsUpdater.createCondition(dbSession, builtInQualityGate,
-      NEW_SECURITY_REMEDIATION_EFFORT_KEY, OPERATOR_GREATER_THAN, null, "5");
+      NEW_SECURITY_REMEDIATION_EFFORT_KEY, OPERATOR_GREATER_THAN, "5");
     dbSession.commit();
 
     underTest.start();
@@ -215,8 +215,7 @@ public class RegisterQualityGatesTest {
     QualityGateConditionDto conditionDto = new QualityGateConditionDto()
       .setMetricId(-1) // This Id does not exist
       .setOperator(OPERATOR_GREATER_THAN)
-      .setErrorThreshold("1")
-      .setWarningThreshold("1");
+      .setErrorThreshold("1");
     gateConditionDao.insert(conditionDto, dbSession);
     dbSession.commit();
 
@@ -250,29 +249,29 @@ public class RegisterQualityGatesTest {
     assertThat(qualityGateDto.getCreatedAt()).isNotNull();
     assertThat(qualityGateDto.isBuiltIn()).isTrue();
     assertThat(gateConditionDao.selectForQualityGate(dbSession, qualityGateDto.getId()))
-      .extracting(QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator, QualityGateConditionDto::getWarningThreshold,
+      .extracting(QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator,
         QualityGateConditionDto::getErrorThreshold)
       .containsOnly(
-        tuple(newReliability.getId().longValue(), OPERATOR_GREATER_THAN, null, "1"),
-        tuple(newSecurity.getId().longValue(), OPERATOR_GREATER_THAN, null, "1"),
-        tuple(newMaintainability.getId().longValue(), OPERATOR_GREATER_THAN, null, "1"),
-        tuple(newCoverage.getId().longValue(), OPERATOR_LESS_THAN, null, "80"),
-        tuple(newDuplication.getId().longValue(), OPERATOR_GREATER_THAN, null, "3"));
+        tuple(newReliability.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
+        tuple(newSecurity.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
+        tuple(newMaintainability.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
+        tuple(newCoverage.getId().longValue(), OPERATOR_LESS_THAN, "80"),
+        tuple(newDuplication.getId().longValue(), OPERATOR_GREATER_THAN, "3"));
   }
 
   private List<QualityGateConditionDto> createBuiltInConditions(QualityGateDto qg) {
     List<QualityGateConditionDto> conditions = new ArrayList<>();
 
     conditions.add(qualityGateConditionsUpdater.createCondition(dbSession, qg,
-      NEW_SECURITY_RATING_KEY, OPERATOR_GREATER_THAN, null, "1"));
+      NEW_SECURITY_RATING_KEY, OPERATOR_GREATER_THAN, "1"));
     conditions.add(qualityGateConditionsUpdater.createCondition(dbSession, qg,
-      NEW_RELIABILITY_RATING_KEY, OPERATOR_GREATER_THAN, null, "1"));
+      NEW_RELIABILITY_RATING_KEY, OPERATOR_GREATER_THAN, "1"));
     conditions.add(qualityGateConditionsUpdater.createCondition(dbSession, qg,
-      NEW_MAINTAINABILITY_RATING_KEY, OPERATOR_GREATER_THAN, null, "1"));
+      NEW_MAINTAINABILITY_RATING_KEY, OPERATOR_GREATER_THAN, "1"));
     conditions.add(qualityGateConditionsUpdater.createCondition(dbSession, qg,
-      NEW_COVERAGE_KEY, OPERATOR_LESS_THAN, null, "80"));
+      NEW_COVERAGE_KEY, OPERATOR_LESS_THAN, "80"));
     conditions.add(qualityGateConditionsUpdater.createCondition(dbSession, qg,
-      NEW_DUPLICATED_LINES_DENSITY_KEY, OPERATOR_GREATER_THAN, null, "3"));
+      NEW_DUPLICATED_LINES_DENSITY_KEY, OPERATOR_GREATER_THAN, "3"));
 
     return conditions;
   }
index 906c8529eaf8d844783d2560df010e11f13b4a2e..ed37d41f6f660b84a25edf0a471b44b5dae3e2a4 100644 (file)
@@ -109,8 +109,8 @@ public class CopyActionTest {
     assertThat(actual.getUuid()).isNotEqualTo(qualityGate.getUuid());
 
     assertThat(db.getDbClient().gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId()))
-      .extracting(c-> (int) c.getMetricId(), QualityGateConditionDto::getWarningThreshold, QualityGateConditionDto::getErrorThreshold)
-      .containsExactlyInAnyOrder(tuple(metric.getId(), condition.getWarningThreshold(), condition.getErrorThreshold()));
+      .extracting(c-> (int) c.getMetricId(), QualityGateConditionDto::getErrorThreshold)
+      .containsExactlyInAnyOrder(tuple(metric.getId(), condition.getErrorThreshold()));
   }
 
   @Test
index 48ac02b70b6e37b99177db7e6843909152ce588c..f0b1e768e3becd98aa97e763c6eefb3bff3b1dd4 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.qualitygate.ws;
 
 import java.util.ArrayList;
-import javax.annotation.Nullable;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -50,7 +49,6 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GAT
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_METRIC;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_OPERATOR;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_WARNING;
 
 public class CreateConditionActionTest {
 
@@ -71,24 +69,6 @@ public class CreateConditionActionTest {
 
   private WsActionTester ws = new WsActionTester(underTest);
 
-  @Test
-  public void create_warning_condition() {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    MetricDto metric = insertMetric();
-
-    ws.newRequest()
-      .setParam(PARAM_GATE_ID, qualityGate.getId().toString())
-      .setParam(PARAM_METRIC, metric.getKey())
-      .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .execute();
-
-    assertCondition(qualityGate, metric, "LT", "90", null, null);
-  }
-
   @Test
   public void create_error_condition() {
     OrganizationDto organization = db.organizations().insert();
@@ -104,7 +84,7 @@ public class CreateConditionActionTest {
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
-    assertCondition(qualityGate, metric, "LT", null, "90", null);
+    assertCondition(qualityGate, metric, "LT", "90");
   }
 
   @Test
@@ -122,7 +102,7 @@ public class CreateConditionActionTest {
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .execute();
 
-    assertCondition(qualityGate, metric, "LT", null, "90", 1);
+    assertCondition(qualityGate, metric, "LT", "90");
   }
 
   @Test
@@ -138,48 +118,10 @@ public class CreateConditionActionTest {
       .setParam(PARAM_GATE_ID, qualityGate.getId().toString())
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
-      .execute();
-
-    assertCondition(qualityGate, metric, "LT", "90", null, null);
-  }
-
-  @Test
-  public void create_warning_condition_with_empty_string_on_error() {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    MetricDto metric = insertMetric();
-
-    ws.newRequest()
-      .setParam(PARAM_GATE_ID, qualityGate.getId().toString())
-      .setParam(PARAM_METRIC, metric.getKey())
-      .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
-      .setParam(PARAM_ERROR, "")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .execute();
-
-    assertCondition(qualityGate, metric, "LT", "90", null, null);
-  }
-
-  @Test
-  public void create_error_condition_with_empty_string_on_warning() {
-    OrganizationDto organization = db.organizations().insert();
-    logInAsQualityGateAdmin(organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    MetricDto metric = insertMetric();
-
-    ws.newRequest()
-      .setParam(PARAM_GATE_ID, qualityGate.getId().toString())
-      .setParam(PARAM_METRIC, metric.getKey())
-      .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "")
-      .setParam(PARAM_ERROR, "90")
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
+      .setParam(PARAM_ERROR, "10")
       .execute();
 
-    assertCondition(qualityGate, metric, "LT", null, "90", null);
+    assertCondition(qualityGate, metric, "LT", "10");
   }
 
   @Test
@@ -213,7 +155,6 @@ public class CreateConditionActionTest {
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
       .setParam(PARAM_ERROR, "45")
-      .setParam(PARAM_WARNING, "90")
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .executeProtobuf(CreateConditionResponse.class);
 
@@ -221,7 +162,6 @@ public class CreateConditionActionTest {
     assertThat(response.getId()).isEqualTo(condition.getId());
     assertThat(response.getMetric()).isEqualTo(metric.getKey());
     assertThat(response.getOp()).isEqualTo("LT");
-    assertThat(response.getWarning()).isEqualTo("90");
     assertThat(response.getError()).isEqualTo("45");
   }
 
@@ -256,17 +196,16 @@ public class CreateConditionActionTest {
       .containsExactlyInAnyOrder(
         tuple("gateId", true),
         tuple("metric", true),
+        tuple("error", true),
         tuple("op", false),
-        tuple("warning", false),
-        tuple("error", false),
         tuple("organization", false));
   }
 
-  private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) {
+  private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, String error) {
     assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId()))
       .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator,
-        QualityGateConditionDto::getWarningThreshold, QualityGateConditionDto::getErrorThreshold)
-      .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getId().longValue(), operator, warning, error));
+        QualityGateConditionDto::getErrorThreshold)
+      .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getId().longValue(), operator, error));
   }
 
   private void logInAsQualityGateAdmin(OrganizationDto organization) {
index 6b5141ff621339d595f8f046fde11319f460cfd5..19d7b9481ac8183489c41f5113291a3f847a7f9e 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
@@ -76,8 +75,6 @@ public class ProjectStatusActionTest {
   @Test
   public void test_definition() {
     WebService.Action action = ws.getDef();
-    assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactly(
-      tuple("6.4", "The field 'ignoredConditions' is added to the response"));
     assertThat(action.params())
       .extracting(WebService.Param::key, WebService.Param::isRequired)
       .containsExactlyInAnyOrder(
index e026fb2e62688513d2dcaf97b76c87c3746df23f..512981485017d143060d6860d57a5b856027571c 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.qualitygate.ws;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
@@ -87,10 +86,10 @@ public class ShowActionTest {
     assertThat(response.getIsBuiltIn()).isFalse();
     assertThat(response.getConditionsList()).hasSize(2);
     assertThat(response.getConditionsList())
-      .extracting(Condition::getId, Condition::getMetric, Condition::getOp, Condition::getError, Condition::getWarning)
+      .extracting(Condition::getId, Condition::getMetric, Condition::getOp, Condition::getError)
       .containsExactlyInAnyOrder(
-        tuple(condition1.getId(), metric1.getKey(), "GT", condition1.getErrorThreshold(), condition1.getWarningThreshold()),
-        tuple(condition2.getId(), metric2.getKey(), "LT", condition2.getErrorThreshold(), condition2.getWarningThreshold()));
+        tuple(condition1.getId(), metric1.getKey(), "GT", condition1.getErrorThreshold()),
+        tuple(condition2.getId(), metric2.getKey(), "LT", condition2.getErrorThreshold()));
   }
 
   @Test
@@ -397,9 +396,9 @@ public class ShowActionTest {
     QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("My Quality Gate 2"));
     db.qualityGates().setDefaultQualityGate(organization, qualityGate2);
     MetricDto blockerViolationsMetric = db.measures().insertMetric(m -> m.setKey("blocker_violations"));
-    MetricDto criticalViolationsMetric = db.measures().insertMetric(m -> m.setKey("critical_violations"));
-    db.qualityGates().addCondition(qualityGate, blockerViolationsMetric, c -> c.setOperator("GT").setErrorThreshold("0").setWarningThreshold(null));
-    db.qualityGates().addCondition(qualityGate, criticalViolationsMetric, c -> c.setOperator("LT").setErrorThreshold(null).setWarningThreshold("0"));
+    MetricDto criticalViolationsMetric = db.measures().insertMetric(m -> m.setKey("tests"));
+    db.qualityGates().addCondition(qualityGate, blockerViolationsMetric, c -> c.setOperator("GT").setErrorThreshold("0"));
+    db.qualityGates().addCondition(qualityGate, criticalViolationsMetric, c -> c.setOperator("LT").setErrorThreshold("10"));
 
     String response = ws.newRequest()
       .setParam("name", qualityGate.getName())
@@ -415,10 +414,6 @@ public class ShowActionTest {
   public void verify_definition() {
     WebService.Action action = ws.getDef();
     assertThat(action.since()).isEqualTo("4.3");
-    assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription)
-      .containsExactlyInAnyOrder(
-        tuple("7.0", "'isBuiltIn' field is added to the response"),
-        tuple("7.0", "'actions' field is added in the response"));
     assertThat(action.params())
       .extracting(Param::key, Param::isRequired)
       .containsExactlyInAnyOrder(
index 0f1b91b5f45dbe47ea40968dc29aa319bd2cf707..7d8353aa39b7d08df256461dbdeb8ef14ed3b2f1 100644 (file)
@@ -19,7 +19,9 @@
  */
 package org.sonar.server.qualitygate.ws;
 
-import javax.annotation.Nullable;
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -51,7 +53,6 @@ import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_METRIC;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_OPERATOR;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ORGANIZATION;
-import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_WARNING;
 
 public class UpdateConditionActionTest {
 
@@ -72,26 +73,6 @@ public class UpdateConditionActionTest {
 
   private WsActionTester ws = new WsActionTester(underTest);
 
-  @Test
-  public void update_warning_condition() {
-    OrganizationDto organization = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    MetricDto metric = insertMetric();
-    QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("GT").setWarningThreshold(null).setErrorThreshold("80"));
-
-    ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
-      .setParam(PARAM_METRIC, metric.getKey())
-      .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
-      .execute();
-
-    assertCondition(qualityGate, metric, "LT", "90", null);
-  }
-
   @Test
   public void update_error_condition() {
     OrganizationDto organization = db.organizations().insert();
@@ -99,7 +80,7 @@ public class UpdateConditionActionTest {
     QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
     MetricDto metric = insertMetric();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("GT").setWarningThreshold(null).setErrorThreshold("80"));
+      c -> c.setOperator("GT").setErrorThreshold("80"));
 
     ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
@@ -109,7 +90,7 @@ public class UpdateConditionActionTest {
       .setParam(PARAM_ERROR, "90")
       .execute();
 
-    assertCondition(qualityGate, metric, "LT", null, "90");
+    assertCondition(qualityGate, metric, "LT", "90");
   }
 
   @Test
@@ -123,52 +104,10 @@ public class UpdateConditionActionTest {
       .setParam(PARAM_ID, Long.toString(condition.getId()))
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
+      .setParam(PARAM_ERROR, "10")
       .execute();
 
-    assertCondition(qualityGate, metric, "LT", "90", null);
-  }
-
-  @Test
-  public void update_warning_condition_with_empty_string_on_error() {
-    OrganizationDto organization = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    MetricDto metric = insertMetric();
-    QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("GT").setWarningThreshold(null).setErrorThreshold("80"));
-
-    ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
-      .setParam(PARAM_METRIC, metric.getKey())
-      .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
-      .setParam(PARAM_ERROR, "")
-      .execute();
-
-    assertCondition(qualityGate, metric, "LT", "90", null);
-  }
-
-  @Test
-  public void update_error_condition_with_empty_string_on_warning() {
-    OrganizationDto organization = db.organizations().insert();
-    userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
-    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
-    MetricDto metric = insertMetric();
-    QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("GT").setWarningThreshold(null).setErrorThreshold("80"));
-
-    ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
-      .setParam(PARAM_ID, Long.toString(condition.getId()))
-      .setParam(PARAM_METRIC, metric.getKey())
-      .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_ERROR, "90")
-      .setParam(PARAM_WARNING, "")
-      .execute();
-
-    assertCondition(qualityGate, metric, "LT", null, "90");
+    assertCondition(qualityGate, metric, "LT", "10");
   }
 
   @Test
@@ -178,21 +117,19 @@ public class UpdateConditionActionTest {
     QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
     MetricDto metric = insertMetric();
     QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric,
-      c -> c.setOperator("GT").setWarningThreshold(null).setErrorThreshold("80"));
+      c -> c.setOperator("GT").setErrorThreshold("80"));
 
     CreateConditionResponse response = ws.newRequest()
       .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_ID, Long.toString(condition.getId()))
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
       .setParam(PARAM_ERROR, "45")
       .executeProtobuf(CreateConditionResponse.class);
 
     assertThat(response.getId()).isEqualTo(condition.getId());
     assertThat(response.getMetric()).isEqualTo(metric.getKey());
     assertThat(response.getOp()).isEqualTo("LT");
-    assertThat(response.getWarning()).isEqualTo("90");
     assertThat(response.getError()).isEqualTo("45");
   }
 
@@ -212,7 +149,7 @@ public class UpdateConditionActionTest {
       .setParam(PARAM_ID, Long.toString(condition.getId()))
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
+      .setParam(PARAM_ERROR, "10")
       .execute();
   }
 
@@ -232,7 +169,7 @@ public class UpdateConditionActionTest {
       .setParam(PARAM_ID, "123")
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
+      .setParam(PARAM_ERROR, "90")
       .execute();
   }
 
@@ -253,7 +190,7 @@ public class UpdateConditionActionTest {
       .setParam(PARAM_ID, Long.toString(condition.getId()))
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
+      .setParam(PARAM_ERROR, "90")
       .execute();
   }
 
@@ -273,7 +210,7 @@ public class UpdateConditionActionTest {
       .setParam(PARAM_ID, Long.toString(condition.getId()))
       .setParam(PARAM_METRIC, metric.getKey())
       .setParam(PARAM_OPERATOR, "LT")
-      .setParam(PARAM_WARNING, "90")
+      .setParam(PARAM_ERROR, "90")
       .execute();
   }
 
@@ -289,18 +226,16 @@ public class UpdateConditionActionTest {
       .containsExactlyInAnyOrder(
         tuple("id", true),
         tuple("metric", true),
+        tuple("error", true),
         tuple("op", false),
-        tuple("warning", false),
-        tuple("error", false),
         tuple("organization", false));
-
   }
 
-  private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, @Nullable String warning, @Nullable String error) {
+  private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, String error) {
     assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId()))
       .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator,
-        QualityGateConditionDto::getWarningThreshold, QualityGateConditionDto::getErrorThreshold)
-      .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getId().longValue(), operator, warning, error));
+        QualityGateConditionDto::getErrorThreshold)
+      .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getId().longValue(), operator, error));
   }
 
   private MetricDto insertMetric() {
index cee92e7367741a70a170e27f6902a0eb4f747127..38c36070556117679715c6ca08ae36fcff2d800a 100644 (file)
@@ -13,7 +13,6 @@
       "metric": "new_blocker_violations",
       "op": "GT",
       "period": 1,
-      "warning": "",
       "error": "0",
       "actual": "14",
       "level": "ERROR"
@@ -22,7 +21,6 @@
       "metric": "new_critical_violations",
       "op": "GT",
       "period": 1,
-      "warning": "",
       "error": "0",
       "actual": "1",
       "level": "ERROR"
@@ -31,7 +29,6 @@
       "metric": "new_sqale_debt_ratio",
       "op": "GT",
       "period": 1,
-      "warning": "",
       "error": "5",
       "actual": "0.6562109862671661",
       "level": "OK"
@@ -40,7 +37,6 @@
       "metric": "reopened_issues",
       "op": "GT",
       "period": 1,
-      "warning": "0",
       "actual": "0",
       "level": "OK"
     },
       "metric": "open_issues",
       "op": "GT",
       "period": 1,
-      "warning": "0",
-      "error": "",
+      "error": "0",
       "actual": "17",
-      "level": "WARN"
+      "level": "ERROR"
     },
     {
       "metric": "skipped_tests",
       "op": "GT",
       "period": 1,
-      "warning": "0",
-      "error": "",
+      "error": "0",
       "actual": "0",
       "level": "OK"
     }
index a320c66a7d819d8589fda4ab75b5208b50c49b4c..30a4e3293d4ae13e3f8414772ceb7343693f6f19 100644 (file)
@@ -510,11 +510,11 @@ public class PostProjectAnalysisTaskTester {
   public static final class ConditionBuilder {
     private static final String METRIC_KEY_CAN_NOT_BE_NULL = "metricKey cannot be null";
     private static final String OPERATOR_CAN_NOT_BE_NULL = "operator cannot be null";
+    private static final String ERROR_THRESHOLD_CAN_NOT_BE_NULL = "errorThreshold cannot be null";
 
     private String metricKey;
     private QualityGate.Operator operator;
     private String errorThreshold;
-    private String warningThreshold;
 
     private ConditionBuilder() {
       // prevents instantiation outside PostProjectAnalysisTaskTester
@@ -530,13 +530,16 @@ public class PostProjectAnalysisTaskTester {
       return this;
     }
 
-    public ConditionBuilder setErrorThreshold(@Nullable String errorThreshold) {
-      this.errorThreshold = errorThreshold;
+    public ConditionBuilder setErrorThreshold(String errorThreshold) {
+      this.errorThreshold = requireNonNull(errorThreshold, ERROR_THRESHOLD_CAN_NOT_BE_NULL);
       return this;
     }
 
+    /**
+     * @deprecated in 7.6. This method has no longer any effect.
+     */
+    @Deprecated
     public ConditionBuilder setWarningThreshold(@Nullable String warningThreshold) {
-      this.warningThreshold = warningThreshold;
       return this;
     }
 
@@ -572,9 +575,10 @@ public class PostProjectAnalysisTaskTester {
           return errorThreshold;
         }
 
+        @Deprecated
         @Override
         public String getWarningThreshold() {
-          return warningThreshold;
+          return null;
         }
 
         /**
@@ -598,7 +602,6 @@ public class PostProjectAnalysisTaskTester {
             ", metricKey='" + metricKey + '\'' +
             ", operator=" + operator +
             ", errorThreshold='" + errorThreshold + '\'' +
-            ", warningThreshold='" + warningThreshold + '\'' +
             '}';
         }
       };
@@ -630,9 +633,10 @@ public class PostProjectAnalysisTaskTester {
           return errorThreshold;
         }
 
+        @Deprecated
         @Override
         public String getWarningThreshold() {
-          return warningThreshold;
+          return null;
         }
 
         /**
@@ -656,7 +660,6 @@ public class PostProjectAnalysisTaskTester {
             ", metricKey='" + metricKey + '\'' +
             ", operator=" + operator +
             ", errorThreshold='" + errorThreshold + '\'' +
-            ", warningThreshold='" + warningThreshold + '\'' +
             ", value='" + value + '\'' +
             '}';
         }
@@ -666,7 +669,7 @@ public class PostProjectAnalysisTaskTester {
     private void checkCommonProperties() {
       requireNonNull(metricKey, METRIC_KEY_CAN_NOT_BE_NULL);
       requireNonNull(operator, OPERATOR_CAN_NOT_BE_NULL);
-      checkState(errorThreshold != null || warningThreshold != null, "At least one of errorThreshold and warningThreshold must be non null");
+      requireNonNull(errorThreshold, ERROR_THRESHOLD_CAN_NOT_BE_NULL);
     }
   }
 
index 7c9c719c5dcabbd714d2357d5bfcc560cb8468ce..7fd579c151a5361122071645d252a562d72f44c9 100644 (file)
@@ -50,7 +50,10 @@ public interface QualityGate {
   enum Status {
     /** at least one threshold is defined, no threshold is reached */
     OK,
-    /** at least one warning threshold is reached, no error threshold is reached */
+    /**
+     * @deprecated in 7.6.
+     */
+    @Deprecated
     WARN,
     /** at least one error threshold is reached */
     ERROR
@@ -74,28 +77,19 @@ public interface QualityGate {
     String getMetricKey();
 
     /**
-     * The operator used to evaluate the error and/or warning thresholds against the value of the measure
+     * The operator used to evaluate the error threshold against the value of the measure
      */
     Operator getOperator();
 
     /**
-     * <p>
-     * At least one of {@link #getErrorThreshold()} and {@link #getWarningThreshold()} is guaranteed to be non {@code null}.
-     * 
-     *
-     * @see #getWarningThreshold()
+     * The threshold value which makes the quality gates status change to {@link EvaluationStatus#ERROR} when it's reached.
      */
-    @CheckForNull
     String getErrorThreshold();
 
     /**
-     *
-     * <p>
-     * At least one of {@link #getErrorThreshold()} and {@link #getWarningThreshold()} is guaranteed to be non {@code null}.
-     * 
-     *
-     * @see #getErrorThreshold()
+     * @deprecated in 7.6. Implementations should always return null.
      */
+    @Deprecated
     @CheckForNull
     String getWarningThreshold();
 
@@ -139,12 +133,14 @@ public interface QualityGate {
      */
     NO_VALUE,
     /**
-     * Condition evaluated as OK, neither error nor warning thresholds have been reached.
+     * Condition evaluated as OK, error thresholds has not been reached.
      */
     OK,
     /**
      * Condition evaluated as WARN, only warning thresholds has been reached.
+     * @deprecated in 7.6
      */
+    @Deprecated
     WARN,
     /**
      * Condition evaluated as ERROR, error thresholds has been reached (and most likely warning thresholds too).
index 23b9bdbe500eb13d882a4225ddac4bc946b1ae15..a6dcd3d7e3bc2e595a23d29a258dc8eaf0c03f0b 100644 (file)
@@ -106,7 +106,13 @@ public class Metric<G extends Serializable> implements Serializable, org.sonar.a
   }
 
   public enum Level {
-    OK("Green"), WARN("Orange"), ERROR("Red");
+    OK("Green"),
+    /**
+     * @deprecated in 7.6.
+     */
+    @Deprecated
+    WARN("Orange"),
+    ERROR("Red");
 
     private static final List<String> NAMES = Arrays.stream(values())
       .map(Level::name)
index 990000b6f889b7ced206320c2e2913baaeae6199..ee43194415ed4ab8b243f57dc7844dbecad52ec7 100644 (file)
@@ -29,7 +29,6 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
   private static final String SOME_METRIC_KEY = "some metric key";
   private static final QualityGate.Operator SOME_OPERATOR = QualityGate.Operator.GREATER_THAN;
   private static final String SOME_ERROR_THRESHOLD = "some error threshold";
-  private static final String SOME_WARNING_THRESHOLD = "some warning threshold";
   private static final QualityGate.EvaluationStatus SOME_STATUS_BUT_NO_VALUE = QualityGate.EvaluationStatus.OK;
   private static final String SOME_VALUE = "some value";
 
@@ -56,7 +55,7 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
 
   @Test
   public void buildNoValue_throws_NPE_if_metricKey_is_null() {
-    underTest.setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+    underTest.setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD);
 
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("metricKey cannot be null");
@@ -66,7 +65,7 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
 
   @Test
   public void buildNoValue_throws_NPE_if_operator_is_null() {
-    underTest.setMetricKey(SOME_METRIC_KEY).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+    underTest.setMetricKey(SOME_METRIC_KEY).setErrorThreshold(SOME_ERROR_THRESHOLD);
 
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("operator cannot be null");
@@ -75,11 +74,11 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
   }
 
   @Test
-  public void buildNoValue_throws_ISE_if_both_warningThreshold_and_errorThreshold_are_null() {
+  public void buildNoValue_throws_NPE_if_errorThreshold_is_null() {
     underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR);
 
-    expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage("At least one of errorThreshold and warningThreshold must be non null");
+    expectedException.expect(NullPointerException.class);
+    expectedException.expectMessage("errorThreshold cannot be null");
 
     underTest.buildNoValue();
   }
@@ -102,20 +101,6 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
     condition.getValue();
   }
 
-  @Test
-  public void buildNoValue_does_not_fail_when_only_errorThreshold_is_set() {
-    underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD);
-
-    underTest.buildNoValue();
-  }
-
-  @Test
-  public void buildNoValue_does_not_fail_when_only_wardThreshold_is_set() {
-    underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setWarningThreshold(SOME_WARNING_THRESHOLD);
-
-    underTest.buildNoValue();
-  }
-
   @Test
   public void buildNoValue_returns_new_instance_at_each_call() {
     initValidBuilder();
@@ -130,7 +115,7 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
     assertThat(underTest.buildNoValue().toString())
       .isEqualTo(
         "Condition{status=NO_VALUE, metricKey='some metric key', operator=GREATER_THAN, " +
-          "errorThreshold='some error threshold', warningThreshold='some warning threshold'}");
+          "errorThreshold='some error threshold'}");
   }
 
   @Test
@@ -142,7 +127,6 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
     assertThat(condition.getMetricKey()).isEqualTo(SOME_METRIC_KEY);
     assertThat(condition.getOperator()).isEqualTo(SOME_OPERATOR);
     assertThat(condition.getErrorThreshold()).isEqualTo(SOME_ERROR_THRESHOLD);
-    assertThat(condition.getWarningThreshold()).isEqualTo(SOME_WARNING_THRESHOLD);
   }
 
   @Test
@@ -177,7 +161,7 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
 
   @Test
   public void build_throws_NPE_if_metricKey_is_null() {
-    underTest.setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+    underTest.setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD);
 
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("metricKey cannot be null");
@@ -187,7 +171,7 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
 
   @Test
   public void build_throws_NPE_if_operator_is_null() {
-    underTest.setMetricKey(SOME_METRIC_KEY).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+    underTest.setMetricKey(SOME_METRIC_KEY).setErrorThreshold(SOME_ERROR_THRESHOLD);
 
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("operator cannot be null");
@@ -196,25 +180,11 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
   }
 
   @Test
-  public void build_does_not_fail_when_only_errorThreshold_is_set() {
-    underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD);
-
-    underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
-  }
-
-  @Test
-  public void build_does_not_fail_when_only_wardThreshold_is_set() {
-    underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setWarningThreshold(SOME_WARNING_THRESHOLD);
-
-    underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
-  }
-
-  @Test
-  public void build_throws_ISE_if_both_warningThreshold_and_errorThreshold_are_null() {
+  public void build_throws_NPE_if_errorThreshold_is_null() {
     underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR);
 
-    expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage("At least one of errorThreshold and warningThreshold must be non null");
+    expectedException.expect(NullPointerException.class);
+    expectedException.expectMessage("errorThreshold cannot be null");
 
     underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE);
   }
@@ -233,7 +203,7 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
     assertThat(underTest.build(SOME_STATUS_BUT_NO_VALUE, SOME_VALUE).toString())
       .isEqualTo(
         "Condition{status=OK, metricKey='some metric key', operator=GREATER_THAN, "
-          + "errorThreshold='some error threshold', warningThreshold='some warning threshold', value='some value'}");
+          + "errorThreshold='some error threshold', value='some value'}");
   }
 
   @Test
@@ -264,12 +234,11 @@ public class ConditionBuilder_PostProjectAnalysisTaskTesterTest {
     assertThat(condition.getMetricKey()).isEqualTo(SOME_METRIC_KEY);
     assertThat(condition.getOperator()).isEqualTo(SOME_OPERATOR);
     assertThat(condition.getErrorThreshold()).isEqualTo(SOME_ERROR_THRESHOLD);
-    assertThat(condition.getWarningThreshold()).isEqualTo(SOME_WARNING_THRESHOLD);
     assertThat(condition.getValue()).isEqualTo(SOME_VALUE);
   }
 
   private PostProjectAnalysisTaskTester.ConditionBuilder initValidBuilder() {
-    underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD).setWarningThreshold(SOME_WARNING_THRESHOLD);
+    underTest.setMetricKey(SOME_METRIC_KEY).setOperator(SOME_OPERATOR).setErrorThreshold(SOME_ERROR_THRESHOLD);
     return underTest;
   }
 }
index b17861f2a87e03b53004f8adc59d19ace2312833..ec5c5b4f5a58ad6f5478f2a229e8f0332dea79ac 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonarqube.ws.client.qualitygates;
 
-import java.util.List;
 import javax.annotation.Generated;
 
 /**
@@ -36,7 +35,6 @@ public class CreateConditionRequest {
   private String metric;
   private String op;
   private String organization;
-  private String warning;
 
   /**
    * Example value: "10"
@@ -106,16 +104,4 @@ public class CreateConditionRequest {
   public String getOrganization() {
     return organization;
   }
-
-  /**
-   * Example value: "5"
-   */
-  public CreateConditionRequest setWarning(String warning) {
-    this.warning = warning;
-    return this;
-  }
-
-  public String getWarning() {
-    return warning;
-  }
 }
index 89ee5d8b14cc3ba0551d7a8174f28dad1af30652..12c7331f0d3bea8f931825333aeea0780d11697b 100644 (file)
@@ -91,8 +91,7 @@ public class QualitygatesService extends BaseService {
         .setParam("gateId", request.getGateId())
         .setParam("metric", request.getMetric())
         .setParam("op", request.getOp())
-        .setParam("organization", request.getOrganization())
-        .setParam("warning", request.getWarning()),
+        .setParam("organization", request.getOrganization()),
       CreateConditionResponse.parser());
   }
 
@@ -306,8 +305,7 @@ public class QualitygatesService extends BaseService {
         .setParam("id", request.getId())
         .setParam("metric", request.getMetric())
         .setParam("op", request.getOp())
-        .setParam("organization", request.getOrganization())
-        .setParam("warning", request.getWarning()),
+        .setParam("organization", request.getOrganization()),
       UpdateConditionResponse.parser());
   }
 }
index ca342817ca52c1fa9ff042d2f321a508ca274feb..43c77559bca9660f347a3bdd7c6097a4f10f236f 100644 (file)
@@ -36,7 +36,6 @@ public class UpdateConditionRequest {
   private String metric;
   private String op;
   private String organization;
-  private String warning;
 
   /**
    * Example value: "10"
@@ -106,16 +105,4 @@ public class UpdateConditionRequest {
   public String getOrganization() {
     return organization;
   }
-
-  /**
-   * Example value: "5"
-   */
-  public UpdateConditionRequest setWarning(String warning) {
-    this.warning = warning;
-    return this;
-  }
-
-  public String getWarning() {
-    return warning;
-  }
 }
index a8c14ef3c021d6f78880f5409c549b9db7eb0d9f..3c43684ab18ff26569718f3374772b3bdca3ef90 100644 (file)
@@ -103,7 +103,6 @@ message CreateConditionResponse {
   optional int64 id = 1;
   optional string metric = 2;
   optional string op = 3;
-  optional string warning = 4;
   optional string error = 5;
 }
 
@@ -112,7 +111,6 @@ message UpdateConditionResponse {
   optional int64 id = 1;
   optional string metric = 2;
   optional string op = 3;
-  optional string warning = 4;
   optional string error = 5;
 }
 
@@ -128,7 +126,6 @@ message ShowWsResponse {
     optional int64 id = 1;
     optional string metric = 2;
     optional string op = 4;
-    optional string warning = 5;
     optional string error = 6;
   }
 }