From 73de53243b93e598098fc7a68a7cbf6128c2f88c Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 24 Mar 2016 16:05:28 +0100 Subject: [PATCH] SONAR-7470 Drop ability to manage manual rules from WS --- .../rule/{NewRule.java => NewCustomRule.java} | 57 ++--- .../sonar/server/rule/RubyRuleService.java | 30 +-- .../org/sonar/server/rule/RuleCreator.java | 73 +----- .../org/sonar/server/rule/RuleDeleter.java | 5 +- .../org/sonar/server/rule/RuleService.java | 16 +- .../org/sonar/server/rule/RuleUpdate.java | 25 +- .../org/sonar/server/rule/index/RuleDoc.java | 2 - .../sonar/server/rule/ws/CreateAction.java | 58 ++--- .../sonar/server/rule/ws/DeleteAction.java | 2 +- .../sonar/server/rule/ws/UpdateAction.java | 6 +- .../server/rule/DefaultRuleFinderTest.java | 21 +- .../server/rule/RegisterRulesMediumTest.java | 25 +- .../server/rule/RubyRuleServiceTest.java | 21 -- .../server/rule/RuleCreatorMediumTest.java | 218 ++---------------- .../server/rule/RuleDeleterMediumTest.java | 27 +-- .../server/rule/RuleServiceMediumTest.java | 57 ----- .../server/rule/RuleUpdaterMediumTest.java | 82 +------ .../rule/ws/CreateActionMediumTest.java | 58 +---- .../server/rule/ws/ShowActionMediumTest.java | 22 +- .../rule/ws/UpdateActionMediumTest.java | 14 +- .../create_manual_rule.json | 14 -- .../create_manual_rule_without_severity.json | 13 -- ...th_prevent_reactivation_param_to_true.json | 11 +- ...ncode_html_description_of_manual_rule.json | 6 - .../java/org/sonar/db/rule/RuleTesting.java | 9 - 25 files changed, 110 insertions(+), 762 deletions(-) rename server/sonar-server/src/main/java/org/sonar/server/rule/{NewRule.java => NewCustomRule.java} (71%) delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_manual_rule.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_manual_rule_without_severity.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/encode_html_description_of_manual_rule.json diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/NewRule.java b/server/sonar-server/src/main/java/org/sonar/server/rule/NewCustomRule.java similarity index 71% rename from server/sonar-server/src/main/java/org/sonar/server/rule/NewRule.java rename to server/sonar-server/src/main/java/org/sonar/server/rule/NewCustomRule.java index 6f2393ff469..15c3314ddd7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/NewRule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/NewCustomRule.java @@ -22,15 +22,13 @@ package org.sonar.server.rule; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Maps; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.RuleStatus; - +import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.sonar.api.rule.RuleKey; +import org.sonar.api.rule.RuleStatus; -import java.util.Map; - -public class NewRule { +public class NewCustomRule { private String ruleKey; private RuleKey templateKey; @@ -41,11 +39,9 @@ public class NewRule { private RuleStatus status; private final Map parameters = Maps.newHashMap(); - private boolean isCustom; - private boolean isManual; private boolean preventReactivation = false; - private NewRule() { + private NewCustomRule() { // No direct call to constructor } @@ -63,7 +59,7 @@ public class NewRule { return name; } - public NewRule setName(@Nullable String name) { + public NewCustomRule setName(@Nullable String name) { this.name = name; return this; } @@ -73,7 +69,7 @@ public class NewRule { return htmlDescription; } - public NewRule setHtmlDescription(@Nullable String htmlDescription) { + public NewCustomRule setHtmlDescription(@Nullable String htmlDescription) { this.htmlDescription = htmlDescription; return this; } @@ -83,7 +79,7 @@ public class NewRule { return markdownDescription; } - public NewRule setMarkdownDescription(@Nullable String markdownDescription) { + public NewCustomRule setMarkdownDescription(@Nullable String markdownDescription) { this.markdownDescription = markdownDescription; return this; } @@ -93,7 +89,7 @@ public class NewRule { return severity; } - public NewRule setSeverity(@Nullable String severity) { + public NewCustomRule setSeverity(@Nullable String severity) { this.severity = severity; return this; } @@ -103,8 +99,7 @@ public class NewRule { return status; } - public NewRule setStatus(@Nullable RuleStatus status) { - checkCustomRule(); + public NewCustomRule setStatus(@Nullable RuleStatus status) { this.status = status; return this; } @@ -118,8 +113,7 @@ public class NewRule { return parameters.get(paramKey); } - public NewRule setParameters(Map params) { - checkCustomRule(); + public NewCustomRule setParameters(Map params) { this.parameters.clear(); this.parameters.putAll(params); return this; @@ -132,40 +126,17 @@ public class NewRule { /** * When true, if the rule already exists in status REMOVED, an {@link ReactivationException} will be thrown */ - public NewRule setPreventReactivation(boolean preventReactivation) { + public NewCustomRule setPreventReactivation(boolean preventReactivation) { this.preventReactivation = preventReactivation; return this; } - private void checkCustomRule(){ - if (!isCustom) { - throw new IllegalStateException("Not a custom rule"); - } - } - - public boolean isCustom() { - return isCustom; - } - - public boolean isManual() { - return isManual; - } - - public static NewRule createForCustomRule(String customKey, RuleKey templateKey) { + public static NewCustomRule createForCustomRule(String customKey, RuleKey templateKey) { Preconditions.checkArgument(!Strings.isNullOrEmpty(customKey), "Custom key should be set"); Preconditions.checkArgument(templateKey != null, "Template key should be set"); - NewRule newRule = new NewRule(); + NewCustomRule newRule = new NewCustomRule(); newRule.ruleKey = customKey; newRule.templateKey = templateKey; - newRule.isCustom = true; - return newRule; - } - - public static NewRule createForManualRule(String manualKey) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(manualKey), "Manual key should be set"); - NewRule newRule = new NewRule(); - newRule.ruleKey = manualKey; - newRule.isManual = true; return newRule; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java index 75414cb5f98..cc51cfc1dd0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java @@ -115,39 +115,11 @@ public class RubyRuleService implements Startable { update.setDebtRemediationFunction(new DefaultDebtRemediationFunction( DebtRemediationFunction.Type.valueOf(fn), Strings.emptyToNull((String) params.get("debtRemediationCoefficient")), - Strings.emptyToNull((String) params.get("debtRemediationOffset"))) - ); + Strings.emptyToNull((String) params.get("debtRemediationOffset")))); } updater.update(update, userSession); } - /** - * Used in manual_rules_controller.rb - */ - public void createManualRule(Map params) { - NewRule newRule = NewRule.createForManualRule((String) params.get("manualKey")) - .setName((String) params.get("name")) - .setMarkdownDescription((String) params.get("markdownDescription")); - service.create(newRule); - } - - /** - * Used in manual_rules_controller.rb - */ - public void updateManualRule(Map params) { - RuleUpdate update = RuleUpdate.createForManualRule(RuleKey.parse((String) params.get("ruleKey"))) - .setName((String) params.get("name")) - .setMarkdownDescription((String) params.get("markdownDescription")); - service.update(update); - } - - /** - * Used in manual_rules_controller.rb - */ - public void deleteManualRule(String ruleKey) { - service.delete(RuleKey.parse(ruleKey)); - } - private List loadDtos(List ruleKeys) { DbSession dbSession = dbClient.openSession(false); try { diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java index 26affc8228b..5090295ae9b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java @@ -28,7 +28,6 @@ import javax.annotation.Nullable; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; -import org.sonar.api.rules.RuleType; import org.sonar.api.server.ServerSide; import org.sonar.api.server.rule.RuleParamType; import org.sonar.api.utils.System2; @@ -40,7 +39,6 @@ import org.sonar.db.rule.RuleParamDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.Errors; import org.sonar.server.exceptions.Message; -import org.sonar.server.rule.index.RuleDoc; import org.sonar.server.rule.index.RuleIndexer; import org.sonar.server.util.TypeValidations; @@ -61,25 +59,16 @@ public class RuleCreator { this.typeValidations = typeValidations; } - public RuleKey create(NewRule newRule) { + public RuleKey create(NewCustomRule newRule) { DbSession dbSession = dbClient.openSession(false); try { - - if (newRule.isCustom()) { - return createCustomRule(newRule, dbSession); - } - - if (newRule.isManual()) { - return createManualRule(newRule, dbSession); - } - - throw new IllegalStateException("Only custom rule and manual rule can be created"); + return createCustomRule(newRule, dbSession); } finally { dbSession.close(); } } - private RuleKey createCustomRule(NewRule newRule, DbSession dbSession) { + private RuleKey createCustomRule(NewCustomRule newRule, DbSession dbSession) { RuleKey templateKey = newRule.templateKey(); if (templateKey == null) { throw new IllegalArgumentException("Rule template key should not be null"); @@ -104,23 +93,7 @@ public class RuleCreator { return customRuleKey; } - private RuleKey createManualRule(NewRule newRule, DbSession dbSession) { - validateManualRule(newRule); - - RuleKey customRuleKey = RuleKey.of(RuleDoc.MANUAL_REPOSITORY, newRule.ruleKey()); - Optional existingRule = loadRule(customRuleKey, dbSession); - if (existingRule.isPresent()) { - updateExistingRule(existingRule.get(), newRule, dbSession); - } else { - createManualRule(customRuleKey, newRule, dbSession); - } - - dbSession.commit(); - ruleIndexer.setEnabled(true).index(); - return customRuleKey; - } - - private void validateCustomRule(NewRule newRule, DbSession dbSession, RuleKey templateKey) { + private void validateCustomRule(NewCustomRule newRule, DbSession dbSession, RuleKey templateKey) { Errors errors = new Errors(); validateRuleKey(errors, newRule.ruleKey()); @@ -163,28 +136,13 @@ public class RuleCreator { } } - private static void validateManualRule(NewRule newRule) { - Errors errors = new Errors(); - validateRuleKey(errors, newRule.ruleKey()); - validateName(errors, newRule); - validateDescription(errors, newRule); - - if (!newRule.parameters().isEmpty()) { - errors.add(Message.of("coding_rules.validation.manual_rule_params")); - } - - if (!errors.isEmpty()) { - throw new BadRequestException(errors); - } - } - - private static void validateName(Errors errors, NewRule newRule) { + private static void validateName(Errors errors, NewCustomRule newRule) { if (Strings.isNullOrEmpty(newRule.name())) { errors.add(Message.of("coding_rules.validation.missing_name")); } } - private static void validateDescription(Errors errors, NewRule newRule) { + private static void validateDescription(Errors errors, NewCustomRule newRule) { if (Strings.isNullOrEmpty(newRule.htmlDescription()) && Strings.isNullOrEmpty(newRule.markdownDescription())) { errors.add(Message.of("coding_rules.validation.missing_description")); } @@ -200,7 +158,7 @@ public class RuleCreator { return dbClient.ruleDao().selectByKey(dbSession, ruleKey); } - private RuleKey createCustomRule(RuleKey ruleKey, NewRule newRule, RuleDto templateRuleDto, DbSession dbSession) { + private RuleKey createCustomRule(RuleKey ruleKey, NewCustomRule newRule, RuleDto templateRuleDto, DbSession dbSession) { RuleDto ruleDto = RuleDto.createFor(ruleKey) .setTemplateId(templateRuleDto.getId()) .setConfigKey(templateRuleDto.getConfigKey()) @@ -237,22 +195,7 @@ public class RuleCreator { dbClient.ruleDao().insertRuleParam(dbSession, ruleDto, ruleParamDto); } - private RuleKey createManualRule(RuleKey ruleKey, NewRule newRule, DbSession dbSession) { - RuleDto ruleDto = RuleDto.createFor(ruleKey) - .setName(newRule.name()) - .setDescription(newRule.markdownDescription()) - .setDescriptionFormat(Format.MARKDOWN) - .setSeverity(newRule.severity()) - .setStatus(RuleStatus.READY) - // It's not possible to update type of manual rule for the moment - .setType(RuleType.CODE_SMELL) - .setCreatedAt(system2.now()) - .setUpdatedAt(system2.now()); - dbClient.ruleDao().insert(dbSession, ruleDto); - return ruleKey; - } - - private void updateExistingRule(RuleDto ruleDto, NewRule newRule, DbSession dbSession) { + private void updateExistingRule(RuleDto ruleDto, NewCustomRule newRule, DbSession dbSession) { if (ruleDto.getStatus().equals(RuleStatus.REMOVED)) { if (newRule.isPreventReactivation()) { throw new ReactivationException(String.format("A removed rule with the key '%s' already exists", ruleDto.getKey().rule()), ruleDto.getKey()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleDeleter.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleDeleter.java index e96d2db66da..25ed533da68 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleDeleter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleDeleter.java @@ -27,7 +27,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.RuleDto; import org.sonar.server.qualityprofile.RuleActivator; -import org.sonar.server.rule.index.RuleDoc; import org.sonar.server.rule.index.RuleIndexer; @ServerSide @@ -49,8 +48,8 @@ public class RuleDeleter { DbSession dbSession = dbClient.openSession(false); try { RuleDto rule = dbClient.ruleDao().selectOrFailByKey(dbSession, ruleKey); - if (rule.getTemplateId() == null && !rule.getRepositoryKey().equals(RuleDoc.MANUAL_REPOSITORY)) { - throw new IllegalStateException("Only custom rules and manual rules can be deleted"); + if (rule.getTemplateId() == null) { + throw new IllegalStateException("Only custom rules can be deleted"); } // For custom rule, first deactivate the rule on all profiles diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java index 9d0c3f43be5..581045bf5a1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleService.java @@ -37,16 +37,12 @@ import org.sonar.server.user.UserSession; @ServerSide public class RuleService { - private final RuleUpdater ruleUpdater; private final RuleIndex index; - private final RuleCreator ruleCreator; private final RuleDeleter ruleDeleter; private final UserSession userSession; - public RuleService(RuleUpdater ruleUpdater, RuleIndex index, RuleCreator ruleCreator, RuleDeleter ruleDeleter, UserSession userSession) { - this.ruleUpdater = ruleUpdater; + public RuleService(RuleIndex index, RuleDeleter ruleDeleter, UserSession userSession) { this.index = index; - this.ruleCreator = ruleCreator; this.ruleDeleter = ruleDeleter; this.userSession = userSession; } @@ -75,16 +71,6 @@ public class RuleService { return index.search(query, options); } - public RuleKey create(NewRule newRule) { - checkPermission(); - return ruleCreator.create(newRule); - } - - public void update(RuleUpdate update) { - checkPermission(); - ruleUpdater.update(update, userSession); - } - public void delete(RuleKey ruleKey) { checkPermission(); ruleDeleter.delete(ruleKey); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdate.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdate.java index 6504ffaca1c..72ac59391ab 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdate.java @@ -42,7 +42,6 @@ public class RuleUpdate { private boolean changeStatus = false; private boolean changeParameters = false; private boolean isCustomRule; - private boolean isManual; private Set tags; private String markdownNote; private DebtRemediationFunction debtRemediationFunction; @@ -106,7 +105,7 @@ public class RuleUpdate { } public RuleUpdate setName(@Nullable String name) { - checkCustomOrManualRule(); + checkCustomRule(); this.name = name; this.changeName = true; return this; @@ -118,7 +117,7 @@ public class RuleUpdate { } public RuleUpdate setMarkdownDescription(@Nullable String markdownDescription) { - checkCustomOrManualRule(); + checkCustomRule(); this.markdownDescription = markdownDescription; this.changeDescription = true; return this; @@ -130,7 +129,7 @@ public class RuleUpdate { } public RuleUpdate setSeverity(@Nullable String severity) { - checkCustomOrManualRule(); + checkCustomRule(); this.severity = severity; this.changeSeverity = true; return this; @@ -218,19 +217,12 @@ public class RuleUpdate { } } - private void checkCustomOrManualRule() { - if (!isCustomRule && !isManual) { - throw new IllegalStateException("Not a custom or a manual rule"); - } - } - /** * Use to update a rule provided by a plugin (name, description, severity, status and parameters cannot by changed) */ public static RuleUpdate createForPluginRule(RuleKey ruleKey) { RuleUpdate ruleUpdate = new RuleUpdate(ruleKey); ruleUpdate.isCustomRule = false; - ruleUpdate.isManual = false; return ruleUpdate; } @@ -240,17 +232,6 @@ public class RuleUpdate { public static RuleUpdate createForCustomRule(RuleKey ruleKey) { RuleUpdate ruleUpdate = new RuleUpdate(ruleKey); ruleUpdate.isCustomRule = true; - ruleUpdate.isManual = false; - return ruleUpdate; - } - - /** - * Use to update a manual rule (status and parameters cannot by changed) - */ - public static RuleUpdate createForManualRule(RuleKey ruleKey) { - RuleUpdate ruleUpdate = new RuleUpdate(ruleKey); - ruleUpdate.isManual = true; - ruleUpdate.isCustomRule = false; return ruleUpdate; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java index 2d5e762d299..93d33fc7ac8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleDoc.java @@ -36,8 +36,6 @@ import org.sonar.server.search.BaseDoc; */ public class RuleDoc extends BaseDoc { - public static final String MANUAL_REPOSITORY = "manual"; - public RuleDoc(Map fields) { super(fields); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java index 794b33f2937..9db03663fce 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java @@ -34,8 +34,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; -import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.rule.NewRule; +import org.sonar.server.rule.NewCustomRule; import org.sonar.server.rule.ReactivationException; import org.sonar.server.rule.RuleCreator; import org.sonarqube.ws.Rules; @@ -51,7 +50,6 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf; public class CreateAction implements RulesWsAction { public static final String PARAM_CUSTOM_KEY = "custom_key"; - public static final String PARAM_MANUAL_KEY = "manual_key"; public static final String PARAM_NAME = "name"; public static final String PARAM_DESCRIPTION = "markdown_description"; public static final String PARAM_SEVERITY = "severity"; @@ -75,7 +73,8 @@ public class CreateAction implements RulesWsAction { public void define(WebService.NewController controller) { WebService.NewAction action = controller .createAction("create") - .setDescription("Create a custom rule or a manual rule") + .setDescription("Create a custom rule.
" + + "Since 5.5, it's no more possible to create manual rule.") .setSince("4.4") .setPost(true) .setHandler(this); @@ -83,12 +82,14 @@ public class CreateAction implements RulesWsAction { action .createParam(PARAM_CUSTOM_KEY) .setDescription("Key of the custom rule") - .setExampleValue("Todo_should_not_be_used"); + .setExampleValue("Todo_should_not_be_used") + .setRequired(true); action - .createParam(PARAM_MANUAL_KEY) - .setDescription("Key of the manual rule") - .setExampleValue("Error_handling"); + .createParam("manual_key") + .setDescription("Manual rules are no more supported. This parameter is ignored") + .setExampleValue("Error_handling") + .setDeprecatedSince("5.5"); action .createParam(PARAM_TEMPLATE_KEY) @@ -109,12 +110,12 @@ public class CreateAction implements RulesWsAction { action .createParam(PARAM_SEVERITY) - .setDescription("Rule severity (Only for custom rule)") + .setDescription("Rule severity") .setPossibleValues(Severity.ALL); action .createParam(PARAM_STATUS) - .setDescription("Rule status (Only for custom rule)") + .setDescription("Rule status") .setDefaultValue(RuleStatus.READY) .setPossibleValues(RuleStatus.values()); @@ -130,36 +131,21 @@ public class CreateAction implements RulesWsAction { @Override public void handle(Request request, Response response) throws Exception { - String customKey = request.param(PARAM_CUSTOM_KEY); - String manualKey = request.param(PARAM_MANUAL_KEY); - if (isNullOrEmpty(customKey) && isNullOrEmpty(manualKey)) { - throw new BadRequestException(String.format("Either '%s' or '%s' parameters should be set", PARAM_CUSTOM_KEY, PARAM_MANUAL_KEY)); - } + String customKey = request.mandatoryParam(PARAM_CUSTOM_KEY); DbSession dbSession = dbClient.openSession(false); try { try { - if (!isNullOrEmpty(customKey)) { - NewRule newRule = NewRule.createForCustomRule(customKey, RuleKey.parse(request.mandatoryParam(PARAM_TEMPLATE_KEY))) - .setName(request.mandatoryParam(PARAM_NAME)) - .setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION)) - .setSeverity(request.mandatoryParam(PARAM_SEVERITY)) - .setStatus(RuleStatus.valueOf(request.mandatoryParam(PARAM_STATUS))) - .setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION)); - String params = request.param(PARAMS); - if (!isNullOrEmpty(params)) { - newRule.setParameters(KeyValueFormat.parse(params)); - } - writeResponse(dbSession, request, response, ruleCreator.create(newRule)); - } - - if (!isNullOrEmpty(manualKey)) { - NewRule newRule = NewRule.createForManualRule(manualKey) - .setName(request.mandatoryParam(PARAM_NAME)) - .setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION)) - .setSeverity(request.param(PARAM_SEVERITY)) - .setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION)); - writeResponse(dbSession, request, response, ruleCreator.create(newRule)); + NewCustomRule newRule = NewCustomRule.createForCustomRule(customKey, RuleKey.parse(request.mandatoryParam(PARAM_TEMPLATE_KEY))) + .setName(request.mandatoryParam(PARAM_NAME)) + .setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION)) + .setSeverity(request.mandatoryParam(PARAM_SEVERITY)) + .setStatus(RuleStatus.valueOf(request.mandatoryParam(PARAM_STATUS))) + .setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION)); + String params = request.param(PARAMS); + if (!isNullOrEmpty(params)) { + newRule.setParameters(KeyValueFormat.parse(params)); } + writeResponse(dbSession, request, response, ruleCreator.create(newRule)); } catch (ReactivationException e) { write409(dbSession, request, response, e.ruleKey()); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/DeleteAction.java index 8baf16428c2..d27696e6374 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/DeleteAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/DeleteAction.java @@ -42,7 +42,7 @@ public class DeleteAction implements RulesWsAction { public void define(WebService.NewController controller) { WebService.NewAction action = controller .createAction("delete") - .setDescription("Delete custom rule or manual rule") + .setDescription("Delete custom rule") .setSince("4.4") .setPost(true) .setHandler(this); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java index 1ac8117fff4..1e8980aa1ff 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java @@ -125,7 +125,7 @@ public class UpdateAction implements RulesWsAction { .setDeprecatedSince("5.5"); action.createParam(PARAM_REMEDIATION_FN_GAP_MULTIPLIER) - .setDeprecatedSince("Gap multiplier of the remediation function of the rule") + .setDescription("Gap multiplier of the remediation function of the rule") .setExampleValue("3min") .setSince("5.5"); @@ -134,7 +134,7 @@ public class UpdateAction implements RulesWsAction { action .createParam(PARAM_NAME) - .setDescription("Rule name (mandatory for custom rule and manual rule)") + .setDescription("Rule name (mandatory for custom rule)") .setExampleValue("My custom rule"); action @@ -207,8 +207,6 @@ public class UpdateAction implements RulesWsAction { RuleDto rule = optionalRule.get(); if (rule.getTemplateId() != null) { return RuleUpdate.createForCustomRule(key); - } else if (RuleKey.MANUAL_REPOSITORY_KEY.equals(rule.getRepositoryKey())) { - return RuleUpdate.createForManualRule(key); } else { return RuleUpdate.createForPluginRule(key); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java index c1fe6ebbba6..7655e0b792c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java @@ -31,7 +31,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.rule.RuleDto; -import org.sonar.db.rule.RuleTesting; import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; @@ -76,8 +75,6 @@ public class DefaultRuleFinderTest { .setSeverity(2) .setStatus(RuleStatus.READY); - RuleDto manualRule = RuleTesting.newManualRule("Manual_Rule").setName("Manual Rule"); - DefaultRuleFinder underTest = new DefaultRuleFinder(dbClient); @Before @@ -86,7 +83,6 @@ public class DefaultRuleFinderTest { dbClient.ruleDao().insert(session, rule2); dbClient.ruleDao().insert(session, rule3); dbClient.ruleDao().insert(session, rule4); - dbClient.ruleDao().insert(session, manualRule); session.commit(); } @@ -118,8 +114,8 @@ public class DefaultRuleFinderTest { assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey("checkstyle"))).hasSize(2); // find_all_enabled - assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId(), manualRule.getId()); - assertThat(underTest.findAll(RuleQuery.create())).hasSize(4); + assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId()); + assertThat(underTest.findAll(RuleQuery.create())).hasSize(3); // do_not_find_disabled_rules assertThat(underTest.findByKey("checkstyle", "DisabledCheck")).isNull(); @@ -153,18 +149,7 @@ public class DefaultRuleFinderTest { @Test public void find_all_not_include_removed_rule() { // find rule with id 2 is REMOVED - assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId(), manualRule.getId()); - } - - @Test - public void find_manual_rule() { - // find by id - assertThat(underTest.findById(manualRule.getId())).isNotNull(); - - // find by key - Rule rule = underTest.findByKey("manual", "Manual_Rule"); - assertThat(rule).isNotNull(); - assertThat(rule.isEnabled()).isTrue(); + assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java index 96e6a004063..49b19ff0336 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java @@ -267,7 +267,7 @@ public class RegisterRulesMediumTest { RuleDto template = ruleDao.selectOrFailByKey(dbSession, RuleKey.of("xoo", "T1")); // Create custom rule - RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewRule.createForCustomRule("CUSTOM_RULE", template.getKey()) + RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewCustomRule.createForCustomRule("CUSTOM_RULE", template.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -323,7 +323,7 @@ public class RegisterRulesMediumTest { RuleDto template = ruleDao.selectOrFailByKey(dbSession, RuleKey.of("xoo", "T1")); // Create custom rule - RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewRule.createForCustomRule("CUSTOM_RULE", template.getKey()) + RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewCustomRule.createForCustomRule("CUSTOM_RULE", template.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -358,7 +358,7 @@ public class RegisterRulesMediumTest { RuleDto templateRule = ruleDao.selectOrFailByKey(dbSession, RuleKey.of("xoo", "T1")); // Create custom rule - RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -406,7 +406,7 @@ public class RegisterRulesMediumTest { RuleDto templateRule = ruleDao.selectOrFailByKey(dbSession, RuleKey.of("xoo", "T1")); // Create custom rule - RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -427,23 +427,6 @@ public class RegisterRulesMediumTest { assertThat(ruleDao.selectOrFailByKey(dbSession, customRuleKey).getStatus()).isEqualTo(RuleStatus.READY); } - @Test - public void do_not_disable_manual_rules() { - // Create manual rule - RuleKey manualRuleKey = TESTER.get(RuleCreator.class).create(NewRule.createForManualRule("MANUAL_RULE") - .setName("My manual") - .setHtmlDescription("Some description")); - dbSession.commit(); - dbSession.clearCache(); - assertThat(ruleDao.selectOrFailByKey(dbSession, manualRuleKey).getStatus()).isEqualTo(RuleStatus.READY); - - // Restart - register(null); - - // Verify manual rule is still ready - assertThat(ruleDao.selectOrFailByKey(dbSession, manualRuleKey).getStatus()).isEqualTo(RuleStatus.READY); - } - interface Rules { void init(RulesDefinition.NewRepository repository); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java index acceb7736f1..5e6163923a3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java @@ -165,25 +165,4 @@ public class RubyRuleServiceTest { verify(updater).update(any(RuleUpdate.class), any(ThreadLocalUserSession.class)); } - - @Test - public void create_manual_rules() { - service.createManualRule(ImmutableMap.of("manualKey", "MY_MANUAL")); - - verify(ruleService).create(any(NewRule.class)); - } - - @Test - public void update_manual_rules() { - service.updateManualRule(ImmutableMap.of("ruleKey", "manual:MY_MANUAL")); - - verify(ruleService).update(any(RuleUpdate.class)); - } - - @Test - public void delete_manual_rules() { - service.deleteManualRule("manual:MY_MANUAL"); - - verify(ruleService).delete(RuleKey.of("manual", "MY_MANUAL")); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java index e3b6ee24220..62ed9e3bd9b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java @@ -31,7 +31,6 @@ import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; -import org.sonar.api.rules.RuleType; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -86,7 +85,7 @@ public class RuleCreatorMediumTest { RuleDto templateRule = createTemplateRule(); // Create custom rule - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setMarkdownDescription("Some description") .setSeverity(Severity.MAJOR) @@ -132,7 +131,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRule(); - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -157,7 +156,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRuleWithIntArrayParam(); - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -181,7 +180,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRuleWithIntArrayParam(); - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -207,7 +206,7 @@ public class RuleCreatorMediumTest { RuleDto templateRule = createTemplateRuleWithIntArrayParam(); // Create custom rule - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setMarkdownDescription("Some description") .setSeverity(Severity.MAJOR) @@ -229,7 +228,7 @@ public class RuleCreatorMediumTest { RuleDto templateRule = createTemplateRuleWithTwoIntParams(); // Create custom rule - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setMarkdownDescription("Some description") .setSeverity(Severity.MAJOR) @@ -266,7 +265,7 @@ public class RuleCreatorMediumTest { dbSession.clearCache(); // Create custom rule with same key, but with different values - NewRule newRule = NewRule.createForCustomRule(key, templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule(key, templateRule.getKey()) .setName("New name") .setMarkdownDescription("New description") .setSeverity(Severity.MAJOR) @@ -310,7 +309,7 @@ public class RuleCreatorMediumTest { dbSession.clearCache(); // Create custom rule with same key, but with different values - NewRule newRule = NewRule.createForCustomRule(key, templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule(key, templateRule.getKey()) .setName("New name") .setHtmlDescription("New description") .setSeverity(Severity.MAJOR) @@ -333,7 +332,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRule(); - NewRule newRule = NewRule.createForCustomRule("*INVALID*", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("*INVALID*", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -354,7 +353,7 @@ public class RuleCreatorMediumTest { RuleDto templateRule = createTemplateRule(); // Create a custom rule - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -364,7 +363,7 @@ public class RuleCreatorMediumTest { try { // Create another custom rule having same key - newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My another custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -382,7 +381,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRule(); - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) .setStatus(RuleStatus.READY) @@ -401,7 +400,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRule(); - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setSeverity(Severity.MAJOR) .setStatus(RuleStatus.READY) @@ -420,7 +419,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRule(); - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setStatus(RuleStatus.READY) @@ -439,7 +438,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRule(); - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity("INVALID") @@ -459,7 +458,7 @@ public class RuleCreatorMediumTest { // insert template rule RuleDto templateRule = createTemplateRule(); - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -481,7 +480,7 @@ public class RuleCreatorMediumTest { dbSession.commit(); // Create custom rule with unknown template rule - NewRule newRule = NewRule.createForCustomRule("CUSTOM_RULE", rule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", rule.getKey()) .setName("My custom") .setHtmlDescription("Some description") .setSeverity(Severity.MAJOR) @@ -496,189 +495,6 @@ public class RuleCreatorMediumTest { } } - @Test - public void create_manual_rule() { - NewRule newRule = NewRule.createForManualRule("MANUAL_RULE") - .setName("My manual") - .setMarkdownDescription("Some description"); - RuleKey ruleKey = creator.create(newRule); - - dbSession.clearCache(); - - RuleDto rule = db.ruleDao().selectOrFailByKey(dbSession, ruleKey); - assertThat(rule).isNotNull(); - assertThat(rule.getKey()).isEqualTo(RuleKey.of("manual", "MANUAL_RULE")); - assertThat(rule.getName()).isEqualTo("My manual"); - assertThat(rule.getDescription()).isEqualTo("Some description"); - assertThat(rule.getSeverityString()).isNull(); - assertThat(rule.getStatus()).isEqualTo(RuleStatus.READY); - assertThat(rule.getLanguage()).isNull(); - assertThat(rule.getConfigKey()).isNull(); - assertThat(rule.getDefaultRemediationBaseEffort()).isNull(); - assertThat(rule.getTags()).isEmpty(); - assertThat(rule.getSystemTags()).isEmpty(); - - assertThat(db.ruleDao().selectRuleParamsByRuleKey(dbSession, ruleKey)).isEmpty(); - - assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(ruleKey); - } - - @Test - public void create_manual_rule_with_severity() { - NewRule newRule = NewRule.createForManualRule("MANUAL_RULE") - .setName("My manual") - .setMarkdownDescription("Some description") - .setSeverity(Severity.BLOCKER); - RuleKey ruleKey = creator.create(newRule); - - dbSession.clearCache(); - - RuleDto rule = db.ruleDao().selectOrFailByKey(dbSession, ruleKey); - assertThat(rule).isNotNull(); - assertThat(rule.getKey()).isEqualTo(RuleKey.of("manual", "MANUAL_RULE")); - assertThat(rule.getName()).isEqualTo("My manual"); - assertThat(rule.getDescription()).isEqualTo("Some description"); - assertThat(rule.getSeverityString()).isEqualTo(Severity.BLOCKER); - assertThat(rule.getStatus()).isEqualTo(RuleStatus.READY); - assertThat(rule.getLanguage()).isNull(); - assertThat(rule.getConfigKey()).isNull(); - assertThat(rule.getDefaultRemediationFunction()).isNull(); - assertThat(rule.getTags()).isEmpty(); - assertThat(rule.getSystemTags()).isEmpty(); - - assertThat(db.ruleDao().selectRuleParamsByRuleKey(dbSession, ruleKey)).isEmpty(); - } - - @Test - public void reactivate_manual_rule_if_already_exists_in_removed_status() { - String key = "MANUAL_RULE"; - - // insert a removed rule - RuleDto rule = RuleTesting.newManualRule(key) - .setStatus(RuleStatus.REMOVED) - .setName("Old name") - .setDescription("Old description") - .setSeverity(Severity.INFO) - .setType(RuleType.CODE_SMELL); - dao.insert(dbSession, rule); - dbSession.commit(); - dbSession.clearCache(); - - // Create a rule with the same key and with another name, description and severity - NewRule newRule = NewRule.createForManualRule(key) - .setName("New name") - .setMarkdownDescription("New description"); - RuleKey ruleKey = creator.create(newRule); - - dbSession.clearCache(); - - RuleDto result = db.ruleDao().selectOrFailByKey(dbSession, ruleKey); - assertThat(result.getKey()).isEqualTo(RuleKey.of("manual", key)); - assertThat(result.getStatus()).isEqualTo(RuleStatus.READY); - - // Name, description and severity should be the same than before - assertThat(result.getName()).isEqualTo("Old name"); - assertThat(result.getDescription()).isEqualTo("Old description"); - assertThat(result.getSeverityString()).isEqualTo(Severity.INFO); - } - - @Test - public void fail_to_create_manual_rule_when_missing_key() { - try { - NewRule.createForManualRule("") - .setName("My manual") - .setHtmlDescription("Some description"); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Manual key should be set"); - } - } - - @Test - public void fail_to_create_manual_rule_when_invalid_key() { - NewRule newRule = NewRule.createForManualRule("*INVALID*") - .setName("My custom") - .setHtmlDescription("Some description"); - - try { - creator.create(newRule); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("coding_rules.validation.invalid_rule_key"); - } - } - - @Test - public void fail_to_create_manual_rule_when_rule_key_already_exists() { - NewRule newRule = NewRule.createForManualRule("MANUAL_RULE") - .setName("My manual") - .setHtmlDescription("Some description"); - creator.create(newRule); - - try { - // Create another rule having same key - newRule = NewRule.createForManualRule("MANUAL_RULE") - .setName("My other manual") - .setHtmlDescription("Some description"); - creator.create(newRule); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("A rule with the key 'MANUAL_RULE' already exists"); - } - } - - @Test - public void fail_to_create_manual_rule_when_missing_name() { - NewRule newRule = NewRule.createForManualRule("MANUAL_RULE") - .setHtmlDescription("Some description"); - - try { - creator.create(newRule); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("coding_rules.validation.missing_name"); - } - } - - @Test - public void fail_to_create_manual_rule_when_missing_description() { - NewRule newRule = NewRule.createForManualRule("MANUAL_RULE") - .setName("My manual"); - - try { - creator.create(newRule); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("coding_rules.validation.missing_description"); - } - } - - @Test - public void fail_to_create_manual_rule_with_status() { - try { - NewRule.createForManualRule("MANUAL_RULE") - .setName("My manual") - .setHtmlDescription("Some description") - .setStatus(RuleStatus.BETA); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule"); - } - } - - @Test - public void fail_to_create_manual_rule_with_parameters() { - try { - NewRule.createForManualRule("MANUAL_RULE") - .setName("My manual") - .setHtmlDescription("Some description") - .setParameters(ImmutableMap.of("regex", "a.*")); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule"); - } - } - private RuleDto createTemplateRule() { RuleDto templateRule = RuleTesting.newDto(RuleKey.of("java", "S001")) .setIsTemplate(true) diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java index 7bdff24f593..7e9ef210735 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java @@ -125,30 +125,7 @@ public class RuleDeleterMediumTest { } @Test - public void delete_manual_rule() { - // Create manual rule - RuleDto manualRule = RuleTesting.newManualRule("Manual_Rule") - .setCreatedAt(PAST) - .setUpdatedAt(PAST); - dao.insert(dbSession, manualRule); - dbSession.commit(); - ruleIndexer.index(); - - // Delete manual rule - deleter.delete(manualRule.getKey()); - - // Verify custom rule have status REMOVED - RuleDto result = dao.selectOrFailByKey(dbSession, manualRule.getKey()); - assertThat(result).isNotNull(); - assertThat(result.getStatus()).isEqualTo(RuleStatus.REMOVED); - assertThat(result.getUpdatedAt()).isNotEqualTo(PAST); - - // Verify in index - assertThat(index.search(new RuleQuery(), new SearchOptions()).getIds()).isEmpty(); - } - - @Test - public void fail_to_delete_if_not_custom_or_not_manual() { + public void fail_to_delete_if_not_custom() { // Create rule RuleKey ruleKey = RuleKey.of("java", "S001"); dao.insert(dbSession, RuleTesting.newDto(ruleKey)); @@ -158,7 +135,7 @@ public class RuleDeleterMediumTest { // Delete rule deleter.delete(ruleKey); } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Only custom rules and manual rules can be deleted"); + assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Only custom rules can be deleted"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java index 098a7f4c222..93839de1ae7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleServiceMediumTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.rule; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import java.util.Collections; import java.util.Set; @@ -28,13 +27,10 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.RuleStatus; -import org.sonar.api.rule.Severity; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.RuleDao; -import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.rule.index.RuleIndex; @@ -93,59 +89,6 @@ public class RuleServiceMediumTest { assertThat(tags).containsOnly("tag1", "tag2", "sys1", "sys2"); } - @Test - public void create_rule() { - userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); - - // Create template rule - RuleKey templateRuleKey = RuleKey.of("java", "S001"); - dao.insert(dbSession, RuleTesting.newTemplateRule(templateRuleKey)); - dbSession.commit(); - - // Create custom rule - NewRule newRule = NewRule.createForCustomRule("MY_CUSTOM", templateRuleKey) - .setName("My custom") - .setHtmlDescription("Some description") - .setSeverity(Severity.MAJOR) - .setStatus(RuleStatus.READY) - .setParameters(ImmutableMap.of("regex", "a.*")); - RuleKey customRuleKey = service.create(newRule); - - dbSession.clearCache(); - - RuleDto rule = dao.selectOrFailByKey(dbSession, customRuleKey); - assertThat(rule).isNotNull(); - } - - @Test(expected = UnauthorizedException.class) - public void do_not_create_if_not_granted() { - userSessionRule.setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION); - - service.create(NewRule.createForCustomRule("MY_CUSTOM", RuleKey.of("java", "S001"))); - } - - @Test - public void delete_rule() { - userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); - - // Create template rule - RuleKey templateRuleKey = RuleKey.of("java", "S001"); - dao.insert(dbSession, RuleTesting.newTemplateRule(templateRuleKey)); - dbSession.commit(); - - // Create custom rule - NewRule newRule = NewRule.createForCustomRule("MY_CUSTOM", templateRuleKey) - .setName("My custom") - .setHtmlDescription("Some description") - .setSeverity(Severity.MAJOR) - .setStatus(RuleStatus.READY) - .setParameters(ImmutableMap.of("regex", "a.*")); - RuleKey customRuleKey = service.create(newRule); - - // Delete custom rule - service.delete(customRuleKey); - } - @Test(expected = UnauthorizedException.class) public void do_not_delete_if_not_granted() { userSessionRule.setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java index 19f30e7692d..bdf2ad817b6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java @@ -35,7 +35,6 @@ import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; -import org.sonar.api.rules.RuleType; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction; import org.sonar.db.DbClient; @@ -473,7 +472,7 @@ public class RuleUpdaterMediumTest { List activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); // FIXME why 4 parameters are returned ??? (This issue already exists in 5.4) - //assertThat(activeRuleParams).hasSize(2); + // assertThat(activeRuleParams).hasSize(2); Map activeRuleParamsByKey = ActiveRuleParamDto.groupByKey(activeRuleParams); assertThat(activeRuleParamsByKey.get("regex").getValue()).isEqualTo("b.*"); assertThat(activeRuleParamsByKey.get("message").getValue()).isEqualTo("a message"); @@ -528,79 +527,6 @@ public class RuleUpdaterMediumTest { } } - @Test - public void update_manual_rule() { - // Create manual rule - RuleDto manualRule = RuleTesting.newManualRule("My manual") - .setName("Old name") - .setDescription("Old description") - .setSeverity(Severity.INFO) - .setType(RuleType.CODE_SMELL); - ruleDao.insert(dbSession, manualRule); - - dbSession.commit(); - - // Update manual rule - RuleUpdate update = RuleUpdate.createForManualRule(manualRule.getKey()) - .setName("New name") - .setMarkdownDescription("New description") - .setSeverity(Severity.CRITICAL); - underTest.update(update, userSessionRule); - - dbSession.clearCache(); - - // Verify manual rule is updated - RuleDto manualRuleReloaded = ruleDao.selectOrFailByKey(dbSession, manualRule.getKey()); - assertThat(manualRuleReloaded).isNotNull(); - assertThat(manualRuleReloaded.getName()).isEqualTo("New name"); - assertThat(manualRuleReloaded.getDescription()).isEqualTo("New description"); - assertThat(manualRuleReloaded.getSeverityString()).isEqualTo(Severity.CRITICAL); - - // Verify in index - assertThat(ruleIndex.search(new RuleQuery().setQueryText("New name"), new SearchOptions()).getIds()).containsOnly(manualRule.getKey()); - assertThat(ruleIndex.search(new RuleQuery().setQueryText("New description"), new SearchOptions()).getIds()).containsOnly(manualRule.getKey()); - - assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old name"), new SearchOptions()).getTotal()).isZero(); - assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old description"), new SearchOptions()).getTotal()).isZero(); - } - - @Test - public void fail_to_update_manual_rule_if_status_is_set() { - // Create manual rule - RuleDto manualRule = RuleTesting.newManualRule("My manual"); - ruleDao.insert(dbSession, manualRule); - - dbSession.commit(); - - try { - // Update manual rule - RuleUpdate.createForManualRule(manualRule.getKey()) - .setStatus(RuleStatus.BETA); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule"); - } - } - - @Test - public void fail_to_update_manual_rule_if_parameters_are_set() { - // Create manual rule - RuleDto manualRule = RuleTesting.newManualRule("My manual"); - ruleDao.insert(dbSession, manualRule); - - dbSession.commit(); - - try { - // Update manual rule - RuleUpdate.createForManualRule(manualRule.getKey()) - .setStatus(RuleStatus.BETA) - .setParameters(ImmutableMap.of("regex", "b.*", "message", "a message")); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule"); - } - } - @Test public void fail_to_update_plugin_rule_if_name_is_set() { // Create rule rule @@ -615,7 +541,7 @@ public class RuleUpdaterMediumTest { .setName("New name"); fail(); } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom or a manual rule"); + assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule"); } } @@ -633,7 +559,7 @@ public class RuleUpdaterMediumTest { .setMarkdownDescription("New description"); fail(); } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom or a manual rule"); + assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule"); } } @@ -651,7 +577,7 @@ public class RuleUpdaterMediumTest { .setSeverity(Severity.CRITICAL); fail(); } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom or a manual rule"); + assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java index 1837c789357..fe11b2ab303 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java @@ -36,14 +36,10 @@ import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; -import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - @RunWith(MockitoJUnitRunner.class) public class CreateActionMediumTest { @@ -92,57 +88,25 @@ public class CreateActionMediumTest { } @Test - public void create_manual_rule() throws Exception { - WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "create") - .setParam("manual_key", "MY_MANUAL") - .setParam("name", "My manual rule") - .setParam("markdown_description", "Description") - .setParam("severity", "MAJOR"); - request.execute().assertJson(getClass(), "create_manual_rule.json"); - } - - @Test - public void create_manual_rule_without_severity() throws Exception { - WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "create") - .setParam("manual_key", "MY_MANUAL") - .setParam("name", "My manual rule") - .setParam("markdown_description", "Description"); - request.execute().assertJson(getClass(), "create_manual_rule_without_severity.json"); - } - - @Test - public void fail_if_custom_key_and_manual_key_parameters_are_not_set() { - WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "create") - .setParam("key", "MY_MANUAL") - .setParam("name", "My manual rule") - .setParam("markdown_description", "Description") - .setParam("severity", "MAJOR"); - - try { - request.execute(); - fail(); - } catch (Exception e) { - assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("Either 'custom_key' or 'manual_key' parameters should be set"); - } - } - - @Test - public void create_manual_rule_with_prevent_reactivation_param_to_true() throws Exception { - String key = "MY_MANUAL"; + public void create_custom_rule_with_prevent_reactivation_param_to_true() throws Exception { + RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); + ruleDao.insert(session, templateRule); // insert a removed rule - tester.get(RuleDao.class).insert(session, RuleTesting.newManualRule(key) + RuleDto customRule = RuleTesting.newCustomRule(templateRule) + .setRuleKey("MY_CUSTOM") .setStatus(RuleStatus.REMOVED) - .setName("My manual rule") + .setName("My custom rule") .setDescription("Description") .setDescriptionFormat(RuleDto.Format.MARKDOWN) - .setSeverity(Severity.MAJOR)); + .setSeverity(Severity.MAJOR); + tester.get(RuleDao.class).insert(session, customRule); session.commit(); - session.clearCache(); WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "create") - .setParam("manual_key", key) - .setParam("name", "My manual rule") + .setParam("custom_key", "MY_CUSTOM") + .setParam("template_key", templateRule.getKey().toString()) + .setParam("name", "My custom rule") .setParam("markdown_description", "Description") .setParam("severity", "MAJOR") .setParam("prevent_reactivation", "true"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java index eda854b4fab..c1a5705738b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java @@ -42,7 +42,8 @@ import org.sonar.db.rule.RuleDto.Format; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; -import org.sonar.server.rule.NewRule; +import org.sonar.server.rule.NewCustomRule; +import org.sonar.server.rule.RuleCreator; import org.sonar.server.rule.RuleService; import org.sonar.server.rule.index.RuleIndexer; import org.sonar.server.tester.ServerTester; @@ -213,12 +214,12 @@ public class ShowActionMediumTest { session.commit(); // Custom rule - NewRule customRule = NewRule.createForCustomRule("MY_CUSTOM", templateRule.getKey()) + NewCustomRule customRule = NewCustomRule.createForCustomRule("MY_CUSTOM", templateRule.getKey()) .setName("My custom") .setSeverity(MINOR) .setStatus(RuleStatus.READY) .setMarkdownDescription("
line1\nline2
"); - RuleKey customRuleKey = ruleService.create(customRule); + RuleKey customRuleKey = tester.get(RuleCreator.class).create(customRule); session.clearCache(); WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show") @@ -226,21 +227,6 @@ public class ShowActionMediumTest { request.execute().assertJson(getClass(), "encode_html_description_of_custom_rule.json"); } - @Test - public void encode_html_description_of_manual_rule() throws Exception { - // Manual rule - NewRule manualRule = NewRule.createForManualRule("MY_MANUAL") - .setName("My manual") - .setSeverity(MINOR) - .setMarkdownDescription("
line1\nline2
"); - RuleKey customRuleKey = ruleService.create(manualRule); - session.clearCache(); - - WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show") - .setParam("key", customRuleKey.toString()); - request.execute().assertJson(getClass(), "encode_html_description_of_manual_rule.json"); - } - @Test public void show_deprecated_rule_rem_function_fields() throws Exception { RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")) diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java index d9cd19b4512..6c6b39fbb98 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java @@ -35,7 +35,8 @@ import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; -import org.sonar.server.rule.NewRule; +import org.sonar.server.rule.NewCustomRule; +import org.sonar.server.rule.RuleCreator; import org.sonar.server.rule.RuleService; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; @@ -55,8 +56,7 @@ public class UpdateActionMediumTest { public static ServerTester tester = new ServerTester().withEsIndexes(); @Rule - public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester). - login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); + public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); WsTester wsTester; @@ -94,8 +94,7 @@ public class UpdateActionMediumTest { .setParam("key", rule.getKey().toString()) .setParam(PARAM_REMEDIATION_FN_TYPE, LINEAR_OFFSET.toString()) .setParam(PARAM_REMEDIATION_FN_GAP_MULTIPLIER, "15d") - .setParam(PARAM_REMEDIATION_FN_BASE_EFFORT, "5min") - ; + .setParam(PARAM_REMEDIATION_FN_BASE_EFFORT, "5min"); request.execute().assertJson(getClass(), "update_rule_remediation_function.json"); } @@ -129,13 +128,14 @@ public class UpdateActionMediumTest { session.commit(); // Custom rule - NewRule newRule = NewRule.createForCustomRule("MY_CUSTOM", templateRule.getKey()) + NewCustomRule newRule = NewCustomRule.createForCustomRule("MY_CUSTOM", templateRule.getKey()) .setName("Old custom") .setHtmlDescription("Old description") .setSeverity(Severity.MINOR) .setStatus(RuleStatus.BETA) .setParameters(ImmutableMap.of("regex", "a")); - RuleKey customRuleKey = ruleService.create(newRule); + + RuleKey customRuleKey = tester.get(RuleCreator.class).create(newRule); session.clearCache(); WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "update") diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_manual_rule.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_manual_rule.json deleted file mode 100644 index a78fb0fadf3..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_manual_rule.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "rule": { - "key": "manual:MY_MANUAL", - "repo": "manual", - "name": "My manual rule", - "htmlDesc": "Description", - "severity": "MAJOR", - "status": "READY", - "isTemplate": false, - "tags": [], - "sysTags": [], - "params": [] - } -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_manual_rule_without_severity.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_manual_rule_without_severity.json deleted file mode 100644 index 0f0e195298e..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_manual_rule_without_severity.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "rule": { - "key": "manual:MY_MANUAL", - "repo": "manual", - "name": "My manual rule", - "htmlDesc": "Description", - "status": "READY", - "isTemplate": false, - "tags": [], - "sysTags": [], - "params": [] - } -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_rule_with_prevent_reactivation_param_to_true.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_rule_with_prevent_reactivation_param_to_true.json index f3c87c66e8f..c5ddaaff00f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_rule_with_prevent_reactivation_param_to_true.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/CreateActionMediumTest/create_rule_with_prevent_reactivation_param_to_true.json @@ -1,14 +1,11 @@ { "rule": { - "key": "manual:MY_MANUAL", - "repo": "manual", - "name": "My manual rule", + "key": "java:MY_CUSTOM", + "repo": "java", + "name": "My custom rule", "htmlDesc": "Description", "severity": "MAJOR", "status": "REMOVED", - "isTemplate": false, - "tags": [], - "sysTags": [], - "params": [] + "isTemplate": false } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/encode_html_description_of_manual_rule.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/encode_html_description_of_manual_rule.json deleted file mode 100644 index 8708432c1b6..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/encode_html_description_of_manual_rule.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "rule": { - "key": "manual:MY_MANUAL", - "htmlDesc": "<div>line1
line2</div>" - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java index ba4bb76b3e8..4688032aff3 100644 --- a/sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleTesting.java @@ -96,13 +96,4 @@ public class RuleTesting { .setType(templateRule.getType()); } - public static RuleDto newManualRule(String manualKey) { - return new RuleDto().setRuleKey(manualKey) - .setName("Name " + manualKey) - .setRepositoryKey(RuleKey.MANUAL_REPOSITORY_KEY) - .setDescription("Description " + manualKey) - .setStatus(RuleStatus.READY) - .setType(RuleType.CODE_SMELL); - } - } -- 2.39.5