use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class ComponentTreeActionTest method sort_by_metric_value.
@Test
public void sort_by_metric_value() {
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4"));
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1"));
ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-2"));
MetricDto ncloc = newMetricDtoWithoutOptimization().setKey("ncloc").setValueType(ValueType.INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file1, projectSnapshot).setValue(1.0d), newMeasureDto(ncloc, file2, projectSnapshot).setValue(2.0d), newMeasureDto(ncloc, file3, projectSnapshot).setValue(3.0d));
db.commit();
ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(Param.SORT, METRIC_SORT).setParam(PARAM_METRIC_SORT, "ncloc").setParam(PARAM_METRIC_KEYS, "ncloc"));
assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3", "file-uuid-4");
assertThat(response.getPaging().getTotal()).isEqualTo(4);
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class SearchActionTest method search_as_project_admin.
@Test
public void search_as_project_admin() throws Exception {
userSessionRule.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
MetricDto metric1 = insertCustomMetric(1);
insertCustomMeasure(1, metric1);
String response = newRequest().setParam(SearchAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).execute().outputAsString();
assertThat(response).contains("text-value-1");
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class SearchActionTest method search_by_project_key.
@Test
public void search_by_project_key() throws Exception {
MetricDto metric1 = insertCustomMetric(1);
MetricDto metric2 = insertCustomMetric(2);
MetricDto metric3 = insertCustomMetric(3);
insertCustomMeasure(1, metric1);
insertCustomMeasure(2, metric2);
insertCustomMeasure(3, metric3);
String response = newRequest().setParam(SearchAction.PARAM_PROJECT_KEY, DEFAULT_PROJECT_KEY).execute().outputAsString();
assertThat(response).contains("text-value-1", "text-value-2", "text-value-3");
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class UpdateActionTest method update_description_only.
@Test
public void update_description_only() throws Exception {
MetricDto metric = insertNewMetric(ValueType.STRING);
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto component = db.components().insertProject(organizationDto, "project-uuid");
CustomMeasureDto customMeasure = newCustomMeasure(component, metric).setMetricId(metric.getId()).setComponentUuid(component.uuid()).setCreatedAt(system.now()).setDescription("custom-measure-description").setTextValue("text-measure-value");
dbClient.customMeasureDao().insert(dbSession, customMeasure);
dbSession.commit();
when(system.now()).thenReturn(123_456_789L);
logInAsProjectAdministrator(component);
ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION).setParam(PARAM_ID, String.valueOf(customMeasure.getId())).setParam(PARAM_VALUE, "new-text-measure-value").execute();
CustomMeasureDto updatedCustomMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
assertThat(updatedCustomMeasure.getTextValue()).isEqualTo("new-text-measure-value");
assertThat(updatedCustomMeasure.getDescription()).isEqualTo("custom-measure-description");
assertThat(updatedCustomMeasure.getUpdatedAt()).isEqualTo(123_456_789L);
assertThat(customMeasure.getCreatedAt()).isEqualTo(updatedCustomMeasure.getCreatedAt());
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class UpdateActionTest method update_text_value_and_description_in_db.
@Test
public void update_text_value_and_description_in_db() throws Exception {
MetricDto metric = insertNewMetric(ValueType.STRING);
ComponentDto component = db.components().insertProject(db.getDefaultOrganization(), "project-uuid");
CustomMeasureDto customMeasure = newCustomMeasure(component, metric).setDescription("custom-measure-description").setTextValue("text-measure-value");
dbClient.customMeasureDao().insert(dbSession, customMeasure);
dbSession.commit();
when(system.now()).thenReturn(123_456_789L);
logInAsProjectAdministrator(component);
ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION).setParam(PARAM_ID, String.valueOf(customMeasure.getId())).setParam(PARAM_DESCRIPTION, "new-custom-measure-description").setParam(PARAM_VALUE, "new-text-measure-value").execute();
logInAsProjectAdministrator(component);
CustomMeasureDto updatedCustomMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
assertThat(updatedCustomMeasure.getTextValue()).isEqualTo("new-text-measure-value");
assertThat(updatedCustomMeasure.getDescription()).isEqualTo("new-custom-measure-description");
assertThat(updatedCustomMeasure.getUpdatedAt()).isEqualTo(123_456_789L);
assertThat(customMeasure.getCreatedAt()).isEqualTo(updatedCustomMeasure.getCreatedAt());
}
Aggregations