Search in sources :

Example 96 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ActionsIT method oldRevisionActionVisitor.

@Test
public void oldRevisionActionVisitor() throws Exception {
    String id = createChange().getChangeId();
    amendChange(id);
    ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
    class Visitor implements ActionVisitor {

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo) {
            // Do nothing; implicitly called for CURRENT_ACTIONS.
            return true;
        }

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo, RevisionInfo revisionInfo) {
            assertThat(changeInfo).isNotNull();
            assertThat(changeInfo._number).isEqualTo(origChange._number);
            assertThat(revisionInfo).isNotNull();
            assertThat(revisionInfo._number).isEqualTo(1);
            if (name.equals("description")) {
                actionInfo.label = "Describify";
            }
            return true;
        }
    }
    Map<String, ActionInfo> origActions = gApi.changes().id(id).revision(1).actions();
    assertThat(origActions.keySet()).containsExactly("description");
    assertThat(origActions.get("description").label).isEqualTo("Edit Description");
    try (Registration registration = extensionRegistry.newRegistration().add(new Visitor())) {
        // Unlike for the current revision, actions for old revisions are only available via the
        // revision API.
        Map<String, ActionInfo> newActions = gApi.changes().id(id).revision(1).actions();
        assertThat(newActions).isNotNull();
        assertThat(newActions.keySet()).isEqualTo(origActions.keySet());
        ActionInfo description = newActions.get("description");
        assertThat(description).isNotNull();
        assertThat(description.label).isEqualTo("Describify");
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 97 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ChangeIT method customCommitFooters.

@Test
public void customCommitFooters() throws Exception {
    PushOneCommit.Result change = createChange();
    ChangeInfo actual;
    ChangeMessageModifier link = new ChangeMessageModifier() {

        @Override
        public String onSubmit(String newCommitMessage, RevCommit original, RevCommit mergeTip, BranchNameKey destination) {
            assertThat(original.getName()).isNotEqualTo(mergeTip.getName());
            return newCommitMessage + "Custom: " + destination.branch();
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(link)) {
        actual = gApi.changes().id(change.getChangeId()).get(ALL_REVISIONS, COMMIT_FOOTERS);
    }
    List<String> footers = new ArrayList<>(Arrays.asList(actual.revisions.get(change.getCommit().getName()).commitWithFooters.split("\\n")));
    // remove subject + blank line
    footers.remove(0);
    footers.remove(0);
    List<String> expectedFooters = Arrays.asList("Change-Id: " + change.getChangeId(), "Reviewed-on: " + canonicalWebUrl.get() + "c/" + project.get() + "/+/" + change.getChange().getId(), "Custom: refs/heads/master");
    assertThat(footers).containsExactlyElementsIn(expectedFooters);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ArrayList(java.util.ArrayList) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 98 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ChangeIT method rebaseWithValidationOptions.

@Test
public void rebaseWithValidationOptions() throws Exception {
    // Create two changes both with the same parent
    PushOneCommit.Result r = createChange();
    testRepo.reset("HEAD~1");
    PushOneCommit.Result r2 = createChange();
    // Approve and submit the first change
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    revision.review(ReviewInput.approve());
    revision.submit();
    RebaseInput rebaseInput = new RebaseInput();
    rebaseInput.validationOptions = ImmutableMap.of("key", "value");
    TestCommitValidationListener testCommitValidationListener = new TestCommitValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(testCommitValidationListener)) {
        // Rebase the second change
        gApi.changes().id(r2.getChangeId()).current().rebase(rebaseInput);
        assertThat(testCommitValidationListener.receiveEvent.pushOptions).containsExactly("key", "value");
    }
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 99 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ChangeIT method pluginCanContributeToETagComputation.

@Test
public void pluginCanContributeToETagComputation() throws Exception {
    PushOneCommit.Result r = createChange();
    String oldETag = parseResource(r).getETag();
    try (Registration registration = extensionRegistry.newRegistration().add(TestChangeETagComputation.withETag("foo"))) {
        assertThat(parseResource(r).getETag()).isNotEqualTo(oldETag);
    }
    assertThat(parseResource(r).getETag()).isEqualTo(oldETag);
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 100 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ChangeIT method rebaseConflict_conflictsAllowed.

@Test
public void rebaseConflict_conflictsAllowed() throws Exception {
    String patchSetSubject = "patch set change";
    String patchSetContent = "patch set content";
    String baseSubject = "base change";
    String baseContent = "base content";
    PushOneCommit.Result r1 = createChange(baseSubject, PushOneCommit.FILE_NAME, baseContent);
    gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).review(ReviewInput.approve());
    gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).submit();
    testRepo.reset("HEAD~1");
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, patchSetSubject, PushOneCommit.FILE_NAME, patchSetContent);
    PushOneCommit.Result r2 = push.to("refs/for/master");
    r2.assertOkStatus();
    String changeId = r2.getChangeId();
    RevCommit patchSet = r2.getCommit();
    RevCommit base = r1.getCommit();
    TestWorkInProgressStateChangedListener wipStateChangedListener = new TestWorkInProgressStateChangedListener();
    try (Registration registration = extensionRegistry.newRegistration().add(wipStateChangedListener)) {
        RebaseInput rebaseInput = new RebaseInput();
        rebaseInput.allowConflicts = true;
        ChangeInfo changeInfo = gApi.changes().id(changeId).revision(patchSet.name()).rebaseAsInfo(rebaseInput);
        assertThat(changeInfo.containsGitConflicts).isTrue();
        assertThat(changeInfo.workInProgress).isTrue();
    }
    assertThat(wipStateChangedListener.invoked).isTrue();
    assertThat(wipStateChangedListener.wip).isTrue();
    // To get the revisions, we must retrieve the change with more change options.
    ChangeInfo changeInfo = gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
    assertThat(changeInfo.revisions).hasSize(2);
    assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isEqualTo(base.name());
    // Verify that the file content in the created patch set is correct.
    // We expect that it has conflict markers to indicate the conflict.
    BinaryResult bin = gApi.changes().id(changeId).current().file(PushOneCommit.FILE_NAME).content();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    bin.writeTo(os);
    String fileContent = new String(os.toByteArray(), UTF_8);
    String patchSetSha1 = abbreviateName(patchSet, 6);
    String baseSha1 = abbreviateName(base, 6);
    assertThat(fileContent).isEqualTo("<<<<<<< PATCH SET (" + patchSetSha1 + " " + patchSetSubject + ")\n" + patchSetContent + "\n" + "=======\n" + baseContent + "\n" + ">>>>>>> BASE      (" + baseSha1 + " " + baseSubject + ")\n");
    // Verify the message that has been posted on the change.
    List<ChangeMessageInfo> messages = gApi.changes().id(changeId).messages();
    assertThat(messages).hasSize(2);
    assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 2: Patch Set 1 was rebased\n\n" + "The following files contain Git conflicts:\n" + "* " + PushOneCommit.FILE_NAME + "\n");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)205 Test (org.junit.Test)200 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)194 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)90 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)47 RestResponse (com.google.gerrit.acceptance.RestResponse)39 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)38 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)31 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)23 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)22 TestAccount (com.google.gerrit.acceptance.TestAccount)19 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)16 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)15 Config (org.eclipse.jgit.lib.Config)14 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)12 CreateProjectArgs (com.google.gerrit.server.project.CreateProjectArgs)11 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 ImmutableList (com.google.common.collect.ImmutableList)10