aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooBasicProfile.java26
-rw-r--r--tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java7
-rw-r--r--tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooBasicProfile.java27
-rw-r--r--tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java6
-rw-r--r--tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java17
5 files changed, 62 insertions, 21 deletions
diff --git a/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooBasicProfile.java b/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooBasicProfile.java
index 3a53e9293ff..73f54dc30f4 100644
--- a/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooBasicProfile.java
+++ b/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooBasicProfile.java
@@ -21,7 +21,9 @@ package org.sonar.foo.rule;
import org.sonar.api.profiles.ProfileDefinition;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RulePriority;
import org.sonar.api.utils.ValidationMessages;
import static org.sonar.api.rules.RulePriority.MAJOR;
@@ -30,12 +32,28 @@ import static org.sonar.foo.rule.FooRulesDefinition.FOO_REPOSITORY;
public class FooBasicProfile extends ProfileDefinition {
+ private final RuleFinder ruleFinder;
+
+ public FooBasicProfile(RuleFinder ruleFinder) {
+ this.ruleFinder = ruleFinder;
+ }
+
@Override
public RulesProfile createProfile(ValidationMessages validation) {
final RulesProfile profile = RulesProfile.create("Basic", KEY);
- profile.activateRule(Rule.create(FOO_REPOSITORY, "UnchangedRule"), MAJOR);
- profile.activateRule(Rule.create(FOO_REPOSITORY, "ChangedRule"), MAJOR);
- profile.activateRule(Rule.create(FOO_REPOSITORY, "RemovedRule"), MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "UnchangedRule", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "ChangedRule", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "ToBeDeactivatedRule", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "ToBeRemovedRule", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "RuleWithUnchangedParameter", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "RuleWithChangedParameter", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "RuleWithRemovedParameter", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "RuleWithAddedParameter", MAJOR);
return profile;
}
+
+ private ActiveRule activateRule(RulesProfile profile, String repo, String key, RulePriority severity) {
+ return profile.activateRule(ruleFinder.findByKey(repo, key), severity);
+ }
+
}
diff --git a/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java b/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java
index 7257dd72681..039cea9fd2b 100644
--- a/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java
+++ b/tests/plugins/foo-plugin-v1/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java
@@ -35,7 +35,12 @@ public class FooRulesDefinition implements RulesDefinition {
NewRepository repo = context.createRepository(FOO_REPOSITORY, Foo.KEY).setName("Foo");
createRule(repo, "UnchangedRule");
createRule(repo, "ChangedRule");
- createRule(repo, "RemovedRule");
+ createRule(repo, "ToBeDeactivatedRule");
+ createRule(repo, "ToBeRemovedRule");
+ createRule(repo, "RuleWithUnchangedParameter").createParam("unchanged").setDefaultValue("10");
+ createRule(repo, "RuleWithChangedParameter").createParam("toBeChanged").setDefaultValue("10");
+ createRule(repo, "RuleWithRemovedParameter").createParam("toBeRemoved").setDefaultValue("10");
+ createRule(repo, "RuleWithAddedParameter").createParam("added");
repo.done();
}
diff --git a/tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooBasicProfile.java b/tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooBasicProfile.java
index 1c2d051f7cf..aceb76331e2 100644
--- a/tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooBasicProfile.java
+++ b/tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooBasicProfile.java
@@ -21,7 +21,9 @@ package org.sonar.foo.rule;
import org.sonar.api.profiles.ProfileDefinition;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RulePriority;
import org.sonar.api.utils.ValidationMessages;
import static org.sonar.api.rules.RulePriority.MAJOR;
@@ -31,12 +33,29 @@ import static org.sonar.foo.rule.FooRulesDefinition.FOO_REPOSITORY;
public class FooBasicProfile extends ProfileDefinition {
+ private final RuleFinder ruleFinder;
+
+ public FooBasicProfile(RuleFinder ruleFinder) {
+ this.ruleFinder = ruleFinder;
+ }
+
@Override
public RulesProfile createProfile(ValidationMessages validation) {
final RulesProfile profile = RulesProfile.create("Basic", KEY);
- profile.activateRule(Rule.create(FOO_REPOSITORY, "UnchangedRule"), MAJOR);
- profile.activateRule(Rule.create(FOO_REPOSITORY, "ChangedRule"), MINOR);
- profile.activateRule(Rule.create(FOO_REPOSITORY, "NewRule"), MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "UnchangedRule", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "ChangedRule", MINOR);
+ activateRule(profile, FOO_REPOSITORY, "NewRule", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "RuleWithUnchangedParameter", MAJOR);
+ // Update of the default value of a parameter is not taken into account in quality profile as long as it's not also explicitly set in the quality profile
+ // TODO Remove the parameter value when SONAR_9475 will be fixed
+ activateRule(profile, FOO_REPOSITORY, "RuleWithChangedParameter", MAJOR).setParameter("toBeChanged", "20");
+ activateRule(profile, FOO_REPOSITORY, "RuleWithRemovedParameter", MAJOR);
+ activateRule(profile, FOO_REPOSITORY, "RuleWithAddedParameter", MAJOR);
return profile;
}
+
+ private ActiveRule activateRule(RulesProfile profile, String repo, String key, RulePriority severity) {
+ return profile.activateRule(ruleFinder.findByKey(repo, key), severity);
+ }
+
}
diff --git a/tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java b/tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java
index aacc2335262..a0ef0ccbdf7 100644
--- a/tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java
+++ b/tests/plugins/foo-plugin-v2/src/main/java/org/sonar/foo/rule/FooRulesDefinition.java
@@ -36,6 +36,12 @@ public class FooRulesDefinition implements RulesDefinition {
createRule(repo, "UnchangedRule");
createRule(repo, "ChangedRule");
createRule(repo, "NewRule");
+ createRule(repo, "ToBeDeactivatedRule");
+ createRule(repo, "RuleWithUnchangedParameter").createParam("unchanged").setDefaultValue("10");
+ // Update of the default value of a parameter is not taken into account in quality profile as long as it's not also explicitly set in the quality profile
+ createRule(repo, "RuleWithChangedParameter").createParam("toBeChanged").setDefaultValue("20");
+ createRule(repo, "RuleWithRemovedParameter");
+ createRule(repo, "RuleWithAddedParameter").createParam("added").setDefaultValue("10");
repo.done();
}
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java b/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java
index 4f287380171..7845f3ced14 100644
--- a/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java
@@ -70,8 +70,7 @@ public class BuiltInQualityProfilesNotificationTest {
.addPlugin(pluginArtifact("foo-plugin-v1"))
.setServerProperty("email.smtp_host.secured", "localhost")
.setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()))
- // .setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")// FIXME
- // remove web debugging
+ //.setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")// FIXME remove web debugging
.build();
orchestrator.start();
@@ -101,8 +100,7 @@ public class BuiltInQualityProfilesNotificationTest {
.addPlugin(pluginArtifact("foo-plugin-v1"))
.setServerProperty("email.smtp_host.secured", "localhost")
.setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()))
- // .setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")// FIXME
- // remove web debugging
+ //.setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")// FIXME remove web debugging
.build();
orchestrator.start();
@@ -139,6 +137,9 @@ public class BuiltInQualityProfilesNotificationTest {
.containsSequence(
"Built-in quality profiles have been updated:",
"\"Basic\" - Foo",
+ " 1 new rules",
+ " 3 rules have been updated",
+ " 1 rules removed",
"This is a good time to review your quality profiles and update them to benefit from the latest evolutions.")
.isEqualTo(messages.get(1).getMimeMessage().getContent().toString());
}
@@ -151,14 +152,6 @@ public class BuiltInQualityProfilesNotificationTest {
}
}
- private String getContent(MimeMessage mimeMessage1) {
- try {
- return mimeMessage1.getContent().toString();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
private String getAllRecipients(MimeMessage mimeMessage) {
try {
return mimeMessage.getHeader("To", null);