Search in sources :

Example 1 with QProfileRef

use of org.sonar.server.qualityprofile.QProfileRef in project sonarqube by SonarSource.

the class QProfileRefTest method create_name_ref_from_ws_request.

@Test
public void create_name_ref_from_ws_request() {
    SimpleGetRequest req = new SimpleGetRequest();
    req.setParam("language", "js");
    req.setParam("profileName", "Sonar way");
    QProfileRef ref = QProfileRef.from(req);
    assertThat(ref.getLanguage()).isEqualTo("js");
    assertThat(ref.getName()).isEqualTo("Sonar way");
}
Also used : SimpleGetRequest(org.sonar.api.server.ws.internal.SimpleGetRequest) QProfileRef(org.sonar.server.qualityprofile.QProfileRef) Test(org.junit.Test)

Example 2 with QProfileRef

use of org.sonar.server.qualityprofile.QProfileRef in project sonarqube by SonarSource.

the class QProfileRefTest method test_equals_and_hashCode_of_key_ref.

@Test
public void test_equals_and_hashCode_of_key_ref() {
    QProfileRef key1 = QProfileRef.fromKey("one");
    QProfileRef key1bis = QProfileRef.fromKey("one");
    QProfileRef key2 = QProfileRef.fromKey("two");
    QProfileRef name = QProfileRef.fromName("js", "one");
    assertThat(key1.equals(key1)).isTrue();
    assertThat(key1.equals(key1bis)).isTrue();
    assertThat(key1.equals(key2)).isFalse();
    assertThat(key1.equals(name)).isFalse();
    assertThat(key1.hashCode()).isEqualTo(key1.hashCode());
    assertThat(key1.hashCode()).isEqualTo(key1bis.hashCode());
}
Also used : QProfileRef(org.sonar.server.qualityprofile.QProfileRef) Test(org.junit.Test)

Example 3 with QProfileRef

use of org.sonar.server.qualityprofile.QProfileRef in project sonarqube by SonarSource.

the class QProfileRefTest method create_ref_by_key.

@Test
public void create_ref_by_key() {
    QProfileRef ref = QProfileRef.fromKey("foo");
    assertThat(ref.hasKey()).isTrue();
    assertThat(ref.getKey()).isEqualTo("foo");
}
Also used : QProfileRef(org.sonar.server.qualityprofile.QProfileRef) Test(org.junit.Test)

Example 4 with QProfileRef

use of org.sonar.server.qualityprofile.QProfileRef in project sonarqube by SonarSource.

the class QProfileRefTest method getKey_throws_ISE_if_name_ref.

@Test
public void getKey_throws_ISE_if_name_ref() {
    QProfileRef ref = QProfileRef.fromName("js", "Sonar way");
    expectedException.expect(IllegalStateException.class);
    ref.getKey();
}
Also used : QProfileRef(org.sonar.server.qualityprofile.QProfileRef) Test(org.junit.Test)

Example 5 with QProfileRef

use of org.sonar.server.qualityprofile.QProfileRef in project sonarqube by SonarSource.

the class ChangeParentAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    qProfileWsSupport.checkQProfileAdminPermission();
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
        String parentKey = request.param(PARAM_PARENT_KEY);
        String parentName = request.param(PARAM_PARENT_NAME);
        if (isEmpty(parentKey) && isEmpty(parentName)) {
            ruleActivator.setParent(dbSession, profile.getKey(), null);
        } else {
            QProfileRef parentRef = QProfileRef.from(parentKey, request.param(QProfileRef.PARAM_LANGUAGE), parentName);
            QualityProfileDto parent = profileFactory.find(dbSession, parentRef);
            ruleActivator.setParent(dbSession, profile.getKey(), parent.getKey());
        }
        response.noContent();
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) QProfileRef(org.sonar.server.qualityprofile.QProfileRef)

Aggregations

QProfileRef (org.sonar.server.qualityprofile.QProfileRef)10 Test (org.junit.Test)9 SimpleGetRequest (org.sonar.api.server.ws.internal.SimpleGetRequest)2 DbSession (org.sonar.db.DbSession)1 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)1