]> source.dussan.org Git - sonarqube.git/commitdiff
Complete WebService with new param metadata
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 25 Apr 2014 18:42:57 +0000 (20:42 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 25 Apr 2014 18:43:08 +0000 (20:43 +0200)
27 files changed:
sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
sonar-server/pom.xml
sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/rule2/ws/RulesWebService.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/rule2/ws/SearchAction.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/rule2/ws/ShowAction.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/rule2/ws/package-info.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWsTest.java
sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/issue/ws/IssuesWsTest.java
sonar-server/src/test/java/org/sonar/server/platform/ws/RestartHandlerTest.java
sonar-server/src/test/java/org/sonar/server/plugins/BatchWsTest.java
sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java
sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QualityGatesWsTest.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileBackupWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RemoveTagsWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RuleSearchWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RuleShowWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RuleTagsWsTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsTest.java
sonar-server/src/test/java/org/sonar/server/rule2/ws/RulesWebServiceTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/source/ws/SourcesWsTest.java
sonar-server/src/test/java/org/sonar/server/ws/WsTester.java [new file with mode: 0644]
sonar-testing-harness/src/main/java/org/sonar/api/server/ws/WsTester.java [deleted file]

index a4725146bdd745fb318edae7a192767d3c270111..0dbcfd0aa5c13bffb1eb4e7a3e02a4fbad53bef1 100644 (file)
@@ -35,10 +35,10 @@ import java.util.Map;
 /**
  * Defines a web service. Note that contrary to the deprecated {@link org.sonar.api.web.Webservice}
  * the ws is fully implemented in Java and does not require any Ruby on Rails code.
- *
+ * <p/>
  * <p/>
  * The classes implementing this extension point must be declared in {@link org.sonar.api.SonarPlugin#getExtensions()}.
- *
+ * <p/>
  * <h3>How to use</h3>
  * <pre>
  * public class HelloWs implements WebService {
@@ -370,7 +370,9 @@ public interface WebService extends ServerExtension {
   }
 
   class NewParam {
-    private String key, description;
+    private String key, description, exampleValue;
+    private boolean required = false;
+    private String[] possibleValues = null;
 
     private NewParam(String key) {
       this.key = key;
@@ -381,6 +383,33 @@ public interface WebService extends ServerExtension {
       return this;
     }
 
+    /**
+     * Is the parameter required or optional ? Default value is false (optional).
+     * @since 4.4
+     */
+    public NewParam setRequired(boolean b) {
+      this.required = b;
+      return this;
+    }
+
+    /**
+     * @since 4.4
+     */
+    public NewParam setExampleValue(@Nullable String s) {
+      this.exampleValue = s;
+      return this;
+    }
+
+    /**
+     * Exhaustive list of possible values when it makes sense, for example
+     * list of severities.
+     * @since 4.4
+     */
+    public NewParam setPossibleValues(@Nullable String... s) {
+      this.possibleValues = s;
+      return this;
+    }
+
     @Override
     public String toString() {
       return key;
@@ -389,11 +418,16 @@ public interface WebService extends ServerExtension {
 
   @Immutable
   class Param {
-    private final String key, description;
+    private final String key, description, exampleValue;
+    private final boolean required;
+    private final String[] possibleValues;
 
     public Param(NewParam newParam) {
       this.key = newParam.key;
       this.description = newParam.description;
+      this.exampleValue = newParam.exampleValue;
+      this.required = newParam.required;
+      this.possibleValues = (newParam.possibleValues == null ? new String[0] : newParam.possibleValues);
     }
 
     public String key() {
@@ -405,6 +439,29 @@ public interface WebService extends ServerExtension {
       return description;
     }
 
+    /**
+     * @since 4.4
+     */
+    @CheckForNull
+    public String exampleValue() {
+      return exampleValue;
+    }
+
+    /**
+     * Is the parameter required or optional ?
+     * @since 4.4
+     */
+    public boolean isRequired() {
+      return required;
+    }
+
+    /**
+     * @since 4.4
+     */
+    public String[] possibleValues() {
+      return possibleValues;
+    }
+
     @Override
     public String toString() {
       return key;
index afe7cbc62749c877231d3d65738c4b770d2e5228..335705fda92aca4c833c51bdca3c066a86c8b098 100644 (file)
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>sonar-testing-harness</artifactId>
+      <groupId>org.skyscreamer</groupId>
+      <artifactId>jsonassert</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-all</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
     <profile>
       <id>js-tests</id>
       <activation>
-        <property><name>!skipTests</name></property>
+        <property>
+          <name>!skipTests</name>
+        </property>
       </activation>
       <build>
         <plugins>
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java
new file mode 100644 (file)
index 0000000..f00af95
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import org.sonar.api.rule.RuleKey;
+
+import javax.annotation.CheckForNull;
+
+/**
+ * @since 4.4
+ */
+public class RuleService {
+
+  @CheckForNull
+  public Rule getByKey(RuleKey key) {
+    return null;
+  }
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/ws/RulesWebService.java b/sonar-server/src/main/java/org/sonar/server/rule2/ws/RulesWebService.java
new file mode 100644 (file)
index 0000000..7b54490
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.server.ws.WebService;
+
+public class RulesWebService implements WebService {
+
+  private final SearchAction search;
+  private final ShowAction show;
+
+  public RulesWebService(SearchAction search, ShowAction show) {
+    this.search = search;
+    this.show = show;
+  }
+
+  @Override
+  public void define(Context context) {
+    NewController controller = context
+      .createController("api/rules2")
+      .setDescription("Coding rules")
+      .setSince("4.4");
+
+    search.define(controller);
+    show.define(controller);
+
+    controller.done();
+  }
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/ws/SearchAction.java b/sonar-server/src/main/java/org/sonar/server/rule2/ws/SearchAction.java
new file mode 100644 (file)
index 0000000..21f659a
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.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;
+
+/**
+ * @since 4.4
+ */
+public class SearchAction implements RequestHandler {
+
+  private final RuleService service;
+
+  public SearchAction(RuleService service) {
+    this.service = service;
+  }
+
+  void define(WebService.NewController controller) {
+    WebService.NewAction action = controller
+      .createAction("search")
+      .setDescription("Returns a collection of relevant rules matching a specified query")
+      .setSince("4.4")
+      .setHandler(this);
+
+    action
+      .createParam("q")
+      .setDescription("UTF-8 search query")
+      .setExampleValue("null pointer");
+
+    action
+      .createParam("qProfile")
+      .setDescription("Key of Quality profile")
+      .setExampleValue("java:Sonar way");
+
+    action
+      .createParam("activation")
+      .setDescription("Only if 'qProfile' is set. Possible values are: true | false | all")
+      .setExampleValue("java:Sonar way");
+  }
+
+  @Override
+  public void handle(Request request, Response response) {
+
+  }
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/ws/ShowAction.java b/sonar-server/src/main/java/org/sonar/server/rule2/ws/ShowAction.java
new file mode 100644 (file)
index 0000000..b844aad
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.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;
+
+/**
+ * @since 4.4
+ */
+public class ShowAction implements RequestHandler {
+
+  private final RuleService service;
+
+  public ShowAction(RuleService service) {
+    this.service = service;
+  }
+
+  void define(WebService.NewController controller) {
+    WebService.NewAction action = controller
+      .createAction("show")
+      .setDescription("Returns detailed information about a rule")
+      .setSince("4.4")
+      .setHandler(this);
+
+    action
+      .createParam("key")
+      .setDescription("Rule key")
+      .setRequired(true)
+      .setExampleValue("javascript:EmptyBlock");
+  }
+
+  @Override
+  public void handle(Request request, Response response) {
+
+  }
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/ws/package-info.java b/sonar-server/src/main/java/org/sonar/server/rule2/ws/package-info.java
new file mode 100644 (file)
index 0000000..8fcf3f3
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.rule2.ws;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 87e1fef48e19e46d4b8890894b515029d07c39d9..8757a9855a2837c283ad2f6ecd7c281c483e904d 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.issue.filter;
 
 import org.junit.Test;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.core.issue.DefaultIssueFilter;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.user.MockUserSession;
index 9f21f8646ccce9e61df4aef24fc4ce63fe965aaf..01ddbfbabd9f6b21e72d6b475fcf82679e3f8eb0 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.api.issue.internal.FieldDiffs;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.api.user.User;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.Duration;
index ba6ec3fd9fbbde33753f9f2c95c2b0188684f37a..9fd33aa4b2deebc30cbbd1cead91019e90d49dc0 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.issue.ws;
 
 import org.junit.Test;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index 84590153905cd89838cbcf7d570998f3035a49b9..9a6f5641c308e33c06af00e075858f769c2c16c9 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.platform.ws;
 
 import org.junit.Test;
 import org.sonar.api.config.Settings;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.api.utils.System2;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.platform.Platform;
index d20d346180d0af88b368df46f573e4b039ceb799..fbc92faa24aef9a3a6bad1d895d59ff88356c931 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.platform.Server;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 
 import java.io.File;
 import java.io.IOException;
index 1e6baad3415403d5dcf5c03733a480e53040e95c..4771a5857102feb9ebf6972d10f3e993352b8de4 100644 (file)
@@ -31,7 +31,7 @@ import org.mockito.stubbing.Answer;
 import org.sonar.api.i18n.I18n;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.measures.Metric.ValueType;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.core.timemachine.Periods;
 import org.sonar.server.qualitygate.QualityGates;
 
index 1953a8490e5111f203a428078f979d405f7df9c4..ef9108c1a8e125e739caebff0c0e2902cecd5daa 100644 (file)
@@ -28,7 +28,6 @@ import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.api.server.ws.WebService.Controller;
-import org.sonar.api.server.ws.WsTester;
 import org.sonar.core.qualitygate.db.ProjectQgateAssociation;
 import org.sonar.core.qualitygate.db.ProjectQgateAssociationQuery;
 import org.sonar.core.qualitygate.db.QualityGateConditionDto;
@@ -37,6 +36,7 @@ import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.qualitygate.QgateProjectFinder;
 import org.sonar.server.qualitygate.QgateProjectFinder.Association;
 import org.sonar.server.qualitygate.QualityGates;
+import org.sonar.server.ws.WsTester;
 
 import java.util.List;
 
@@ -253,7 +253,7 @@ public class QualityGatesWsTest {
     ));
     when(qGates.currentUserHasWritePermission()).thenReturn(false);
     tester.newRequest("list").execute().assertJson(
-        "{'qualitygates':[{'id':42,'name':'Golden'},{'id':43,'name':'Star'},{'id':666,'name':'Ninth'}]}");
+      "{'qualitygates':[{'id':42,'name':'Golden'},{'id':43,'name':'Star'},{'id':666,'name':'Ninth'}]}");
   }
 
   @Test
@@ -266,7 +266,7 @@ public class QualityGatesWsTest {
     ));
     when(qGates.getDefault()).thenReturn(defaultQgate);
     tester.newRequest("list").execute().assertJson(
-        "{'qualitygates':[{'id':42,'name':'Golden'},{'id':43,'name':'Star'},{'id':666,'name':'Ninth'}],'default':42}");
+      "{'qualitygates':[{'id':42,'name':'Golden'},{'id':43,'name':'Star'},{'id':666,'name':'Ninth'}],'default':42}");
   }
 
   @Test
@@ -282,14 +282,15 @@ public class QualityGatesWsTest {
     long gateId = 12345L;
     when(qGates.get(gateId)).thenReturn(new QualityGateDto().setId(gateId).setName("Golden"));
     when(qGates.listConditions(gateId)).thenReturn(ImmutableList.of(
-        new QualityGateConditionDto().setId(1L).setMetricKey("ncloc").setOperator("GT").setErrorThreshold("10000"),
-        new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3)
+      new QualityGateConditionDto().setId(1L).setMetricKey("ncloc").setOperator("GT").setErrorThreshold("10000"),
+      new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3)
     ));
     tester.newRequest("show").setParam("id", Long.toString(gateId)).execute().assertJson(
       "{'id':12345,'name':'Golden','conditions':["
         + "{'id':1,'metric':'ncloc','op':'GT','error':'10000'},"
         + "{'id':2,'metric':'new_coverage','op':'LT','warning':'90','period':3}"
-    + "]}");
+        + "]}"
+    );
   }
 
   @Test
@@ -298,14 +299,15 @@ public class QualityGatesWsTest {
     String gateName = "Golden";
     when(qGates.get(gateName)).thenReturn(new QualityGateDto().setId(qGateId).setName(gateName));
     when(qGates.listConditions(qGateId)).thenReturn(ImmutableList.of(
-        new QualityGateConditionDto().setId(1L).setMetricKey("ncloc").setOperator("GT").setErrorThreshold("10000"),
-        new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3)
+      new QualityGateConditionDto().setId(1L).setMetricKey("ncloc").setOperator("GT").setErrorThreshold("10000"),
+      new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3)
     ));
     tester.newRequest("show").setParam("name", gateName).execute().assertJson(
       "{'id':12345,'name':'Golden','conditions':["
         + "{'id':1,'metric':'ncloc','op':'GT','error':'10000'},"
         + "{'id':2,'metric':'new_coverage','op':'LT','warning':'90','period':3}"
-    + "]}");
+        + "]}"
+    );
   }
 
   @Test(expected = BadRequestException.class)
