aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-03-06 01:34:12 +0300
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-03-06 05:14:27 +0300
commitdd4e31cbf0384a1114344602967dfc225b450ddb (patch)
treea5cf71334d91d735a00b0a3a569716a016bf8d99
parent7231e7772647d3af6fb2a16147659907febd2d50 (diff)
downloadsonarqube-dd4e31cbf0384a1114344602967dfc225b450ddb.tar.gz
sonarqube-dd4e31cbf0384a1114344602967dfc225b450ddb.zip
SONAR-2204,SONAR-2259 Fix URL encoding
* For correct URL encoding we must encode parameters on lower level - in Query itself, but not in concrete implementation of Connector, because in Query we can distinguish concrete parts of URL. * Moreover in this case any additional encoding routines in Connector are useless, so were removed.
-rw-r--r--sonar-ws-client/pom.xml2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java94
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java47
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java23
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java22
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java20
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java4
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java1
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java9
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java1
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java4
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java1
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java46
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/AbstractQueryTest.java27
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/DependencyQueryTest.java6
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/EventQueryTest.java24
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/MetricQueryTest.java6
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java8
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java8
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java8
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/QueryTestCase.java34
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java10
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/RuleQueryTest.java6
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerQueryTest.java9
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/SourceQueryTest.java17
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java19
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/UpdateCenterQueryTest.java7
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyCreateQueryTest.java6
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java6
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java12
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java1
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallerTestCase.java1
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallersTest.java1
40 files changed, 262 insertions, 242 deletions
diff --git a/sonar-ws-client/pom.xml b/sonar-ws-client/pom.xml
index dbd5c4658b6..ed92d1fdf86 100644
--- a/sonar-ws-client/pom.xml
+++ b/sonar-ws-client/pom.xml
@@ -87,4 +87,4 @@
<scope>test</scope>
</dependency>
</dependencies>
-</project> \ No newline at end of file
+</project>
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java
index 94cf646b6c9..25545be4446 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient3Connector.java
@@ -19,27 +19,35 @@
*/
package org.sonar.wsclient.connectors;
-import org.apache.commons.httpclient.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
-import org.apache.commons.httpclient.util.URIUtil;
import org.sonar.wsclient.Host;
+import org.sonar.wsclient.services.AbstractQuery;
import org.sonar.wsclient.services.CreateQuery;
import org.sonar.wsclient.services.DeleteQuery;
import org.sonar.wsclient.services.Query;
import org.sonar.wsclient.services.UpdateQuery;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-
/**
* @since 2.1
*/
@@ -123,61 +131,43 @@ public class HttpClient3Connector extends Connector {
}
private HttpMethodBase newGetRequest(Query<?> query) {
- try {
- String url = server.getHost() + URIUtil.encodeQuery(query.getUrl());
- HttpMethodBase method = new GetMethod(url);
- method.setRequestHeader("Accept", "application/json");
- return method;
+ HttpMethodBase method = new GetMethod(server.getHost() + query.getUrl());
+ setJsonHeader(method);
+ return method;
+ }
- } catch (URIException e) {
- throw new ConnectionException("Query: " + query, e);
- }
+ private HttpMethodBase newDeleteRequest(DeleteQuery<?> query) {
+ HttpMethodBase method = new DeleteMethod(server.getHost() + query.getUrl());
+ setJsonHeader(method);
+ return method;
}
private HttpMethodBase newPostRequest(CreateQuery<?> query) {
- try {
- String url = server.getHost() + URIUtil.encodeQuery(query.getUrl());
- PostMethod method = new PostMethod(url);
- method.setRequestHeader("Accept", "application/json");
- if (query.getBody() != null) {
- method.setRequestEntity(new StringRequestEntity(query.getBody(), "text/plain; charset=UTF-8", "UTF-8"));
- }
- return method;
-
- } catch (URIException e) {
- throw new ConnectionException("Query: " + query, e);
- } catch (UnsupportedEncodingException e) {
- throw new ConnectionException("Unsupported encoding", e);
- }
+ PostMethod method = new PostMethod(server.getHost() + query.getUrl());
+ setJsonHeader(method);
+ setRequestEntity(method, query);
+ return method;
}
private HttpMethodBase newPutRequest(UpdateQuery<?> query) {
- try {
- String url = server.getHost() + URIUtil.encodeQuery(query.getUrl());
- PutMethod method = new PutMethod(url);
- method.setRequestHeader("Accept", "application/json");
- if (query.getBody() != null) {
- method.setRequestEntity(new StringRequestEntity(query.getBody(), "text/plain; charset=UTF-8", "UTF-8"));
- }
- return method;
+ PutMethod method = new PutMethod(server.getHost() + query.getUrl());
+ setJsonHeader(method);
+ setRequestEntity(method, query);
+ return method;
+ }
- } catch (URIException e) {
- throw new ConnectionException("Query: " + query, e);
- } catch (UnsupportedEncodingException e) {
- throw new ConnectionException("Unsupported encoding", e);
+ private void setRequestEntity(EntityEnclosingMethod request, AbstractQuery<?> query) {
+ if (query.getBody() != null) {
+ try {
+ request.setRequestEntity(new StringRequestEntity(query.getBody(), "text/plain; charset=UTF-8", "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new ConnectionException("Unsupported encoding", e);
+ }
}
}
- private HttpMethodBase newDeleteRequest(DeleteQuery<?> query) {
- try {
- String url = server.getHost() + URIUtil.encodeQuery(query.getUrl());
- HttpMethodBase method = new DeleteMethod(url);
- method.setRequestHeader("Accept", "application/json");
- return method;
-
- } catch (URIException e) {
- throw new ConnectionException("Query: " + query, e);
- }
+ private void setJsonHeader(HttpMethodBase request) {
+ request.setRequestHeader("Accept", "application/json");
}
private String getResponseBodyAsString(HttpMethod method) {
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java
index d85796ebc55..382f5bd3614 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java
@@ -19,10 +19,24 @@
*/
package org.sonar.wsclient.connectors;
-import org.apache.http.*;
-import org.apache.http.auth.*;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.AuthState;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
@@ -38,14 +52,12 @@ import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.sonar.wsclient.Host;
+import org.sonar.wsclient.services.AbstractQuery;
import org.sonar.wsclient.services.CreateQuery;
import org.sonar.wsclient.services.DeleteQuery;
import org.sonar.wsclient.services.Query;
import org.sonar.wsclient.services.UpdateQuery;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-
/**
* @since 2.1
*/
@@ -85,7 +97,9 @@ public class HttpClient4Connector extends Connector {
json = EntityUtils.toString(entity);
} else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_FOUND) {
- throw new ConnectionException("HTTP error: " + response.getStatusLine().getStatusCode() + ", msg: " + response.getStatusLine().getReasonPhrase() + ", query: " + request.toString());
+ throw new ConnectionException("HTTP error: " + response.getStatusLine().getStatusCode()
+ + ", msg: " + response.getStatusLine().getReasonPhrase()
+ + ", query: " + request.toString());
}
}
@@ -104,7 +118,8 @@ public class HttpClient4Connector extends Connector {
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_MS);
HttpConnectionParams.setSoTimeout(params, TIMEOUT_MS);
if (server.getUsername() != null) {
- client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(server.getUsername(), server.getPassword()));
+ client.getCredentialsProvider()
+ .setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(server.getUsername(), server.getPassword()));
}
return client;
}
@@ -138,28 +153,26 @@ public class HttpClient4Connector extends Connector {
private HttpPost newPostMethod(CreateQuery<?> query) {
HttpPost post = new HttpPost(server.getHost() + query.getUrl());
- if (query.getBody() != null) {
- try {
- post.setEntity(new StringEntity(query.getBody(), "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- throw new ConnectionException("Encoding is not supported", e);
- }
- }
setJsonHeader(post);
+ setRequestEntity(post, query);
return post;
}
private HttpPut newPutMethod(UpdateQuery<?> query) {
HttpPut put = new HttpPut(server.getHost() + query.getUrl());
+ setJsonHeader(put);
+ setRequestEntity(put, query);
+ return put;
+ }
+
+ private void setRequestEntity(HttpEntityEnclosingRequestBase request, AbstractQuery<?> query) {
if (query.getBody() != null) {
try {
- put.setEntity(new StringEntity(query.getBody(), "UTF-8"));
+ request.setEntity(new StringEntity(query.getBody(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new ConnectionException("Encoding is not supported", e);
}
}
- setJsonHeader(put);
- return put;
}
private void setJsonHeader(HttpRequestBase request) {
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java
index 923830480e4..288dfba7ee2 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/AbstractQuery.java
@@ -28,21 +28,36 @@ public abstract class AbstractQuery<MODEL extends Model> {
/**
* Must start with a slash, for example: /api/metrics
+ * <p>
+ * IMPORTANT: In implementations of this method we must use helper methods to construct URL.
+ * </p>
+ *
+ * @see #encode(String)
+ * @see #appendUrlParameter(StringBuilder, String, Object)
+ * @see #appendUrlParameter(StringBuilder, String, Object[])
+ * @see #appendUrlParameter(StringBuilder, String, Date, boolean)
*/
public abstract String getUrl();
/**
- * Request body. By defaut it is empty but it can be overriden.
+ * Request body. By default it is empty but it can be overridden.
*/
public String getBody() {
return null;
}
+ /**
+ * Encodes single parameter value.
+ */
+ protected static String encode(String value) {
+ return WSUtils.getINSTANCE().encodeUrl(value);
+ }
+
protected static void appendUrlParameter(StringBuilder url, String paramKey, Object paramValue) {
if (paramValue != null) {
url.append(paramKey)
.append('=')
- .append(paramValue)
+ .append(encode(paramValue.toString()))
.append('&');
}
}
@@ -55,7 +70,7 @@ public abstract class AbstractQuery<MODEL extends Model> {
url.append(',');
}
if (paramValues[index] != null) {
- url.append(paramValues[index]);
+ url.append(encode(paramValues[index].toString()));
}
}
url.append('&');
@@ -67,7 +82,7 @@ public abstract class AbstractQuery<MODEL extends Model> {
String format = (includeTime ? "yyyy-MM-dd'T'HH:mm:ssZ" : "yyyy-MM-dd");
url.append(paramKey)
.append('=')
- .append(WSUtils.getINSTANCE().encodeUrl(WSUtils.getINSTANCE().format(paramValue, format)))
+ .append(encode(WSUtils.getINSTANCE().format(paramValue, format)))
.append('&');
}
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java
index 65e4447c7f2..5c20923c731 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyQuery.java
@@ -59,18 +59,10 @@ public class DependencyQuery extends Query<Dependency> {
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
url.append('?');
- if (resourceIdOrKey != null) {
- url.append("resource=").append(resourceIdOrKey).append('&');
- }
- if (direction != null) {
- url.append("dir=").append(direction).append('&');
- }
- if (parentId !=null) {
- url.append("parent=").append(parentId).append('&');
- }
- if (id !=null) {
- url.append("id=").append(id).append('&');
- }
+ appendUrlParameter(url, "resource", resourceIdOrKey);
+ appendUrlParameter(url, "dir", direction);
+ appendUrlParameter(url, "parent", parentId);
+ appendUrlParameter(url, "id", id);
return url.toString();
}
@@ -99,7 +91,7 @@ public class DependencyQuery extends Query<Dependency> {
/**
* Resources that depend upon a resource
- *
+ *
* @param resourceIdOrKey the target resource. Can be the primary key (a number) or the logical key (String)
*/
public static DependencyQuery createForIncomingDependencies(String resourceIdOrKey) {
@@ -111,7 +103,7 @@ public class DependencyQuery extends Query<Dependency> {
/**
* Resources that are depended upon a resource = all the resources that a resource depends upon
- *
+ *
* @param resourceIdOrKey the target resource. Can be the primary key (an integer) or the logical key (String)
*/
public static DependencyQuery createForOutgoingDependencies(String resourceIdOrKey) {
@@ -124,7 +116,7 @@ public class DependencyQuery extends Query<Dependency> {
/**
* Resources that depend upon or are depended upon a resource. It equals the merge of createForIncomingDependencies(resourceIdOrKey)
* and createForOutgoingDependencies(resourceIdOrKey)
- *
+ *
* @param resourceIdOrKey the target resource. Can be the primary key (an integer) or the logical key (String)
*/
public static DependencyQuery createForResource(String resourceIdOrKey) {
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java
index 27e25081a52..552de333a4e 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/DependencyTreeQuery.java
@@ -53,23 +53,9 @@ public class DependencyTreeQuery extends Query<DependencyTree> {
@Override
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
- url.append("?resource=")
- .append(resourceId)
- .append("&");
- if (scopes != null) {
- url.append("scopes=");
- if (scopes != null) {
- for (int index = 0; index < scopes.length; index++) {
- if (index > 0) {
- url.append(',');
- }
- if (scopes[index] != null) {
- url.append(scopes[index]);
- }
- }
- url.append('&');
- }
- }
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceId);
+ appendUrlParameter(url, "scopes", scopes);
return url.toString();
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java
index 9ec9958e3ec..a22b11bfc78 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteCreateQuery.java
@@ -29,7 +29,9 @@ public class FavouriteCreateQuery extends CreateQuery<Favourite> {
@Override
public String getUrl() {
- return new StringBuilder().append(FavouriteQuery.BASE_URL).append("?key=").append(idOrKey).toString();
+ StringBuilder url = new StringBuilder(FavouriteQuery.BASE_URL).append('?');
+ appendUrlParameter(url, "key", idOrKey);
+ return url.toString();
}
@Override
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java
index b1d64eaca7b..40ac6d21e79 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/FavouriteDeleteQuery.java
@@ -33,6 +33,6 @@ public class FavouriteDeleteQuery extends DeleteQuery<Favourite> {
@Override
public String getUrl() {
- return new StringBuilder().append(FavouriteQuery.BASE_URL).append('/').append(idOrKey).toString();
+ return new StringBuilder().append(FavouriteQuery.BASE_URL).append('/').append(encode(idOrKey)).toString();
}
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java
index 708d4836639..b0647b2f7b0 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/MetricQuery.java
@@ -36,7 +36,7 @@ public final class MetricQuery extends Query<Metric> {
StringBuilder sb = new StringBuilder(BASE_URL);
if (key != null && !"".equals(key)) {
sb.append("/");
- sb.append(key);
+ sb.append(encode(key));
}
sb.append("?");
return sb.toString();
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java
index 5c945ce6205..f2159494d3b 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java
@@ -17,7 +17,6 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-
package org.sonar.wsclient.services;
/**
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java
index 2a1f9d46514..bc26094bdfa 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyCreateQuery.java
@@ -78,7 +78,7 @@ public class PropertyCreateQuery extends CreateQuery<Property> {
public String getUrl() {
StringBuilder url = new StringBuilder();
url.append(PropertyQuery.BASE_URL);
- url.append("/").append(key);
+ url.append("/").append(encode(key));
url.append('?');
appendUrlParameter(url, "value", value);
appendUrlParameter(url, "resource", resourceKeyOrId);
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java
index 316059671c4..8e6b7b119dd 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java
@@ -62,7 +62,7 @@ public class PropertyDeleteQuery extends DeleteQuery<Property> {
public String getUrl() {
StringBuilder url = new StringBuilder();
url.append(PropertyQuery.BASE_URL);
- url.append("/").append(key);
+ url.append("/").append(encode(key));
url.append('?');
appendUrlParameter(url, "resource", resourceKeyOrId);
return url.toString();
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java
index d4dbbfd2d54..21715c96be8 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyQuery.java
@@ -47,7 +47,7 @@ public class PropertyQuery extends Query<Property> {
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
if (key != null) {
- url.append("/").append(key);
+ url.append("/").append(encode(key));
}
url.append('?');
appendUrlParameter(url, "resource", resourceKeyOrId);
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java
index 749870393ce..35964e16d39 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java
@@ -78,7 +78,7 @@ public class PropertyUpdateQuery extends UpdateQuery<Property> {
public String getUrl() {
StringBuilder url = new StringBuilder();
url.append(PropertyQuery.BASE_URL);
- url.append("/").append(key);
+ url.append("/").append(encode(key));
url.append('?');
appendUrlParameter(url, "resource", resourceKeyOrId);
return url.toString();
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java
index d4c9070fa34..64cde183f34 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/SourceQuery.java
@@ -46,8 +46,8 @@ public class SourceQuery extends Query<Source> {
/**
* Get only a few lines
- *
- * @param from Index of the first line, starts to 1
+ *
+ * @param from Index of the first line, starts to 1
* @param excludedTo Index of the last line (excluded).
*/
public SourceQuery setFromLineToLine(int from, int excludedTo) {
@@ -78,9 +78,8 @@ public class SourceQuery extends Query<Source> {
@Override
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
- url.append("?resource=")
- .append(resourceKeyOrId)
- .append("&");
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
if (from > 0 && to > 0) {
url.append("from=").append(from).append("&to=").append(to).append("&");
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java
index daef570e499..19a3b989cb4 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UpdateCenterQuery.java
@@ -17,7 +17,6 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-
package org.sonar.wsclient.services;
/**
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java
index 972cc8d4e34..81f1e182134 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyDeleteQuery.java
@@ -45,6 +45,6 @@ public class UserPropertyDeleteQuery extends DeleteQuery<Property> {
@Override
public String getUrl() {
- return new StringBuilder().append(UserPropertyQuery.BASE_URL).append('/').append(key).toString();
+ return new StringBuilder().append(UserPropertyQuery.BASE_URL).append('/').append(encode(key)).toString();
}
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java
index 999375228d4..6307b596b07 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/UserPropertyQuery.java
@@ -21,7 +21,7 @@ package org.sonar.wsclient.services;
/**
* Get properties of the authenticated user.
- *
+ *
* @since 2.2
*/
public class UserPropertyQuery extends Query<Property> {
@@ -55,7 +55,7 @@ public class UserPropertyQuery extends Query<Property> {
public String getUrl() {
String url = BASE_URL;
if (key != null) {
- url += "/" + key;
+ url += "/" + encode(key);
}
return url + "?";
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java
index d3b0917de24..3c5f9b69dc1 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java
@@ -17,7 +17,6 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-
package org.sonar.wsclient.unmarshallers;
import org.sonar.wsclient.services.Plugin;
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java
index 1794466a5e2..716919076ea 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java
@@ -19,6 +19,14 @@
*/
package org.sonar.wsclient;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+
+import java.util.Arrays;
+import java.util.Collection;
+
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -27,15 +35,11 @@ import org.mortbay.jetty.testing.ServletTester;
import org.sonar.wsclient.connectors.ConnectionException;
import org.sonar.wsclient.connectors.HttpClient3Connector;
import org.sonar.wsclient.connectors.HttpClient4Connector;
-import org.sonar.wsclient.services.*;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
+import org.sonar.wsclient.services.Metric;
+import org.sonar.wsclient.services.MetricQuery;
+import org.sonar.wsclient.services.Query;
+import org.sonar.wsclient.services.Server;
+import org.sonar.wsclient.services.ServerQuery;
@RunWith(value = Parameterized.class)
public class SonarTest {
@@ -64,13 +68,12 @@ public class SonarTest {
baseUrl = tester.createSocketConnector(true);
tester.start();
- return Arrays.asList(new Object[][]{
- {new Sonar(new HttpClient4Connector(new Host(baseUrl)))},
- {new Sonar(new HttpClient3Connector(new Host(baseUrl)))}
+ return Arrays.asList(new Object[][] {
+ { new Sonar(new HttpClient4Connector(new Host(baseUrl))) },
+ { new Sonar(new HttpClient3Connector(new Host(baseUrl))) }
});
}
-
@AfterClass
public static void stopServer() throws Exception {
tester.stop();
@@ -90,12 +93,6 @@ public class SonarTest {
}
@Test
- public void urlWithCharactersToEncode() {
- sonar.find(new QueryWithInvalidCharacters());
- // no exception
- }
-
- @Test
public void returnNullWhenSingleResultNotFound() {
Query<Metric> query = new EmptyQuery();
assertThat(sonar.find(query), nullValue());
@@ -124,15 +121,4 @@ public class SonarTest {
}
}
- static class QueryWithInvalidCharacters extends Query<Metric> {
- public String getUrl() {
- // [] must be encoded
- return "/api/violations?resource=myproject:[default]:Foo";
- }
-
- public Class<Metric> getModelClass() {
- return Metric.class;
- }
- }
}
-
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/AbstractQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/AbstractQueryTest.java
index 76e73b8832d..c932a6f28ba 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/AbstractQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/AbstractQueryTest.java
@@ -17,20 +17,19 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-
package org.sonar.wsclient.services;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.sonar.wsclient.JdkUtils;
+import static junit.framework.Assert.assertEquals;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
-import static junit.framework.Assert.assertEquals;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.sonar.wsclient.JdkUtils;
public class AbstractQueryTest {
@@ -45,6 +44,20 @@ public class AbstractQueryTest {
}
@Test
+ public void appendSpecialChars() {
+ StringBuilder url = new StringBuilder();
+ AbstractQuery.appendUrlParameter(url, "foo", "should escape []()");
+ assertEquals("foo=should+escape+%5B%5D%28%29&", url.toString());
+ }
+
+ @Test
+ public void appendSpecialCharsInArray() {
+ StringBuilder url = new StringBuilder();
+ AbstractQuery.appendUrlParameter(url, "foo", new String[] { "should escape", "[]()" });
+ assertEquals("foo=should+escape,%5B%5D%28%29&", url.toString());
+ }
+
+ @Test
public void appendUrlParameter() {
StringBuilder url = new StringBuilder();
AbstractQuery.appendUrlParameter(url, "foo", "bar");
@@ -70,7 +83,7 @@ public class AbstractQueryTest {
@Test
public void appendUrlArrayParameter() {
StringBuilder url = new StringBuilder();
- AbstractQuery.appendUrlParameter(url, "foo", new String[]{"bar", "bar2"});
+ AbstractQuery.appendUrlParameter(url, "foo", new String[] { "bar", "bar2" });
assertEquals("foo=bar,bar2&", url.toString());
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/DependencyQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/DependencyQueryTest.java
index b19568040de..98ccfca2b11 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/DependencyQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/DependencyQueryTest.java
@@ -19,13 +19,13 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
-public class DependencyQueryTest {
+import org.junit.Test;
+
+public class DependencyQueryTest extends QueryTestCase {
@Test
public void createAllDependencies() {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/EventQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/EventQueryTest.java
index 332d1eb966b..428a2985bc8 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/EventQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/EventQueryTest.java
@@ -19,22 +19,16 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.wsclient.JdkUtils;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.Date;
-import static org.junit.Assert.*;
-
-public final class EventQueryTest {
+import org.junit.Test;
- @Before
- public void before() {
- // WSUtils is called during getUrl()
- // It has to be initialized.
- WSUtils.setInstance(new JdkUtils());
- }
+public final class EventQueryTest extends QueryTestCase {
@Test
public void from() {
@@ -59,7 +53,7 @@ public final class EventQueryTest {
@Test
public void urlWithTime() {
EventQuery query = new EventQuery("key");
- query.setCategories(new String[]{"category"});
+ query.setCategories(new String[] { "category" });
Date date = new Date();
query.setTo(date, true);
query.setFrom(date, true);
@@ -76,7 +70,7 @@ public final class EventQueryTest {
@Test
public void urlWithoutTime() {
EventQuery query = new EventQuery("key");
- query.setCategories(new String[]{"category"});
+ query.setCategories(new String[] { "category" });
Date date = new Date();
query.setTo(date, false);
query.setFrom(date, false);
@@ -92,7 +86,7 @@ public final class EventQueryTest {
@Test
public void urlWithoutDate() {
EventQuery query = new EventQuery("key");
- query.setCategories(new String[]{"category"});
+ query.setCategories(new String[] { "category" });
final String url = query.getUrl();
assertNotNull(url);
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/MetricQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/MetricQueryTest.java
index 3b9690dc43d..5545f093058 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/MetricQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/MetricQueryTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class MetricQueryTest {
+import org.junit.Test;
+
+public class MetricQueryTest extends QueryTestCase {
@Test
public void all() {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java
index 9d1c321648a..269d5bb4463 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyCreateQueryTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class PropertyCreateQueryTest {
+import org.junit.Test;
+
+public class PropertyCreateQueryTest extends QueryTestCase {
@Test
public void create() {
@@ -36,7 +36,7 @@ public class PropertyCreateQueryTest {
@Test
public void createForResource() {
PropertyCreateQuery query = new PropertyCreateQuery("foo", "bar", "my:resource");
- assertThat(query.getUrl(), is("/api/properties/foo?value=bar&resource=my:resource&"));
+ assertThat(query.getUrl(), is("/api/properties/foo?value=bar&resource=my%3Aresource&"));
assertThat(query.getModelClass().getName(), is(Property.class.getName()));
}
} \ No newline at end of file
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java
index 0c9b7484cd5..88819fa0b71 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyDeleteQueryTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class PropertyDeleteQueryTest {
+import org.junit.Test;
+
+public class PropertyDeleteQueryTest extends QueryTestCase {
@Test
public void delete() {
@@ -35,6 +35,6 @@ public class PropertyDeleteQueryTest {
@Test
public void deleteResourceProp() {
PropertyDeleteQuery query = new PropertyDeleteQuery("foo", "my:resource");
- assertThat(query.getUrl(), is("/api/properties/foo?resource=my:resource&"));
+ assertThat(query.getUrl(), is("/api/properties/foo?resource=my%3Aresource&"));
}
} \ No newline at end of file
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
index 4c1e5cc15f2..85bb9f17d1d 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PropertyQueryTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class PropertyQueryTest {
+import org.junit.Test;
+
+public class PropertyQueryTest extends QueryTestCase {
@Test
public void all() {
@@ -40,7 +40,7 @@ public class PropertyQueryTest {
@Test
public void byKeyAndResource() {
- assertThat(PropertyQuery.createForResource("myprop", "my:resource").getUrl(), is("/api/properties/myprop?resource=my:resource&"));
+ assertThat(PropertyQuery.createForResource("myprop", "my:resource").getUrl(), is("/api/properties/myprop?resource=my%3Aresource&"));
assertThat(PropertyQuery.createForResource("myprop", "my:resource").getModelClass().getName(), is(Property.class.getName()));
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/QueryTestCase.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/QueryTestCase.java
new file mode 100644
index 00000000000..8e1e6573b6f
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/QueryTestCase.java
@@ -0,0 +1,34 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import org.junit.BeforeClass;
+import org.sonar.wsclient.JdkUtils;
+
+public abstract class QueryTestCase {
+
+ @BeforeClass
+ public static void setupWsUtils() {
+ // WSUtils is called during getUrl()
+ // It has to be initialized.
+ WSUtils.setInstance(new JdkUtils());
+ }
+
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java
index 6d9b506bbb4..017288450ba 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceQueryTest.java
@@ -19,18 +19,18 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
-public class ResourceQueryTest {
+import org.junit.Test;
+
+public class ResourceQueryTest extends QueryTestCase {
@Test
public void resource() {
ResourceQuery query = new ResourceQuery("org.foo:bar");
- assertThat(query.getUrl(), is("/api/resources?resource=org.foo:bar&verbose=false&"));
+ assertThat(query.getUrl(), is("/api/resources?resource=org.foo%3Abar&verbose=false&"));
assertThat(query.getResourceKeyOrId(), is("org.foo:bar"));
assertThat(query.isVerbose(), is(false));
}
@@ -62,7 +62,7 @@ public class ResourceQueryTest {
@Test
public void measuresOnRulePriorities() {
ResourceQuery query = new ResourceQuery().setMetrics("violations");
- query.setRuleSeverities("MAJOR,MINOR");
+ query.setRuleSeverities("MAJOR", "MINOR");
assertThat(query.getUrl(), is("/api/resources?metrics=violations&rule_priorities=MAJOR,MINOR&verbose=false&"));
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/RuleQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/RuleQueryTest.java
index 14ed894a277..46954f41e42 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/RuleQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/RuleQueryTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-public class RuleQueryTest {
+import org.junit.Test;
+
+public class RuleQueryTest extends QueryTestCase {
@Test
public void languageRules() {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerQueryTest.java
index 6f93db0171c..e90ad0480c4 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ServerQueryTest.java
@@ -19,15 +19,12 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-/**
- * @author Evgeny Mandrikov
- */
-public class ServerQueryTest {
+import org.junit.Test;
+
+public class ServerQueryTest extends QueryTestCase {
@Test
public void index() {
ServerQuery query = new ServerQuery();
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/SourceQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/SourceQueryTest.java
index 710296c201f..b639b992fa1 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/SourceQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/SourceQueryTest.java
@@ -19,28 +19,31 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class SourceQueryTest {
+import org.junit.Test;
+
+public class SourceQueryTest extends QueryTestCase {
@Test
public void create() {
- assertThat(SourceQuery.create("myproject:org.foo.Bar").getUrl(), is("/api/sources?resource=myproject:org.foo.Bar&"));
+ assertThat(SourceQuery.create("myproject:org.foo.Bar").getUrl(), is("/api/sources?resource=myproject%3Aorg.foo.Bar&"));
assertThat(SourceQuery.create("myproject:org.foo.Bar").getModelClass().getName(), is(Source.class.getName()));
}
@Test
public void createWithHighlightedSyntax() {
- assertThat(SourceQuery.createWithHighlightedSyntax("myproject:org.foo.Bar").getUrl(), is("/api/sources?resource=myproject:org.foo.Bar&color=true&"));
+ assertThat(SourceQuery.createWithHighlightedSyntax("myproject:org.foo.Bar").getUrl(),
+ is("/api/sources?resource=myproject%3Aorg.foo.Bar&color=true&"));
assertThat(SourceQuery.createWithHighlightedSyntax("myproject:org.foo.Bar").getModelClass().getName(), is(Source.class.getName()));
}
@Test
public void getOnlyAFewLines() {
- assertThat(SourceQuery.create("myproject:org.foo.Bar").setFromLineToLine(10, 30).getUrl(), is("/api/sources?resource=myproject:org.foo.Bar&from=10&to=30&"));
- assertThat(SourceQuery.create("myproject:org.foo.Bar").setLinesFromLine(10, 20).getUrl(), is("/api/sources?resource=myproject:org.foo.Bar&from=10&to=30&"));
+ assertThat(SourceQuery.create("myproject:org.foo.Bar").setFromLineToLine(10, 30).getUrl(),
+ is("/api/sources?resource=myproject%3Aorg.foo.Bar&from=10&to=30&"));
+ assertThat(SourceQuery.create("myproject:org.foo.Bar").setLinesFromLine(10, 20).getUrl(),
+ is("/api/sources?resource=myproject%3Aorg.foo.Bar&from=10&to=30&"));
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java
index cd20be13f04..0fe80630287 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java
@@ -19,21 +19,20 @@
*/
package org.sonar.wsclient.services;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.wsclient.JdkUtils;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.Locale;
import java.util.TimeZone;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.wsclient.JdkUtils;
-public class TimeMachineQueryTest {
+public class TimeMachineQueryTest extends QueryTestCase {
private TimeZone systemTimeZone;
@@ -60,6 +59,8 @@ public class TimeMachineQueryTest {
Date from = new SimpleDateFormat("yyyy-MM-dd").parse("2010-02-18");
Date to = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2010-03-25 14:59");
TimeMachineQuery query = TimeMachineQuery.createForMetrics("12345", "ncloc").setFrom(from).setTo(to);
- assertThat(query.getUrl(), is("/api/timemachine?resource=12345&metrics=ncloc&fromDateTime=2010-02-18T00%3A00%3A00%2B0000&toDateTime=2010-03-25T14%3A59%3A00%2B0000&"));
+ assertThat(
+ query.getUrl(),
+ is("/api/timemachine?resource=12345&metrics=ncloc&fromDateTime=2010-02-18T00%3A00%3A00%2B0000&toDateTime=2010-03-25T14%3A59%3A00%2B0000&"));
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UpdateCenterQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UpdateCenterQueryTest.java
index c0d51e18191..86cbb742ce3 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UpdateCenterQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UpdateCenterQueryTest.java
@@ -17,15 +17,14 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-public class UpdateCenterQueryTest {
+import org.junit.Test;
+
+public class UpdateCenterQueryTest extends QueryTestCase {
@Test
public void index() {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyCreateQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyCreateQueryTest.java
index ad60316a29f..09aa7a03c21 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyCreateQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyCreateQueryTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class UserPropertyCreateQueryTest {
+import org.junit.Test;
+
+public class UserPropertyCreateQueryTest extends QueryTestCase {
@Test
public void create() {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
index 4978ff2d739..f9ef7be3bf1 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/UserPropertyDeleteQueryTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class UserPropertyDeleteQueryTest {
+import org.junit.Test;
+
+public class UserPropertyDeleteQueryTest extends QueryTestCase {
@Test
public void delete() {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
index 818ad935c3f..f7f9279906d 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
@@ -19,17 +19,17 @@
*/
package org.sonar.wsclient.services;
-import org.junit.Test;
-
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-public class ViolationQueryTest {
+import org.junit.Test;
+
+public class ViolationQueryTest extends QueryTestCase {
@Test
public void resourceViolations() {
ViolationQuery query = ViolationQuery.createForResource("myproject:org.foo:bar");
- assertThat(query.getUrl(), is("/api/violations?resource=myproject:org.foo:bar&"));
+ assertThat(query.getUrl(), is("/api/violations?resource=myproject%3Aorg.foo%3Abar&"));
assertThat(query.getModelClass().getName(), is(Violation.class.getName()));
}
@@ -41,6 +41,8 @@ public class ViolationQueryTest {
.setSeverities("MAJOR", "BLOCKER")
.setQualifiers("FIL")
.setRuleKeys("checkstyle:foo", "pmd:bar");
- assertThat(query.getUrl(), is("/api/violations?resource=myproject&depth=-1&limit=20&qualifiers=FIL&rules=checkstyle:foo,pmd:bar&priorities=MAJOR,BLOCKER&"));
+ assertThat(
+ query.getUrl(),
+ is("/api/violations?resource=myproject&depth=-1&limit=20&qualifiers=FIL&rules=checkstyle%3Afoo,pmd%3Abar&priorities=MAJOR,BLOCKER&"));
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java
index 7a920dd3ec3..96c175a56cd 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java
@@ -17,7 +17,6 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-
package org.sonar.wsclient.unmarshallers;
import org.junit.Test;
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallerTestCase.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallerTestCase.java
index ef5f03afa67..2a4351b6a34 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallerTestCase.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallerTestCase.java
@@ -17,7 +17,6 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-
package org.sonar.wsclient.unmarshallers;
import org.apache.commons.io.IOUtils;
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallersTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallersTest.java
index 0f1e3094e9d..33387b4e0ed 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallersTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/UnmarshallersTest.java
@@ -17,7 +17,6 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-
package org.sonar.wsclient.unmarshallers;
import org.junit.Test;