summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-17 14:23:03 (EDT)
committer Tomasz Zarna2013-07-26 12:24:36 (EDT)
commit31649c82814e6a54fa8159b40ffd81427d5687b0 (patch)
tree6d31a086db5a44e121ae0c01c618093af921a32e
parent2925fa0c6e1f4c9ecf45d65acc3e4cd64f429e78 (diff)
downloadorg.eclipse.mylyn.reviews-31649c82814e6a54fa8159b40ffd81427d5687b0.zip
org.eclipse.mylyn.reviews-31649c82814e6a54fa8159b40ffd81427d5687b0.tar.gz
org.eclipse.mylyn.reviews-31649c82814e6a54fa8159b40ffd81427d5687b0.tar.bz2
395059: allow to abandon a change in Gerrit 2.6refs/changes/25/14625/7
Bug: 395059 Change-Id: Ib2e6e9ce81257f4891ab01db666234c58bfcd254 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.java27
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/AbandonInput.java29
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/AccountInfo.java46
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java111
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/AllGerritTests.java6
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.java62
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AccountInfoTest.java63
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ChangeInfoTest.java109
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java16
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_emptyMessage.json1
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_message.json1
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/AccountInfo_johnDoe.json6
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_abandoned.json19
13 files changed, 484 insertions, 12 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 b9b651f..fc566a5 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.AbandonInput;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ChangeInfo;
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;
@@ -61,7 +63,6 @@ import org.osgi.framework.Version;
import com.google.gerrit.common.data.AccountDashboardInfo;
import com.google.gerrit.common.data.AccountService;
import com.google.gerrit.common.data.ChangeDetail;
-import com.google.gerrit.common.data.ChangeInfo;
import com.google.gerrit.common.data.ChangeListService;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.common.data.PatchScript;
@@ -245,12 +246,18 @@ public class GerritClient extends ReviewsClient {
public ChangeDetail abandon(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).abandonChange(id, message, this);
- }
- });
+ if (hasJsonRpcApi(monitor)) {
+ return execute(monitor, new Operation<ChangeDetail>() {
+ @Override
+ public void execute(IProgressMonitor monitor) throws GerritException {
+ getChangeManageService(monitor).abandonChange(id, message, this);
+ }
+ });
+ } else {
+ final String uri = "/a/changes/" + id.getParentKey().get() + "/abandon"; //$NON-NLS-1$ //$NON-NLS-2$
+ execute(uri, new AbandonInput(message), ChangeInfo.class, monitor);
+ return getChangeDetail(id.getParentKey().get(), monitor);
+ }
}
/**
@@ -539,7 +546,7 @@ public class GerritClient extends ReviewsClient {
}
});
- List<ChangeInfo> allMyChanges = ad.getByOwner();
+ List<com.google.gerrit.common.data.ChangeInfo> allMyChanges = ad.getByOwner();
allMyChanges.addAll(ad.getForReview());
allMyChanges.addAll(ad.getClosed());
return convert(allMyChanges);
@@ -719,9 +726,9 @@ public class GerritClient extends ReviewsClient {
return executeQueryRest(monitor, queryString);
}
- private List<GerritQueryResult> convert(List<ChangeInfo> changes) {
+ private List<GerritQueryResult> convert(List<com.google.gerrit.common.data.ChangeInfo> changes) {
List<GerritQueryResult> results = new ArrayList<GerritQueryResult>(changes.size());
- for (ChangeInfo changeInfo : changes) {
+ for (com.google.gerrit.common.data.ChangeInfo changeInfo : changes) {
GerritQueryResult result = new GerritQueryResult(changeInfo);
results.add(result);
}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/AbandonInput.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/AbandonInput.java
new file mode 100644
index 0000000..e2f66e8
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/AbandonInput.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#abandon-input">AbandonInput</a>.
+ */
+public class AbandonInput {
+
+ @SuppressWarnings("unused")
+ private final String message;
+
+ public AbandonInput(String msg) {
+ Assert.isLegal(msg != null);
+ this.message = msg;
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/AccountInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/AccountInfo.java
new file mode 100644
index 0000000..ec98154
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/AccountInfo.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Data model object for <a
+ * href="https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#account-info">AccountInfo</a>.
+ */
+public class AccountInfo {
+ private int _account_id = -1;
+
+ private String name;
+
+ private String email;
+
+ private String username;
+
+ public int getId() {
+ return _account_id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setId(int id) {
+ _account_id = id;
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java
new file mode 100644
index 0000000..d0518b2
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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.sql.Timestamp;
+
+import com.google.gerrit.reviewdb.Change;
+
+/**
+ * Data model object for <a
+ * href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-info">ChangeInfo</a>.
+ */
+public class ChangeInfo {
+ // e.g. "gerritcodereview#change"
+ private String kind;
+
+ // e.g. "myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940"
+ private String id;
+
+ // e.g. "myProject"
+ private String project;
+
+ // e.g. "master"
+ private String branch;
+
+ // e.g. "I8473b95934b5732ac55d26311a706c9c2bde9940"
+ private String change_id;
+
+ // e.g. "Implementing Feature X"
+ private String subject;
+
+ // e.g. "ABANDONED"
+ private Change.Status status;
+
+ // e.g. "2013-02-01 09:59:32.126000000"
+ private Timestamp created;
+
+ // e.g. "2013-02-21 11:16:36.775000000",
+ private Timestamp updated;
+
+ private boolean reviewed;
+
+ private boolean mergeable;
+
+ private AccountInfo owner;
+
+ // e.g. "0023412400000f7d"
+ @SuppressWarnings("unused")
+ private String _sortkey;
+
+ // e.g. 3965
+ @SuppressWarnings("unused")
+ private int _number;
+
+ public String getKind() {
+ return kind;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getProject() {
+ return project;
+ }
+
+ public String getBranch() {
+ return branch;
+ }
+
+ public String getChangeId() {
+ return change_id;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public Change.Status getStatus() {
+ return status;
+ }
+
+ public Timestamp getCreated() {
+ return created;
+ }
+
+ public Timestamp getUpdated() {
+ return updated;
+ }
+
+ public boolean isReviewed() {
+ return reviewed;
+ }
+
+ public boolean isMergeable() {
+ return mergeable;
+ }
+
+ public AccountInfo getOwner() {
+ return owner;
+ }
+}
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 209a50d..e1a89c3 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,9 @@ 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.AbandonInputTest;
+import org.eclipse.mylyn.gerrit.tests.core.client.rest.AccountInfoTest;
+import org.eclipse.mylyn.gerrit.tests.core.client.rest.ChangeInfoTest;
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;
@@ -50,6 +53,9 @@ public class AllGerritTests {
private static void addTests(TestSuite suite, TestConfiguration configuration) {
suite.addTestSuite(GerritVersionTest.class);
+ suite.addTestSuite(AbandonInputTest.class);
+ suite.addTestSuite(AccountInfoTest.class);
+ suite.addTestSuite(ChangeInfoTest.class);
suite.addTestSuite(ReviewInfoTest.class);
suite.addTestSuite(ReviewInputTest.class);
if (!configuration.isLocalOnly()) {
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
new file mode 100644
index 0000000..ee6d084
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AbandonInputTest.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.AbandonInput;
+import org.junit.Test;
+
+public class AbandonInputTest extends TestCase {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testFromNull() throws Exception {
+ try {
+ new AbandonInput(null);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testFromEmpty() throws Exception {
+ AbandonInput abandonInput = new AbandonInput("");
+
+ String json = new JSonSupport().getGson().toJson(abandonInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/AbandonInput_emptyMessage.json"), json);
+ }
+
+ @Test
+ public void testFromValid() throws Exception {
+ AbandonInput abandonInput = new AbandonInput("No go!");
+
+ String json = new JSonSupport().getGson().toJson(abandonInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/AbandonInput_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/gerrit/tests/core/client/rest/AccountInfoTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AccountInfoTest.java
new file mode 100644
index 0000000..c57bfd4
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/AccountInfoTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.AccountInfo;
+import org.junit.Test;
+
+public class AccountInfoTest extends TestCase {
+
+ @Test
+ public void testFromEmptyJson() throws Exception {
+ AccountInfo accountInfo = parseFile("testdata/EmptyWithMagic.json");
+
+ assertNotNull(accountInfo);
+ assertEquals(-1, accountInfo.getId());
+ assertNull(accountInfo.getName());
+ assertNull(accountInfo.getEmail());
+ assertNull(accountInfo.getUsername());
+ }
+
+ @Test
+ public void testFromInvalid() throws Exception {
+ AccountInfo accountInfo = parseFile("testdata/InvalidWithMagic.json");
+
+ assertNotNull(accountInfo);
+ assertEquals(-1, accountInfo.getId());
+ assertNull(accountInfo.getName());
+ assertNull(accountInfo.getEmail());
+ assertNull(accountInfo.getUsername());
+ }
+
+ @Test
+ public void testFromValid() throws IOException {
+ AccountInfo accountInfo = parseFile("testdata/AccountInfo_johnDoe.json");
+
+ assertEquals(1000195, accountInfo.getId());
+ assertEquals("John Doe", accountInfo.getName());
+ assertEquals("john.doe@example.com", accountInfo.getEmail());
+ assertNull(accountInfo.getUsername());
+ }
+
+ private AccountInfo parseFile(String path) throws IOException {
+ File file = CommonTestUtil.getFile(this, path);
+ String content = CommonTestUtil.read(file);
+ return new JSonSupport().parseResponse(content, AccountInfo.class);
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ChangeInfoTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ChangeInfoTest.java
new file mode 100644
index 0000000..14374f7
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ChangeInfoTest.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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 java.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+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.AccountInfo;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ChangeInfo;
+import org.junit.Test;
+
+import com.google.gerrit.reviewdb.Change;
+
+public class ChangeInfoTest extends TestCase {
+ @Test
+ public void testFromEmptyJson() throws Exception {
+ ChangeInfo changeInfo = parseFile("testdata/EmptyWithMagic.json");
+
+ assertNotNull(changeInfo);
+ assertNull(changeInfo.getKind());
+ assertNull(changeInfo.getId());
+ assertNull(changeInfo.getProject());
+ assertNull(changeInfo.getBranch());
+ assertNull(changeInfo.getChangeId());
+ assertNull(changeInfo.getSubject());
+ assertNull(changeInfo.getStatus());
+ assertNull(changeInfo.getCreated());
+ assertNull(changeInfo.getUpdated());
+ assertEquals(false, changeInfo.isReviewed());
+ assertEquals(false, changeInfo.isMergeable());
+ assertNull(changeInfo.getOwner());
+ }
+
+ @Test
+ public void testFromInvalid() throws Exception {
+ ChangeInfo changeInfo = parseFile("testdata/InvalidWithMagic.json");
+
+ assertNotNull(changeInfo);
+ assertNotNull(changeInfo);
+ assertNull(changeInfo.getKind());
+ assertNull(changeInfo.getId());
+ assertNull(changeInfo.getProject());
+ assertNull(changeInfo.getBranch());
+ assertNull(changeInfo.getChangeId());
+ assertNull(changeInfo.getSubject());
+ assertNull(changeInfo.getStatus());
+ assertNull(changeInfo.getCreated());
+ assertNull(changeInfo.getUpdated());
+ assertEquals(false, changeInfo.isReviewed());
+ assertEquals(false, changeInfo.isMergeable());
+ assertNull(changeInfo.getOwner());
+ }
+
+ @Test
+ public void testCodeReviewMinusOne() throws Exception {
+ ChangeInfo changeInfo = parseFile("testdata/ChangeInfo_abandoned.json");
+
+ assertNotNull(changeInfo);
+ assertEquals(changeInfo.getKind(), "gerritcodereview#change");
+ assertEquals(changeInfo.getId(), "myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940");
+ assertEquals(changeInfo.getProject(), "myProject");
+ assertEquals(changeInfo.getBranch(), "master");
+ assertEquals("I8473b95934b5732ac55d26311a706c9c2bde9940", changeInfo.getChangeId());
+ assertEquals("Implementing Feature X", changeInfo.getSubject());
+ assertEquals(Change.Status.ABANDONED, changeInfo.getStatus());
+ assertEquals(timestamp("2013-02-01 09:59:32.126"), changeInfo.getCreated());
+ assertEquals(timestamp("2013-02-21 11:16:36.775"), changeInfo.getUpdated());
+ assertEquals(true, changeInfo.isReviewed());
+ assertEquals(true, changeInfo.isMergeable());
+ AccountInfo changeOwner = changeInfo.getOwner();
+ assertNotNull(changeOwner);
+ assertEquals("John Doe", changeOwner.getName());
+ assertNull(changeOwner.getEmail());
+ assertNull(changeOwner.getUsername());
+ assertEquals(-1, changeOwner.getId());
+ }
+
+ private static Timestamp timestamp(String date) throws ParseException {
+ Calendar cal = Calendar.getInstance();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ cal.setTime(sdf.parse(date));
+ cal.add(Calendar.MILLISECOND, TimeZone.getDefault().getRawOffset());
+ return new Timestamp(cal.getTimeInMillis());
+ }
+
+ private ChangeInfo parseFile(String path) throws IOException {
+ File file = CommonTestUtil.getFile(this, path);
+ String content = CommonTestUtil.read(file);
+ return new JSonSupport().parseResponse(content, ChangeInfo.class);
+ }
+}
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 3319473..5c704ed 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
@@ -49,10 +49,12 @@ import org.eclipse.mylyn.reviews.core.spi.remote.emf.RemoteEmfConsumer;
import org.eclipse.osgi.util.NLS;
import org.junit.Test;
+import com.google.gerrit.common.data.ChangeDetail;
import com.google.gerrit.common.data.ReviewerResult;
import com.google.gerrit.reviewdb.ApprovalCategory;
import com.google.gerrit.reviewdb.ApprovalCategoryValue;
import com.google.gerrit.reviewdb.Change.Status;
+import com.google.gerrit.reviewdb.ChangeMessage;
/**
* @author Miles Parker
@@ -201,16 +203,26 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
public void testAbandonChange() throws Exception {
String message1 = "abandon, time: " + System.currentTimeMillis(); //$NON-NLS-1$
- reviewHarness.client.abandon(reviewHarness.shortId, 1, message1, new NullProgressMonitor());
+ ChangeDetail changeDetail = reviewHarness.client.abandon(reviewHarness.shortId, 1, message1,
+ new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
reviewHarness.listener.waitForResponse(2, 2);
+ assertThat(changeDetail, notNullValue());
+ assertThat(changeDetail.getChange().getStatus(), is(Status.ABANDONED));
+ List<ChangeMessage> messages = changeDetail.getMessages();
+ assertThat(messages.size(), is(1));
+ ChangeMessage lastMessage = messages.get(0);
+ assertThat(lastMessage.getAuthor().get(), is(1000001));
+ assertThat(lastMessage.getMessage(), endsWith("Abandoned\n\n" + message1));
+
assertThat(getReview().getState(), is(ReviewStatus.ABANDONED));
List<IComment> comments = getReview().getComments();
assertThat(comments.size(), is(1));
IComment lastComment = comments.get(0);
assertThat(lastComment.getAuthor().getDisplayName(), is("tests"));
- assertThat(lastComment.getDescription(), is("Patch Set 1: Abandoned\n\n" + message1));
+ assertThat(lastComment.getAuthor().getId(), is("1000001"));
+ assertThat(lastComment.getDescription(), endsWith("Abandoned\n\n" + message1));
}
@Test
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_emptyMessage.json b/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_emptyMessage.json
new file mode 100644
index 0000000..740e214
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_emptyMessage.json
@@ -0,0 +1 @@
+{"message":""} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_message.json b/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_message.json
new file mode 100644
index 0000000..e544c19
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/AbandonInput_message.json
@@ -0,0 +1 @@
+{"message":"No go!"} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/AccountInfo_johnDoe.json b/org.eclipse.mylyn.gerrit.tests/testdata/AccountInfo_johnDoe.json
new file mode 100644
index 0000000..5cd5800
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/AccountInfo_johnDoe.json
@@ -0,0 +1,6 @@
+)]}'
+{
+ "_account_id": 1000195,
+ "name": "John Doe",
+ "email": "john.doe@example.com"
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_abandoned.json b/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_abandoned.json
new file mode 100644
index 0000000..cb17e79
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_abandoned.json
@@ -0,0 +1,19 @@
+)]}'
+{
+ "kind": "gerritcodereview#change",
+ "id": "myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940",
+ "project": "myProject",
+ "branch": "master",
+ "change_id": "I8473b95934b5732ac55d26311a706c9c2bde9940",
+ "subject": "Implementing Feature X",
+ "status": "ABANDONED",
+ "created": "2013-02-01 09:59:32.126000000",
+ "updated": "2013-02-21 11:16:36.775000000",
+ "reviewed": true,
+ "mergeable": true,
+ "_sortkey": "0023412400000f7d",
+ "_number": 3965,
+ "owner": {
+ "name": "John Doe"
+ }
+} \ No newline at end of file