Search in sources :

Example 76 with ResourceConflictException

use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.

the class PushAccountIT method pushAccountConfigToUserBranchForReviewIsRejectedOnSubmitIfConfigIsInvalid.

@Test
public void pushAccountConfigToUserBranchForReviewIsRejectedOnSubmitIfConfigIsInvalid() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String userRef = RefNames.refsUsers(admin.id());
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
        fetch(allUsersRepo, userRef + ":userRef");
        allUsersRepo.reset("userRef");
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, "invalid config").to(MagicBranch.NEW_CHANGE + userRef);
        r.assertOkStatus();
        accountIndexedCounter.assertNoReindex();
        assertThat(r.getChange().change().getDest().branch()).isEqualTo(userRef);
        gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
        ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(r.getChangeId()).current().submit());
        assertThat(thrown).hasMessageThat().contains(String.format("invalid account configuration: commit '%s' has an invalid '%s' file for account" + " '%s': Invalid config file %s in project %s in branch %s in commit %s", r.getCommit().name(), AccountProperties.ACCOUNT_CONFIG, admin.id(), AccountProperties.ACCOUNT_CONFIG, allUsers.get(), userRef, r.getCommit().name()));
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 77 with ResourceConflictException

use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.

the class DeleteBranchesIT method deleteMultiBranchesWithoutPermissionForbidden.

@Test
public void deleteMultiBranchesWithoutPermissionForbidden() throws Exception {
    DeleteBranchesInput input = new DeleteBranchesInput();
    input.branches = BRANCHES;
    requestScopeOperations.setApiUser(user.id());
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> project().deleteBranches(input));
    assertThat(thrown).hasMessageThat().isEqualTo(errorMessageForBranches(BRANCHES));
    requestScopeOperations.setApiUser(admin.id());
    assertBranches(BRANCHES);
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) DeleteBranchesInput(com.google.gerrit.extensions.api.projects.DeleteBranchesInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 78 with ResourceConflictException

use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.

the class DeleteBranchesIT method deleteBranchesNotFound.

@Test
public void deleteBranchesNotFound() throws Exception {
    DeleteBranchesInput input = new DeleteBranchesInput();
    List<String> branches = Lists.newArrayList(BRANCHES);
    branches.add("refs/heads/does-not-exist");
    input.branches = branches;
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> project().deleteBranches(input));
    assertThat(thrown).hasMessageThat().isEqualTo(errorMessageForBranches(ImmutableList.of("refs/heads/does-not-exist")));
    assertBranchesDeleted(BRANCHES);
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) DeleteBranchesInput(com.google.gerrit.extensions.api.projects.DeleteBranchesInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 79 with ResourceConflictException

use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.

the class DeleteTagsIT method deleteTagsNotFoundContinue.

@Test
public void deleteTagsNotFoundContinue() throws Exception {
    // If it fails on the first tag in the input, it should still
    // continue to process the remaining tags.
    DeleteTagsInput input = new DeleteTagsInput();
    List<String> tags = Lists.newArrayList("refs/tags/does-not-exist");
    tags.addAll(TAGS);
    input.tags = tags;
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> project().deleteTags(input));
    assertThat(thrown).hasMessageThat().isEqualTo(errorMessageForTags(ImmutableList.of("refs/tags/does-not-exist")));
    assertTagsDeleted();
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) DeleteTagsInput(com.google.gerrit.extensions.api.projects.DeleteTagsInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 80 with ResourceConflictException

use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.

the class CreateLabelIT method cannotCreateLabelWithNameThatIsAlreadyInUse.

@Test
public void cannotCreateLabelWithNameThatIsAlreadyInUse() throws Exception {
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.projects().name(allProjects.get()).label(LabelId.CODE_REVIEW).create(new LabelDefinitionInput()));
    assertThat(thrown).hasMessageThat().contains("label Code-Review already exists");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)252 Test (org.junit.Test)106 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)102 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)57 AuthException (com.google.gerrit.extensions.restapi.AuthException)46 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)44 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)42 IOException (java.io.IOException)39 ObjectId (org.eclipse.jgit.lib.ObjectId)36 Repository (org.eclipse.jgit.lib.Repository)34 Change (com.google.gerrit.entities.Change)29 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)28 RevCommit (org.eclipse.jgit.revwalk.RevCommit)27 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)26 RevWalk (org.eclipse.jgit.revwalk.RevWalk)25 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)23 ArrayList (java.util.ArrayList)21 PatchSet (com.google.gerrit.entities.PatchSet)20 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)20 ProjectState (com.google.gerrit.server.project.ProjectState)19