*/
package org.sonar.batch.qualitygate;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.utils.Duration;
import org.sonar.api.utils.Durations;
+import org.sonar.core.qualitygate.db.QualityGateConditionDto;
import org.sonar.core.timemachine.Periods;
-import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
+import java.util.*;
public class QualityGateVerifier implements Decorator {
private static final String VARIATION_METRIC_PREFIX = "new_";
private static final String VARIATION = "variation";
+ private static final Map<String, String> OPERATOR_LABELS = ImmutableMap.of(
+ QualityGateConditionDto.OPERATOR_EQUALS, "=",
+ QualityGateConditionDto.OPERATOR_NOT_EQUALS, "!=",
+ QualityGateConditionDto.OPERATOR_GREATER_THAN, ">",
+ QualityGateConditionDto.OPERATOR_LESS_THAN, "<");
private QualityGate qualityGate;
}
stringBuilder
- .append(" ").append(condition.operator()).append(" ")
+ .append(" ").append(operatorLabel(condition.operator())).append(" ")
.append(alertValue(condition, level));
if (alertPeriod != null) {
}
}
+ private String operatorLabel(String operator) {
+ return OPERATOR_LABELS.get(operator);
+ }
+
@Override
public String toString() {
return getClass().getSimpleName();
verifier.decorate(project, context);
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes LT 10000, Coverages LT 50.0")));
+ verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes < 10000, Coverages < 50.0")));
}
@Test
when(qualityGate.conditions()).thenReturn(conditions);
verifier.decorate(project, context);
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "THE RATING LT 10")));
+ verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "THE RATING < 10")));
}
@Test
verifier.decorate(project, context);
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes LT 10000")));
+ verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes < 10000")));
}
@Test
verifier.decorate(project, context);
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "Classes variation GT 30 since someday")));
+ verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "Classes variation > 30 since someday")));
}
@Test
verifier.decorate(project, context);
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "New Measure GT 30 since someday")));
+ verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "New Measure > 30 since someday")));
}
@Test
when(qualityGate.conditions()).thenReturn(conditions);
verifier.decorate(project, context);
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "The Debt LT 1h")));
+ verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "The Debt < 1h")));
}
private ArgumentMatcher<Measure> matchesMetric(final Metric metric, final Metric.Level alertStatus, final String alertText) {