Search in sources :

Example 1 with ShowResponse

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

the class ShowActionTest method statistics.

@Test
public void statistics() {
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    // Active rules
    range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition()).forEach(r -> db.qualityProfiles().activateRule(profile, r));
    // Deprecated rules
    range(0, 3).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey()).setStatus(DEPRECATED)).getDefinition()).forEach(r -> db.qualityProfiles().activateRule(profile, r));
    // Projects
    range(0, 7).mapToObj(i -> db.components().insertPrivateProjectDto()).forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
    ShowResponse result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()));
    assertThat(result.getProfile()).extracting(QualityProfile::getActiveRuleCount, QualityProfile::getActiveDeprecatedRuleCount, QualityProfile::getProjectCount).containsExactly(13L, 3L, 7L);
}
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) ShowResponse(org.sonarqube.ws.Qualityprofiles.ShowResponse) Test(org.junit.Test)

Example 2 with ShowResponse

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

the class ShowActionTest method no_comparison_when_profile_is_built_in.

@Test
public void no_comparison_when_profile_is_built_in() {
    QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
    QProfileDto anotherBuiltInProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setLanguage(XOO1.getKey()));
    ShowResponse result = call(ws.newRequest().setParam(PARAM_KEY, anotherBuiltInProfile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"));
    assertThat(result.hasCompareToSonarWay()).isFalse();
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ShowResponse(org.sonarqube.ws.Qualityprofiles.ShowResponse) Test(org.junit.Test)

Example 3 with ShowResponse

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

the class ShowActionTest method non_default_profile.

@Test
public void non_default_profile() {
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    QProfileDto defaultProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    db.qualityProfiles().setAsDefault(defaultProfile);
    ShowResponse result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()));
    assertThat(result.getProfile().getIsDefault()).isFalse();
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ShowResponse(org.sonarqube.ws.Qualityprofiles.ShowResponse) Test(org.junit.Test)

Example 4 with ShowResponse

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

the class ShowActionTest method no_comparison_if_sonar_way_is_not_built_in.

@Test
public void no_comparison_if_sonar_way_is_not_built_in() {
    QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(false).setName("Sonar way").setLanguage(XOO1.getKey()));
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    ShowResponse result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"));
    assertThat(result.hasCompareToSonarWay()).isFalse();
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ShowResponse(org.sonarqube.ws.Qualityprofiles.ShowResponse) Test(org.junit.Test)

Example 5 with ShowResponse

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

the class ShowActionTest method no_comparison_when_param_is_false.

@Test
public void no_comparison_when_param_is_false() {
    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()));
    ShowResponse result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "false"));
    assertThat(result.hasCompareToSonarWay()).isFalse();
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ShowResponse(org.sonarqube.ws.Qualityprofiles.ShowResponse) Test(org.junit.Test)

Aggregations

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