@Test
public void create_condition_on_rating_metric() {
- QualityGateConditionDto result = underTest.createCondition(dbSession, qualityGateDto.getId(), "rating_metric", "LT", null, "3", 1);
+ QualityGateConditionDto result = underTest.createCondition(dbSession, qualityGateDto.getId(), "rating_metric", "GT", null, "3", 1);
- verifyCondition(result, ratingMetricDto.getId(), "LT", null, "3", 1);
+ verifyCondition(result, ratingMetricDto.getId(), "GT", null, "3", 1);
}
@Test
public void fail_to_create_warning_condition_on_invalid_rating_metric() {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("'6' is not a valid rating");
- underTest.createCondition(dbSession, qualityGateDto.getId(), ratingMetricDto.getKey(), "LT", "6", null, null);
+ underTest.createCondition(dbSession, qualityGateDto.getId(), ratingMetricDto.getKey(), "GT", "6", null, null);
}
@Test
public void fail_to_create_error_condition_on_invalid_rating_metric() {
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("'80' is not a valid rating");
- underTest.createCondition(dbSession, qualityGateDto.getId(), ratingMetricDto.getKey(), "LT", null, "80", null);
+ underTest.createCondition(dbSession, qualityGateDto.getId(), ratingMetricDto.getKey(), "GT", null, "80", null);
}
@Test
underTest.createCondition(dbSession, qualityGateDto.getId(), ratingMetricDto.getKey(), "GT", "5", null, null);
}
- @Test
- public void fail_to_create_condition_on_lesser_than_A() {
- expectedException.expect(BadRequestException.class);
- expectedException.expectMessage("There's no better rating than A (1)");
- underTest.createCondition(dbSession, qualityGateDto.getId(), ratingMetricDto.getKey(), "LT", null, "1", null);
- }
-
@Test
public void update_condition() {
QualityGateConditionDto condition = insertCondition(coverageMetricDto.getId(), "LT", null, "80", null);
OPERATOR_LESS_THAN,
OPERATOR_GREATER_THAN,
OPERATOR_EQUALS,
- OPERATOR_NOT_EQUALS
- );
+ OPERATOR_NOT_EQUALS);
private static final List<String> NUMERIC_OPERATORS = ImmutableList.of(
OPERATOR_LESS_THAN,
OPERATOR_GREATER_THAN,
OPERATOR_EQUALS,
- OPERATOR_NOT_EQUALS
- );
+ OPERATOR_NOT_EQUALS);
+
private static final List<String> STRING_OPERATORS = ImmutableList.of(
OPERATOR_EQUALS,
OPERATOR_NOT_EQUALS,
OPERATOR_LESS_THAN,
- OPERATOR_GREATER_THAN
- );
+ OPERATOR_GREATER_THAN);
+
private static final List<String> LEVEL_OPERATORS = ImmutableList.of(
OPERATOR_EQUALS,
- OPERATOR_NOT_EQUALS
- );
+ OPERATOR_NOT_EQUALS);
+
private static final List<String> BOOLEAN_OPERATORS = ImmutableList.of(
- OPERATOR_EQUALS
- );
+ OPERATOR_EQUALS);
+
+ private static final List<String> RATING_OPERATORS = ImmutableList.of(
+ OPERATOR_GREATER_THAN);
private static final Map<ValueType, List<String>> OPERATORS_BY_TYPE = ImmutableMap.<ValueType, List<String>>builder()
.put(ValueType.BOOL, BOOLEAN_OPERATORS)
.put(ValueType.FLOAT, NUMERIC_OPERATORS)
.put(ValueType.PERCENT, NUMERIC_OPERATORS)
.put(ValueType.MILLISEC, NUMERIC_OPERATORS)
- .put(ValueType.RATING, NUMERIC_OPERATORS)
+ .put(ValueType.RATING, RATING_OPERATORS)
.put(ValueType.WORK_DUR, NUMERIC_OPERATORS)
.build();
*/
package org.sonar.db.qualitygate;
+import java.util.Arrays;
import org.junit.Test;
import org.sonar.api.measures.Metric.ValueType;
public class QualityGateConditionDtoTest {
@Test
- public void should_validate_operators_for_metric_type() {
- assertThat(isOperatorAllowed("WHATEVER", null)).isFalse();
+ public void validate_operators_for_DATA() {
assertThat(isOperatorAllowed("WHATEVER", DATA)).isFalse();
+ }
+ @Test
+ public void validate_operators_for_BOOL() throws Exception {
assertThat(isOperatorAllowed("EQ", BOOL)).isTrue();
assertThat(isOperatorAllowed("NE", BOOL)).isFalse();
assertThat(isOperatorAllowed("LT", BOOL)).isFalse();
assertThat(isOperatorAllowed("GT", BOOL)).isFalse();
+ }
+ @Test
+ public void validate_operators_for_LEVEL() throws Exception {
assertThat(isOperatorAllowed("EQ", LEVEL)).isTrue();
assertThat(isOperatorAllowed("NE", LEVEL)).isTrue();
assertThat(isOperatorAllowed("LT", LEVEL)).isFalse();
assertThat(isOperatorAllowed("GT", LEVEL)).isFalse();
+ }
- for (ValueType type : new ValueType[] {STRING, INT, FLOAT, PERCENT, MILLISEC, RATING}) {
+ @Test
+ public void validate_operators_for_RATING() throws Exception {
+ assertThat(isOperatorAllowed("EQ", RATING)).isFalse();
+ assertThat(isOperatorAllowed("NE", RATING)).isFalse();
+ assertThat(isOperatorAllowed("LT", RATING)).isFalse();
+ assertThat(isOperatorAllowed("GT", RATING)).isTrue();
+ }
+
+ @Test
+ public void validate_operators_for_other_types() throws Exception {
+ Arrays.stream(new ValueType[] {STRING, INT, FLOAT, PERCENT, MILLISEC}).forEach(type -> {
assertThat(isOperatorAllowed("EQ", type)).isTrue();
assertThat(isOperatorAllowed("NE", type)).isTrue();
assertThat(isOperatorAllowed("LT", type)).isTrue();
assertThat(isOperatorAllowed("GT", type)).isTrue();
- }
+ });
}
+
}