summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-30 06:47:02 (EDT)
committerGerrit Code Review @ Eclipse.org2013-07-30 07:08:02 (EDT)
commit530437d1830fded3816c4b45a1e6684d5d78a90e (patch)
tree9299db8f2dd51880faa05624b6ca74f6e40b660c
parenteaedac4a935d9e58aad072affd2d42d99517adbd (diff)
downloadorg.eclipse.mylyn.reviews-530437d1830fded3816c4b45a1e6684d5d78a90e.zip
org.eclipse.mylyn.reviews-530437d1830fded3816c4b45a1e6684d5d78a90e.tar.gz
org.eclipse.mylyn.reviews-530437d1830fded3816c4b45a1e6684d5d78a90e.tar.bz2
395059: throw the expected exception when approval is not permittedrefs/changes/87/14887/4
Bug: 395059 Change-Id: I12b096c58bc856edee28cdf23bc42485ad18811a 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.tests/src/org/eclipse/mylyn/internal/gerrit/core/remote/GerritReviewRemoteFactoryTest.java21
2 files changed, 43 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
index a973b17..3c1cb11 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
@@ -520,7 +520,28 @@ public class GerritClient extends ReviewsClient {
}
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);
+ executePostRestRequest(uri, reviewInput, ReviewInfo.class, new ErrorHandler() {
+
+ @Override
+ public void handleError(HttpMethodBase method) throws GerritException {
+ if (method.getStatusCode() == HttpURLConnection.HTTP_FORBIDDEN) {
+ String msg = getResponseBodyAsString(method);
+ if (msg.startsWith("Applying label") && msg.endsWith("is restricted")) { //$NON-NLS-1$ //$NON-NLS-2$
+ throw new GerritException(msg);
+ }
+ }
+ }
+
+ private String getResponseBodyAsString(HttpMethodBase method) {
+ try {
+ String msg = method.getResponseBodyAsString();
+ return msg.trim();
+ } catch (IOException e) {
+ // ignore
+ }
+ return null;
+ }
+ }, monitor);
}
}
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 53fecc5..84423b8 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
@@ -435,6 +435,27 @@ public class GerritReviewRemoteFactoryTest extends GerritRemoteTest {
ChangeInfoTest.assertHasCodeReviewLabels(changeInfo);
}
+ @Test
+ public void testUnpermittedApproval() throws Exception {
+ String approvalMessage = "approval, time: " + System.currentTimeMillis();
+ try {
+ reviewHarness.client.publishComments(
+ reviewHarness.shortId,
+ 1,
+ approvalMessage,
+ new HashSet<ApprovalCategoryValue.Id>(Collections.singleton(ApprovalUtil.CRVW.getValue((short) 2)
+ .getId())), new NullProgressMonitor());
+ fail("Expected to fail when trying to vote +2 when it's not permitted");
+ } catch (GerritException e) {
+ if (isVersion26rLater()) {
+ assertEquals("Applying label \"Code-Review\": 2 is restricted", e.getMessage());
+ } else {
+ assertEquals("Code-Review=2 not permitted", e.getMessage());
+ }
+
+ }
+ }
+
private boolean isVersion26rLater() throws GerritException {
return GerritVersion.isVersion26OrLater(reviewHarness.client.getVersion(new NullProgressMonitor()));
}