Search in sources :

Example 1 with CompareToSonarWay

use of org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay in project sonarqube by SonarSource.

the class ShowAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = qProfileWsSupport.getProfile(dbSession, QProfileReference.fromKey(request.mandatoryParam(PARAM_KEY)));
        boolean isDefault = dbClient.defaultQProfileDao().isDefault(dbSession, profile.getKee());
        ActiveRuleCountQuery.Builder builder = ActiveRuleCountQuery.builder();
        long activeRuleCount = countActiveRulesByQuery(dbSession, profile, builder);
        long deprecatedActiveRuleCount = countActiveRulesByQuery(dbSession, profile, builder.setRuleStatus(DEPRECATED));
        long projectCount = countProjectsByProfiles(dbSession, profile);
        CompareToSonarWay compareToSonarWay = getSonarWay(request, dbSession, profile);
        writeProtobuf(buildResponse(profile, isDefault, getLanguage(profile), activeRuleCount, deprecatedActiveRuleCount, projectCount, compareToSonarWay), request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ActiveRuleCountQuery(org.sonar.db.qualityprofile.ActiveRuleCountQuery) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay)

Example 2 with CompareToSonarWay

use of org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay in project sonarqube by SonarSource.

the class ShowActionTest method compare_to_sonar_way_profile.

@Test
public void compare_to_sonar_way_profile() {
    QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
    RuleDefinitionDto sonarWayRule1 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
    RuleDefinitionDto sonarWayRule2 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
    RuleDefinitionDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
    RuleDefinitionDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
    RuleDefinitionDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
    db.qualityProfiles().activateRule(profile, commonRule);
    db.qualityProfiles().activateRule(profile, profileRule1);
    db.qualityProfiles().activateRule(profile, profileRule2);
    db.qualityProfiles().activateRule(profile, profileRule3);
    db.qualityProfiles().activateRule(sonarWayProfile, commonRule);
    db.qualityProfiles().activateRule(sonarWayProfile, sonarWayRule1);
    db.qualityProfiles().activateRule(sonarWayProfile, sonarWayRule2);
    ruleIndexer.indexAll();
    activeRuleIndexer.indexAll();
    CompareToSonarWay result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "true")).getCompareToSonarWay();
    assertThat(result).extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName, CompareToSonarWay::getMissingRuleCount).containsExactly(sonarWayProfile.getKee(), sonarWayProfile.getName(), 2L);
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) IntStream.range(java.util.stream.IntStream.range) EsTester(org.sonar.server.es.EsTester) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) DateUtils(org.sonar.api.utils.DateUtils) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_COMPARE_TO_SONAR_WAY(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY) ShowResponse(org.sonarqube.ws.Qualityprofiles.ShowResponse) MediaTypes(org.sonarqube.ws.MediaTypes) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Language(org.sonar.api.resources.Language) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) QualityProfile(org.sonarqube.ws.Qualityprofiles.ShowResponse.QualityProfile) System2(org.sonar.api.utils.System2) LanguageTesting.newLanguage(org.sonar.server.language.LanguageTesting.newLanguage) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) RuleIndex(org.sonar.server.rule.index.RuleIndex) WsActionTester(org.sonar.server.ws.WsActionTester) DEPRECATED(org.sonar.api.rule.RuleStatus.DEPRECATED) NotFoundException(org.sonar.server.exceptions.NotFoundException) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay) Rule(org.junit.Rule) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) PARAM_KEY(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay) Test(org.junit.Test)

Example 3 with CompareToSonarWay

use of org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay in project sonarqube by SonarSource.

the class ShowActionTest method compare_to_sonar_way_profile_when_same_active_rules.

@Test
public void compare_to_sonar_way_profile_when_same_active_rules() {
    QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
    db.qualityProfiles().activateRule(profile, commonRule);
    db.qualityProfiles().activateRule(sonarWayProfile, commonRule);
    ruleIndexer.indexAll();
    activeRuleIndexer.indexAll();
    CompareToSonarWay result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "true")).getCompareToSonarWay();
    assertThat(result).extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName, CompareToSonarWay::getMissingRuleCount).containsExactly(sonarWayProfile.getKee(), sonarWayProfile.getName(), 0L);
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) IntStream.range(java.util.stream.IntStream.range) EsTester(org.sonar.server.es.EsTester) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) DateUtils(org.sonar.api.utils.DateUtils) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_COMPARE_TO_SONAR_WAY(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY) ShowResponse(org.sonarqube.ws.Qualityprofiles.ShowResponse) MediaTypes(org.sonarqube.ws.MediaTypes) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Language(org.sonar.api.resources.Language) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) QualityProfile(org.sonarqube.ws.Qualityprofiles.ShowResponse.QualityProfile) System2(org.sonar.api.utils.System2) LanguageTesting.newLanguage(org.sonar.server.language.LanguageTesting.newLanguage) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) RuleIndex(org.sonar.server.rule.index.RuleIndex) WsActionTester(org.sonar.server.ws.WsActionTester) DEPRECATED(org.sonar.api.rule.RuleStatus.DEPRECATED) NotFoundException(org.sonar.server.exceptions.NotFoundException) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay) Rule(org.junit.Rule) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) PARAM_KEY(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay) Test(org.junit.Test)

Example 4 with CompareToSonarWay

use of org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay in project sonarqube by SonarSource.

the class ShowActionTest method compare_to_sonarqube_way_profile.

@Test
public void compare_to_sonarqube_way_profile() {
    QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("SonarQube way").setLanguage(XOO1.getKey()));
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    CompareToSonarWay result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "true")).getCompareToSonarWay();
    assertThat(result).extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName).containsExactly(sonarWayProfile.getKee(), sonarWayProfile.getName());
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay) Test(org.junit.Test)

Example 5 with CompareToSonarWay

use of org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay in project sonarqube by SonarSource.

the class ShowActionTest method compare_to_sonar_way_over_sonarqube_way.

@Test
public void compare_to_sonar_way_over_sonarqube_way() {
    QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
    QProfileDto sonarQubeWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("SonarQube way").setLanguage(XOO1.getKey()));
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    CompareToSonarWay result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "true")).getCompareToSonarWay();
    assertThat(result).extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName).containsExactly(sonarWayProfile.getKee(), sonarWayProfile.getName());
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay) Test(org.junit.Test)

Aggregations

QProfileDto (org.sonar.db.qualityprofile.QProfileDto)5 CompareToSonarWay (org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay)5 Test (org.junit.Test)4 IntStream.range (java.util.stream.IntStream.range)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Rule (org.junit.Rule)2 Language (org.sonar.api.resources.Language)2 Languages (org.sonar.api.resources.Languages)2 DEPRECATED (org.sonar.api.rule.RuleStatus.DEPRECATED)2 WebService (org.sonar.api.server.ws.WebService)2 DateUtils (org.sonar.api.utils.DateUtils)2 DateUtils.parseDateTime (org.sonar.api.utils.DateUtils.parseDateTime)2 System2 (org.sonar.api.utils.System2)2 DbTester (org.sonar.db.DbTester)2 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)2 UserDto (org.sonar.db.user.UserDto)2 EsTester (org.sonar.server.es.EsTester)2 NotFoundException (org.sonar.server.exceptions.NotFoundException)2 LanguageTesting.newLanguage (org.sonar.server.language.LanguageTesting.newLanguage)2