use of org.sonar.db.measure.custom.CustomMeasureDto 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());
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class UpdateActionTest method update_double_value_and_description_in_db.
@Test
public void update_double_value_and_description_in_db() throws Exception {
MetricDto metric = insertNewMetric(ValueType.INT);
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto component = db.components().insertProject(organizationDto, "project-uuid");
CustomMeasureDto customMeasure = newCustomMeasure(component, metric).setDescription("custom-measure-description").setValue(42d);
dbClient.customMeasureDao().insert(dbSession, customMeasure);
dbSession.commit();
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, "1984").execute();
CustomMeasureDto updatedCustomMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
assertThat(updatedCustomMeasure.getValue()).isCloseTo(1984d, offset(0.01d));
assertThat(updatedCustomMeasure.getDescription()).isEqualTo("new-custom-measure-description");
assertThat(customMeasure.getCreatedAt()).isEqualTo(updatedCustomMeasure.getCreatedAt());
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class UpdateActionTest method fail_if_not_logged_in.
@Test
public void fail_if_not_logged_in() throws Exception {
userSessionRule.anonymous();
expectedException.expect(UnauthorizedException.class);
MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name());
dbClient.metricDao().insert(dbSession, metric);
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto component = ComponentTesting.newProjectDto(organizationDto, "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();
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();
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class MetricsActionTest method list_metrics_where_no_existing_custom_measure.
@Test
public void list_metrics_where_no_existing_custom_measure() throws Exception {
MetricDto metric = insertCustomMetric("metric-key-1");
insertCustomMetric("metric-key-2");
insertProject("project-uuid-2", "project-key-2");
CustomMeasureDto customMeasure = newCustomMeasureDto().setComponentUuid(defaultProject.uuid()).setMetricId(metric.getId());
dbClient.customMeasureDao().insert(dbSession, customMeasure);
dbSession.commit();
String response = newRequest().outputAsString();
assertThat(response).contains("metric-key-2").doesNotContain("metric-key-1");
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class CreateActionTest method create_boolean_custom_measure_in_db.
@Test
public void create_boolean_custom_measure_in_db() throws Exception {
insertProject(DEFAULT_PROJECT_UUID);
MetricDto metric = insertMetric(BOOL);
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, "true").execute();
List<CustomMeasureDto> customMeasures = dbClient.customMeasureDao().selectByMetricId(dbSession, metric.getId());
CustomMeasureDto customMeasure = customMeasures.get(0);
assertThat(customMeasures).hasSize(1);
assertThat(customMeasure.getDescription()).isEqualTo("custom-measure-description");
assertThat(customMeasure.getTextValue()).isNullOrEmpty();
assertThat(customMeasure.getValue()).isCloseTo(1.0d, offset(0.01d));
assertThat(customMeasure.getComponentUuid()).isEqualTo(DEFAULT_PROJECT_UUID);
}
Aggregations