use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class CreateActionTest method update_existing_metric_when_custom_and_disabled.
@Test
public void update_existing_metric_when_custom_and_disabled() throws Exception {
MetricDto metricInDb = MetricTesting.newMetricDto().setKey(DEFAULT_KEY).setValueType(ValueType.BOOL.name()).setUserManaged(true).setEnabled(false);
dbClient.metricDao().insert(dbSession, metricInDb);
dbSession.commit();
WsTester.Result result = newRequest().setParam(PARAM_KEY, DEFAULT_KEY).setParam(PARAM_NAME, DEFAULT_NAME).setParam(PARAM_TYPE, DEFAULT_TYPE).setParam(PARAM_DESCRIPTION, DEFAULT_DESCRIPTION).setParam(PARAM_DOMAIN, DEFAULT_DOMAIN).execute();
result.assertJson(getClass(), "metric.json");
result.outputAsString().matches("\"id\"\\s*:\\s*\"" + metricInDb.getId() + "\"");
MetricDto metricAfterWs = dbClient.metricDao().selectByKey(dbSession, DEFAULT_KEY);
assertThat(metricAfterWs.getId()).isEqualTo(metricInDb.getId());
assertThat(metricAfterWs.getDomain()).isEqualTo(DEFAULT_DOMAIN);
assertThat(metricAfterWs.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
assertThat(metricAfterWs.getValueType()).isEqualTo(DEFAULT_TYPE);
assertThat(metricAfterWs.getShortName()).isEqualTo(DEFAULT_NAME);
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class CreateActionTest method insert_new_minimalist_metric.
@Test
public void insert_new_minimalist_metric() throws Exception {
newRequest().setParam(PARAM_KEY, DEFAULT_KEY).setParam(PARAM_NAME, DEFAULT_NAME).setParam(PARAM_TYPE, DEFAULT_TYPE).execute();
MetricDto metric = dbClient.metricDao().selectByKey(dbSession, DEFAULT_KEY);
assertThat(metric.getKey()).isEqualTo(DEFAULT_KEY);
assertThat(metric.getShortName()).isEqualTo(DEFAULT_NAME);
assertThat(metric.getValueType()).isEqualTo(DEFAULT_TYPE);
assertThat(metric.getDescription()).isNull();
assertThat(metric.getDomain()).isNull();
assertThat(metric.isUserManaged()).isTrue();
assertThat(metric.isEnabled()).isTrue();
assertThat(metric.getDirection()).isEqualTo(0);
assertThat(metric.isQualitative()).isFalse();
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class DeleteActionTest method do_not_delete_non_custom_metric.
@Test
public void do_not_delete_non_custom_metric() throws Exception {
metricDao.insert(dbSession, newCustomEnabledMetric(1).setUserManaged(false));
dbSession.commit();
newRequest().setParam("keys", "key-1").execute();
dbSession.commit();
MetricDto metric = metricDao.selectByKey(dbSession, "key-1");
assertThat(metric.isEnabled()).isTrue();
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class UpdateActionTest method update_all_fields.
@Test
public void update_all_fields() throws Exception {
int id = insertMetric(newDefaultMetric());
newRequest().setParam(PARAM_ID, String.valueOf(id)).setParam(PARAM_KEY, "another-key").setParam(PARAM_NAME, "another-name").setParam(PARAM_TYPE, ValueType.BOOL.name()).setParam(PARAM_DOMAIN, "another-domain").setParam(PARAM_DESCRIPTION, "another-description").execute();
dbSession.commit();
MetricDto result = dbClient.metricDao().selectById(dbSession, id);
assertThat(result.getKey()).isEqualTo("another-key");
assertThat(result.getShortName()).isEqualTo("another-name");
assertThat(result.getValueType()).isEqualTo(ValueType.BOOL.name());
assertThat(result.getDomain()).isEqualTo("another-domain");
assertThat(result.getDescription()).isEqualTo("another-description");
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class UpdateActionTest method update_one_field.
@Test
public void update_one_field() throws Exception {
int id = insertMetric(newDefaultMetric());
dbClient.customMeasureDao().insert(dbSession, newCustomMeasureDto().setMetricId(id));
dbSession.commit();
newRequest().setParam(PARAM_ID, String.valueOf(id)).setParam(PARAM_DESCRIPTION, "another-description").execute();
dbSession.commit();
MetricDto result = dbClient.metricDao().selectById(dbSession, id);
assertThat(result.getKey()).isEqualTo(DEFAULT_KEY);
assertThat(result.getShortName()).isEqualTo(DEFAULT_NAME);
assertThat(result.getValueType()).isEqualTo(DEFAULT_TYPE);
assertThat(result.getDomain()).isEqualTo(DEFAULT_DOMAIN);
assertThat(result.getDescription()).isEqualTo("another-description");
}
Aggregations