Search in sources :

Example 31 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class SearchActionTest method search_with_pagination.

@Test
public void search_with_pagination() throws Exception {
    for (int i = 0; i < 10; i++) {
        MetricDto metric = insertCustomMetric(i);
        insertCustomMeasure(i, metric);
    }
    String response = newRequest().setParam(SearchAction.PARAM_PROJECT_KEY, DEFAULT_PROJECT_KEY).setParam(WebService.Param.PAGE, "3").setParam(WebService.Param.PAGE_SIZE, "4").execute().outputAsString();
    assertThat(StringUtils.countMatches(response, "text-value")).isEqualTo(2);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 32 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class SearchActionTest method search_with_selectable_fields.

@Test
public void search_with_selectable_fields() throws Exception {
    MetricDto metric = insertCustomMetric(1);
    insertCustomMeasure(1, metric);
    String response = newRequest().setParam(SearchAction.PARAM_PROJECT_KEY, DEFAULT_PROJECT_KEY).setParam(WebService.Param.FIELDS, "value, description").execute().outputAsString();
    assertThat(response).contains("id", "value", "description").doesNotContain("createdAt").doesNotContain("updatedAt").doesNotContain("user").doesNotContain("metric");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 33 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class SearchActionTest method json_well_formatted.

@Test
public void json_well_formatted() throws Exception {
    MetricDto metric1 = insertCustomMetric(1);
    MetricDto metric2 = insertCustomMetric(2);
    MetricDto metric3 = insertCustomMetric(3);
    CustomMeasureDto customMeasure1 = insertCustomMeasure(1, metric1);
    CustomMeasureDto customMeasure2 = insertCustomMeasure(2, metric2);
    CustomMeasureDto customMeasure3 = insertCustomMeasure(3, metric3);
    WsTester.Result response = newRequest().setParam(SearchAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).execute();
    response.assertJson(getClass(), "custom-measures.json");
    String responseAsString = response.outputAsString();
    assertThat(responseAsString).matches(nameStringValuePattern("id", metric1.getId().toString()));
    assertThat(responseAsString).matches(nameStringValuePattern("id", metric2.getId().toString()));
    assertThat(responseAsString).matches(nameStringValuePattern("id", metric3.getId().toString()));
    assertThat(responseAsString).matches(nameStringValuePattern("id", String.valueOf(customMeasure1.getId())));
    assertThat(responseAsString).matches(nameStringValuePattern("id", String.valueOf(customMeasure2.getId())));
    assertThat(responseAsString).matches(nameStringValuePattern("id", String.valueOf(customMeasure3.getId())));
    assertThat(responseAsString).contains("createdAt", "updatedAt");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) WsTester(org.sonar.server.ws.WsTester) CustomMeasureTesting.newCustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 34 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class CreateActionTest method response_with_object_and_id.

@Test
public void response_with_object_and_id() throws Exception {
    insertProject(DEFAULT_PROJECT_UUID);
    MetricDto metric = insertMetric(STRING);
    WsTester.Result response = newRequest().setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString()).setParam(CreateAction.PARAM_DESCRIPTION, "custom-measure-description").setParam(CreateAction.PARAM_VALUE, "custom-measure-free-text").execute();
    CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectByMetricId(dbSession, metric.getId()).get(0);
    response.assertJson(getClass(), "custom-measure.json");
    assertThat(response.outputAsString()).matches(String.format(".*\"id\"\\s*:\\s*\"%d\".*", customMeasure.getId()));
    assertThat(response.outputAsString()).matches(String.format(".*\"id\"\\s*:\\s*\"%d\".*", metric.getId()));
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) WsTester(org.sonar.server.ws.WsTester) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 35 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class CreateActionTest method fail_when_project_id_does_not_exist_in_db.

@Test
public void fail_when_project_id_does_not_exist_in_db() throws Exception {
    expectedException.expect(NotFoundException.class);
    expectedException.expectMessage("Component id 'another-project-uuid' not found");
    insertProject(DEFAULT_PROJECT_UUID);
    MetricDto metric = insertMetric(STRING);
    newRequest().setParam(CreateAction.PARAM_PROJECT_ID, "another-project-uuid").setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString()).setParam(CreateAction.PARAM_VALUE, "whatever-value").execute();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Aggregations

MetricDto (org.sonar.db.metric.MetricDto)137 Test (org.junit.Test)83 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)61 ComponentDto (org.sonar.db.component.ComponentDto)49 SnapshotDto (org.sonar.db.component.SnapshotDto)33 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)26 DbSession (org.sonar.db.DbSession)11 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)11 CustomMeasureTesting.newCustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto)10 MeasureDto (org.sonar.db.measure.MeasureDto)9 OrganizationDto (org.sonar.db.organization.OrganizationDto)8 ProjectMeasures (org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)7 QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)6 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 WsTester (org.sonar.server.ws.WsTester)5 SearchWsResponse (org.sonarqube.ws.WsMeasures.SearchWsResponse)5 MeasureQuery (org.sonar.db.measure.MeasureQuery)3 UserDto (org.sonar.db.user.UserDto)3 WsMeasures (org.sonarqube.ws.WsMeasures)3 ComponentWsResponse (org.sonarqube.ws.WsMeasures.ComponentWsResponse)3