]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9482 Add IT for WS api/qualityprofiles/show
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 29 Jun 2017 13:51:28 +0000 (15:51 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 4 Jul 2017 14:29:36 +0000 (16:29 +0200)
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2BasicProfile.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2SonarWayProfile.java [new file with mode: 0644]
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooBasicProfile.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooSonarWayProfile.java [new file with mode: 0644]
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java
tests/src/test/java/org/sonarqube/tests/Category6Suite.java
tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesTest.java
tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesWsTest.java [new file with mode: 0644]

index eee749572bed587b0107353364d6774e1cbaaf6f..a61386c233fab73531552ffdf5ea9896845d9d29 100644 (file)
@@ -58,12 +58,14 @@ import org.sonar.xoo.rule.OneVulnerabilityIssuePerModuleSensor;
 import org.sonar.xoo.rule.RandomAccessSensor;
 import org.sonar.xoo.rule.SaveDataTwiceSensor;
 import org.sonar.xoo.rule.Xoo2BasicProfile;
+import org.sonar.xoo.rule.Xoo2SonarWayProfile;
 import org.sonar.xoo.rule.XooBasicProfile;
 import org.sonar.xoo.rule.XooEmptyProfile;
 import org.sonar.xoo.rule.XooFakeExporter;
 import org.sonar.xoo.rule.XooFakeImporter;
 import org.sonar.xoo.rule.XooFakeImporterWithMessages;
 import org.sonar.xoo.rule.XooRulesDefinition;
+import org.sonar.xoo.rule.XooSonarWayProfile;
 import org.sonar.xoo.scm.XooBlameCommand;
 import org.sonar.xoo.scm.XooScmProvider;
 import org.sonar.xoo.test.CoveragePerTestSensor;
@@ -92,7 +94,9 @@ public class XooPlugin implements Plugin {
       Xoo.class,
       Xoo2.class,
       XooRulesDefinition.class,
+      XooSonarWayProfile.class,
       XooBasicProfile.class,
+      Xoo2SonarWayProfile.class,
       Xoo2BasicProfile.class,
       XooEmptyProfile.class,
 
index ae25fddc95e878177410b73d0e186da5f48962d4..901bb18dfb15b711400b441ac907526bac01f397 100644 (file)
  */
 package org.sonar.xoo.rule;
 
-import org.sonar.xoo.Xoo2;
-
 import org.sonar.api.profiles.ProfileDefinition;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RulePriority;
 import org.sonar.api.utils.ValidationMessages;
+import org.sonar.xoo.Xoo2;
 
 public class Xoo2BasicProfile extends ProfileDefinition {
 
   @Override
   public RulesProfile createProfile(ValidationMessages messages) {
     RulesProfile profile = RulesProfile.create("Basic", Xoo2.KEY);
+    profile.setDefaultProfile(true);
 
     // so UGLY
     profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2SonarWayProfile.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2SonarWayProfile.java
new file mode 100644 (file)
index 0000000..c468890
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.sonar.xoo.rule;
+
+import org.sonar.api.profiles.ProfileDefinition;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.api.utils.ValidationMessages;
+import org.sonar.xoo.Xoo2;
+
+public class Xoo2SonarWayProfile extends ProfileDefinition {
+
+  @Override
+  public RulesProfile createProfile(ValidationMessages messages) {
+    RulesProfile profile = RulesProfile.create("Sonar way", Xoo2.KEY);
+
+    profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
+    profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.MINOR);
+
+    return profile;
+  }
+}
index a1fdf3dc3133ec369283e31ade84637a37f9c191..22c9ac75b308b6e20207b3c3b96a6ac49d2d31ee 100644 (file)
@@ -31,6 +31,7 @@ public class XooBasicProfile extends ProfileDefinition {
   @Override
   public RulesProfile createProfile(ValidationMessages validation) {
     final RulesProfile profile = RulesProfile.create("Basic", Xoo.KEY);
+    profile.setDefaultProfile(true);
 
     profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
 
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooSonarWayProfile.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooSonarWayProfile.java
new file mode 100644 (file)
index 0000000..47317c9
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.sonar.xoo.rule;
+
+import org.sonar.api.profiles.ProfileDefinition;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.api.utils.ValidationMessages;
+import org.sonar.xoo.Xoo;
+
+public class XooSonarWayProfile extends ProfileDefinition {
+
+  @Override
+  public RulesProfile createProfile(ValidationMessages validation) {
+    final RulesProfile profile = RulesProfile.create("Sonar way", Xoo.KEY);
+
+    profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
+    profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.INFO);
+    profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerFileSensor.RULE_KEY), RulePriority.CRITICAL);
+
+    return profile;
+  }
+}
index 7bfcd00d4eab8cd05079a5b3b67c4d7ff7769d25..94fdc279df15d57a6f2de8bab6a52e75957d25da 100644 (file)
@@ -36,7 +36,7 @@ public class XooPluginTest {
     SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4"));
     Plugin.Context context = new Plugin.Context(runtime);
     new XooPlugin().define(context);
-    assertThat(context.getExtensions()).hasSize(44).doesNotContain(CpdTokenizerSensor.class);
+    assertThat(context.getExtensions()).hasSize(46).doesNotContain(CpdTokenizerSensor.class);
   }
 
   @Test
@@ -44,6 +44,6 @@ public class XooPluginTest {
     SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);
     Plugin.Context context = new Plugin.Context(runtime);
     new XooPlugin().define(context);
-    assertThat(context.getExtensions()).hasSize(47).contains(CpdTokenizerSensor.class);
+    assertThat(context.getExtensions()).hasSize(49).contains(CpdTokenizerSensor.class);
   }
 }
