return l10nKey;
}
- @CheckForNull
public Object[] l10nParams() {
if (l10nParams == null) {
- return null;
+ return new Object[0];
} else {
return Arrays.copyOf(l10nParams, l10nParams.length);
}
*/
package org.sonar.server.rule.ws;
+import org.sonar.server.exceptions.NotFoundException;
+
import com.google.common.collect.Sets;
import org.elasticsearch.common.collect.Lists;
import org.sonar.api.rule.RuleKey;
@Override
public void handle(Request request, Response response) {
- Rule rule = rules.findByKey(RuleKey.parse(request.mandatoryParam("key")));
+ RuleKey ruleKey = RuleKey.parse(request.mandatoryParam("key"));
+ Rule rule = rules.findByKey(ruleKey);
+ if (rule == null) {
+ throw new NotFoundException("No rule found for key " + ruleKey);
+ }
Set<String> allAdminTags = Sets.newHashSet(rule.adminTags());
String[] tagsFromRequest = request.mandatoryParam("tags").split(",");
updateTags(allAdminTags, tagsFromRequest);
package org.sonar.server.rule.ws;
+import org.sonar.server.exceptions.NotFoundException;
+
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
assertThat((List<String>) newTags).hasSize(4).containsOnly("admin1", "admin2", "tag1", "tag2");
}
+ @Test(expected = NotFoundException.class)
+ public void add_tags_key_not_found() throws Exception {
+ tester.newRequest("add_tags").setParam("key", "polop:palap").setParam("tags", "tag1,tag2").execute();
+ }
+
private Rule create(String repoKey, String key, String name, String description) {
Rule mockRule = mock(Rule.class);
when(mockRule.adminTags()).thenReturn(ImmutableList.of("admin1", "admin2"));