Search in sources :

Example 6 with ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery 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 7 with ProjectMeasuresQuery

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

the class ProjectMeasuresQueryFactoryTest method create_query_on_tag_using_in_operator.

@Test
public void create_query_on_tag_using_in_operator() throws Exception {
    ProjectMeasuresQuery query = newProjectMeasuresQuery(singletonList(Criterion.builder().setKey("tags").setOperator(IN).setValues(asList("java", "js")).build()), emptySet());
    assertThat(query.getTags().get()).containsOnly("java", "js");
}
Also used : ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) Test(org.junit.Test)

Example 8 with ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery 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 9 with ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery 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 10 with ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery 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)

Aggregations

ProjectMeasuresQuery (org.sonar.server.measure.index.ProjectMeasuresQuery)24 Test (org.junit.Test)22 ProjectMeasuresQueryFactory.newProjectMeasuresQuery (org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery)16 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)10 Criterion (org.sonar.server.component.ws.FilterParser.Criterion)4 ComponentDto (org.sonar.db.component.ComponentDto)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 SearchOptions (org.sonar.server.es.SearchOptions)1