Browse Source

SONAR-5007 add ws api/rules2/set_note

tags/4.4-RC1
Simon Brandhof 10 years ago
parent
commit
e2d2a138c7

+ 2
- 0
sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java View 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

+ 5
- 1
sonar-server/src/main/java/org/sonar/server/rule2/ws/RulesWebService.java View 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();

+ 61
- 0
sonar-server/src/main/java/org/sonar/server/rule2/ws/SetNoteAction.java View File

@@ -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"));
}
}

+ 38
- 0
sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java View File

@@ -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 {


}
}

+ 2
- 2
sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java View 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);

+ 2
- 2
sonar-server/src/test/java/org/sonar/server/rule2/ws/AppActionTest.java View 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");

+ 2
- 1
sonar-server/src/test/java/org/sonar/server/rule2/ws/RulesWebServiceTest.java View 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();
}


Loading…
Cancel
Save