aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-05-05 15:16:18 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-05-05 15:36:51 +0200
commit5fc90d5d8a59460eef1776a5c6013912105c53b8 (patch)
tree6dc0d6cd1fb7012c446bff8698ca9c3dbebca074 /sonar-server
parentbeeb454dd1053cbc980a48920e2b7297fa8b64bd (diff)
downloadsonarqube-5fc90d5d8a59460eef1776a5c6013912105c53b8.tar.gz
sonarqube-5fc90d5d8a59460eef1776a5c6013912105c53b8.zip
SONAR-5111 Split quality profiles WS into old style Rails description and new dedicated Java WS
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java (renamed from sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWs.java)11
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QualityProfilesWs.java41
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java (renamed from sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java)32
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java10
-rw-r--r--sonar-server/src/test/java/org/sonar/server/ws/WsTester.java9
6 files changed, 69 insertions, 38 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
index 614013342a3..392cc06c452 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
@@ -113,7 +113,7 @@ import org.sonar.server.qualitygate.RegisterQualityGates;
import org.sonar.server.qualitygate.ws.*;
import org.sonar.server.qualityprofile.*;
import org.sonar.server.qualityprofile.ws.QProfileRestoreDefaultAction;
-import org.sonar.server.qualityprofile.ws.QProfilesWs;
+import org.sonar.server.qualityprofile.ws.ProfilesWs;
import org.sonar.server.rule.*;
import org.sonar.server.rule.ws.*;
import org.sonar.server.rule2.RuleService;
@@ -278,7 +278,7 @@ class ServerComponents {
pico.addSingleton(DefaultProfilesCache.class);
pico.addSingleton(ESActiveRule.class);
pico.addSingleton(QProfileRestoreDefaultAction.class);
- pico.addSingleton(QProfilesWs.class);
+ pico.addSingleton(ProfilesWs.class);
// rule
pico.addSingleton(AnnotationRuleParser.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWs.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java
index 42aa536fffd..c0b9920f83a 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWs.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java
@@ -24,20 +24,13 @@ import com.google.common.io.Resources;
import org.sonar.api.server.ws.RailsHandler;
import org.sonar.api.server.ws.WebService;
-public class QProfilesWs implements WebService {
-
- private final QProfileRestoreDefaultAction qProfileRestoreDefaultAction;
-
- public QProfilesWs(QProfileRestoreDefaultAction qProfileRestoreDefaultAction) {
- this.qProfileRestoreDefaultAction = qProfileRestoreDefaultAction;
- }
+public class ProfilesWs implements WebService {
@Override
public void define(Context context) {
- NewController controller = context.createController("api/qprofiles")
+ NewController controller = context.createController("api/profiles")
.setDescription("Quality profiles management");
- qProfileRestoreDefaultAction.define(controller);
defineListAction(controller);
defineBackupAction(controller);
defineRestoreAction(controller);
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QualityProfilesWs.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QualityProfilesWs.java
new file mode 100644
index 00000000000..e6d95603ec6
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QualityProfilesWs.java
@@ -0,0 +1,41 @@
+/*
+ * 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.ws;
+
+import org.sonar.api.server.ws.WebService;
+
+public class QualityProfilesWs implements WebService {
+
+ private final QProfileRestoreDefaultAction qProfileRestoreDefaultAction;
+
+ public QualityProfilesWs(QProfileRestoreDefaultAction qProfileRestoreDefaultAction) {
+ this.qProfileRestoreDefaultAction = qProfileRestoreDefaultAction;
+ }
+
+ @Override
+ public void define(Context context) {
+ NewController controller = context.createController("api/qualityprofiles")
+ .setDescription("Quality profiles management");
+
+ qProfileRestoreDefaultAction.define(controller);
+
+ controller.done();
+ }
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java
index 664c0f1528f..34bb4606c5b 100644
--- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java
@@ -26,44 +26,32 @@ import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.server.ws.RailsHandler;
import org.sonar.api.server.ws.WebService;
-import org.sonar.server.qualityprofile.QProfileBackup;
import org.sonar.server.ws.WsTester;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
@RunWith(MockitoJUnitRunner.class)
-public class QProfilesWsTest {
+public class ProfilesWsTest {
WsTester tester;
@Before
public void setUp() {
- tester = new WsTester(new QProfilesWs(new QProfileRestoreDefaultAction(mock(QProfileBackup.class))));
+ tester = new WsTester(new ProfilesWs());
}
@Test
public void define_controller() throws Exception {
- WebService.Controller controller = tester.controller("api/qprofiles");
+ WebService.Controller controller = tester.controller("api/profiles");
assertThat(controller).isNotNull();
- assertThat(controller.path()).isEqualTo("api/qprofiles");
+ assertThat(controller.path()).isEqualTo("api/profiles");
assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(6);
- }
-
- @Test
- public void define_restore_default_action() throws Exception {
- WebService.Controller controller = tester.controller("api/qprofiles");
-
- WebService.Action restoreProfiles = controller.action("restore_default");
- assertThat(restoreProfiles).isNotNull();
- assertThat(restoreProfiles.handler()).isNotNull();
- assertThat(restoreProfiles.params()).hasSize(1);
+ assertThat(controller.actions()).hasSize(5);
}
@Test
public void define_list_action() throws Exception {
- WebService.Controller controller = tester.controller("api/qprofiles");
+ WebService.Controller controller = tester.controller("api/profiles");
WebService.Action restoreProfiles = controller.action("list");
assertThat(restoreProfiles).isNotNull();
@@ -74,7 +62,7 @@ public class QProfilesWsTest {
@Test
public void define_backup_action() throws Exception {
- WebService.Controller controller = tester.controller("api/qprofiles");
+ WebService.Controller controller = tester.controller("api/profiles");
WebService.Action restoreProfiles = controller.action("backup");
assertThat(restoreProfiles).isNotNull();
@@ -84,7 +72,7 @@ public class QProfilesWsTest {
@Test
public void define_restore_action() throws Exception {
- WebService.Controller controller = tester.controller("api/qprofiles");
+ WebService.Controller controller = tester.controller("api/profiles");
WebService.Action restoreProfiles = controller.action("restore");
assertThat(restoreProfiles).isNotNull();
@@ -94,7 +82,7 @@ public class QProfilesWsTest {
@Test
public void define_destroy_action() throws Exception {
- WebService.Controller controller = tester.controller("api/qprofiles");
+ WebService.Controller controller = tester.controller("api/profiles");
WebService.Action restoreProfiles = controller.action("destroy");
assertThat(restoreProfiles).isNotNull();
@@ -104,7 +92,7 @@ public class QProfilesWsTest {
@Test
public void define_set_as_default_action() throws Exception {
- WebService.Controller controller = tester.controller("api/qprofiles");
+ WebService.Controller controller = tester.controller("api/profiles");
WebService.Action restoreProfiles = controller.action("set_as_default");
assertThat(restoreProfiles).isNotNull();
diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java
index c09a49f35cc..5ac3bdab5eb 100644
--- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java
@@ -42,14 +42,14 @@ public class QProfileRestoreDefaultActionTest {
@Before
public void setUp() throws Exception {
- tester = new WsTester(new QProfilesWs(new QProfileRestoreDefaultAction(qProfileBackup)));
+ tester = new WsTester(new QualityProfilesWs(new QProfileRestoreDefaultAction(qProfileBackup)));
}
@Test
public void return_empty_result_when_no_infos_or_warnings() throws Exception {
when(qProfileBackup.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult());
- WsTester.TestRequest request = tester.newPostRequest("api/qprofiles", "restore_default").setParam("language", "java");
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
request.execute().assertNoContent();
}
@@ -57,7 +57,7 @@ public class QProfileRestoreDefaultActionTest {
public void show_infos() throws Exception {
when(qProfileBackup.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")));
- WsTester.TestRequest request = tester.newPostRequest("api/qprofiles", "restore_default").setParam("language", "java");
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
request.execute().assertJson(getClass(), "show_infos.json");
}
@@ -65,7 +65,7 @@ public class QProfileRestoreDefaultActionTest {
public void show_warnings() throws Exception {
when(qProfileBackup.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addWarnings(newArrayList("Some warning")));
- WsTester.TestRequest request = tester.newPostRequest("api/qprofiles", "restore_default").setParam("language", "java");
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
request.execute().assertJson(getClass(), "show_warnings.json");
}
@@ -73,7 +73,7 @@ public class QProfileRestoreDefaultActionTest {
public void show_infos_and_warnings() throws Exception {
when(qProfileBackup.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")).addWarnings(newArrayList("Some warning")));
- WsTester.TestRequest request = tester.newPostRequest("api/qprofiles", "restore_default").setParam("language", "java");
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
request.execute().assertJson(getClass(), "show_infos_and_warnings.json");
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java b/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
index f3263d9b5ce..f809921a901 100644
--- a/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
+++ b/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
@@ -30,6 +30,7 @@ import org.sonar.api.utils.text.XmlWriter;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@@ -217,7 +218,15 @@ public class WsTester {
private TestRequest newRequest(String controllerKey, String actionKey, String method) {
TestRequest request = new TestRequest(method);
WebService.Controller controller = context.controller(controllerKey);
+ if (controller == null) {
+ throw new IllegalArgumentException(
+ String.format("Controller '%s' is unknown, did you forget to call NewController.done()?", controllerKey));
+ }
WebService.Action action = controller.action(actionKey);
+ if (action == null) {
+ throw new IllegalArgumentException(
+ String.format("Action '%s' not found on controller '%s'.", actionKey, controllerKey));
+ }
request.setAction(action);
return request;
}