@CheckForNull private static Criterion tryParsingCriterionNotHavingValues(String criterion) { Matcher matcher = PATTERN.matcher(criterion); if (!matcher.find()) { return null; } Criterion.Builder builder = new Criterion.Builder(); builder.setKey(matcher.group(1)); String operatorValue = matcher.group(2); String value = matcher.group(3); if (!isNullOrEmpty(operatorValue) && !isNullOrEmpty(value)) { builder.setOperator(ProjectMeasuresQuery.Operator.getByValue(operatorValue)); builder.setValue(sanitizeValue(value)); } return builder.build(); }
@Test public void create_query_on_tag_using_in_operator() { ProjectMeasuresQuery query = newProjectMeasuresQuery( singletonList(Criterion.builder().setKey("tags").setOperator(IN).setValues(asList("java", "js")).build()), emptySet()); assertThat(query.getTags().get()).containsOnly("java", "js"); }
@CheckForNull private static Criterion tryParsingCriterionNotHavingValues(String criterion) { Matcher matcher = PATTERN.matcher(criterion); if (!matcher.find()) { return null; } Criterion.Builder builder = new Criterion.Builder(); builder.setKey(matcher.group(1)); String operatorValue = matcher.group(2); String value = matcher.group(3); if (!isNullOrEmpty(operatorValue) && !isNullOrEmpty(value)) { builder.setOperator(Operator.getByValue(operatorValue)); builder.setValue(sanitizeValue(value)); } return builder.build(); }
public static Builder builder() { return new Builder(); }
@CheckForNull private static Criterion tryParsingCriterionHavingValues(String criterion) { Matcher matcher = PATTERN_HAVING_VALUES.matcher(criterion); if (!matcher.find()) { return null; } Criterion.Builder builder = new Criterion.Builder(); builder.setKey(matcher.group(1)); builder.setOperator(Operator.IN); builder.setValues(IN_VALUES_SPLITTER.splitToList(matcher.group(3))); return builder.build(); }
public static Builder builder() { return new Builder(); }
@Test public void fail_to_create_query_having_q_with_no_value() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Query is invalid"); newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("query").setOperator(EQ).build()), emptySet()); }
@Test public void filter_no_data_with_other_case() { List<Criterion> criteria = singletonList(Criterion.builder().setKey("duplicated_lines_density").setOperator(EQ).setValue("nO_DaTa").build()); ProjectMeasuresQuery underTest = newProjectMeasuresQuery(criteria, emptySet()); assertThat(underTest.getMetricCriteria()) .extracting(MetricCriterion::getMetricKey, MetricCriterion::isNoData) .containsOnly(tuple("duplicated_lines_density", true)); }
@Test public void fail_to_use_no_data_with_operator_lower_than() { List<Criterion> criteria = singletonList(Criterion.builder().setKey("duplicated_lines_density").setOperator(LT).setValue("NO_DATA").build()); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("NO_DATA can only be used with equals operator"); newProjectMeasuresQuery(criteria, emptySet()); }
@Test public void fail_to_create_query_on_quality_gate_when_value_is_incorrect() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Unknown quality gate status : 'unknown'"); newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("alert_status").setOperator(EQ).setValue("unknown").build()), emptySet()); }
@Test public void create_query_on_quality_gate() { ProjectMeasuresQuery query = newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("alert_status").setOperator(EQ).setValue("OK").build()), emptySet()); assertThat(query.getQualityGateStatus().get().name()).isEqualTo("OK"); }
@Test public void fail_to_create_query_on_language_using_eq_operator_and_values() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Languages should be set either by using 'languages = java' or 'languages IN (java, js)"); newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("languages").setOperator(EQ).setValues(asList("java")).build()), emptySet()); }
@Test public void convert_metric_to_lower_case() { ProjectMeasuresQuery query = newProjectMeasuresQuery(asList( Criterion.builder().setKey("NCLOC").setOperator(GT).setValue("10").build(), Criterion.builder().setKey("coVERage").setOperator(LTE).setValue("80").build()), emptySet()); assertThat(query.getMetricCriteria()) .extracting(MetricCriterion::getMetricKey, MetricCriterion::getOperator, MetricCriterion::getValue) .containsOnly( tuple("ncloc", GT, 10d), tuple("coverage", Operator.LTE, 80d)); }
@Test public void fail_to_create_query_on_tag_using_eq_operator_and_values() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Tags should be set either by using 'tags = java' or 'tags IN (finance, platform)"); newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("tags").setOperator(EQ).setValues(asList("java")).build()), emptySet()); }
@Test public void create_query_on_language_using_equals_operator() { ProjectMeasuresQuery query = newProjectMeasuresQuery( singletonList(Criterion.builder().setKey("languages").setOperator(EQ).setValue("java").build()), emptySet()); assertThat(query.getLanguages().get()).containsOnly("java"); }
@Test public void fail_to_create_query_on_quality_gate_when_operator_is_not_equal() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Only equals operator is available for quality gate criteria"); newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("alert_status").setOperator(GT).setValue("OK").build()), emptySet()); }
@CheckForNull private static Criterion tryParsingCriterionHavingValues(String criterion) { Matcher matcher = PATTERN_HAVING_VALUES.matcher(criterion); if (!matcher.find()) { return null; } Criterion.Builder builder = new Criterion.Builder(); builder.setKey(matcher.group(1)); builder.setOperator(ProjectMeasuresQuery.Operator.IN); builder.setValues(IN_VALUES_SPLITTER.splitToList(matcher.group(3))); return builder.build(); }
@Test public void filter_no_data() { List<Criterion> criteria = singletonList(Criterion.builder().setKey("duplicated_lines_density").setOperator(EQ).setValue("NO_DATA").build()); ProjectMeasuresQuery underTest = newProjectMeasuresQuery(criteria, emptySet()); assertThat(underTest.getMetricCriteria()) .extracting(MetricCriterion::getMetricKey, MetricCriterion::isNoData) .containsOnly(tuple("duplicated_lines_density", true)); }
@Test public void fail_to_create_query_having_q_with_other_operator_than_equals() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Query should only be used with equals operator"); newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("query").setOperator(LT).setValue("java").build()), emptySet()); }
@Test public void fail_to_create_query_on_tag_using_in_operator_and_value() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Tags should be set either by using 'tags = java' or 'tags IN (finance, platform)"); newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("tags").setOperator(IN).setValue("java").build()), emptySet()); }