@@ -375,8 +377,8 @@ public class QualityGatesWsTest {
     List<ProjectQgateAssociation> projects = ImmutableList.of(
       new ProjectQgateAssociation().setId(42L).setName("Project One").setMember(false),
       new ProjectQgateAssociation().setId(24L).setName("Project Two").setMember(true)
-      );
-    when(assoc.projects()).thenReturn(projects );
+    );
+    when(assoc.projects()).thenReturn(projects);
     when(projectFinder.find(any(ProjectQgateAssociationQuery.class))).thenReturn(assoc);
     tester.newRequest("search")
       .setParam("gateId", Long.toString(gateId))
index bd5e43be632ae3647d3b43db7a1a3ef171390490..2c947e16bc46801119d1a08a48cacdb279acb323 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.server.qualityprofile.QProfileBackup;
 import org.sonar.server.qualityprofile.QProfileResult;
 
index 74501b9af40bc14b6948c2a97ee6a95b980fb92d..9b93e8e1cdb183544e3cee9b8c694ac98cd21e33 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 
 import static org.fest.assertions.Assertions.assertThat;
 
index a6d58d7679908a19886594504ae99060d878a68e..31c91202065e9c77916712ed0197cbb8337e651d 100644 (file)
@@ -30,7 +30,7 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.rule.RuleKey;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.server.rule.Rule;
 import org.sonar.server.rule.Rules;
