summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-26 08:34:35 (EDT)
committerTomasz Zarna2013-07-30 05:24:26 (EDT)
commite521b05707b000c4e90a6f21b500cb03e36281d1 (patch)
treefb81b27a18c7f575c083c65809e4723fe8cf5574
parent41803058772d3c266133a56ccb42acd3e09f0798 (diff)
downloadorg.eclipse.mylyn.reviews-e521b05707b000c4e90a6f21b500cb03e36281d1.zip
org.eclipse.mylyn.reviews-e521b05707b000c4e90a6f21b500cb03e36281d1.tar.gz
org.eclipse.mylyn.reviews-e521b05707b000c4e90a6f21b500cb03e36281d1.tar.bz2
395059: approvals no longer returned as part of configurationrefs/changes/89/14589/15
* read approval categories from ChangeInfo * allow to publish comments with approvals Bug: 395059 Change-Id: Ia1258fcabe3533e8f4191d169a9bb4b116ec488e 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.java20
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/ChangeDetailX.java12
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalInfo.java24
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java7
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ChangeInfo.java92
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/LabelInfo.java34
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInfo.java3
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewInput.java20
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/RevisionInfo.java30
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java134
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ChangeInfoTest.java155
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/IsEmpty.java47
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewInputTest.java44
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java71
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_CodeReviewMinusOne.json51
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_NoReviews.json44
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_TwoRevisions.json51
-rw-r--r--org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_emptyMessageCodeReviewPlusOne.json1
18 files changed, 754 insertions, 86 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 f421661..10b2b05 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
@@ -275,12 +275,23 @@ public class GerritClient extends ReviewsClient {
*/
public ChangeDetailX getChangeDetail(int reviewId, IProgressMonitor monitor) throws GerritException {
final Change.Id id = new Change.Id(reviewId);
- return execute(monitor, new Operation<ChangeDetailX>() {
+ ChangeDetailX changeDetail = execute(monitor, new Operation<ChangeDetailX>() {
@Override
public void execute(IProgressMonitor monitor) throws GerritException {
getChangeDetailService(monitor).changeDetailX(id, this);
}
});
+ if (changeDetail.getApprovals() == null && isVersion26OrLater(monitor)) {
+ ChangeInfo changeInfo = getChangeInfo(reviewId, monitor);
+ changeDetail.setApprovals(changeInfo.convertToApprovalDetails());
+ changeDetail.setApprovalTypes(changeInfo.convertToApprovalTypes());
+ }
+ return changeDetail;
+ }
+
+ public ChangeInfo getChangeInfo(final int reviewId, IProgressMonitor monitor) throws GerritException {
+ final String uri = "/changes/" + reviewId + "/revisions/current/review"; //$NON-NLS-1$ //$NON-NLS-2$
+ return executeGetRestRequest(uri, ChangeInfo.class, monitor);
}
public void loadPatchSetContent(PatchSetContent patchSetContent, IProgressMonitor monitor) throws GerritException {
@@ -501,6 +512,7 @@ public class GerritClient extends ReviewsClient {
if (!comments.isEmpty()) {
reviewInput.setComments(comments);
}
+ reviewInput.setApprovals(approvals);
final String uri = "/a/changes/" + id.getParentKey().get() + "/revisions/" + id.get() + "/review"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
executePostRestRequest(uri, reviewInput, ReviewInfo.class, null /*no error handler*/, monitor);
}
@@ -605,8 +617,12 @@ public class GerritClient extends ReviewsClient {
}
private boolean hasJsonRpcApi(IProgressMonitor monitor) throws GerritException {
+ return !isVersion26OrLater(monitor);
+ }
+
+ private boolean isVersion26OrLater(IProgressMonitor monitor) throws GerritException {
Version version = getCachedVersion(monitor);
- return !GerritVersion.isVersion26OrLater(version);
+ return GerritVersion.isVersion26OrLater(version);
}
/**
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/ChangeDetailX.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/ChangeDetailX.java
index f7a4929..feaaa72 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/ChangeDetailX.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/ChangeDetailX.java
@@ -12,7 +12,9 @@
package org.eclipse.mylyn.internal.gerrit.core.client.compat;
import java.util.List;
+import java.util.Set;
+import com.google.gerrit.common.data.ApprovalType;
import com.google.gerrit.common.data.ChangeDetail;
/**
@@ -46,6 +48,8 @@ public class ChangeDetailX extends ChangeDetail {
protected List<SubmitRecord> submitRecords;
+ private Set<ApprovalType> approvalTypes;
+
public boolean canRevert() {
return canRevert;
}
@@ -73,4 +77,12 @@ public class ChangeDetailX extends ChangeDetail {
public void setSubmitRecords(List<SubmitRecord> submitRecords) {
this.submitRecords = submitRecords;
}
+
+ public Set<ApprovalType> getApprovalTypes() {
+ return approvalTypes;
+ }
+
+ public void setApprovalTypes(Set<ApprovalType> approvalTypes) {
+ this.approvalTypes = approvalTypes;
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalInfo.java
new file mode 100644
index 0000000..7b42992
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalInfo.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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-changes.html#approval-info">ApprovalInfo</a>.
+ */
+public class ApprovalInfo extends AccountInfo {
+ private short value;
+
+ public short getValue() {
+ return value;
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java
index aeff052..b34433d 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ApprovalUtil.java
@@ -20,7 +20,7 @@ import com.google.gerrit.common.data.ApprovalType;
import com.google.gerrit.reviewdb.ApprovalCategory;
import com.google.gerrit.reviewdb.ApprovalCategoryValue;
-public abstract class ApprovalUtil {
+public final class ApprovalUtil {
public static final ApprovalType VRIF;
@@ -97,4 +97,7 @@ public abstract class ApprovalUtil {
}
return null;
}
-} \ No newline at end of file
+
+ private ApprovalUtil() {
+ }
+}
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
index d0518b2..d4eabaf 100644
--- 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
@@ -12,8 +12,22 @@
package org.eclipse.mylyn.internal.gerrit.core.client.rest;
import java.sql.Timestamp;
-
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import com.google.gerrit.common.data.ApprovalDetail;
+import com.google.gerrit.common.data.ApprovalType;
+import com.google.gerrit.reviewdb.Account;
+import com.google.gerrit.reviewdb.ApprovalCategory;
+import com.google.gerrit.reviewdb.ApprovalCategoryValue;
import com.google.gerrit.reviewdb.Change;
+import com.google.gerrit.reviewdb.PatchSet;
+import com.google.gerrit.reviewdb.PatchSetApproval;
/**
* Data model object for <a
@@ -108,4 +122,80 @@ public class ChangeInfo {
public AccountInfo getOwner() {
return owner;
}
+
+ private Map<String/*Label*/, LabelInfo> labels;
+
+ private String current_revision;
+
+ private Map<String/*commit ID*/, RevisionInfo> revisions;
+
+ public Map<String, LabelInfo> getLabels() {
+ return labels;
+ }
+
+ public String getCurrentRevision() {
+ return current_revision;
+ }
+
+ public Map<String, RevisionInfo> getRevisions() {
+ return revisions;
+ }
+
+ private PatchSet.Id getCurrentPatchSetId() {
+ Change.Id changeId = new Change.Id(_number);
+ int patchSetId = revisions.get(current_revision).getNumber();
+ return new PatchSet.Id(changeId, patchSetId);
+ }
+
+ public Set<ApprovalDetail> convertToApprovalDetails() {
+ if (labels == null) {
+ return Collections.<ApprovalDetail> emptySet();
+ }
+ Set<ApprovalDetail> result = new HashSet<ApprovalDetail>();
+ for (Entry<String, LabelInfo> entry : labels.entrySet()) {
+ List<ApprovalInfo> all = entry.getValue().getAll();
+ if (all != null) {
+ String name = entry.getKey().replace('-', ' ');
+ ApprovalCategory.Id approvalCategoryId = ApprovalUtil.findCategoryIdByName(name);
+ for (ApprovalInfo approvalInfo : all) {
+ Account.Id accountId = new Account.Id(approvalInfo.getId());
+ ApprovalDetail approvalDetail = new ApprovalDetail(accountId);
+ approvalDetail.add(new PatchSetApproval(new PatchSetApproval.Key(getCurrentPatchSetId(), accountId,
+ approvalCategoryId), approvalInfo.getValue()));
+ result.add(approvalDetail);
+ }
+ }
+ }
+ return result;
+ }
+
+ public Set<ApprovalType> convertToApprovalTypes() {
+ if (labels == null) {
+ return null;
+ }
+ Set<ApprovalType> result = new HashSet<ApprovalType>();
+ for (Entry<String, LabelInfo> entry : labels.entrySet()) {
+ String name = entry.getKey().replace('-', ' ');
+ ApprovalCategory.Id approvalCategoryId = ApprovalUtil.findCategoryIdByName(name);
+ ApprovalCategory approvalCategory = new ApprovalCategory(approvalCategoryId, name);
+ List<ApprovalCategoryValue> valueList = new ArrayList<ApprovalCategoryValue>();
+ for (Entry<String, String> valueEntry : entry.getValue().getValues().entrySet()) {
+ valueList.add(new ApprovalCategoryValue(new ApprovalCategoryValue.Id(approvalCategoryId,
+ parseShort(valueEntry.getKey())), valueEntry.getValue()));
+ }
+ ApprovalType approvalType = new ApprovalType(approvalCategory, valueList);
+ result.add(approvalType);
+ }
+ return result;
+ }
+
+ private static short parseShort(String s) {
+ s = s.trim();
+ // only Java7 handles a plus sign as indication of a positive value
+ if (s.startsWith("+")) { //$NON-NLS-1$
+ s = s.substring(1);
+ }
+ return Short.parseShort(s);
+ }
+
}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/LabelInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/LabelInfo.java
new file mode 100644
index 0000000..d1ff68b
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/LabelInfo.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.List;
+import java.util.Map;
+
+/**
+ * Data model object for <a
+ * href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#label-info">LabelInfo</a>.
+ */
+public class LabelInfo {
+
+ private List<ApprovalInfo> all;
+
+ private Map<String, String> values;
+
+ public List<ApprovalInfo> getAll() {
+ return all;
+ }
+
+ public Map<String/*vote*/, String/*description*/> getValues() {
+ return values;
+ }
+}
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
index a96f278..34c5a16 100644
--- 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
@@ -13,7 +13,8 @@ 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
+ * Data model object for <a
+ * href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-info">ReviewInfo</a>.
*/
public class ReviewInfo {
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
index 5d800aa..0121852 100644
--- 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
@@ -10,10 +10,14 @@
*******************************************************************************/
package org.eclipse.mylyn.internal.gerrit.core.client.rest;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import org.eclipse.core.runtime.Assert;
+import com.google.gerrit.reviewdb.ApprovalCategoryValue;
+
/**
* Data model object for <a
* href="https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-input">ReviewInput</a>.
@@ -24,6 +28,8 @@ public class ReviewInput {
private Map<String, CommentInput[]> comments;
+ private Map<String, Short> labels;
+
public ReviewInput(String msg) {
Assert.isLegal(msg != null);
this.message = msg;
@@ -40,4 +46,18 @@ public class ReviewInput {
public void setComments(Map<String, CommentInput[]> comments) {
this.comments = comments;
}
+
+ public void setApprovals(Set<ApprovalCategoryValue.Id> approvals) {
+ if (approvals == null || approvals.isEmpty()) {
+ return;
+ }
+ labels = new HashMap<String, Short>(approvals.size());
+ for (ApprovalCategoryValue.Id approval : approvals) {
+ String labelName = ApprovalUtil.findCategoryNameById(approval.getParentKey().get());
+ labelName = labelName.replace(' ', '-');
+ Short voteValue = Short.valueOf(approval.get());
+ labels.put(labelName, voteValue);
+ }
+ }
+
}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/RevisionInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/RevisionInfo.java
new file mode 100644
index 0000000..0435a7f
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/RevisionInfo.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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-changes.html#revision-info">RevisionInfo</a>.
+ */
+public class RevisionInfo {
+
+ private boolean draft;
+
+ private int _number;
+
+ public boolean isDraft() {
+ return draft;
+ }
+
+ public int getNumber() {
+ return _number;
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java
index ede7215..a388f16 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactory.java
@@ -111,10 +111,8 @@ public class GerritReviewRemoteFactory extends ReviewRemoteFactory<GerritChange,
getGerritProvider().pullUser(parent, detail.getAccounts(),
patchSetDetail.getInfo().getCommitter().getAccount(), monitor);
}
- if (detail.getApprovals() != null) {
- for (ApprovalDetail remoteApproval : detail.getApprovals()) {
- getGerritProvider().pullUser(parent, detail.getAccounts(), remoteApproval.getAccount(), monitor);
- }
+ for (ApprovalDetail remoteApproval : detail.getApprovals()) {
+ getGerritProvider().pullUser(parent, detail.getAccounts(), remoteApproval.getAccount(), monitor);
}
if (detail.getSubmitRecords() != null) {
@@ -280,6 +278,7 @@ public class GerritReviewRemoteFactory extends ReviewRemoteFactory<GerritChange,
for (IApprovalType type : parent.getApprovalTypes()) {
typeForKey.put(type.getKey(), type);
}
+ // read approvals from configuration
GerritConfiguration configuration = getGerritProvider().getClient().getConfiguration();
if (configuration.getGerritConfig().getApprovalTypes() != null) {
for (ApprovalType remoteType : configuration.getGerritConfig().getApprovalTypes().getApprovalTypes()) {
@@ -293,70 +292,85 @@ public class GerritReviewRemoteFactory extends ReviewRemoteFactory<GerritChange,
}
String approvalName = remoteType.getCategory().getName();
//Special case so we can match different label name for status records. (?!)
- approvalName = approvalName.replace(" ", "-");
+ approvalName = approvalName.replace(' ', '-');
typeForName.put(approvalName, localApprovalType);
}
+ }
+ // read approvals from change detail
+ if (detail.getApprovalTypes() != null) {
+ for (ApprovalType approvalType : detail.getApprovalTypes()) {
+ IApprovalType localApprovalType = typeForKey.get(approvalType.getCategory().getId().get());
+ if (localApprovalType == null) {
+ localApprovalType = IReviewsFactory.INSTANCE.createApprovalType();
+ localApprovalType.setKey(approvalType.getCategory().getId().get());
+ localApprovalType.setName(approvalType.getCategory().getName());
+ parent.getApprovalTypes().add(localApprovalType);
+ typeForKey.put(localApprovalType.getKey(), localApprovalType);
+ }
+ String approvalName = approvalType.getCategory().getName();
+ //Special case so we can match different label name for status records. (?!)
+ approvalName = approvalName.replace(' ', '-');
+ typeForName.put(approvalName, localApprovalType);
+ }
+ }
- //Approvals
- review.getReviewerApprovals().clear();
- if (detail.getApprovals() != null) {
- for (ApprovalDetail remoteApproval : detail.getApprovals()) {
- IUser reviewer = getGerritProvider().createUser(parent, detail.getAccounts(),
- remoteApproval.getAccount());
- if (reviewer == null) {
- throw new RuntimeException("Internal Error, no reviewer found for: "
- + remoteApproval.getAccount());
- }
- IReviewerEntry reviewerEntry = review.getReviewerApprovals().get(reviewer);
- if (reviewerEntry == null) {
- reviewerEntry = IReviewsFactory.INSTANCE.createReviewerEntry();
- review.getReviewerApprovals().put(reviewer, reviewerEntry);
- }
- for (Entry<com.google.gerrit.reviewdb.ApprovalCategory.Id, PatchSetApproval> remoteMap : remoteApproval.getApprovalMap()
- .entrySet()) {
- String remoteType = remoteMap.getValue().getCategoryId().get();
- IApprovalType approvalType = typeForKey.get(remoteType);
- if (approvalType == null) {
- approvalType = IReviewsFactory.INSTANCE.createApprovalType();
- approvalType.setKey(remoteType);
- approvalType.setName(remoteType);
- parent.getApprovalTypes().add(approvalType);
- typeForKey.put(approvalType.getKey(), approvalType);
- }
- reviewerEntry.getApprovals().put(approvalType, (int) remoteMap.getValue().getValue());
+ //Approvals
+ review.getReviewerApprovals().clear();
+ if (detail.getApprovals() != null) {
+ for (ApprovalDetail remoteApproval : detail.getApprovals()) {
+ IUser reviewer = getGerritProvider().createUser(parent, detail.getAccounts(),
+ remoteApproval.getAccount());
+ if (reviewer == null) {
+ throw new RuntimeException("Internal Error, no reviewer found for: " + remoteApproval.getAccount());
+ }
+ IReviewerEntry reviewerEntry = review.getReviewerApprovals().get(reviewer);
+ if (reviewerEntry == null) {
+ reviewerEntry = IReviewsFactory.INSTANCE.createReviewerEntry();
+ review.getReviewerApprovals().put(reviewer, reviewerEntry);
+ }
+ for (Entry<com.google.gerrit.reviewdb.ApprovalCategory.Id, PatchSetApproval> remoteMap : remoteApproval.getApprovalMap()
+ .entrySet()) {
+ String remoteType = remoteMap.getValue().getCategoryId().get();
+ IApprovalType approvalType = typeForKey.get(remoteType);
+ if (approvalType == null) {
+ approvalType = IReviewsFactory.INSTANCE.createApprovalType();
+ approvalType.setKey(remoteType);
+ approvalType.setName(remoteType);
+ parent.getApprovalTypes().add(approvalType);
+ typeForKey.put(approvalType.getKey(), approvalType);
}
+ reviewerEntry.getApprovals().put(approvalType, (int) remoteMap.getValue().getValue());
}
}
+ }
- //Requirements
- review.getRequirements().clear();
- if (detail.getSubmitRecords() != null) {
- for (SubmitRecord record : detail.getSubmitRecords()) {
- for (Label label : record.getLabels()) {
- IApprovalType approvalType = typeForName.get(label.getLabel());
- if (approvalType == null) {
- throw new RuntimeException("Internal Error, no approval type found for: "
- + label.getLabel());
- }
- IRequirementEntry requirementEntry = IReviewsFactory.INSTANCE.createRequirementEntry();
- if (label.getStatus().equals("OK")) {
- requirementEntry.setStatus(RequirementStatus.SATISFIED);
- } else if (label.getStatus().equals("NEED")) {
- requirementEntry.setStatus(RequirementStatus.NOT_SATISFIED);
- } else if (label.getStatus().equals("REJECT")) {
- requirementEntry.setStatus(RequirementStatus.REJECTED);
- } else if (label.getStatus().equals("MAY")) {
- requirementEntry.setStatus(RequirementStatus.OPTIONAL);
- } else if (label.getStatus().equals("IMPOSSIBLE")) {
- requirementEntry.setStatus(RequirementStatus.ERROR);
- }
- if (label.getAppliedBy() != null) {
- IUser approver = getGerritProvider().createUser(parent, detail.getAccounts(),
- label.getAppliedBy());
- requirementEntry.setBy(approver);
- }
- review.getRequirements().put(approvalType, requirementEntry);
+ //Requirements
+ review.getRequirements().clear();
+ if (detail.getSubmitRecords() != null) {
+ for (SubmitRecord record : detail.getSubmitRecords()) {
+ for (Label label : record.getLabels()) {
+ IApprovalType approvalType = typeForName.get(label.getLabel());
+ if (approvalType == null) {
+ throw new RuntimeException("Internal Error, no approval type found for: " + label.getLabel());
+ }
+ IRequirementEntry requirementEntry = IReviewsFactory.INSTANCE.createRequirementEntry();
+ if (label.getStatus().equals("OK")) {
+ requirementEntry.setStatus(RequirementStatus.SATISFIED);
+ } else if (label.getStatus().equals("NEED")) {
+ requirementEntry.setStatus(RequirementStatus.NOT_SATISFIED);
+ } else if (label.getStatus().equals("REJECT")) {
+ requirementEntry.setStatus(RequirementStatus.REJECTED);
+ } else if (label.getStatus().equals("MAY")) {
+ requirementEntry.setStatus(RequirementStatus.OPTIONAL);
+ } else if (label.getStatus().equals("IMPOSSIBLE")) {
+ requirementEntry.setStatus(RequirementStatus.ERROR);
+ }
+ if (label.getAppliedBy() != null) {
+ IUser approver = getGerritProvider().createUser(parent, detail.getAccounts(),
+ label.getAppliedBy());
+ requirementEntry.setBy(approver);
}
+ review.getRequirements().put(approvalType, requirementEntry);
}
}
}
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
index 14374f7..5ae1cea 100644
--- 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
@@ -11,12 +11,25 @@
package org.eclipse.mylyn.gerrit.tests.core.client.rest;
+import static org.eclipse.mylyn.gerrit.tests.core.client.rest.IsEmpty.empty;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+
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.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.TimeZone;
import junit.framework.TestCase;
@@ -24,10 +37,20 @@ 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.ApprovalInfo;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ApprovalUtil;
import org.eclipse.mylyn.internal.gerrit.core.client.rest.ChangeInfo;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.LabelInfo;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.RevisionInfo;
+import org.hamcrest.Matchers;
import org.junit.Test;
+import com.google.gerrit.common.data.ApprovalDetail;
+import com.google.gerrit.common.data.ApprovalType;
+import com.google.gerrit.reviewdb.ApprovalCategory.Id;
+import com.google.gerrit.reviewdb.ApprovalCategoryValue;
import com.google.gerrit.reviewdb.Change;
+import com.google.gerrit.reviewdb.PatchSetApproval;
public class ChangeInfoTest extends TestCase {
@Test
@@ -70,7 +93,7 @@ public class ChangeInfoTest extends TestCase {
}
@Test
- public void testCodeReviewMinusOne() throws Exception {
+ public void testFromAbandoned() throws Exception {
ChangeInfo changeInfo = parseFile("testdata/ChangeInfo_abandoned.json");
assertNotNull(changeInfo);
@@ -93,6 +116,73 @@ public class ChangeInfoTest extends TestCase {
assertEquals(-1, changeOwner.getId());
}
+ @Test
+ public void testNewChangeInfo() {
+ ChangeInfo changeInfo = new ChangeInfo();
+
+ assertThat(changeInfo.getLabels(), nullValue());
+ // reviews, no labels = no reviews
+ assertThat(changeInfo.convertToApprovalDetails(), empty());
+ assertThat(changeInfo.convertToApprovalTypes(), nullValue());
+ assertThat(changeInfo.getRevisions(), nullValue());
+ }
+
+ @Test
+ public void testNoReviews() throws Exception {
+ ChangeInfo changeInfo = parseFile("testdata/ChangeInfo_NoReviews.json");
+
+ assertHasCodeReviewLabels(changeInfo);
+ assertThat(changeInfo.getLabels().get("Code-Review").getAll(), nullValue());
+ assertThat(changeInfo.convertToApprovalDetails(), empty());
+ assertHasCodeReviewApprovalType(changeInfo.convertToApprovalTypes());
+ assertHasRevisions(changeInfo, 1);
+ }
+
+ @Test
+ public void testCodeReviewMinusOne() throws IOException {
+ ChangeInfo changeInfo = parseFile("testdata/ChangeInfo_CodeReviewMinusOne.json");
+
+ assertHasCodeReviewLabels(changeInfo);
+ assertHasApprovalInfo(changeInfo.getLabels().get("Code-Review").getAll(), -1);
+ assertHasApprovalDetail(changeInfo.convertToApprovalDetails(), -1);
+ assertHasCodeReviewApprovalType(changeInfo.convertToApprovalTypes());
+ assertHasRevisions(changeInfo, 1);
+ }
+
+ @Test
+ public void testTwoRevisions() throws IOException {
+ ChangeInfo changeInfo = parseFile("testdata/ChangeInfo_TwoRevisions.json");
+
+ assertHasCodeReviewLabels(changeInfo);
+ assertHasApprovalInfo(changeInfo.getLabels().get("Code-Review").getAll(), 0);
+ assertHasApprovalDetail(changeInfo.convertToApprovalDetails(), 0);
+ assertHasCodeReviewApprovalType(changeInfo.convertToApprovalTypes());
+ assertHasRevisions(changeInfo, 2);
+ }
+
+ // Utility methods
+
+ public static void assertHasCodeReviewLabels(ChangeInfo changeInfo) {
+ assertThat(changeInfo, notNullValue());
+ Map<String, LabelInfo> labels = changeInfo.getLabels();
+ assertThat(labels, not(empty()));
+ assertThat(labels.size(), is(1));
+ assertThat(labels, Matchers.<String, LabelInfo> hasKey("Code-Review"));
+ Map<String, String> values = labels.get("Code-Review").getValues();
+ assertThat(values, not(empty()));
+ assertThat(values.size(), is(5));
+ assertThat(values, Matchers.<String, String> hasKey("-2"));
+ assertThat(values, Matchers.<String, String> hasKey("-1"));
+ assertThat(values, Matchers.<String, String> hasKey(" 0"));
+ assertThat(values, Matchers.<String, String> hasKey("+1"));
+ assertThat(values, Matchers.<String, String> hasKey("+2"));
+ assertThat(values.get("-2"), equalTo(ApprovalUtil.CRVW.getValue((short) -2).getName()));
+ assertThat(values.get("-1"), equalTo(ApprovalUtil.CRVW.getValue((short) -1).getName()));
+ assertThat(values.get(" 0"), equalTo(ApprovalUtil.CRVW.getValue((short) 0).getName()));
+ assertThat(values.get("+1"), equalTo(ApprovalUtil.CRVW.getValue((short) 1).getName()));
+ assertThat(values.get("+2"), equalTo(ApprovalUtil.CRVW.getValue((short) 2).getName()));
+ }
+
private static Timestamp timestamp(String date) throws ParseException {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
@@ -106,4 +196,67 @@ public class ChangeInfoTest extends TestCase {
String content = CommonTestUtil.read(file);
return new JSonSupport().parseResponse(content, ChangeInfo.class);
}
+
+ private static void assertHasCodeReviewApprovalType(Set<ApprovalType> approvalTypes) {
+ assertThat(approvalTypes, not(empty()));
+ assertThat(approvalTypes.size(), is(1));
+ ApprovalType approvalType = approvalTypes.iterator().next();
+ assertThat(approvalType.getCategory().getId(), equalTo(ApprovalUtil.CRVW.getCategory().getId()));
+ assertThat(approvalType.getCategory().getName(), is("Code Review"));
+ assertThat(approvalType.getValues().size(), is(5));
+ for (ApprovalCategoryValue approvalCategoryValue : ApprovalUtil.CRVW.getValues()) {
+ assertHasItem(approvalType.getValues(), ApprovalCategoryValueComparator.INSTANCE, approvalCategoryValue);
+ }
+ }
+
+ private static void assertHasApprovalInfo(List<ApprovalInfo> all, int value) {
+ assertThat(all, not(empty()));
+ assertThat(all.size(), is(1));
+ ApprovalInfo approvalInfo = all.get(0);
+ assertThat(approvalInfo, notNullValue());
+ assertThat(approvalInfo.getValue(), is((short) value));
+ assertThat(approvalInfo.getEmail(), equalTo("tests@mylyn.eclipse.org"));
+ }
+
+ private static void assertHasApprovalDetail(Set<ApprovalDetail> approvalDetails, int value) {
+ assertThat(approvalDetails, not(empty()));
+ assertThat(approvalDetails.size(), is(1));
+ ApprovalDetail approvalDetail = approvalDetails.iterator().next();
+ assertThat(approvalDetail, notNullValue());
+ Map<Id, PatchSetApproval> approvalMap = approvalDetail.getApprovalMap();
+ assertThat(approvalMap, notNullValue());
+ assertThat(approvalMap, Matchers.<Id, PatchSetApproval> hasKey(ApprovalUtil.CRVW.getCategory().getId()));
+ PatchSetApproval patchSetApproval = approvalMap.get(ApprovalUtil.CRVW.getCategory().getId());
+ assertThat(patchSetApproval.getValue(), is((short) value));
+ }
+
+ private static void assertHasRevisions(ChangeInfo changeInfo, int patchSetNr) {
+ assertThat(changeInfo, notNullValue());
+ String currentRevision = changeInfo.getCurrentRevision();
+ assertThat(currentRevision, notNullValue());
+ Map<String, RevisionInfo> revisions = changeInfo.getRevisions();
+ assertThat(revisions, not(empty()));
+ assertThat(revisions.size(), is(1));
+ RevisionInfo currentRevisionInfo = revisions.get(currentRevision);
+ assertThat(currentRevisionInfo, notNullValue());
+ assertThat(currentRevisionInfo.isDraft(), is(false));
+ assertThat(currentRevisionInfo.getNumber(), is(patchSetNr));
+ }
+
+ private static <T> void assertHasItem(Collection<T> collection, Comparator<T> comparator, T itemToFind) {
+ for (T item : collection) {
+ if (comparator.compare(item, itemToFind) == 0) {
+ return;
+ }
+ }
+ fail("Item " + itemToFind + " not found in " + collection);
+ }
+
+ private static class ApprovalCategoryValueComparator implements Comparator<ApprovalCategoryValue> {
+ private final static Comparator<ApprovalCategoryValue> INSTANCE = new ApprovalCategoryValueComparator();
+
+ public int compare(ApprovalCategoryValue acv1, ApprovalCategoryValue acv2) {
+ return acv1.format().compareTo(acv2.format());
+ }
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/IsEmpty.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/IsEmpty.java
new file mode 100644
index 0000000..4258357
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/IsEmpty.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.util.Collection;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+
+/**
+ * TODO: to be removed once https://git.eclipse.org/r/#/c/14691/ is merged
+ */
+public class IsEmpty<T> extends BaseMatcher<T> {
+
+ public boolean matches(Object o) {
+ if (o instanceof Collection) {
+ Collection<?> collection = (Collection<?>) o;
+ return collection.isEmpty();
+ }
+ return false;
+ }
+
+ public void describeTo(Description buffer) {
+ buffer.appendText("is empty");
+ }
+
+ @Factory
+ public static <T> Matcher<T> isEmpty() {
+ return new IsEmpty<T>();
+ }
+
+ @Factory
+ public static <T> Matcher<T> empty() {
+ return isEmpty();
+ }
+}
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
index 03651b8..36a545a 100644
--- 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
@@ -12,14 +12,20 @@ package org.eclipse.mylyn.gerrit.tests.core.client.rest;
import java.io.File;
import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
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.ApprovalUtil;
import org.eclipse.mylyn.internal.gerrit.core.client.rest.ReviewInput;
import org.junit.Test;
+import com.google.gerrit.reviewdb.ApprovalCategoryValue;
+
public class ReviewInputTest extends TestCase {
@Test
@@ -54,6 +60,44 @@ public class ReviewInputTest extends TestCase {
assertEquals(readFile("testdata/ReviewInput_message.json"), json);
}
+ @Test
+ public void testSetNullApprovals() throws Exception {
+ ReviewInput reviewInput = new ReviewInput("");
+ reviewInput.setApprovals(null);
+
+ String json = new JSonSupport().getGson().toJson(reviewInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/ReviewInput_emptyMessage.json"), json);
+ }
+
+ @Test
+ public void testSetEmptyApprovals() throws Exception {
+ ReviewInput reviewInput = new ReviewInput("");
+ reviewInput.setApprovals(Collections.<ApprovalCategoryValue.Id> emptySet());
+
+ String json = new JSonSupport().getGson().toJson(reviewInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/ReviewInput_emptyMessage.json"), json);
+ }
+
+ @Test
+ public void testSetApprovals() throws Exception {
+ ReviewInput reviewInput = new ReviewInput("");
+ Set<ApprovalCategoryValue.Id> approvals = new HashSet<ApprovalCategoryValue.Id>(1);
+ approvals.add(ApprovalUtil.CRVW.getValue((short) 1).getId());
+ reviewInput.setApprovals(approvals);
+
+ String json = new JSonSupport().getGson().toJson(reviewInput);
+
+ assertNotNull(json);
+ assertFalse(json.isEmpty());
+ assertEquals(readFile("testdata/ReviewInput_emptyMessageCodeReviewPlusOne.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 c7408cf..01a1c15 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
@@ -11,6 +11,9 @@
package org.eclipse.mylyn.internal.gerrit.core.remote;
+import static org.eclipse.mylyn.gerrit.tests.core.client.rest.IsEmpty.empty;
+import static org.eclipse.mylyn.internal.gerrit.core.client.rest.ApprovalUtil.CRVW;
+import static org.eclipse.mylyn.internal.gerrit.core.client.rest.ApprovalUtil.VRIF;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
@@ -32,9 +35,13 @@ import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jgit.api.CommitCommand;
+import org.eclipse.mylyn.gerrit.tests.core.client.rest.ChangeInfoTest;
import org.eclipse.mylyn.gerrit.tests.support.GerritProject.CommitResult;
import org.eclipse.mylyn.internal.gerrit.core.client.GerritChange;
import org.eclipse.mylyn.internal.gerrit.core.client.GerritException;
+import org.eclipse.mylyn.internal.gerrit.core.client.GerritVersion;
+import org.eclipse.mylyn.internal.gerrit.core.client.compat.ChangeDetailX;
+import org.eclipse.mylyn.internal.gerrit.core.client.rest.ChangeInfo;
import org.eclipse.mylyn.reviews.core.model.IApprovalType;
import org.eclipse.mylyn.reviews.core.model.IChange;
import org.eclipse.mylyn.reviews.core.model.IComment;
@@ -51,7 +58,6 @@ 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;
@@ -124,21 +130,16 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
@Test
public void testApprovals() throws Exception {
- assertThat(reviewHarness.getRepository().getApprovalTypes().size(), is(2));
- IApprovalType verifyApproval = reviewHarness.getRepository().getApprovalTypes().get(0);
- assertThat(verifyApproval.getKey(), is("VRIF"));
- assertThat(verifyApproval.getName(), is("Verified"));
- IApprovalType codeReviewApproval = reviewHarness.getRepository().getApprovalTypes().get(1);
- assertThat(codeReviewApproval.getKey(), is("CRVW"));
- assertThat(codeReviewApproval.getName(), is("Code Review"));
+ int approvals = isVersion26rLater() ? 1 : 2;
+ assertThat(reviewHarness.getRepository().getApprovalTypes().size(), is(approvals));
+ IApprovalType codeReviewApproval = reviewHarness.getRepository().getApprovalTypes().get(approvals - 1);
+ assertThat(codeReviewApproval.getKey(), is(CRVW.getCategory().getId().get()));
+ assertThat(codeReviewApproval.getName(), is(CRVW.getCategory().getName()));
String approvalMessage = "approval, time: " + System.currentTimeMillis(); //$NON-NLS-1$
- reviewHarness.client.publishComments(
- reviewHarness.shortId,
- 1,
- approvalMessage,
- new HashSet<ApprovalCategoryValue.Id>(Collections.singleton(new ApprovalCategoryValue.Id(
- new ApprovalCategory.Id("CRVW"), (short) 1))), null);
+ reviewHarness.client.publishComments(reviewHarness.shortId, 1, approvalMessage,
+ new HashSet<ApprovalCategoryValue.Id>(Collections.singleton(CRVW.getValue((short) 1).getId())),
+ new NullProgressMonitor());
reviewHarness.consumer.retrieve(false);
reviewHarness.listener.waitForResponse(2, 2);
assertThat(getReview().getReviewerApprovals().size(), is(1));
@@ -150,15 +151,21 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
assertThat(next.getValue(), is(1));
Set<Entry<IApprovalType, IRequirementEntry>> reviewApprovals = getReview().getRequirements().entrySet();
- assertThat(reviewApprovals.size(), is(2));
+ assertThat(reviewApprovals.size(), is(approvals));
IRequirementEntry codeReviewEntry = getReview().getRequirements().get(codeReviewApproval);
assertThat(codeReviewEntry, notNullValue());
assertThat(codeReviewEntry.getBy(), nullValue());
assertThat(codeReviewEntry.getStatus(), is(RequirementStatus.NOT_SATISFIED));
- IRequirementEntry verifyEntry = getReview().getRequirements().get(verifyApproval);
- assertThat(verifyEntry, notNullValue());
- assertThat(verifyEntry.getBy(), nullValue());
- assertThat(verifyEntry.getStatus(), is(RequirementStatus.NOT_SATISFIED));
+ if (!isVersion26rLater()) {
+ IApprovalType verifyApproval = reviewHarness.getRepository().getApprovalTypes().get(0);
+ assertThat(verifyApproval.getKey(), is(VRIF.getCategory().getId().get()));
+ assertThat(verifyApproval.getName(), is(VRIF.getCategory().getName()));
+
+ IRequirementEntry verifyEntry = getReview().getRequirements().get(verifyApproval);
+ assertThat(verifyEntry, notNullValue());
+ assertThat(verifyEntry.getBy(), nullValue());
+ assertThat(verifyEntry.getStatus(), is(RequirementStatus.NOT_SATISFIED));
+ }
assertThat(getReview().getState(), is(ReviewStatus.NEW));
}
@@ -327,4 +334,30 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
assertThat(e.getMessage(), is("Change is already up to date."));
}
}
+
+ @Test
+ public void testGetChangeDetailWithNoApprovals() throws Exception {
+ int reviewId = Integer.parseInt(reviewHarness.shortId);
+
+ ChangeDetailX changeDetail = reviewHarness.client.getChangeDetail(reviewId, new NullProgressMonitor());
+
+ assertThat(changeDetail, notNullValue());
+ assertThat(changeDetail.getApprovals(), empty());
+ }
+
+ @Test
+ public void testGetChangeInfo() throws Exception {
+ if (!isVersion26rLater()) {
+ return; // testing Gerrit REST API, available in 2.6 and later
+ }
+ int reviewId = Integer.parseInt(reviewHarness.shortId);
+
+ ChangeInfo changeInfo = reviewHarness.client.getChangeInfo(reviewId, new NullProgressMonitor());
+
+ ChangeInfoTest.assertHasCodeReviewLabels(changeInfo);
+ }
+
+ private boolean isVersion26rLater() throws GerritException {
+ return GerritVersion.isVersion26OrLater(reviewHarness.client.getVersion(new NullProgressMonitor()));
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_CodeReviewMinusOne.json b/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_CodeReviewMinusOne.json
new file mode 100644
index 0000000..9004a19
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_CodeReviewMinusOne.json
@@ -0,0 +1,51 @@
+)]}'
+{
+ "kind": "gerritcodereview#change",
+ "id": "org.eclipse.mylyn.test~master~I20dd58d06da5f39c561738469bee134e23b5e977",
+ "project": "org.eclipse.mylyn.test",
+ "branch": "master",
+ "change_id": "I20dd58d06da5f39c561738469bee134e23b5e977",
+ "subject": "dCvGEK",
+ "status": "NEW",
+ "created": "2013-06-20 15:13:23.132000000",
+ "updated": "2013-07-16 22:14:15.759000000",
+ "mergeable": false,
+ "_sortkey": "0026735600000002",
+ "_number": 2,
+ "owner": {
+ "_account_id": 1000001,
+ "email": "tests@mylyn.eclipse.org"
+ },
+ "labels": {
+ "Code-Review": {
+ "all": [
+ {
+ "value": -1,
+ "_account_id": 1000001,
+ "email": "tests@mylyn.eclipse.org"
+ }
+ ],
+ "values": {
+ "-2": "Do not submit",
+ "-1": "I would prefer that you didn\u0027t submit this",
+ " 0": "No score",
+ "+1": "Looks good to me, but someone else must approve",
+ "+2": "Looks good to me, approved"
+ }
+ }
+ },
+ "permitted_labels": {},
+ "removable_reviewers": [],
+ "current_revision": "d164521a077df962fdd674ba0fa8574d1c5eaa47",
+ "revisions": {
+ "d164521a077df962fdd674ba0fa8574d1c5eaa47": {
+ "_number": 1,
+ "fetch": {
+ "http": {
+ "url": "http://mylyn.org/gerrit-2.6-rc3/org.eclipse.mylyn.test",
+ "ref": "refs/changes/02/2/1"
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_NoReviews.json b/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_NoReviews.json
new file mode 100644
index 0000000..167a31c
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_NoReviews.json
@@ -0,0 +1,44 @@
+)]}'
+{
+ "kind": "gerritcodereview#change",
+ "id": "org.eclipse.mylyn.test~master~I20dd58d06da5f39c561738469bee134e23b5e977",
+ "project": "org.eclipse.mylyn.test",
+ "branch": "master",
+ "change_id": "I20dd58d06da5f39c561738469bee134e23b5e977",
+ "subject": "dCvGEK",
+ "status": "NEW",
+ "created": "2013-06-20 15:13:23.132000000",
+ "updated": "2013-06-20 15:13:23.132000000",
+ "mergeable": false,
+ "_sortkey": "0025df7100000002",
+ "_number": 2,
+ "owner": {
+ "_account_id": 1000001,
+ "email": "tests@mylyn.eclipse.org"
+ },
+ "labels": {
+ "Code-Review": {
+ "values": {
+ "-2": "Do not submit",
+ "-1": "I would prefer that you didn\u0027t submit this",
+ " 0": "No score",
+ "+1": "Looks good to me, but someone else must approve",
+ "+2": "Looks good to me, approved"
+ }
+ }
+ },
+ "permitted_labels": {},
+ "removable_reviewers": [],
+ "current_revision": "d164521a077df962fdd674ba0fa8574d1c5eaa47",
+ "revisions": {
+ "d164521a077df962fdd674ba0fa8574d1c5eaa47": {
+ "_number": 1,
+ "fetch": {
+ "http": {
+ "url": "http://mylyn.org/gerrit-2.6-rc3/org.eclipse.mylyn.test",
+ "ref": "refs/changes/02/2/1"
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_TwoRevisions.json b/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_TwoRevisions.json
new file mode 100644
index 0000000..dd4a0db
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ChangeInfo_TwoRevisions.json
@@ -0,0 +1,51 @@
+)]}'
+{
+ "kind": "gerritcodereview#change",
+ "id": "org.eclipse.mylyn.test~master~Ifa2226cce8a8de82c1468ec0f6d90422e1a7f759",
+ "project": "org.eclipse.mylyn.test",
+ "branch": "master",
+ "change_id": "Ifa2226cce8a8de82c1468ec0f6d90422e1a7f759",
+ "subject": "eAWYhV 2222",
+ "status": "NEW",
+ "created": "2013-06-20 15:13:19.644000000",
+ "updated": "2013-07-16 21:49:31.903000000",
+ "mergeable": false,
+ "_sortkey": "0026733d00000001",
+ "_number": 1,
+ "owner": {
+ "_account_id": 1000001,
+ "email": "tests@mylyn.eclipse.org"
+ },
+ "labels": {
+ "Code-Review": {
+ "all": [
+ {
+ "value": 0,
+ "_account_id": 1000001,
+ "email": "tests@mylyn.eclipse.org"
+ }
+ ],
+ "values": {
+ "-2": "Do not submit",
+ "-1": "I would prefer that you didn\u0027t submit this",
+ " 0": "No score",
+ "+1": "Looks good to me, but someone else must approve",
+ "+2": "Looks good to me, approved"
+ }
+ }
+ },
+ "permitted_labels": {},
+ "removable_reviewers": [],
+ "current_revision": "820a996d6a1e2563e91ddcf89d84cc6576fc92df",
+ "revisions": {
+ "820a996d6a1e2563e91ddcf89d84cc6576fc92df": {
+ "_number": 2,
+ "fetch": {
+ "http": {
+ "url": "http://mylyn.org/gerrit-2.6-rc3/org.eclipse.mylyn.test",
+ "ref": "refs/changes/01/1/2"
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_emptyMessageCodeReviewPlusOne.json b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_emptyMessageCodeReviewPlusOne.json
new file mode 100644
index 0000000..2127626
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.tests/testdata/ReviewInput_emptyMessageCodeReviewPlusOne.json
@@ -0,0 +1 @@
+{"message":"","labels":{"Code-Review":1}} \ No newline at end of file