summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-26 04:37:14 (EDT)
committerTomasz Zarna2013-07-26 16:06:16 (EDT)
commit62ccc93a82954a3a75193e0d87a2219ec4106f16 (patch)
tree6fe13250a81dedd8dd39e24000e8d58f64dc7a2f
parent433e5de744f11a0657eb5dd59f3de922eb617ab9 (diff)
downloadorg.eclipse.mylyn.reviews-62ccc93a82954a3a75193e0d87a2219ec4106f16.zip
org.eclipse.mylyn.reviews-62ccc93a82954a3a75193e0d87a2219ec4106f16.tar.gz
org.eclipse.mylyn.reviews-62ccc93a82954a3a75193e0d87a2219ec4106f16.tar.bz2
395059: allow to restore a changerefs/changes/79/14879/4
Bug: 395059 Change-Id: Id276bc20f043641626c96b97520e02a93422fb9d Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=395059 Signed-off-by: Tomasz Zarna <tomasz.zarna@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java23
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/RestoreInput.java29
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java6
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java62
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java2
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_message.json1
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/EmptyMessage.json (renamed from org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_emptyMessage.json)0
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/Message.json1
8 files changed, 114 insertions, 10 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 935f7b8..a70529a 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
@@ -51,6 +51,7 @@ 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.AbandonInput;
import org.eclipse.mylyn.internal.gerrit.core.client.rest.ChangeInfo;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.RestoreInput;
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.client.rest.SubmitInfo;
@@ -673,12 +674,24 @@ public class GerritClient extends ReviewsClient {
public ChangeDetail restore(String reviewId, int patchSetId, final String message, IProgressMonitor monitor)
throws GerritException {
final PatchSet.Id id = new PatchSet.Id(new Change.Id(id(reviewId)), patchSetId);
- return execute(monitor, new Operation<ChangeDetail>() {
- @Override
- public void execute(IProgressMonitor monitor) throws GerritException {
- getChangeManageService(monitor).restoreChange(id, message, this);
+ if (hasJsonRpcApi(monitor)) {
+ return execute(monitor, new Operation<ChangeDetail>() {
+ @Override
+ public void execute(IProgressMonitor monitor) throws GerritException {
+ getChangeManageService(monitor).restoreChange(id, message, this);
+ }
+ });
+ } else {
+ final String uri = "/a/changes/" + id.getParentKey().get() + "/restore"; //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ execute(uri, new RestoreInput(message), ChangeInfo.class, null/*no error handler*/, monitor);
+ } catch (GerritHttpException e) {
+ if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
+ throw new GerritException("Not Found", e); //$NON-NLS-1$
+ }
}
- });
+ return getChangeDetail(id.getParentKey().get(), monitor);
+ }
}
/**
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/RestoreInput.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/RestoreInput.java
new file mode 100644
index 0000000..8abc696
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/RestoreInput.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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 <a
+ * href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#restore-input">RestoreInput</a>.
+ */
+public class RestoreInput {
+
+ @SuppressWarnings("unused")
+ private final String message;
+
+ public RestoreInput(String msg) {
+ Assert.isLegal(msg != null);
+ this.message = msg;
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java
index ee6d084..39523f7 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java
@@ -41,18 +41,18 @@ public class AbandonInputTest extends TestCase {
assertNotNull(json);
assertFalse(json.isEmpty());
- assertEquals(readFile("testdata/AbandonInput_emptyMessage.json"), json);
+ assertEquals(readFile("testdata/EmptyMessage.json"), json);
}
@Test
public void testFromValid() throws Exception {
- AbandonInput abandonInput = new AbandonInput("No go!");
+ AbandonInput abandonInput = new AbandonInput("Whatever");
String json = new JSonSupport().getGson().toJson(abandonInput);
assertNotNull(json);
assertFalse(json.isEmpty());
- assertEquals(readFile("testdata/AbandonInput_message.json"), json);
+ assertEquals(readFile("testdata/Message.json"), json);
}
private String readFile(String path) throws IOException {
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java
new file mode 100644
index 0000000..c81d74d
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/RestoreInputTest.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.RestoreInput;
+import org.junit.Test;
+
+public class RestoreInputTest extends TestCase {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testFromNull() throws Exception {
+ try {
+ new RestoreInput(null);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testFromEmpty() throws Exception {
+ RestoreInput restoreInput = new RestoreInput("");
+
+ String json = new JSonSupport().getGson().toJson(restoreInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/EmptyMessage.json"), json);
+ }
+
+ @Test
+ public void testFromValid() throws Exception {
+ RestoreInput restoreInput = new RestoreInput("Whatever");
+
+ String json = new JSonSupport().getGson().toJson(restoreInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/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/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java
index cb58f48..c7408cf 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java
@@ -242,7 +242,7 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
assertThat(comments.size(), is(2)); // abandon + restore
IComment lastComment = comments.get(1);
assertThat(lastComment.getAuthor().getDisplayName(), is("tests"));
- assertThat(lastComment.getDescription(), is("Patch Set 1: Restored\n\n" + message2));
+ assertThat(lastComment.getDescription(), endsWith("Restored\n\n" + message2));
}
@Test
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_message.json b/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_message.json
deleted file mode 100644
index e544c19..0000000
--- a/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_message.json
+++ /dev/null
@@ -1 +0,0 @@
-{"message":"No go!"} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_emptyMessage.json b/org.eclipse.mylyn.gerrit.tests/testdata/EmptyMessage.json
index 740e214..740e214 100644
--- a/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_emptyMessage.json
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/EmptyMessage.json
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/Message.json b/org.eclipse.mylyn.gerrit.tests/testdata/Message.json
new file mode 100644
index 0000000..bdd5aa3
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/Message.json
@@ -0,0 +1 @@
+{"message":"Whatever"} \ No newline at end of file