import java.util.Map;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.user.UserSession;
import static java.lang.String.format;
+import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ACTIVATE_RULE;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters.PARAM_PARAMS;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters.PARAM_PROFILE_KEY;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters.PARAM_RESET;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters.PARAM_RULE_KEY;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters.PARAM_SEVERITY;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARAMS;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RESET;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SEVERITY;
-@ServerSide
public class ActivateRuleAction implements QProfileWsAction {
private final DbClient dbClient;
public void define(WebService.NewController controller) {
WebService.NewAction activate = controller
.createAction(ACTION_ACTIVATE_RULE)
- .setDescription("Activate a rule on a Quality profile")
+ .setDescription("Activate a rule on a Quality Profile.<br> " +
+ "Requires to be logged in and the 'Administer Quality Profiles' permission.")
.setHandler(this)
.setPost(true)
.setSince("4.4");
- activate.createParam(PARAM_PROFILE_KEY)
- .setDescription("Key of Quality profile, can be obtained through <code>api/qualityprofiles/search</code>")
+ activate.createParam(PARAM_PROFILE)
+ .setDescription("Quality Profile key. Can be obtained through <code>api/qualityprofiles/search</code>")
+ .setDeprecatedKey("profile_key", "6.5")
.setRequired(true)
- .setExampleValue(Uuids.UUID_EXAMPLE_01);
+ .setExampleValue(UUID_EXAMPLE_01);
- activate.createParam(PARAM_RULE_KEY)
- .setDescription("Key of the rule")
+ activate.createParam(PARAM_RULE)
+ .setDescription("Rule key")
+ .setDeprecatedKey("rule_key", "6.5")
.setRequired(true)
.setExampleValue("squid:AvoidCycles");
.setPossibleValues(Severity.ALL);
activate.createParam(PARAM_PARAMS)
- .setDescription(format("Parameters as semi-colon list of <key>=<value>. Ignored if parameter %s is true.", PARAM_RESET))
+ .setDescription(format("Parameters as semi-colon list of <code>key=value</code>. Ignored if parameter %s is true.", PARAM_RESET))
.setExampleValue("params=key1=v1;key2=v2");
activate.createParam(PARAM_RESET)
- .setDescription("Reset severity and parameters of activated rule. Set the values defined on parent profile " +
- "or from rule default values.")
+ .setDescription("Reset severity and parameters of activated rule. Set the values defined on parent profile or from rule default values.")
.setBooleanPossibleValues();
}
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
- String profileKey = request.mandatoryParam(PARAM_PROFILE_KEY);
+ String profileKey = request.mandatoryParam(PARAM_PROFILE);
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
dbSession.commit();
activeRuleIndexer.indexChanges(dbSession, changes);
}
+
response.noContent();
}
private static RuleActivation readActivation(Request request) {
- RuleKey ruleKey = RuleKey.parse(request.mandatoryParam(PARAM_RULE_KEY));
+ RuleKey ruleKey = RuleKey.parse(request.mandatoryParam(PARAM_RULE));
boolean reset = Boolean.TRUE.equals(request.paramAsBoolean(PARAM_RESET));
if (reset) {
return RuleActivation.createReset(ruleKey);
*/
package org.sonar.server.qualityprofile.ws;
+import java.net.HttpURLConnection;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.Severity;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
+import org.sonar.server.qualityprofile.RuleActivation;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE;
public class ActivateRuleActionTest {
private RuleActivator ruleActivator = mock(RuleActivator.class);
private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(dbTester));
private ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
- private ActivateRuleAction underTest = new ActivateRuleAction(dbClient, ruleActivator, userSession, wsSupport, activeRuleIndexer);
- private WsActionTester wsActionTester = new WsActionTester(underTest);
+
+ private WsActionTester ws = new WsActionTester(new ActivateRuleAction(dbClient, ruleActivator, userSession, wsSupport, activeRuleIndexer));
+
private OrganizationDto defaultOrganization;
private OrganizationDto organization;
@Test
public void define_activate_rule_action() {
- WebService.Action definition = wsActionTester.getDef();
+ WebService.Action definition = ws.getDef();
assertThat(definition).isNotNull();
assertThat(definition.isPost()).isTrue();
- assertThat(definition.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("severity", "profile_key", "reset", "rule_key", "params");
+ assertThat(definition.params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("severity", "profile", "reset", "rule", "params");
+ WebService.Param profileKey = definition.param("profile");
+ assertThat(profileKey.deprecatedKey()).isEqualTo("profile_key");
+ WebService.Param ruleKey = definition.param("rule");
+ assertThat(ruleKey.deprecatedKey()).isEqualTo("rule_key");
}
@Test
public void should_fail_if_not_logged_in() {
- TestRequest request = wsActionTester.newRequest()
+ TestRequest request = ws.newRequest()
.setMethod("POST")
- .setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
- .setParam("profile_key", randomAlphanumeric(UUID_SIZE));
+ .setParam(PARAM_RULE, RuleTesting.newRule().getKey().toString())
+ .setParam(PARAM_PROFILE, randomAlphanumeric(UUID_SIZE));
expectedException.expect(UnauthorizedException.class);
+
request.execute();
}
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
- TestRequest request = wsActionTester.newRequest()
+ TestRequest request = ws.newRequest()
.setMethod("POST")
- .setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
- .setParam("profile_key", qualityProfile.getKee());
+ .setParam(PARAM_RULE, RuleTesting.newRuleDto().getKey().toString())
+ .setParam(PARAM_PROFILE, qualityProfile.getKee());
expectedException.expect(ForbiddenException.class);
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization, profile -> profile.setIsBuiltIn(true).setName("Xoo profile").setLanguage("xoo"));
- TestRequest request = wsActionTester.newRequest()
+ TestRequest request = ws.newRequest()
.setMethod("POST")
- .setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
- .setParam("profile_key", qualityProfile.getKee());
+ .setParam(PARAM_RULE, RuleTesting.newRuleDto().getKey().toString())
+ .setParam(PARAM_PROFILE, qualityProfile.getKee());
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Operation forbidden for built-in Quality Profile 'Xoo profile' with language 'xoo'");
request.execute();
}
-// @Test
-// public void activate_rule_in_default_organization() {
-// userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
-// QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
-// RuleKey ruleKey = RuleTesting.randomRuleKey();
-// TestRequest request = wsActionTester.newRequest()
-// .setMethod("POST")
-// .setParam("rule_key", ruleKey.toString())
-// .setParam("profile_key", qualityProfile.getKee())
-// .setParam("severity", "BLOCKER")
-// .setParam("params", "key1=v1;key2=v2")
-// .setParam("reset", "false");
-//
-// TestResponse response = request.execute();
-//
-// assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
-// ArgumentCaptor<RuleActivation> captor = ArgumentCaptor.forClass(RuleActivation.class);
-// Mockito.verify(ruleActivator).activate(any(DbSession.class), captor.capture(), eq(qualityProfile.getKee()));
-// assertThat(captor.getValue().getRuleKey()).isEqualTo(ruleKey);
-// assertThat(captor.getValue().getSeverity()).isEqualTo(Severity.BLOCKER);
-// assertThat(captor.getValue().getParameters()).containsExactly(entry("key1", "v1"), entry("key2", "v2"));
-// assertThat(captor.getValue().isReset()).isFalse();
-// }
-//
-// @Test
-// public void activate_rule_in_specific_organization() {
-// userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
-// QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
-// RuleKey ruleKey = RuleTesting.randomRuleKey();
-// TestRequest request = wsActionTester.newRequest()
-// .setMethod("POST")
-// .setParam("rule_key", ruleKey.toString())
-// .setParam("profile_key", qualityProfile.getKee())
-// .setParam("severity", "BLOCKER")
-// .setParam("params", "key1=v1;key2=v2")
-// .setParam("reset", "false");
-//
-// TestResponse response = request.execute();
-//
-// assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
-// ArgumentCaptor<RuleActivation> captor = ArgumentCaptor.forClass(RuleActivation.class);
-// Mockito.verify(ruleActivator).activate(any(DbSession.class), captor.capture(), eq(qualityProfile.getKee()));
-// assertThat(captor.getValue().getRuleKey()).isEqualTo(ruleKey);
-// assertThat(captor.getValue().getSeverity()).isEqualTo(Severity.BLOCKER);
-// assertThat(captor.getValue().getParameters()).containsExactly(entry("key1", "v1"), entry("key2", "v2"));
-// assertThat(captor.getValue().isReset()).isFalse();
-// }
+ @Test
+ public void activate_rule_in_default_organization() {
+ userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
+ RuleKey ruleKey = RuleTesting.randomRuleKey();
+ TestRequest request = ws.newRequest()
+ .setMethod("POST")
+ .setParam(PARAM_RULE, ruleKey.toString())
+ .setParam(PARAM_PROFILE, qualityProfile.getKee())
+ .setParam("severity", "BLOCKER")
+ .setParam("params", "key1=v1;key2=v2")
+ .setParam("reset", "false");
+
+ TestResponse response = request.execute();
+
+ assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
+ ArgumentCaptor<RuleActivation> captor = ArgumentCaptor.forClass(RuleActivation.class);
+ verify(ruleActivator).activate(any(DbSession.class), captor.capture(), any(QProfileDto.class));
+ RuleActivation value = captor.getValue();
+ assertThat(value.getRuleKey()).isEqualTo(ruleKey);
+ assertThat(value.getSeverity()).isEqualTo(Severity.BLOCKER);
+ assertThat(value.isReset()).isFalse();
+ }
+
+ @Test
+ public void activate_rule_in_specific_organization() {
+ userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
+ QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
+ RuleKey ruleKey = RuleTesting.randomRuleKey();
+ TestRequest request = ws.newRequest()
+ .setMethod("POST")
+ .setParam(PARAM_RULE, ruleKey.toString())
+ .setParam(PARAM_PROFILE, qualityProfile.getKee())
+ .setParam("severity", "BLOCKER")
+ .setParam("params", "key1=v1;key2=v2")
+ .setParam("reset", "false");
+
+ TestResponse response = request.execute();
+
+ assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
+ ArgumentCaptor<RuleActivation> captor = ArgumentCaptor.forClass(RuleActivation.class);
+ verify(ruleActivator).activate(any(DbSession.class), captor.capture(), any(QProfileDto.class));
+ assertThat(captor.getValue().getRuleKey()).isEqualTo(ruleKey);
+ assertThat(captor.getValue().getSeverity()).isEqualTo(Severity.BLOCKER);
+ assertThat(captor.getValue().isReset()).isFalse();
+ }
}
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
-import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
+import org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
+import static org.sonar.server.qualityprofile.ws.QProfilesWs.API_ENDPOINT;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ACTIVATE_RULE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_DEACTIVATE_RULE;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters.PARAM_PROFILE_KEY;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters.PARAM_RULE_KEY;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ActivateActionParameters.PARAM_SEVERITY;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RESET;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SEVERITY;
import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_LANGUAGES;
import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_QPROFILE;
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ACTION_DEACTIVATE_RULE);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
- request.setParam(PARAM_RULE_KEY, rule.getKey().toString());
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, profile.getKee());
+ request.setParam(ActivateActionParameters.PARAM_RULE_KEY, rule.getKey().toString());
request.execute();
session.clearCache();
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, DeactivateRulesAction.DEACTIVATE_RULES_ACTION);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, profile.getKee());
WsTester.Result result = request.execute();
session.clearCache();
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, DeactivateRulesAction.DEACTIVATE_RULES_ACTION);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, profile.getKee());
WsTester.Result result = request.execute();
session.clearCache();
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, DeactivateRulesAction.DEACTIVATE_RULES_ACTION);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
- request.setParam(WebService.Param.TEXT_QUERY, "hello");
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, profile.getKee());
+ request.setParam(Param.TEXT_QUERY, "hello");
WsTester.Result result = request.execute();
session.clearCache();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ACTION_ACTIVATE_RULE);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
- request.setParam(PARAM_RULE_KEY, rule.getKey().toString());
+ request.setParam(PARAM_PROFILE, profile.getKee());
+ request.setParam(PARAM_RULE, rule.getKey().toString());
WsTester.Result result = request.execute();
session.clearCache();
try {
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ACTION_ACTIVATE_RULE);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
- request.setParam(PARAM_RULE_KEY, rule.getKey().toString());
+ request.setParam(PARAM_PROFILE, profile.getKee());
+ request.setParam(PARAM_RULE, rule.getKey().toString());
request.execute();
session.clearCache();
fail();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ACTION_ACTIVATE_RULE);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
- request.setParam(PARAM_RULE_KEY, rule.getKey().toString());
+ request.setParam(PARAM_PROFILE, profile.getKee());
+ request.setParam(PARAM_RULE, rule.getKey().toString());
request.setParam(PARAM_SEVERITY, "MINOR");
WsTester.Result result = request.execute();
session.clearCache();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ActivateRulesAction.ACTIVATE_RULES_ACTION);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, profile.getKee());
request.setParam(PARAM_LANGUAGES, "java");
request.execute().assertJson(getClass(), "bulk_activate_rule.json");
session.clearCache();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ActivateRulesAction.ACTIVATE_RULES_ACTION);
- request.setParam(PARAM_PROFILE_KEY, php.getKee());
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, php.getKee());
request.setParam(PARAM_LANGUAGES, "php");
request.execute().assertJson(getClass(), "bulk_activate_rule_not_all.json");
session.clearCache();
// 1. Activate Rule with query returning 0 hits
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ActivateRulesAction.ACTIVATE_RULES_ACTION);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
- request.setParam(WebService.Param.TEXT_QUERY, "php");
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, profile.getKee());
+ request.setParam(Param.TEXT_QUERY, "php");
request.execute();
session.clearCache();
// 1. Activate Rule with query returning 1 hits
request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ActivateRulesAction.ACTIVATE_RULES_ACTION);
- request.setParam(PARAM_PROFILE_KEY, profile.getKee());
- request.setParam(WebService.Param.TEXT_QUERY, "world");
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, profile.getKee());
+ request.setParam(Param.TEXT_QUERY, "world");
request.execute();
session.commit();
new SearchOptions()).getIds()).hasSize(2);
// 1. Activate Rule with query returning 2 hits
- WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ActivateRulesAction.ACTIVATE_RULES_ACTION);
+ WsTester.TestRequest request = wsTester.newPostRequest(API_ENDPOINT, ActivateRulesAction.ACTIVATE_RULES_ACTION);
request.setParam(ActivateRulesAction.PROFILE_KEY, profile.getKee());
request.setParam(ActivateRulesAction.SEVERITY, "MINOR");
request.execute();
session.commit();
// 1. Activate Rule
- WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ActivateRulesAction.ACTIVATE_RULES_ACTION);
- request.setParam(PARAM_PROFILE_KEY, javaProfile.getKee());
+ WsTester.TestRequest request = wsTester.newPostRequest(API_ENDPOINT, ActivateRulesAction.ACTIVATE_RULES_ACTION);
+ request.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, javaProfile.getKee());
request.setParam(PARAM_QPROFILE, javaProfile.getKee());
request.setParam("activation", "false");
request.execute().assertJson(getClass(), "does_not_return_warnings_when_bulk_activate_on_profile_and_rules_exist_on_another_language_than_profile.json");
assertThat(activeRuleDto.get().getSeverityString()).isEqualTo(Severity.MINOR);
// 1. reset child rule
- WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, ACTION_ACTIVATE_RULE);
- request.setParam("profile_key", subProfile.getKee());
- request.setParam("rule_key", rule.getKey().toString());
- request.setParam("reset", "true");
+ WsTester.TestRequest request = wsTester.newPostRequest(API_ENDPOINT, ACTION_ACTIVATE_RULE);
+ request.setParam(PARAM_PROFILE, subProfile.getKee());
+ request.setParam(PARAM_RULE, rule.getKey().toString());
+ request.setParam(PARAM_RESET, "true");
request.execute();
session.clearCache();
public class QualityProfileWsParameters {
public static final String CONTROLLER_QUALITY_PROFILES = "api/qualityprofiles";
-
- public static final String ACTION_ACTIVATE_RULE = "activate_rule";
public interface ActivateActionParameters {
String PARAM_PROFILE_KEY = "profile_key";
String PARAM_RULE_KEY = "rule_key";
- String PARAM_SEVERITY = "severity";
- String PARAM_RESET = "reset";
- String PARAM_PARAMS = "params";
}
-
public static final String ACTION_RESTORE = "restore";
+
public interface RestoreActionParameters {
String PARAM_BACKUP = "backup";
}
+ public static final String ACTION_ACTIVATE_RULE = "activate_rule";
- public static final String ACTION_DEACTIVATE_RULE = "deactivate_rule";
- public static final String ACTION_SEARCH = "search";
public static final String ACTION_ADD_PROJECT = "add_project";
- public static final String ACTION_REMOVE_PROJECT = "remove_project";
- public static final String ACTION_CREATE = "create";
- public static final String ACTION_COPY = "copy";
public static final String ACTION_CHANGE_PARENT = "change_parent";
- public static final String ACTION_SET_DEFAULT = "set_default";
+ public static final String ACTION_COPY = "copy";
+ public static final String ACTION_CREATE = "create";
+ public static final String ACTION_DEACTIVATE_RULE = "deactivate_rule";
public static final String ACTION_DELETE = "delete";
+ public static final String ACTION_REMOVE_PROJECT = "remove_project";
+ public static final String ACTION_SEARCH = "search";
+ public static final String ACTION_SET_DEFAULT = "set_default";
- public static final String PARAM_ORGANIZATION = "organization";
public static final String PARAM_DEFAULTS = "defaults";
+ public static final String PARAM_FROM_KEY = "fromKey";
+ public static final String PARAM_ORGANIZATION = "organization";
public static final String PARAM_LANGUAGE = "language";
- public static final String PARAM_PROFILE_NAME = "profileName";
+ public static final String PARAM_PARAMS = "params";
+ public static final String PARAM_PARENT_KEY = "parentKey";
+ public static final String PARAM_PARENT_NAME = "parentName";
+ public static final String PARAM_PROFILE = "profile";
public static final String PARAM_PROFILE_KEY = "profileKey";
+ public static final String PARAM_PROFILE_NAME = "profileName";
public static final String PARAM_PROJECT_KEY = "projectKey";
public static final String PARAM_PROJECT_UUID = "projectUuid";
- public static final String PARAM_FROM_KEY = "fromKey";
+ public static final String PARAM_RESET = "reset";
+ public static final String PARAM_RULE = "rule";
+ public static final String PARAM_RULE_KEY = "ruleKey";
+ public static final String PARAM_SEVERITY = "severity";
public static final String PARAM_TO_NAME = "toName";
- public static final String PARAM_PARENT_NAME = "parentName";
- public static final String PARAM_PARENT_KEY = "parentKey";
private QualityProfileWsParameters() {
// Only static stuff
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_FROM_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_ORGANIZATION;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARAMS;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_NAME;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_NAME;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_UUID;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RESET;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE_KEY;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SEVERITY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TO_NAME;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.RestoreActionParameters.PARAM_BACKUP;
public void activateRule(ActivateRuleWsRequest request) {
PostRequest httpRequest = new PostRequest(path(ACTION_ACTIVATE_RULE));
httpRequest.setParam(PARAM_ORGANIZATION, request.getOrganization().orElse(null));
- httpRequest.setParam(ActivateActionParameters.PARAM_PARAMS, request.getParams().orElse(null));
- httpRequest.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, request.getProfileKey());
- httpRequest.setParam(ActivateActionParameters.PARAM_RESET, request.getReset().orElse(null));
- httpRequest.setParam(ActivateActionParameters.PARAM_RULE_KEY, request.getRuleKey());
- httpRequest.setParam(ActivateActionParameters.PARAM_SEVERITY, request.getSeverity().map(Enum::name).orElse(null));
+ httpRequest.setParam(PARAM_PARAMS, request.getParams().orElse(null));
+ httpRequest.setParam(PARAM_PROFILE, request.getProfileKey());
+ httpRequest.setParam(PARAM_RESET, request.getReset().orElse(null));
+ httpRequest.setParam(PARAM_RULE, request.getRuleKey());
+ httpRequest.setParam(PARAM_SEVERITY, request.getSeverity().map(Enum::name).orElse(null));
call(httpRequest);
}
import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.ws.Common.Severity;
import org.sonarqube.ws.QualityProfiles;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_FROM_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_ORGANIZATION;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARAMS;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_NAME;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SEVERITY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TO_NAME;
public class QualityProfilesServiceTest {
.hasParam(QualityProfileWsParameters.ActivateActionParameters.PARAM_RULE_KEY, "R1")
.andNoOtherParam();
}
+
+ @Test
+ public void activate_rule() {
+ underTest.activateRule(ActivateRuleWsRequest.builder()
+ .setRuleKey("R1")
+ .setProfileKey("P1")
+ .setOrganization("O1")
+ .setParams("PS1")
+ .setSeverity(Severity.INFO)
+ .build());
+ PostRequest request = serviceTester.getPostRequest();
+
+ serviceTester.assertThat(request)
+ .hasPath("activate_rule")
+ .hasParam(PARAM_PROFILE, "P1")
+ .hasParam(PARAM_RULE, "R1")
+ .hasParam(PARAM_ORGANIZATION, "O1")
+ .hasParam(PARAM_PARAMS, "PS1")
+ .hasParam(PARAM_SEVERITY, Severity.INFO.toString())
+ .andNoOtherParam();
+ }
}