Search in sources :

Example 1 with QProfileChangeQuery

use of org.sonar.db.qualityprofile.QProfileChangeQuery in project sonarqube by SonarSource.

the class ChangelogAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
        QProfileChangeQuery query = new QProfileChangeQuery(profile.getKey());
        Date since = parseStartingDateOrDateTime(request.param(PARAM_SINCE));
        if (since != null) {
            query.setFromIncluded(since.getTime());
        }
        Date to = parseEndingDateOrDateTime(request.param(PARAM_TO));
        if (to != null) {
            query.setToExcluded(to.getTime());
        }
        int page = request.mandatoryParamAsInt(Param.PAGE);
        int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
        query.setPage(page, pageSize);
        ChangelogLoader.Changelog changelog = changelogLoader.load(dbSession, query);
        writeResponse(response.newJsonWriter(), page, pageSize, changelog);
    }
}
Also used : DbSession(org.sonar.db.DbSession) QProfileChangeQuery(org.sonar.db.qualityprofile.QProfileChangeQuery) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Date(java.util.Date)

Example 2 with QProfileChangeQuery

use of org.sonar.db.qualityprofile.QProfileChangeQuery in project sonarqube by SonarSource.

the class ChangelogLoaderTest method return_name_of_user.

@Test
public void return_name_of_user() {
    insertChange("C1", ActiveRuleChange.Type.ACTIVATED, A_DATE, A_USER_LOGIN, null);
    insertUser(A_USER_LOGIN, "Marcel");
    QProfileChangeQuery query = new QProfileChangeQuery(A_PROFILE_KEY);
    ChangelogLoader.Change change = underTest.load(dbSession, query).getChanges().get(0);
    assertThat(change.getUserLogin()).isEqualTo(A_USER_LOGIN);
    assertThat(change.getUserName()).isEqualTo("Marcel");
}
Also used : QProfileChangeQuery(org.sonar.db.qualityprofile.QProfileChangeQuery) Test(org.junit.Test)

Example 3 with QProfileChangeQuery

use of org.sonar.db.qualityprofile.QProfileChangeQuery in project sonarqube by SonarSource.

the class ChangelogLoaderTest method return_changes_in_reverse_chronological_order.

@Test
public void return_changes_in_reverse_chronological_order() {
    insertChange("C1", ActiveRuleChange.Type.ACTIVATED, A_DATE, A_USER_LOGIN, null);
    insertChange("C2", ActiveRuleChange.Type.DEACTIVATED, A_DATE + 10, "mazout", null);
    QProfileChangeQuery query = new QProfileChangeQuery(A_PROFILE_KEY);
    ChangelogLoader.Changelog changes = underTest.load(dbSession, query);
    assertThat(changes.getTotal()).isEqualTo(2);
    assertThat(changes.getChanges()).extracting(ChangelogLoader.Change::getKey).containsExactly("C2", "C1");
}
Also used : QProfileChangeQuery(org.sonar.db.qualityprofile.QProfileChangeQuery) Test(org.junit.Test)

Example 4 with QProfileChangeQuery

use of org.sonar.db.qualityprofile.QProfileChangeQuery in project sonarqube by SonarSource.

the class ChangelogLoaderTest method return_change_with_all_fields.

@Test
public void return_change_with_all_fields() {
    Map<String, String> data = ImmutableMap.of("ruleKey", A_RULE_KEY.toString(), "severity", "MINOR", "inheritance", ActiveRule.Inheritance.INHERITED.name(), "param_foo", "foo_value", "param_bar", "bar_value");
    insertChange("C1", ActiveRuleChange.Type.ACTIVATED, A_DATE, A_USER_LOGIN, data);
    QProfileChangeQuery query = new QProfileChangeQuery(A_PROFILE_KEY);
    ChangelogLoader.Change change = underTest.load(dbSession, query).getChanges().get(0);
    assertThat(change.getKey()).isEqualTo("C1");
    assertThat(change.getCreatedAt()).isEqualTo(A_DATE);
    assertThat(change.getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED.name());
    assertThat(change.getInheritance()).isEqualTo(ActiveRule.Inheritance.INHERITED.name());
    assertThat(change.getRuleKey()).isEqualTo(A_RULE_KEY);
    assertThat(change.getRuleName()).isNull();
    assertThat(change.getSeverity()).isEqualTo("MINOR");
    assertThat(change.getUserLogin()).isEqualTo(A_USER_LOGIN);
    assertThat(change.getUserName()).isNull();
    assertThat(change.getParams()).containsOnly(entry("foo", "foo_value"), entry("bar", "bar_value"));
}
Also used : QProfileChangeQuery(org.sonar.db.qualityprofile.QProfileChangeQuery) Test(org.junit.Test)

Example 5 with QProfileChangeQuery

use of org.sonar.db.qualityprofile.QProfileChangeQuery in project sonarqube by SonarSource.

the class ChangelogLoaderTest method return_name_of_rule.

@Test
public void return_name_of_rule() {
    Map<String, String> data = ImmutableMap.of("ruleKey", "java:S001");
    insertChange("C1", ActiveRuleChange.Type.ACTIVATED, A_DATE, A_USER_LOGIN, data);
    insertRule(A_RULE_KEY, "Potential NPE");
    QProfileChangeQuery query = new QProfileChangeQuery(A_PROFILE_KEY);
    ChangelogLoader.Change change = underTest.load(dbSession, query).getChanges().get(0);
    assertThat(change.getRuleKey()).isEqualTo(A_RULE_KEY);
    assertThat(change.getRuleName()).isEqualTo("Potential NPE");
}
Also used : QProfileChangeQuery(org.sonar.db.qualityprofile.QProfileChangeQuery) Test(org.junit.Test)

Aggregations

QProfileChangeQuery (org.sonar.db.qualityprofile.QProfileChangeQuery)7 Test (org.junit.Test)6 Date (java.util.Date)1 DbSession (org.sonar.db.DbSession)1 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)1