summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancois Chouinard2013-11-07 11:19:49 (EST)
committer Gerrit Code Review @ Eclipse.org2013-11-21 11:08:25 (EST)
commita45bbf8957d44a6240619c0ea20633ef500f6ad8 (patch)
tree36d014965b4be011a762f0d98932d4497b7f18e0
parent76c7d8b02af690e869a8ef0e3876a368e66e1773 (diff)
downloadorg.eclipse.mylyn.reviews-a45bbf8957d44a6240619c0ea20633ef500f6ad8.zip
org.eclipse.mylyn.reviews-a45bbf8957d44a6240619c0ea20633ef500f6ad8.tar.gz
org.eclipse.mylyn.reviews-a45bbf8957d44a6240619c0ea20633ef500f6ad8.tar.bz2
414219: Add support for gerrit changes query optionsrefs/changes/44/15044/12
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=414219 Change-Id: I42215034ce4f412f07ac59b2c394b8222c849a4e Signed-off-by: Francois Chouinard<fchouinard@gmail.com> Also-By Jacques Bouthillier <lmcbout@gmail.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java62
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/GerritClientTest.java93
2 files changed, 154 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
index c4aca58..9bdf0e3 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
@@ -35,6 +35,7 @@ import java.util.regex.Pattern;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
@@ -860,8 +861,36 @@ public class GerritClient extends ReviewsClient {
return getChangeDetail(id.get(), monitor);
}
+ /**
+ * Sends a query for the changes visible to the caller to the gerrit server.
+ *
+ * @param monitor
+ * A progress monitor
+ * @param queryString
+ * The specific gerrit change query
+ * @return a list of GerritQueryResults built from the parsed query result (ChangeInfo:s)
+ * @throws GerritException
+ */
public List<GerritQueryResult> executeQuery(IProgressMonitor monitor, final String queryString)
throws GerritException {
+ return executeQuery(monitor, queryString, null);
+ }
+
+ /**
+ * Sends a query for the changes visible to the caller to the gerrit server with the possibility of adding options
+ * to the query.
+ *
+ * @param monitor
+ * A progress monitor
+ * @param queryString
+ * The specific gerrit change query
+ * @param optionString
+ * Query options ("&o=" parameter). Only applicable for the REST API, ignored otherwise. May be null.
+ * @return a list of GerritQueryResults built from the parsed query result (ChangeInfo:s)
+ * @throws GerritException
+ */
+ public List<GerritQueryResult> executeQuery(IProgressMonitor monitor, final String queryString, String optionString)
+ throws GerritException {
if (hasJsonRpcApi(monitor) && !restQueryAPIEnabled) {
try {
SingleListChangeInfo sl = execute(monitor, new Operation<SingleListChangeInfo>() {
@@ -880,7 +909,7 @@ public class GerritClient extends ReviewsClient {
}
}
- return executeQueryRest(monitor, queryString);
+ return executeQueryRest(monitor, queryString, optionString);
}
private List<GerritQueryResult> convert(List<com.google.gerrit.common.data.ChangeInfo> changes) {
@@ -892,10 +921,41 @@ public class GerritClient extends ReviewsClient {
return results;
}
+ /**
+ * Sends a query for the changes visible to the caller to the gerrit server. Uses the gerrit REST API.
+ *
+ * @param monitor
+ * A progress monitor
+ * @param queryString
+ * The specific gerrit change query
+ * @return a list of GerritQueryResults built from the parsed query result (ChangeInfo:s)
+ * @throws GerritException
+ */
public List<GerritQueryResult> executeQueryRest(IProgressMonitor monitor, final String queryString)
throws GerritException {
+ return executeQueryRest(monitor, queryString, null);
+ }
+
+ /**
+ * Sends a query for the changes visible to the caller to the gerrit server with the possibility of adding options
+ * to the query. Uses the gerrit REST API.
+ *
+ * @param monitor
+ * A progress monitor
+ * @param queryString
+ * The specific gerrit change query
+ * @param optionString
+ * Query options ("&o=" parameter). May be null or empty.
+ * @return a list of GerritQueryResults built from the parsed query result (ChangeInfo:s)
+ * @throws GerritException
+ */
+ public List<GerritQueryResult> executeQueryRest(IProgressMonitor monitor, final String queryString,
+ String optionString) throws GerritException {
try {
String uri = "/changes/?q=" + URLEncoder.encode(queryString, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (StringUtils.isNotBlank(optionString)) {
+ uri += "&o=" + URLEncoder.encode(optionString, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
TypeToken<List<GerritQueryResult>> queryResultListType = new TypeToken<List<GerritQueryResult>>() {
};
return executeGetRestRequest(uri, queryResultListType.getType(), monitor);
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/GerritClientTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/GerritClientTest.java
index f6ba2a6..842ebd7 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/GerritClientTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/GerritClientTest.java
@@ -1,4 +1,5 @@
/*******************************************************************************
+ /*******************************************************************************
* Copyright (c) 2011, 2013 Tasktop Technologies and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +9,8 @@
* Contributors:
* Tasktop Technologies - initial API and implementation
* Sascha Scholz (SAP) - improvements
+ * Francois Chouinard (Ericsson) - Bug 414219 Add new Test
+ * Jacques Bouthillier (Ericsson) - Fix comments for Bug 414219
*******************************************************************************/
package org.eclipse.mylyn.gerrit.tests.core.client;
@@ -30,6 +33,7 @@ import org.eclipse.mylyn.internal.gerrit.core.client.GerritConfiguration;
import org.eclipse.mylyn.internal.gerrit.core.client.GerritException;
import org.eclipse.mylyn.internal.gerrit.core.client.GerritSystemInfo;
import org.eclipse.mylyn.internal.gerrit.core.client.compat.CommentLink;
+import org.eclipse.mylyn.internal.gerrit.core.client.data.GerritQueryResult;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -39,6 +43,7 @@ import com.google.gerrit.reviewdb.Account;
/**
* @author Steffen Pingel
* @author Sascha Scholz
+ * @author Francois Chouinard
*/
public class GerritClientTest extends TestCase {
@@ -133,4 +138,92 @@ public class GerritClientTest extends TestCase {
assertEquals(GerritFixture.current().getGerritVersion(), client.getVersion(new NullProgressMonitor()));
}
+ private List<GerritQueryResult> executeQuery(String query) throws GerritException {
+ List<GerritQueryResult> results = null;
+ results = client.executeQuery(new NullProgressMonitor(), query);
+ return results;
+ }
+
+ private List<GerritQueryResult> executeQuery(String query, String option) throws GerritException {
+ List<GerritQueryResult> results = null;
+ results = client.executeQuery(new NullProgressMonitor(), query, option);
+ return results;
+ }
+
+ @Test
+ public void testExecuteQueryWithoutOption() throws Exception {
+ String query = "status:open";
+ List<GerritQueryResult> results = null;
+ results = executeQuery(query);
+ assertNotNull(results);
+ }
+
+ @Test
+ public void testExecuteQueryWithNullOption() throws Exception {
+ String query = "status:open";
+ String option = null;
+ List<GerritQueryResult> results = executeQuery(query, option);
+ assertNotNull(results);
+ }
+
+ @Test
+ public void testExecuteQueryWithEmptyOption() throws Exception {
+ String query = "status:open";
+ String option = "";
+ List<GerritQueryResult> results = null;
+ results = executeQuery(query, option);
+ assertNotNull(results);
+ }
+
+ @Test
+ public void testExecuteQueryWithOption() throws Exception {
+ String query = "status:open";
+ String option = "LABELS";
+ List<GerritQueryResult> results = executeQuery(query, option);
+ assertNotNull(results);
+ for (int index = 0; index < results.size(); index++) {
+ assertNotNull(results.get(index));
+ }
+ }
+
+ private List<GerritQueryResult> executeQueryRest(String query) throws GerritException {
+ return client.executeQueryRest(new NullProgressMonitor(), query);
+ }
+
+ private List<GerritQueryResult> executeQueryRest(String query, String option) throws GerritException {
+ return client.executeQueryRest(new NullProgressMonitor(), query, option);
+ }
+
+ @Test
+ public void testExecuteQueryRestWithoutOption() throws Exception {
+ String query = "status:open";
+ List<GerritQueryResult> results = executeQueryRest(query);
+ assertNotNull(results);
+ }
+
+ @Test
+ public void testExecuteQueryRestWithNullOption() throws Exception {
+ String query = "status:open";
+ String option = null;
+ List<GerritQueryResult> results = executeQueryRest(query, option);
+ assertNotNull(results);
+ }
+
+ @Test
+ public void testExecuteQueryRestWithEmptyOption() throws Exception {
+ String query = "status:open";
+ String option = "";
+ List<GerritQueryResult> results = null;
+ results = executeQueryRest(query, option);
+ assertNotNull(results);
+ }
+
+ @Test
+ public void testExecuteQueryvWithOption() throws Exception {
+ String query = "status:open";
+ String option = "LABELS";
+ List<GerritQueryResult> results = executeQueryRest(query, option);
+ assertNotNull(results);
+ }
+
}