use of org.sonar.db.metric.MetricDto 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.metric.MetricDto 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.metric.MetricDto in project sonarqube by SonarSource.
the class MeasureDtoToWsMeasureTest method fail_when_mapping_fails.
@Test
public void fail_when_mapping_fails() {
MetricDto metric = spy(newMetricDto().setKey("metric-key"));
when(metric.getValueType()).thenThrow(NullPointerException.class);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Error while mapping a measure of metric key 'metric-key' and parameters ");
MeasureDtoToWsMeasure.measureDtoToWsMeasure(metric, newMeasure());
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class SearchActionTest method insertComplexityMetric.
private MetricDto insertComplexityMetric() {
MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization().setKey("complexity").setShortName("Complexity").setDescription("Cyclomatic complexity").setDomain("Complexity").setValueType("INT").setDirection(-1).setQualitative(false).setHidden(false).setUserManaged(false));
db.commit();
return metric;
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class SearchActionTest method insertCoverageMetric.
private MetricDto insertCoverageMetric() {
MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization().setKey("coverage").setShortName("Coverage").setDescription("Code Coverage").setDomain("Coverage").setValueType(Metric.ValueType.FLOAT.name()).setDirection(1).setQualitative(false).setHidden(false).setUserManaged(false));
db.commit();
return metric;
}
Aggregations