aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-testing-harness
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-01-24 10:01:44 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-01-24 10:26:00 +0100
commit5c1b16ad0a7941ff3a5f02be6f926e3b7e5eae84 (patch)
treeac6d925873dd46df50f4cfc1ea974e3d13c67433 /sonar-testing-harness
parentb16c495b004e952cea0cc9dba5beb303d7724840 (diff)
downloadsonarqube-5c1b16ad0a7941ff3a5f02be6f926e3b7e5eae84.tar.gz
sonarqube-5c1b16ad0a7941ff3a5f02be6f926e3b7e5eae84.zip
SONAR-5010 improve WS API
* remove "throws Exception" from signature of RequestHandler * add Request#action() * prefer action "list" over "index"
Diffstat (limited to 'sonar-testing-harness')
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/api/server/ws/WsTester.java26
1 files changed, 17 insertions, 9 deletions
diff --git a/sonar-testing-harness/src/main/java/org/sonar/api/server/ws/WsTester.java b/sonar-testing-harness/src/main/java/org/sonar/api/server/ws/WsTester.java
index aad0844ea5c..6ae58c338cb 100644
--- a/sonar-testing-harness/src/main/java/org/sonar/api/server/ws/WsTester.java
+++ b/sonar-testing-harness/src/main/java/org/sonar/api/server/ws/WsTester.java
@@ -43,13 +43,18 @@ public class WsTester {
public static class TestRequest extends Request {
private final WebService.Controller controller;
- private final String actionKey;
+ private final WebService.Action action;
private String method = "GET";
private Map<String, String> params = new HashMap<String, String>();
- private TestRequest(WebService.Controller controller, String actionKey) {
+ private TestRequest(WebService.Controller controller, WebService.Action action) {
this.controller = controller;
- this.actionKey = actionKey;
+ this.action = action;
+ }
+
+ @Override
+ public WebService.Action action() {
+ return action;
}
@Override
@@ -81,10 +86,6 @@ public class WsTester {
}
public Result execute() throws Exception {
- WebService.Action action = controller.action(actionKey);
- if (action == null) {
- throw new IllegalArgumentException("Action not found: " + actionKey);
- }
TestResponse response = new TestResponse();
action.handler().handle(this, response);
return new Result(response);
@@ -207,10 +208,17 @@ public class WsTester {
if (context.controllers().size() != 1) {
throw new IllegalStateException("The method newRequest(String) requires to define one, and only one, controller");
}
- return new TestRequest(context.controllers().get(0), actionKey);
+ WebService.Controller controller = context.controllers().get(0);
+ WebService.Action action = controller.action(actionKey);
+ if (action == null) {
+ throw new IllegalArgumentException("Action not found: " + actionKey);
+ }
+ return new TestRequest(controller, action);
}
public TestRequest newRequest(String controllerPath, String actionKey) {
- return new TestRequest(context.controller(controllerPath), actionKey);
+ WebService.Controller controller = context.controller(controllerPath);
+ WebService.Action action = controller.action(actionKey);
+ return new TestRequest(controller, action);
}
}