@Test
public void use_best_value_for_rating() {
ComponentDto project = db.components().insertPrivateProject();
userSession.anonymous().addProjectPermission(UserRole.USER, project);
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
.setPeriodMode("previous_version")
.setPeriodParam("1.0-SNAPSHOT"));
ComponentDto directory = newDirectory(project, "directory-uuid", "path/to/directory").setName("directory-1");
db.components().insertComponent(directory);
ComponentDto file = newFileDto(directory, null, "file-uuid").setName("file-1");
db.components().insertComponent(file);
MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDto()
.setKey(NEW_SECURITY_RATING_KEY)
.setOptimizedBestValue(true)
.setBestValue(1d)
.setValueType(RATING.name()));
db.commit();
db.measures().insertLiveMeasure(directory, metric, m -> m.setVariation(2d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, project.getKey())
.setParam(PARAM_METRIC_KEYS, NEW_SECURITY_RATING_KEY)
.setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
.executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getComponentsList().get(0).getMeasuresList().get(0).getPeriods().getPeriodsValue(0).getValue()).isEqualTo("2.0");
assertThat(response.getComponentsList().get(1).getMeasuresList().get(0).getPeriods().getPeriodsValue(0).getValue()).isEqualTo("1.0");
}