use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class CreateActionTest method create_custom_measure_on_a_sub_view.
@Test
public void create_custom_measure_on_a_sub_view() throws Exception {
String subViewUuid = "SUB_VIEW_UUID";
ComponentDto view = ComponentTesting.newView(db.organizations().insert());
dbClient.componentDao().insert(dbSession, view);
dbClient.componentDao().insert(dbSession, ComponentTesting.newSubView(view, subViewUuid, "SUB_VIEW_KEY"));
dbSession.commit();
MetricDto metric = insertMetric(BOOL);
userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, view.uuid());
newRequest().setParam(CreateAction.PARAM_PROJECT_ID, subViewUuid).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.getComponentUuid()).isEqualTo(subViewUuid);
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class DeleteActionTest method delete_associated_measures.
@Test
public void delete_associated_measures() throws Exception {
MetricDto metric = newCustomEnabledMetric(1);
metricDao.insert(dbSession, metric);
CustomMeasureDto customMeasure = CustomMeasureTesting.newCustomMeasureDto().setMetricId(metric.getId());
CustomMeasureDto undeletedCustomMeasure = CustomMeasureTesting.newCustomMeasureDto().setMetricId(metric.getId() + 1);
dbClient.customMeasureDao().insert(dbSession, customMeasure);
dbClient.customMeasureDao().insert(dbSession, undeletedCustomMeasure);
dbSession.commit();
newRequest().setParam("keys", "key-1").execute();
assertThat(dbClient.customMeasureDao().selectById(dbSession, customMeasure.getId())).isNull();
assertThat(dbClient.customMeasureDao().selectById(dbSession, undeletedCustomMeasure.getId())).isNotNull();
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class UpdateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
int id = request.mandatoryParamAsInt(PARAM_ID);
String value = request.param(PARAM_VALUE);
String description = request.param(PARAM_DESCRIPTION);
checkParameters(value, description);
try (DbSession dbSession = dbClient.openSession(true)) {
CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, id);
MetricDto metric = dbClient.metricDao().selectOrFailById(dbSession, customMeasure.getMetricId());
ComponentDto component = dbClient.componentDao().selectOrFailByUuid(dbSession, customMeasure.getComponentUuid());
checkPermissions(userSession, component);
UserDto user = dbClient.userDao().selectOrFailByLogin(dbSession, userSession.getLogin());
setValue(customMeasure, value, metric);
setDescription(customMeasure, description);
customMeasure.setUserLogin(user.getLogin());
customMeasure.setUpdatedAt(system.now());
dbClient.customMeasureDao().update(dbSession, customMeasure);
dbSession.commit();
JsonWriter json = response.newJsonWriter();
customMeasureJsonWriter.write(json, customMeasure, metric, component, user, true, CustomMeasureJsonWriter.OPTIONAL_FIELDS);
json.close();
}
}
Aggregations