Search in sources :

Example 56 with MetricDto

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);
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) WsTester(org.sonar.server.ws.WsTester) Test(org.junit.Test)

Example 57 with MetricDto

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();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 58 with MetricDto

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();
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 59 with MetricDto

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");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 60 with MetricDto

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");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Aggregations

MetricDto (org.sonar.db.metric.MetricDto)137 Test (org.junit.Test)83 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)61 ComponentDto (org.sonar.db.component.ComponentDto)49 SnapshotDto (org.sonar.db.component.SnapshotDto)33 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)26 DbSession (org.sonar.db.DbSession)11 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)11 CustomMeasureTesting.newCustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto)10 MeasureDto (org.sonar.db.measure.MeasureDto)9 OrganizationDto (org.sonar.db.organization.OrganizationDto)8 ProjectMeasures (org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)7 QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)6 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 WsTester (org.sonar.server.ws.WsTester)5 SearchWsResponse (org.sonarqube.ws.WsMeasures.SearchWsResponse)5 MeasureQuery (org.sonar.db.measure.MeasureQuery)3 UserDto (org.sonar.db.user.UserDto)3 WsMeasures (org.sonarqube.ws.WsMeasures)3 ComponentWsResponse (org.sonarqube.ws.WsMeasures.ComponentWsResponse)3