Search in sources :

Example 1 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryFactoryTest method create_query.

@Test
public void create_query() throws Exception {
    List<Criterion> criteria = asList(Criterion.builder().setKey("ncloc").setOperator(GT).setValue("10").build(), Criterion.builder().setKey("coverage").setOperator(LTE).setValue("80").build());
    ProjectMeasuresQuery underTest = newProjectMeasuresQuery(criteria, emptySet());
    assertThat(underTest.getMetricCriteria()).extracting(MetricCriterion::getMetricKey, MetricCriterion::getOperator, MetricCriterion::getValue).containsOnly(tuple("ncloc", GT, 10d), tuple("coverage", Operator.LTE, 80d));
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Criterion(org.sonar.server.component.ws.FilterParser.Criterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) Test(org.junit.Test)

Example 2 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryValidatorTest method fail_when_metric_is_disabled.

@Test
public void fail_when_metric_is_disabled() throws Exception {
    insertMetric(createValidMetric("ncloc").setEnabled(false));
    insertMetric(createValidMetric("debt").setEnabled(false));
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("ncloc", GT, 10d)).setSort("debt");
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Following metrics are disabled : [debt, ncloc]");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Example 3 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryValidatorTest method fail_when_metric_are_not_numeric.

@Test
public void fail_when_metric_are_not_numeric() throws Exception {
    insertMetric(createValidMetric("ncloc").setValueType(INT.name()));
    insertMetric(createValidMetric("debt").setValueType(WORK_DUR.name()));
    insertMetric(createValidMetric("data").setValueType(DATA.name()));
    insertMetric(createValidMetric("distrib").setValueType(DISTRIB.name()));
    insertMetric(createValidMetric("string").setValueType(STRING.name()));
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("data", GT, 10d)).addMetricCriterion(new MetricCriterion("distrib", EQ, 11d)).addMetricCriterion(new MetricCriterion("ncloc", LTE, 20d)).addMetricCriterion(new MetricCriterion("debt", LT, 20d)).addMetricCriterion(new MetricCriterion("string", EQ, 40d));
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Following metrics are not numeric : [data, distrib, string]");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Example 4 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryValidatorTest method does_not_fail_when_sort_contains_an_existing_metric.

@Test
public void does_not_fail_when_sort_contains_an_existing_metric() throws Exception {
    insertValidMetric("ncloc");
    insertValidMetric("debt");
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("ncloc", GT, 10d)).setSort("debt");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Example 5 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryValidatorTest method fail_when_metric_does_not_exists.

@Test
public void fail_when_metric_does_not_exists() throws Exception {
    insertValidMetric("ncloc");
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("unknown", GT, 10d)).setSort("debt");
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Unknown metric(s) [debt, unknown]");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Aggregations

MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)22 Test (org.junit.Test)20 ProjectMeasuresQuery (org.sonar.server.measure.index.ProjectMeasuresQuery)8 SearchOptions (org.sonar.server.es.SearchOptions)6 Facets (org.sonar.server.es.Facets)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Multimap (com.google.common.collect.Multimap)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 IntStream (java.util.stream.IntStream)1 Nullable (javax.annotation.Nullable)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1