ChangeIT: Add tests for abandon/restore with/without permissions

Change-Id: Ic2f4a10e6495e43cc19d08c8eacc0c56489f195e
This commit is contained in:
David Pursehouse
2017-03-30 11:22:23 +09:00
parent fd7336e034
commit 3f849afecd

View File

@@ -343,6 +343,30 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes().id(changeId).abandon();
}
@Test
public void abandonNotAllowedWithoutPermission() throws Exception {
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
assertThat(info(changeId).status).isEqualTo(ChangeStatus.NEW);
setApiUser(user);
exception.expect(AuthException.class);
exception.expectMessage("abandon not permitted");
gApi.changes().id(changeId).abandon();
}
@Test
public void abandonAndRestoreAllowedWithPermission() throws Exception {
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
assertThat(info(changeId).status).isEqualTo(ChangeStatus.NEW);
grant(Permission.ABANDON, project, "refs/heads/master", false, REGISTERED_USERS);
setApiUser(user);
gApi.changes().id(changeId).abandon();
assertThat(info(changeId).status).isEqualTo(ChangeStatus.ABANDONED);
gApi.changes().id(changeId).restore();
assertThat(info(changeId).status).isEqualTo(ChangeStatus.NEW);
}
@Test
public void restore() throws Exception {
PushOneCommit.Result r = createChange();
@@ -361,6 +385,19 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes().id(changeId).restore();
}
@Test
public void restoreNotAllowedWithoutPermission() throws Exception {
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
assertThat(info(changeId).status).isEqualTo(ChangeStatus.NEW);
gApi.changes().id(changeId).abandon();
setApiUser(user);
assertThat(info(changeId).status).isEqualTo(ChangeStatus.ABANDONED);
exception.expect(AuthException.class);
exception.expectMessage("restore not permitted");
gApi.changes().id(changeId).restore();
}
@Test
public void revert() throws Exception {
PushOneCommit.Result r = createChange();