Search in sources :

Example 1 with ThrowingRunnable

use of com.google.gerrit.testing.GerritJUnit.ThrowingRunnable in project gerrit by GerritCodeReview.

the class GroupsIT method pushToGroupBranchForReviewAndSubmit.

private void pushToGroupBranchForReviewAndSubmit(Project.NameKey project, String groupRef, String expectedError) throws Throwable {
    projectOperations.project(project).forUpdate().add(allowLabel(LabelId.CODE_REVIEW).ref(RefNames.REFS_GROUPS + "*").group(REGISTERED_USERS).range(-2, 2)).add(allow(Permission.SUBMIT).ref(RefNames.REFS_GROUPS + "*").group(REGISTERED_USERS)).update();
    TestRepository<InMemoryRepository> repo = cloneProject(project);
    fetch(repo, groupRef + ":groupRef");
    repo.reset("groupRef");
    PushOneCommit.Result r = pushFactory.create(admin.newIdent(), repo, "Update group config", "group.config", "some content").to(MagicBranch.NEW_CHANGE + groupRef);
    r.assertOkStatus();
    assertThat(r.getChange().change().getDest().branch()).isEqualTo(groupRef);
    gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
    ThrowingRunnable submit = () -> gApi.changes().id(r.getChangeId()).current().submit();
    if (expectedError != null) {
        Throwable thrown = assertThrows(ResourceConflictException.class, submit);
        assertThat(thrown).hasMessageThat().contains("group update not allowed");
    } else {
        submit.run();
    }
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ThrowingRunnable(com.google.gerrit.testing.GerritJUnit.ThrowingRunnable)

Example 2 with ThrowingRunnable

use of com.google.gerrit.testing.GerritJUnit.ThrowingRunnable in project gerrit by GerritCodeReview.

the class AbstractSubmit method submit.

protected void submit(String changeId, SubmitInput input, @Nullable Class<? extends RestApiException> expectedExceptionType, String expectedExceptionMsg) throws Throwable {
    approve(changeId);
    if (expectedExceptionType == null) {
        assertSubmittable(changeId);
    } else {
        requireNonNull(expectedExceptionMsg);
    }
    ThrowingRunnable submit = () -> gApi.changes().id(changeId).current().submit(input);
    if (expectedExceptionType != null) {
        RestApiException thrown = assertThrows(expectedExceptionType, submit);
        assertThat(thrown).hasMessageThat().isEqualTo(expectedExceptionMsg);
        return;
    }
    submit.run();
    ChangeInfo change = gApi.changes().id(changeId).info();
    assertMerged(change.changeId);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ThrowingRunnable(com.google.gerrit.testing.GerritJUnit.ThrowingRunnable)

Aggregations

ThrowingRunnable (com.google.gerrit.testing.GerritJUnit.ThrowingRunnable)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)1