summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-15 11:16:29 (EDT)
committerTomasz Zarna2013-07-25 05:28:21 (EDT)
commit4ba30c5d81560d47169ff42045c61cd86f65f935 (patch)
tree8641afc3e67dce4fd609032e0b1e67e57d50795c
parent777a2d22a2680649fbfd7de928aa71a32f812c25 (diff)
downloadorg.eclipse.mylyn.reviews-4ba30c5d81560d47169ff42045c61cd86f65f935.zip
org.eclipse.mylyn.reviews-4ba30c5d81560d47169ff42045c61cd86f65f935.tar.gz
org.eclipse.mylyn.reviews-4ba30c5d81560d47169ff42045c61cd86f65f935.tar.bz2
395059: allow to publish comments on a reviewrefs/changes/61/14561/8
Bug: 395059 Change-Id: Icfa7e94b6bb15dddae3d756e5b6c92c230a16855 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=395059 Also-by: Steffen Pingel <steffen.pingel@tasktop.com> Signed-off-by: Tomasz Zarna <tomasz.zarna@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupportTest.java17
-rw-r--r--org.eclipse.mylyn.gerrit.core/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java33
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java55
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritService.java2
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java14
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInfo.java26
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java31
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/AllGerritTests.java4
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInfoTest.java69
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java61
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/EmptyJsonWithMagic.json2
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/EmptyWithMagic.json2
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/InvalidWithMagic.json4
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ReviewInfo_codeReviewMinusOne.json6
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ReviewInfo_verifyZero.json6
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_emptyMessage.json1
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_message.json1
18 files changed, 320 insertions, 15 deletions
diff --git a/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupportTest.java b/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupportTest.java
index 4085b2f..6407460 100644
--- a/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupportTest.java
+++ b/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupportTest.java
@@ -30,15 +30,24 @@ public class JSonSupportTest {
JSonSupport json = new JSonSupport();
Calendar c = new GregorianCalendar(2012, 0, 26, 12, 33, 11);
c.set(Calendar.MILLISECOND, 110);
- c.setTimeZone(TimeZone.getTimeZone("UTC"));
+ c.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
assertEquals(new Timestamp(c.getTimeInMillis()),
- json.getGson().fromJson("\"2012-01-26 12:33:11.110000000\"", Timestamp.class));
+ json.parseResponse("\"2012-01-26 12:33:11.110000000\"", Timestamp.class)); //$NON-NLS-1$
c = new GregorianCalendar(2012, 10, 8, 21, 38, 35);
c.set(Calendar.MILLISECOND, 337);
- c.setTimeZone(TimeZone.getTimeZone("UTC"));
+ c.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
assertEquals(new Timestamp(c.getTimeInMillis()),
- json.getGson().fromJson("\"2012-11-08 21:38:35.337000000\"", Timestamp.class));
+ json.parseResponse("\"2012-11-08 21:38:35.337000000\"", Timestamp.class)); //$NON-NLS-1$
}
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseResponseNull() {
+ new JSonSupport().parseResponse(null, Timestamp.class);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseResponseEmpty() {
+ new JSonSupport().parseResponse("", Timestamp.class); //$NON-NLS-1$
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.gerrit.core/META-INF/MANIFEST.MF
index 2787a8b..8e7aaf8 100644
--- a/org.eclipse.mylyn.gerrit.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.gerrit.core/META-INF/MANIFEST.MF
@@ -22,6 +22,7 @@ Export-Package: org.eclipse.mylyn.internal.gerrit.core;x-friends:="org.eclipse.m
org.eclipse.mylyn.internal.gerrit.core.client;x-friends:="org.eclipse.mylyn.gerrit.ui",
org.eclipse.mylyn.internal.gerrit.core.client.compat;x-friends:="org.eclipse.mylyn.gerrit.ui",
org.eclipse.mylyn.internal.gerrit.core.client.data;x-friends:="org.eclipse.mylyn.gerrit.ui",
+ org.eclipse.mylyn.internal.gerrit.core.client.rest;x-internal:=true,
org.eclipse.mylyn.internal.gerrit.core.egit;x-friends:="org.eclipse.mylyn.gerrit.ui",
org.eclipse.mylyn.internal.gerrit.core.operations;x-friends:="org.eclipse.mylyn.gerrit.ui",
org.eclipse.mylyn.internal.gerrit.core.remote;x-friends:="org.eclipse.mylyn.gerrit.ui"
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 5987dbc..b9b651f 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
@@ -47,6 +47,8 @@ import org.eclipse.mylyn.internal.gerrit.core.client.compat.PatchSetPublishDetai
import org.eclipse.mylyn.internal.gerrit.core.client.compat.ProjectAdminService;
import org.eclipse.mylyn.internal.gerrit.core.client.compat.ProjectDetailX;
import org.eclipse.mylyn.internal.gerrit.core.client.data.GerritQueryResult;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ReviewInfo;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ReviewInput;
import org.eclipse.mylyn.internal.gerrit.core.remote.GerritRemoteFactoryProvider;
import org.eclipse.mylyn.reviews.core.model.IRepository;
import org.eclipse.mylyn.reviews.core.model.IReview;
@@ -468,12 +470,17 @@ public class GerritClient extends ReviewsClient {
public void publishComments(String reviewId, int patchSetId, final String message,
final Set<ApprovalCategoryValue.Id> approvals, IProgressMonitor monitor) throws GerritException {
final PatchSet.Id id = new PatchSet.Id(new Change.Id(id(reviewId)), patchSetId);
- execute(monitor, new Operation<VoidResult>() {
- @Override
- public void execute(IProgressMonitor monitor) throws GerritException {
- getPatchDetailService(monitor).publishComments(id, message, approvals, this);
- }
- });
+ if (hasJsonRpcApi(monitor)) {
+ execute(monitor, new Operation<VoidResult>() {
+ @Override
+ public void execute(IProgressMonitor monitor) throws GerritException {
+ getPatchDetailService(monitor).publishComments(id, message, approvals, this);
+ }
+ });
+ } else {
+ final String uri = "/a/changes/" + id.getParentKey().get() + "/revisions/" + id.get() + "/review"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ execute(uri, new ReviewInput(message), ReviewInfo.class, monitor);
+ }
}
public ReviewerResult addReviewers(String reviewId, final List<String> reviewers, IProgressMonitor monitor)
@@ -881,6 +888,20 @@ public class GerritClient extends ReviewsClient {
}
}
+ private <T> T execute(final String url, final Object input, final Type resultType, IProgressMonitor monitor)
+ throws GerritException {
+ return execute(monitor, new Operation<T>() {
+ @Override
+ public void execute(IProgressMonitor monitor) throws GerritException {
+ try {
+ setResult(client.<T> postRestRequest(url, input, resultType, monitor));
+ } catch (IOException e) {
+ throw new GerritException(e);
+ }
+ }
+ });
+ }
+
private <T> T executeOnce(IProgressMonitor monitor, Operation<T> operation) throws GerritException {
operation.execute(monitor);
if (operation.getException() instanceof GerritException) {
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
index 08b5d88..9f3575e 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
@@ -15,6 +15,7 @@ package org.eclipse.mylyn.internal.gerrit.core.client;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
@@ -94,6 +95,42 @@ public class GerritHttpClient {
}
+ private class RestRequest<T> extends Request<T> {
+
+ private final JSonSupport json = new JSonSupport();
+
+ private final String serviceUri;
+
+ private final Object input;
+
+ private final Type resultType;
+
+ public RestRequest(final String serviceUri, final Object input, Type resultType) {
+ this.serviceUri = serviceUri;
+ this.input = input;
+ this.resultType = resultType;
+ }
+
+ @Override
+ public PostMethod createMethod() throws IOException {
+ PostMethod method = new PostMethod(getUrl() + serviceUri);
+ method.setRequestHeader("Content-Type", "application/json; charset=utf-8"); //$NON-NLS-1$//$NON-NLS-2$
+ method.setRequestHeader("Accept", "application/json"); //$NON-NLS-1$//$NON-NLS-2$
+
+ String content = json.getGson().toJson(input);
+ RequestEntity requestEntity = new StringRequestEntity(content, "application/json", null); //$NON-NLS-1$
+ method.setRequestEntity(requestEntity);
+ return method;
+ }
+
+ @Override
+ public T process(HttpMethodBase method) throws IOException {
+ String content = method.getResponseBodyAsString();
+ return json.parseResponse(content, resultType);
+ }
+
+ }
+
public static abstract class JsonEntity {
public abstract String getContent();
@@ -160,6 +197,15 @@ public class GerritHttpClient {
return execute(new JsonRequest(serviceUri, entity), monitor);
}
+ public <T> T postRestRequest(final String serviceUri, final Object input, Type resultType, IProgressMonitor monitor)
+ throws IOException, GerritException {
+ Assert.isNotNull(serviceUri, "REST Service URI must be not null."); //$NON-NLS-1$
+ Assert.isNotNull(input, "Input object must be not null."); //$NON-NLS-1$
+ Assert.isNotNull(resultType, "Output type must be not null."); //$NON-NLS-1$
+
+ return execute(new RestRequest<T>(serviceUri, input, resultType), monitor);
+ }
+
public <T> T execute(Request<T> request, IProgressMonitor monitor) throws IOException, GerritException {
return execute(request, true, monitor);
}
@@ -185,6 +231,11 @@ public class GerritHttpClient {
}
HttpMethodBase method = request.createMethod();
+ if (obtainedXsrfKey) {
+ // required to authenticate against Gerrit 2.6+ REST endpoints
+ // harmless in previous versions
+ method.setRequestHeader("X-Gerrit-Auth", xsrfKey); //$NON-NLS-1$
+ }
try {
// Execute the method.
WebUtil.execute(httpClient, hostConfiguration, method, monitor);
@@ -340,7 +391,7 @@ public class GerritHttpClient {
}
if (code == HttpURLConnection.HTTP_OK) {
- DiscoveryResult result = json.parseResponse(jsonRequest.process(method), DiscoveryResult.class);
+ DiscoveryResult result = json.parseJsonResponse(jsonRequest.process(method), DiscoveryResult.class);
if (result.status == Status.VALID) {
if (location instanceof IOpenIdLocation) {
String returnUrl = result.providerArgs.get("openid.return_to"); //$NON-NLS-1$
@@ -417,7 +468,7 @@ public class GerritHttpClient {
}
if (code == HttpURLConnection.HTTP_OK) {
- LoginResult result = json.parseResponse(jsonRequest.process(method), LoginResult.class);
+ LoginResult result = json.parseJsonResponse(jsonRequest.process(method), LoginResult.class);
if (result.success) {
return HttpStatus.SC_TEMPORARY_REDIRECT;
} else {
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritService.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritService.java
index b775d0a..2b21b6a 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritService.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritService.java
@@ -113,7 +113,7 @@ public class GerritService implements InvocationHandler {
Type[] types = method.getGenericParameterTypes();
final Type resultType = ((ParameterizedType) types[types.length - 1]).getActualTypeArguments()[0];
- Object result = json.parseResponse(responseMessage, resultType);
+ Object result = json.parseJsonResponse(responseMessage, resultType);
callback.onSuccess(result);
} catch (Throwable e) {
callback.onFailure(e);
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java
index a62b384..a33cbe9 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/JSonSupport.java
@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.jgit.diff.Edit;
import com.google.gerrit.common.data.GerritConfig;
@@ -203,8 +204,8 @@ public class JSonSupport {
return gson.toJson(msg, msg.getClass());
}
- <T> T parseResponse(String responseMessage, Type resultType) throws GerritException {
- JSonResponse response = gson.fromJson(responseMessage, JSonResponse.class);
+ <T> T parseJsonResponse(String responseMessage, Type resultType) throws GerritException {
+ JSonResponse response = parseResponse(responseMessage, JSonResponse.class);
if (response.error != null) {
JSonError error = gson.fromJson(response.error, JSonError.class);
throw new GerritException(error.message, error.code);
@@ -213,4 +214,13 @@ public class JSonSupport {
}
}
+ public <T> T parseResponse(String responseMessage, Type resultType) {
+ Assert.isLegal(responseMessage != null);
+ Assert.isLegal(!responseMessage.isEmpty());
+
+ if (responseMessage.startsWith(")]}'\n")) { //$NON-NLS-1$
+ responseMessage = responseMessage.substring(5);
+ }
+ return gson.fromJson(responseMessage, resultType);
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInfo.java
new file mode 100644
index 0000000..a96f278
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInfo.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.gerrit.core.client.rest;
+
+import java.util.Map;
+
+/**
+ * Data model object for https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-info
+ */
+public class ReviewInfo {
+
+ private Map<String, Short> labels;
+
+ public Map<String, Short> getLabels() {
+ return labels;
+ }
+
+}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java
new file mode 100644
index 0000000..dcb88b5
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.gerrit.core.client.rest;
+
+import org.eclipse.core.runtime.Assert;
+
+/**
+ * Data model object for https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-input
+ */
+public class ReviewInput {
+
+ private final String message;
+
+ public ReviewInput(String msg) {
+ Assert.isLegal(msg != null);
+ this.message = msg;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/AllGerritTests.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/AllGerritTests.java
index 4013000..209a50d 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/AllGerritTests.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/AllGerritTests.java
@@ -23,6 +23,8 @@ import org.eclipse.mylyn.gerrit.tests.core.GerritSynchronizationTest;
import org.eclipse.mylyn.gerrit.tests.core.client.GerritClientTest;
import org.eclipse.mylyn.gerrit.tests.core.client.GerritVersionTest;
import org.eclipse.mylyn.gerrit.tests.core.client.OpenIdAuthenticationTest;
+import org.eclipse.mylyn.gerrit.tests.core.client.rest.ReviewInfoTest;
+import org.eclipse.mylyn.gerrit.tests.core.client.rest.ReviewInputTest;
import org.eclipse.mylyn.gerrit.tests.support.GerritFixture;
import org.eclipse.mylyn.gerrit.tests.ui.GerritUrlHandlerTest;
import org.eclipse.mylyn.internal.gerrit.core.remote.GerritDataLocatorTest;
@@ -48,6 +50,8 @@ public class AllGerritTests {
private static void addTests(TestSuite suite, TestConfiguration configuration) {
suite.addTestSuite(GerritVersionTest.class);
+ suite.addTestSuite(ReviewInfoTest.class);
+ suite.addTestSuite(ReviewInputTest.class);
if (!configuration.isLocalOnly()) {
// network tests
suite.addTestSuite(OpenIdAuthenticationTest.class);
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInfoTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInfoTest.java
new file mode 100644
index 0000000..3edbe40
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInfoTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.gerrit.tests.core.client.rest;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
+import org.eclipse.mylyn.internal.gerrit.core.client.JSonSupport;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ReviewInfo;
+import org.junit.Test;
+
+public class ReviewInfoTest extends TestCase {
+
+ @Test
+ public void testFromEmptyJson() throws Exception {
+ ReviewInfo reviewInfo = parseFile("testdata/EmptyWithMagic.json");
+
+ assertNotNull(reviewInfo);
+ assertNull(reviewInfo.getLabels());
+ }
+
+ @Test
+ public void testFromInvalid() throws Exception {
+ ReviewInfo reviewInfo = parseFile("testdata/InvalidWithMagic.json");
+
+ assertNotNull(reviewInfo);
+ assertNull(reviewInfo.getLabels());
+ }
+
+ @Test
+ public void testFromCodeReviewMinusOne() throws Exception {
+ ReviewInfo reviewInfo = parseFile("testdata/ReviewInfo_codeReviewMinusOne.json");
+
+ assertNotNull(reviewInfo);
+ assertNotNull(reviewInfo.getLabels());
+ assertFalse(reviewInfo.getLabels().isEmpty());
+ assertNotNull(reviewInfo.getLabels().get("Code-Review"));
+ assertEquals(-1, reviewInfo.getLabels().get("Code-Review").shortValue());
+ }
+
+ @Test
+ public void testFromVerifyZero() throws Exception {
+ ReviewInfo reviewInfo = parseFile("testdata/ReviewInfo_verifyZero.json");
+
+ assertNotNull(reviewInfo);
+ assertNotNull(reviewInfo.getLabels());
+ assertFalse(reviewInfo.getLabels().isEmpty());
+ assertNotNull(reviewInfo.getLabels().get("Verify"));
+ assertEquals(0, reviewInfo.getLabels().get("Verify").shortValue());
+ }
+
+ private ReviewInfo parseFile(String path) throws IOException {
+ File file = CommonTestUtil.getFile(this, path);
+ String content = CommonTestUtil.read(file);
+ return new JSonSupport().parseResponse(content, ReviewInfo.class);
+ }
+
+}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java
new file mode 100644
index 0000000..03651b8
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.gerrit.tests.core.client.rest;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
+import org.eclipse.mylyn.internal.gerrit.core.client.JSonSupport;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ReviewInput;
+import org.junit.Test;
+
+public class ReviewInputTest extends TestCase {
+
+ @Test
+ public void testFromNull() throws Exception {
+ try {
+ new ReviewInput(null);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testFromEmpty() throws Exception {
+ ReviewInput reviewInput = new ReviewInput("");
+
+ String json = new JSonSupport().getGson().toJson(reviewInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/ReviewInput_emptyMessage.json"), json);
+ }
+
+ @Test
+ public void testFromValid() throws Exception {
+ ReviewInput reviewInput = new ReviewInput("Looking good!");
+
+ String json = new JSonSupport().getGson().toJson(reviewInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/ReviewInput_message.json"), json);
+ }
+
+ private String readFile(String path) throws IOException {
+ File file = CommonTestUtil.getFile(this, path);
+ return CommonTestUtil.read(file);
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/EmptyJsonWithMagic.json b/org.eclipse.mylyn.gerrit.tests/testdata/EmptyJsonWithMagic.json
new file mode 100644
index 0000000..3596d59
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/EmptyJsonWithMagic.json
@@ -0,0 +1,2 @@
+)]}'
+{}
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/EmptyWithMagic.json b/org.eclipse.mylyn.gerrit.tests/testdata/EmptyWithMagic.json
new file mode 100644
index 0000000..3596d59
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/EmptyWithMagic.json
@@ -0,0 +1,2 @@
+)]}'
+{}
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/InvalidWithMagic.json b/org.eclipse.mylyn.gerrit.tests/testdata/InvalidWithMagic.json
new file mode 100644
index 0000000..d0eba28
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/InvalidWithMagic.json
@@ -0,0 +1,4 @@
+)]}'
+{
+ "valid": false
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInfo_codeReviewMinusOne.json b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInfo_codeReviewMinusOne.json
new file mode 100644
index 0000000..0db8556
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInfo_codeReviewMinusOne.json
@@ -0,0 +1,6 @@
+)]}'
+{
+ "labels": {
+ "Code-Review": -1
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInfo_verifyZero.json b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInfo_verifyZero.json
new file mode 100644
index 0000000..07a69e8
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInfo_verifyZero.json
@@ -0,0 +1,6 @@
+)]}'
+{
+ "labels": {
+ "Verify": 0
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_emptyMessage.json b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_emptyMessage.json
new file mode 100644
index 0000000..740e214
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_emptyMessage.json
@@ -0,0 +1 @@
+{"message":""} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_message.json b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_message.json
new file mode 100644
index 0000000..4b2881a
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_message.json
@@ -0,0 +1 @@
+{"message":"Looking good!"} \ No newline at end of file