Search in sources :

Example 6 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class CustomMeasuresCopyStepTest method test_int_value_type.

@Test
public void test_int_value_type() throws Exception {
    CustomMeasureDto dto = new CustomMeasureDto();
    dto.setValue(10.0);
    assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.INT)).getIntValue()).isEqualTo(10);
}
Also used : MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 7 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class CustomMeasuresCopyStepTest method test_LEVEL_value_type.

@Test
public void test_LEVEL_value_type() throws Exception {
    CustomMeasureDto dto = new CustomMeasureDto();
    dto.setTextValue("OK");
    assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.LEVEL)).getLevelValue()).isEqualTo(Measure.Level.OK);
}
Also used : MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 8 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class UpdateActionTest method fail_if_insufficient_privileges.

@Test
public void fail_if_insufficient_privileges() throws Exception {
    userSessionRule.logIn();
    MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name());
    dbClient.metricDao().insert(dbSession, metric);
    ComponentDto component = ComponentTesting.newProjectDto(db.getDefaultOrganization(), "project-uuid");
    dbClient.componentDao().insert(dbSession, component);
    CustomMeasureDto customMeasure = newCustomMeasureDto().setMetricId(metric.getId()).setComponentUuid(component.uuid()).setCreatedAt(system.now()).setDescription("custom-measure-description").setTextValue("text-measure-value");
    dbClient.customMeasureDao().insert(dbSession, customMeasure);
    dbSession.commit();
    expectedException.expect(ForbiddenException.class);
    ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION).setParam(PARAM_ID, String.valueOf(customMeasure.getId())).setParam(PARAM_DESCRIPTION, "new-custom-measure-description").setParam(PARAM_VALUE, "1984").execute();
}
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)

Example 9 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class UpdateActionTest method returns_full_object_in_response.

@Test
public void returns_full_object_in_response() throws Exception {
    MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name()).setKey("metric-key");
    dbClient.metricDao().insert(dbSession, metric);
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto component = ComponentTesting.newProjectDto(organizationDto, "project-uuid").setKey("project-key");
    dbClient.componentDao().insert(dbSession, component);
    CustomMeasureDto customMeasure = newCustomMeasure(component, metric).setCreatedAt(100_000_000L).setDescription("custom-measure-description").setTextValue("text-measure-value");
    dbClient.customMeasureDao().insert(dbSession, customMeasure);
    dbSession.commit();
    when(system.now()).thenReturn(123_456_789L);
    logInAsProjectAdministrator(component);
    WsTester.Result response = 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();
    response.assertJson(getClass(), "custom-measure.json");
    String responseAsString = response.outputAsString();
    assertThat(responseAsString).matches(String.format(".*\"id\"\\s*:\\s*\"%s\".*", customMeasure.getId()));
    assertThat(responseAsString).matches(String.format(".*\"id\"\\s*:\\s*\"%s\".*", metric.getId()));
    assertThat(responseAsString).matches(".*createdAt.*updatedAt.*");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) WsTester(org.sonar.server.ws.WsTester) 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 10 with CustomMeasureDto

use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.

the class UpdateActionTest method update_value_only.

@Test
public void update_value_only() 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").execute();
    logInAsProjectAdministrator(component);
    CustomMeasureDto updatedCustomMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
    assertThat(updatedCustomMeasure.getTextValue()).isEqualTo("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

CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)38 Test (org.junit.Test)30 MetricDto (org.sonar.db.metric.MetricDto)26 CustomMeasureTesting.newCustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto)12 ComponentDto (org.sonar.db.component.ComponentDto)11 MetricImpl (org.sonar.server.computation.task.projectanalysis.metric.MetricImpl)7 DbSession (org.sonar.db.DbSession)4 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)4 OrganizationDto (org.sonar.db.organization.OrganizationDto)4 UserDto (org.sonar.db.user.UserDto)3 WsTester (org.sonar.server.ws.WsTester)3 JsonWriter (org.sonar.api.utils.text.JsonWriter)2 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)1 Metric (org.sonar.server.computation.task.projectanalysis.metric.Metric)1 SearchOptions (org.sonar.server.es.SearchOptions)1