]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 add ws api/rules2/set_note
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 16 May 2014 08:20:36 +0000 (10:20 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 16 May 2014 08:20:36 +0000 (10:20 +0200)
sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
sonar-server/src/main/java/org/sonar/server/rule2/ws/RulesWebService.java
sonar-server/src/main/java/org/sonar/server/rule2/ws/SetNoteAction.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java
sonar-server/src/test/java/org/sonar/server/rule2/ws/AppActionTest.java
sonar-server/src/test/java/org/sonar/server/rule2/ws/RulesWebServiceTest.java

index 335dbabe63aeb634514beff9b9c8d684f9b2a1e6..0256c391473a4fe89a1bed9519d71c26b50e3cdd 100644 (file)
@@ -131,6 +131,7 @@ import org.sonar.server.rule2.index.RuleNormalizer;
 import org.sonar.server.rule2.persistence.RuleDao;
 import org.sonar.server.rule2.ws.RulesWebService;
 import org.sonar.server.rule2.ws.SearchAction;
+import org.sonar.server.rule2.ws.SetNoteAction;
 import org.sonar.server.rule2.ws.SetTagsAction;
 import org.sonar.server.rule2.ws.TagsAction;
 import org.sonar.server.source.CodeColorizers;
@@ -335,6 +336,7 @@ class ServerComponents {
     pico.addSingleton(org.sonar.server.rule2.ws.ShowAction.class);
     pico.addSingleton(TagsAction.class);
     pico.addSingleton(SetTagsAction.class);
+    pico.addSingleton(SetNoteAction.class);
     pico.addSingleton(org.sonar.server.rule2.ws.AppAction.class);
 
     // measure
index 37a0771fe6c42dc322c2e1a372def6f5c2f99231..9969e4d625e106c355d37d122bbd1f8fee279a48 100644 (file)
@@ -27,13 +27,16 @@ public class RulesWebService implements WebService {
   private final ShowAction show;
   private final TagsAction tags;
   private final SetTagsAction setTags;
+  private final SetNoteAction setNote;
   private final AppAction app;
 
-  public RulesWebService(SearchAction search, ShowAction show, TagsAction tags, SetTagsAction setTags, AppAction app) {
+  public RulesWebService(SearchAction search, ShowAction show, TagsAction tags,
+                         SetTagsAction setTags, SetNoteAction setNote, AppAction app) {
     this.search = search;
     this.show = show;
     this.tags = tags;
     this.setTags = setTags;
+    this.setNote = setNote;
     this.app = app;
   }
 
@@ -47,6 +50,7 @@ public class RulesWebService implements WebService {
     show.define(controller);
     tags.define(controller);
     setTags.define(controller);
+    setNote.define(controller);
     app.define(controller);
 
     controller.done();
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/ws/SetNoteAction.java b/sonar-server/src/main/java/org/sonar/server/rule2/ws/SetNoteAction.java
new file mode 100644 (file)
index 0000000..0fb57f9
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.rule2.ws;
+
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.rule2.RuleService;
+
+public class SetNoteAction implements RequestHandler {
+
+  private final RuleService service;
+
+  public SetNoteAction(RuleService service) {
+    this.service = service;
+  }
+
+  void define(WebService.NewController controller) {
+    WebService.NewAction setTags = controller
+      .createAction("set_note")
+      .setDescription("Extend the description of a coding rule")
+      .setSince("4.4")
+      .setPost(true)
+      .setHandler(this);
+    setTags
+      .createParam("key")
+      .setRequired(true)
+      .setDescription("Rule key")
+      .setExampleValue("javascript:EmptyBlock");
+    setTags
+      .createParam("text")
+      .setDescription("Markdown text. Set to blank to remove the note.")
+      .setRequired(true)
+      .setExampleValue("java8,security");
+  }
+
+  @Override
+  public void handle(Request request, Response response) {
+    RuleKey key = RuleKey.parse(request.mandatoryParam("key"));
+    service.setNote(key, request.mandatoryParam("text"));
+  }
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java
new file mode 100644 (file)
index 0000000..20e647e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.qualityprofile;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.server.tester.ServerTester;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ActiveRuleServiceMediumTest {
+
+  @ClassRule
+  public static ServerTester tester = new ServerTester();
+
+  @Test
+  public void activate() throws Exception {
+
+
+  }
+}
index a5865a143f5decd4cf7223bb99c208aa83919d80..0c723c6862de2c1d58e0f0bcf9adb892e75195f4 100644 (file)
@@ -119,7 +119,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
   }
 
   @Test
-  public void update_rules_on_changes() {
+  public void update_and_remove_rules_on_changes() {
     execute(new FakeRepositoryV1());
     assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2);
 
@@ -152,7 +152,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
     assertThat(param.getDescription()).isEqualTo("parameter one v2");
     assertThat(param.getDefaultValue()).isEqualTo("default1 v2");
 
-    // rule2 has been removed
+    // rule2 has been removed -> status set to REMOVED but db row is not deleted
     RuleDto rule2 = dbClient.ruleDao().getByKey(RuleKey.of("fake", "rule2"), dbSession);
     assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED.toString());
     assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2);
index e2d25074342d0143aff543fffad3e0dbf1972010..253cf78f04562a4ae0d6c4f460164eb2afd636ac 100644 (file)
@@ -64,10 +64,10 @@ public class AppActionTest {
 
   @Test
   public void should_generate_app_init_info() throws Exception {
+    AppAction app = new AppAction(languages, ruleRepositories, i18n, debtModel, qProfiles);
     WsTester tester = new WsTester(new RulesWebService(
       mock(SearchAction.class), mock(ShowAction.class), mock(TagsAction.class), mock(SetTagsAction.class),
-      new AppAction(languages, ruleRepositories, i18n, debtModel, qProfiles)));
-
+      mock(SetNoteAction.class), app));
 
     QProfile profile1 = new QProfile().setName("Profile One").setLanguage("bf");
     QProfile profile2 = new QProfile().setName("Profile Two").setLanguage("bf").setParent("Profile One");
index 18452ee30c083516a4a6de29cdd51a3aa88701a8..81991b3f4ce43d7aee64d6194517981b1a55b39e 100644 (file)
@@ -82,11 +82,12 @@ public class RulesWebServiceTest {
     WebService.Controller controller = context.controller("api/rules2");
 
     assertThat(controller).isNotNull();
-    assertThat(controller.actions()).hasSize(5);
+    assertThat(controller.actions()).hasSize(6);
     assertThat(controller.action("search")).isNotNull();
     assertThat(controller.action("show")).isNotNull();
     assertThat(controller.action("tags")).isNotNull();
     assertThat(controller.action("set_tags")).isNotNull();
+    assertThat(controller.action("set_note")).isNotNull();
     assertThat(controller.action("app")).isNotNull();
   }