index 9698394555548254540bd43d8443fed4897d3fd8..7ba1461f70223ad0e259e887db757ca6ca5706a0 100644 (file)
@@ -20,6 +20,9 @@
 package org.sonarqube.tests;
 
 import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
 import org.sonarqube.tests.issue.IssueTagsTest;
 import org.sonarqube.tests.issue.OrganizationIssueAssignTest;
 import org.sonarqube.tests.organization.BillingTest;
@@ -33,11 +36,9 @@ import org.sonarqube.tests.projectSearch.SearchProjectsTest;
 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.ui.OrganizationUiExtensionsTest;
 import org.sonarqube.tests.user.OrganizationIdentityProviderTest;
-import org.junit.ClassRule;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
 
 import static util.ItUtils.pluginArtifact;
 import static util.ItUtils.xooPlugin;
@@ -57,6 +58,7 @@ import static util.ItUtils.xooPlugin;
   OrganizationUiExtensionsTest.class,
   PersonalOrganizationTest.class,
   BuiltInQualityProfilesTest.class,
+  QualityProfilesWsTest.class,
   CustomQualityProfilesTest.class,
   BillingTest.class,
   IssueTagsTest.class,
index 82719d800f3ea13039af13896299d747933b7cd2..286b412d1fa8184828af8783ad1e49663c7d5bdf 100644 (file)
 package org.sonarqube.tests.qualityProfile;
 
 import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category6Suite;
 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.Session;
 import org.sonarqube.tests.Tester;
 import org.sonarqube.ws.Organizations.Organization;
@@ -61,8 +61,10 @@ public class BuiltInQualityProfilesTest {
       .extracting(QualityProfile::getName, QualityProfile::getLanguage, QualityProfile::getIsBuiltIn, QualityProfile::getIsDefault)
       .containsExactlyInAnyOrder(
         tuple("Basic", "xoo", true, true),
+        tuple("Sonar way", "xoo", true, false),
         tuple("empty", "xoo", true, false),
-        tuple("Basic", "xoo2", true, true));
+        tuple("Basic", "xoo2", true, true),
+        tuple("Sonar way", "xoo2", true, false));
   }
 
   @Test
@@ -73,8 +75,10 @@ public class BuiltInQualityProfilesTest {
       .extracting(QualityProfile::getOrganization, QualityProfile::getName, QualityProfile::getLanguage, QualityProfile::getIsBuiltIn, QualityProfile::getIsDefault)
       .containsExactlyInAnyOrder(
         tuple("default-organization", "Basic", "xoo", true, true),
+        tuple("default-organization", "Sonar way", "xoo", true, false),
         tuple("default-organization", "empty", "xoo", true, false),
-        tuple("default-organization", "Basic", "xoo2", true, true));
+        tuple("default-organization", "Basic", "xoo2", true, true),
+        tuple("default-organization", "Sonar way", "xoo2", true, false));
   }
 
   @Test
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesWsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityProfile/QualityProfilesWsTest.java
new file mode 100644 (file)
index 0000000..8cef4ef
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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.qualityProfile;
+
+import com.sonar.orchestrator.Orchestrator;
+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.QualityProfiles.ShowResponse;
+import org.sonarqube.ws.QualityProfiles.ShowResponse.CompareToSonarWay;
+import org.sonarqube.ws.QualityProfiles.ShowResponse.QualityProfile;
+import org.sonarqube.ws.client.qualityprofile.SearchWsRequest;
+import org.sonarqube.ws.client.qualityprofile.ShowRequest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class QualityProfilesWsTest {
+  private static final String RULE_ONE_BUG_PER_LINE = "xoo:OneBugIssuePerLine";
+  private static final String RULE_ONE_ISSUE_PER_LINE = "xoo:OneIssuePerLine";
+
+  @ClassRule
+  public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+
+  @Rule
+  public Tester tester = new Tester(orchestrator);
+
+  @Test
+  public void show() {
+    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);
+
+    ShowResponse result = tester.qProfiles().service().show(new ShowRequest().setProfile(xooProfile.getKey()));
+
+    assertThat(result.getProfile())
+      .extracting(QualityProfile::getName, QualityProfile::getLanguage, QualityProfile::getIsBuiltIn, QualityProfile::getIsDefault,
+        QualityProfile::getActiveRuleCount, QualityProfile::getActiveDeprecatedRuleCount)
+      .containsExactly(xooProfile.getName(), xooProfile.getLanguage(), false, false, 2L, 0L);
+  }
+
+  @Test
+  public void show_with_sonar_way_comparison() {
+    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());
+
+    CompareToSonarWay result = tester.qProfiles().service().show(new ShowRequest()
+      .setProfile(xooProfile.getKey())
+      .setCompareToSonarWay(true)).getCompareToSonarWay();
+
+    assertThat(result)
+      .extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName, CompareToSonarWay::getMissingRuleCount)
+      .containsExactly(sonarWay.getKey(), sonarWay.getName(), 2L);
+  }
+
+  private SearchWsResponse.QualityProfile getProfile(Organization organization, Predicate<SearchWsResponse.QualityProfile> filter) {
+    return tester.qProfiles().service().search(new SearchWsRequest()
+      .setOrganizationKey(organization.getKey())).getProfilesList()
+      .stream()
+      .filter(filter)
+      .findAny().orElseThrow(IllegalStateException::new);
+  }
+}