Search in sources :

Example 81 with MetricDto

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);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse) Test(org.junit.Test)

Example 82 with MetricDto

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");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 83 with MetricDto

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");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 84 with MetricDto

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());
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) CustomMeasureTesting.newCustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 85 with MetricDto

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());
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) CustomMeasureTesting.newCustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) 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