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);
}
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");
}
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");
}
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()));
}
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();
}
Aggregations