diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-06-30 10:41:56 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-07-04 16:29:36 +0200 |
commit | 5477e21cb5f5329739e5e42c2cbcfbf79174e10f (patch) | |
tree | e2675c729a2a8af90f4b8c277b5239528e79464b /tests/src | |
parent | 323bede55a00b3b6e180b3b8951aa63b639bc308 (diff) | |
download | sonarqube-5477e21cb5f5329739e5e42c2cbcfbf79174e10f.tar.gz sonarqube-5477e21cb5f5329739e5e42c2cbcfbf79174e10f.zip |
SONAR-9483 Add IT on "compare_to_profile" in rules search ws
Diffstat (limited to 'tests/src')
3 files changed, 119 insertions, 1 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java index 7ba1461f702..eae3e358b8a 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java @@ -37,6 +37,7 @@ import org.sonarqube.tests.qualityProfile.BuiltInQualityProfilesTest; import org.sonarqube.tests.qualityProfile.CustomQualityProfilesTest; import org.sonarqube.tests.qualityProfile.OrganizationQualityProfilesUiTest; import org.sonarqube.tests.qualityProfile.QualityProfilesWsTest; +import org.sonarqube.tests.rule.RulesWsTest; import org.sonarqube.tests.ui.OrganizationUiExtensionsTest; import org.sonarqube.tests.user.OrganizationIdentityProviderTest; @@ -63,7 +64,8 @@ import static util.ItUtils.xooPlugin; BillingTest.class, IssueTagsTest.class, LeakProjectsPageTest.class, - SearchProjectsTest.class + SearchProjectsTest.class, + RulesWsTest.class }) public class Category6Suite { diff --git a/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesWsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesWsTest.java index 8cef4efa64c..ed468a40874 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesWsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesWsTest.java @@ -32,6 +32,7 @@ import org.sonarqube.ws.QualityProfiles.SearchWsResponse; import org.sonarqube.ws.QualityProfiles.ShowResponse; import org.sonarqube.ws.QualityProfiles.ShowResponse.CompareToSonarWay; import org.sonarqube.ws.QualityProfiles.ShowResponse.QualityProfile; +import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.qualityprofile.SearchWsRequest; import org.sonarqube.ws.client.qualityprofile.ShowRequest; @@ -79,6 +80,29 @@ public class QualityProfilesWsTest { .containsExactly(sonarWay.getKey(), sonarWay.getName(), 2L); } + @Test + public void bulk_activate_missing_rules_from_sonar_way_profile() { + Organization org = tester.organizations().generate(); + CreateWsResponse.QualityProfile xooProfile = tester.qProfiles().createXooProfile(org); + tester.qProfiles().activateRule(xooProfile, RULE_ONE_BUG_PER_LINE); + tester.qProfiles().activateRule(xooProfile, RULE_ONE_ISSUE_PER_LINE); + SearchWsResponse.QualityProfile sonarWay = getProfile(org, p -> "Sonar way".equals(p.getName()) && "xoo".equals(p.getLanguage()) && p.getIsBuiltIn()); + + // Bulk activate missing rules from the Sonar way profile + tester.wsClient().wsConnector().call(new PostRequest("api/qualityprofiles/activate_rules") + .setParam("targetProfile", xooProfile.getKey()) + .setParam("qprofile", xooProfile.getKey()) + .setParam("activation", "false") + .setParam("compareToProfile", sonarWay.getKey())).failIfNotSuccessful(); + + // Check that the profile has no missing rule from the Sonar way profile + assertThat(tester.qProfiles().service().show(new ShowRequest() + .setProfile(xooProfile.getKey()) + .setCompareToSonarWay(true)).getCompareToSonarWay()) + .extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName, CompareToSonarWay::getMissingRuleCount) + .containsExactly(sonarWay.getKey(), sonarWay.getName(), 0L); + } + private SearchWsResponse.QualityProfile getProfile(Organization organization, Predicate<SearchWsResponse.QualityProfile> filter) { return tester.qProfiles().service().search(new SearchWsRequest() .setOrganizationKey(organization.getKey())).getProfilesList() diff --git a/tests/src/test/java/org/sonarqube/tests/rule/RulesWsTest.java b/tests/src/test/java/org/sonarqube/tests/rule/RulesWsTest.java new file mode 100644 index 00000000000..3b4d1482b94 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/rule/RulesWsTest.java @@ -0,0 +1,92 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarqube.tests.rule; + +import com.sonar.orchestrator.Orchestrator; +import java.util.List; +import java.util.function.Predicate; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.tests.Category6Suite; +import org.sonarqube.tests.Tester; +import org.sonarqube.ws.Organizations.Organization; +import org.sonarqube.ws.QualityProfiles.CreateWsResponse; +import org.sonarqube.ws.QualityProfiles.SearchWsResponse; +import org.sonarqube.ws.Rules; +import org.sonarqube.ws.client.rule.SearchWsRequest; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RulesWsTest { + + private static final String RULE_HAS_TAG = "xoo:HasTag"; + private static final String RULE_ONE_ISSUE_PER_LINE = "xoo:OneIssuePerLine"; + private static final String RULE_ONE_ISSUE_PER_FILE = "xoo:OneIssuePerFile"; + private static final String RULE_ONE_BUG_PER_LINE = "xoo:OneBugIssuePerLine"; + private static final String PROFILE_SONAR_WAY = "Sonar way"; + private static final String LANGUAGE_XOO = "xoo"; + + @ClassRule + public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator); + + @Test + public void search_activated_rules() { + Organization org = tester.organizations().generate(); + SearchWsResponse.QualityProfile sonarWay = getProfile(org, p -> PROFILE_SONAR_WAY.equals(p.getName()) && LANGUAGE_XOO.equals(p.getLanguage()) && p.getIsBuiltIn()); + + List<Rules.Rule> result = tester.wsClient().rules().search(new SearchWsRequest().setQProfile(sonarWay.getKey()).setActivation(true)) + .getRulesList(); + + assertThat(result) + .extracting(Rules.Rule::getKey) + .containsExactlyInAnyOrder(RULE_HAS_TAG, RULE_ONE_ISSUE_PER_LINE, RULE_ONE_ISSUE_PER_FILE); + } + + @Test + public void search_sonar_way_rules_not_activated() { + Organization org = tester.organizations().generate(); + CreateWsResponse.QualityProfile xooProfile = tester.qProfiles().createXooProfile(org); + tester.qProfiles().activateRule(xooProfile, RULE_ONE_BUG_PER_LINE); + tester.qProfiles().activateRule(xooProfile, RULE_ONE_ISSUE_PER_LINE); + SearchWsResponse.QualityProfile sonarWay = getProfile(org, p -> PROFILE_SONAR_WAY.equals(p.getName()) && LANGUAGE_XOO.equals(p.getLanguage()) && p.getIsBuiltIn()); + + List<Rules.Rule> result = tester.wsClient().rules().search(new SearchWsRequest() + .setQProfile(xooProfile.getKey()) + .setActivation(false) + .setCompareToProfile(sonarWay.getKey())) + .getRulesList(); + + assertThat(result) + .extracting(Rules.Rule::getKey) + .containsExactlyInAnyOrder(RULE_HAS_TAG, RULE_ONE_ISSUE_PER_FILE); + } + + private SearchWsResponse.QualityProfile getProfile(Organization organization, Predicate<SearchWsResponse.QualityProfile> filter) { + return tester.qProfiles().service().search(new org.sonarqube.ws.client.qualityprofile.SearchWsRequest() + .setOrganizationKey(organization.getKey())).getProfilesList() + .stream() + .filter(filter) + .findAny().orElseThrow(IllegalStateException::new); + } +} |