import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.core.qualityprofile.db.QualityProfileDto;
import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.rule.Rule;
import org.sonar.server.rule.RuleService;
@Override
protected RuleQuery doQuery(Request request) {
- return createRuleQuery(ruleService.newRuleQuery(), request);
+ RuleQuery plainQuery = createRuleQuery(ruleService.newRuleQuery(), request);
+
+ String qProfileKey = request.param(PARAM_QPROFILE);
+ if (qProfileKey != null) {
+ QualityProfileDto qProfile = activeRuleCompleter.loadProfile(qProfileKey);
+ if (qProfile != null) {
+ plainQuery.setLanguages(ImmutableList.of(qProfile.getLanguage()));
+ }
+ }
+
+ return plainQuery;
}
@Override
request.setParam(SearchOptions.PARAM_FIELDS, "actives");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_profile_active_rules.json", false);
+
+ tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD)
+ .setParam(SearchAction.PARAM_ACTIVATION, "true")
+ .setParam(SearchAction.PARAM_QPROFILE, "unknown_profile")
+ .setParam(SearchOptions.PARAM_FIELDS, "actives")
+ .execute()
+ .assertJson(this.getClass(), "search_no_rules.json", false);
}
@Test