index 8eaf6fded063b22bcb42234e9043ccfef7b77ae5..957424eb283063f0e18611ca486f6c0d8dfbbb26 100644 (file)
@@ -28,7 +28,7 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.rule.RuleKey;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.server.rule.Rule;
 import org.sonar.server.rule.Rules;
index 566d12b1bcc1dfaeb397a63f87b23a728f717746..1100762fd2c62c9beaaa9d6d91c4348ba09e0fdd 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.api.resources.Languages;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.server.paging.PagedResult;
 import org.sonar.server.paging.PagingResult;
 import org.sonar.server.rule.Rule;
index 2719ad27c745567e5a72e15819adb7b334308c32..f44b71fbd0089c62cd23bbb310bfd5a973212d57 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.resources.Language;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.rule.Rule;
index 9290508cc9af67205de45af63d868a659c16a3d8..7674f66b0a5d45b6440eb47553c01b31122ca60c 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.core.rule.RuleTagDto;
 import org.sonar.server.rule.RuleTags;
 
index a8e0e8675784033ff21f1c728beed46b9c4db11b..a513d509ff4fe7a4a705753489b304fa497ea578 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 
 import static org.fest.assertions.Assertions.assertThat;
 
diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/ws/RulesWebServiceTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/ws/RulesWebServiceTest.java
new file mode 100644 (file)
index 0000000..c61a550
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.rule2.RuleService;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class RulesWebServiceTest {
+
+  @Test
+  public void define() throws Exception {
+    RuleService service = mock(RuleService.class);
+    SearchAction search = new SearchAction(service);
+    ShowAction show = new ShowAction(service);
+    RulesWebService ws = new RulesWebService(search, show);
+
+    WebService.Context context = new WebService.Context();
+    ws.define(context);
+
+    WebService.Controller controller = context.controller("api/rules2");
+    assertThat(controller).isNotNull();
+    assertThat(controller.since()).isEqualTo("4.4");
+    assertThat(controller.actions()).hasSize(2);
+    assertThat(controller.action("search")).isNotNull();
+    assertThat(controller.action("show")).isNotNull();
+  }
+}
index f64ec6a8d0a76be72c80c63b567cf0273b6f81bb..537e14039745f6265849d10f47d4a963b03c1124 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.source.SourceService;
 
index 30ca4d9be55efeabbe6d34e305445255ddd6fbd4..b24da55479b4829a022f5ce953dcd9d69fdcf499 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.source.ws;
 
 import org.junit.Test;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.api.server.ws.WsTester;
+import org.sonar.server.ws.WsTester;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
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
new file mode 100644 (file)
index 0000000..8906997
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+ * 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.ws;
+
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.IOUtils;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.api.utils.text.XmlWriter;
+
+import javax.annotation.CheckForNull;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @since 4.2
+ */
+public class WsTester {
+
+  public static class TestRequest extends Request {
+
+    private final WebService.Controller controller;
+    private final WebService.Action action;
+    private String method = "GET";
+    private Map<String, String> params = new HashMap<String, String>();
+
+    private TestRequest(WebService.Controller controller, WebService.Action action) {
+      this.controller = controller;
+      this.action = action;
+    }
+
+    @Override
+    public WebService.Action action() {
+      return action;
+    }
+
+    @Override
+    public String method() {
+      return method;
+    }
+
+    public TestRequest setMethod(String s) {
+      this.method = s;
+      return this;
+    }
+
+    public TestRequest setParams(Map<String, String> m) {
+      this.params = m;
+      return this;
+    }
+
+    public TestRequest setParam(String key, @CheckForNull String value) {
+      if (value != null) {
+        params.put(key, value);
+      }
+      return this;
+    }
+
+    @Override
+    @CheckForNull
+    public String param(String key) {
+      return params.get(key);
+    }
+
+    public Result execute() {
+      TestResponse response = new TestResponse();
+      action.handler().handle(this, response);
+      return new Result(response);
+    }
+  }
+
+  public static class TestResponse implements Response {
+
+    public class TestStream implements Response.Stream {
+      private String mediaType;
+      private int status;
+
+      @CheckForNull
+      public String mediaType() {
+        return mediaType;
+      }
+
+      public int status() {
+        return status;
+      }
+
+      @Override
+      public Response.Stream setMediaType(String s) {
+        this.mediaType = s;
+        return this;
+      }
+
+      @Override
+      public Response.Stream setStatus(int i) {
+        this.status = i;
+        return this;
+      }
+
+      @Override
+      public OutputStream output() {
+        return output;
+      }
+    }
+
+    private final ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+    @Override
+    public JsonWriter newJsonWriter() {
+      return JsonWriter.of(new OutputStreamWriter(output, Charsets.UTF_8));
+    }
+
+    @Override
+    public XmlWriter newXmlWriter() {
+      return XmlWriter.of(new OutputStreamWriter(output, Charsets.UTF_8));
+    }
+
+    @Override
+    public Stream stream() {
+      return new TestStream();
+    }
+
+
+    @Override
+    public Response noContent() {
+      IOUtils.closeQuietly(output);
+      return this;
+    }
+  }
+
+
+  public static class Result {
+    private final TestResponse response;
+
+    private Result(TestResponse response) {
+      this.response = response;
+    }
+
+    public Result assertNoContent() {
+      //FIXME
+      return this;
+    }
+
+    public String outputAsString() {
+      return new String(response.output.toByteArray(), Charsets.UTF_8);
+    }
+
+    public Result assertJson(String expectedJson) throws Exception {
+      String json = outputAsString();
+      JSONAssert.assertEquals(expectedJson, json, true);
+      return this;
+    }
+
+    /**
+     * Compares JSON response with JSON file available in classpath. For example if class
+     * is org.foo.BarTest and filename is index.json, then file must be located
+     * at src/test/resources/org/foo/BarTest/index.json.
+     *
+     * @param clazz                the test class
+     * @param jsonResourceFilename name of the file containing the expected JSON
+     */
+    public Result assertJson(Class clazz, String expectedJsonFilename) throws Exception {
+      String path = clazz.getSimpleName() + "/" + expectedJsonFilename;
+      URL url = clazz.getResource(path);
+      if (url == null) {
+        throw new IllegalStateException("Cannot find " + path);
+      }
+      String json = outputAsString();
+      JSONAssert.assertEquals(IOUtils.toString(url), json, true);
+      return this;
+    }
+  }
+
+  private final WebService.Context context = new WebService.Context();
+
+  public WsTester(WebService... webServices) {
+    for (WebService webService : webServices) {
+      webService.define(context);
+    }
+  }
+
+  public WebService.Context context() {
+    return context;
+  }
+
+  @CheckForNull
+  public WebService.Controller controller(String path) {
+    return context.controller(path);
+  }
+
+  public TestRequest newRequest(String actionKey) {
+    if (context.controllers().size() != 1) {
+      throw new IllegalStateException("The method newRequest(String) requires to define one, and only one, controller");
+    }
+    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) {
+    WebService.Controller controller = context.controller(controllerPath);
+    WebService.Action action = controller.action(actionKey);
+    return new TestRequest(controller, action);
+  }
+}
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
deleted file mode 100644 (file)
index 6c33897..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * 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.api.server.ws;
-
-import org.apache.commons.io.Charsets;
-import org.apache.commons.io.IOUtils;
-import org.skyscreamer.jsonassert.JSONAssert;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.api.utils.text.XmlWriter;
-
-import javax.annotation.CheckForNull;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 4.2
- */
-public class WsTester {
-
-  public static class TestRequest extends Request {
-
-    private final WebService.Controller controller;
-    private final WebService.Action action;
-    private String method = "GET";
-    private Map<String, String> params = new HashMap<String, String>();
-
-    private TestRequest(WebService.Controller controller, WebService.Action action) {
-      this.controller = controller;
-      this.action = action;
-    }
-
-    @Override
-    public WebService.Action action() {
-      return action;
-    }
-
-    @Override
-    public String method() {
-      return method;
-    }
-
-    public TestRequest setMethod(String s) {
-      this.method = s;
-      return this;
-    }
-
-    public TestRequest setParams(Map<String, String> m) {
-      this.params = m;
-      return this;
-    }
-
-    public TestRequest setParam(String key, @CheckForNull String value) {
-      if (value != null) {
-        params.put(key, value);
-      }
-      return this;
-    }
-
-    @Override
-    @CheckForNull
-    public String param(String key) {
-      return params.get(key);
-    }
-
-    public Result execute() {
-      TestResponse response = new TestResponse();
-      action.handler().handle(this, response);
-      return new Result(response);
-    }
-  }
-
-  public static class TestResponse implements Response {
-
-    public class TestStream implements Response.Stream {
-      private String mediaType;
-      private int status;
-
-      @CheckForNull
-      public String mediaType() {
-        return mediaType;
-      }
-
-      public int status() {
-        return status;
-      }
-
-      @Override
-      public Response.Stream setMediaType(String s) {
-        this.mediaType = s;
-        return this;
-      }
-
-      @Override
-      public Response.Stream setStatus(int i) {
-        this.status = i;
-        return this;
-      }
-
-      @Override
-      public OutputStream output() {
-        return output;
-      }
-    }
-
-    private final ByteArrayOutputStream output = new ByteArrayOutputStream();
-
-    @Override
-    public JsonWriter newJsonWriter() {
-      return JsonWriter.of(new OutputStreamWriter(output, Charsets.UTF_8));
-    }
-
-    @Override
-    public XmlWriter newXmlWriter() {
-      return XmlWriter.of(new OutputStreamWriter(output, Charsets.UTF_8));
-    }
-
-    @Override
-    public Stream stream() {
-      return new TestStream();
-    }
-
-
-    @Override
-    public Response noContent() {
-      IOUtils.closeQuietly(output);
-      return this;
-    }
-  }
-
-
-  public static class Result {
-    private final TestResponse response;
-
-    private Result(TestResponse response) {
-      this.response = response;
-    }
-
-    public Result assertNoContent() {
-      //FIXME
-      return this;
-    }
-
-    public String outputAsString() {
-      return new String(response.output.toByteArray(), Charsets.UTF_8);
-    }
-
-    public Result assertJson(String expectedJson) throws Exception {
-      String json = outputAsString();
-      JSONAssert.assertEquals(expectedJson, json, true);
-      return this;
-    }
-
-    /**
-     * Compares JSON response with JSON file available in classpath. For example if class
-     * is org.foo.BarTest and filename is index.json, then file must be located
-     * at src/test/resources/org/foo/BarTest/index.json.
-     *
-     * @param clazz                the test class
-     * @param jsonResourceFilename name of the file containing the expected JSON
-     */
-    public Result assertJson(Class clazz, String expectedJsonFilename) throws Exception {
-      String path = clazz.getSimpleName() + "/" + expectedJsonFilename;
-      URL url = clazz.getResource(path);
-      if (url == null) {
-        throw new IllegalStateException("Cannot find " + path);
-      }
-      String json = outputAsString();
-      JSONAssert.assertEquals(IOUtils.toString(url), json, true);
-      return this;
-    }
-  }
-
-  private final WebService.Context context = new WebService.Context();
-
-  public WsTester(WebService... webServices) {
-    for (WebService webService : webServices) {
-      webService.define(context);
-    }
-  }
-
-  public WebService.Context context() {
-    return context;
-  }
-
-  @CheckForNull
-  public WebService.Controller controller(String path) {
-    return context.controller(path);
-  }
-
-  public TestRequest newRequest(String actionKey) {
-    if (context.controllers().size() != 1) {
-      throw new IllegalStateException("The method newRequest(String) requires to define one, and only one, controller");
-    }
-    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) {
-    WebService.Controller controller = context.controller(controllerPath);
-    WebService.Action action = controller.action(actionKey);
-    return new TestRequest(controller, action);
-  }
-}