Search in sources :

Example 11 with Registration

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

the class PostReviewIT method onPostReviewCallbackGetsCorrectChangeAndPatchSet.

@Test
public void onPostReviewCallbackGetsCorrectChangeAndPatchSet() throws Exception {
    PushOneCommit.Result r = createChange();
    amendChange(r.getChangeId());
    TestOnPostReview testOnPostReview = new TestOnPostReview(/* message= */
    null);
    try (Registration registration = extensionRegistry.newRegistration().add(testOnPostReview)) {
        ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
        // Vote on current patch set.
        gApi.changes().id(r.getChangeId()).current().review(input);
        testOnPostReview.assertChangeAndPatchSet(r.getChange().getId(), 2);
        // Vote on old patch set.
        gApi.changes().id(r.getChangeId()).revision(1).review(input);
        testOnPostReview.assertChangeAndPatchSet(r.getChange().getId(), 1);
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with Registration

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

the class SubmitByRebaseAlwaysIT method rebaseInvokesChangeMessageModifiers.

@Test
public void rebaseInvokesChangeMessageModifiers() throws Throwable {
    ChangeMessageModifier modifier1 = (msg, orig, tip, dest) -> msg + "This-change-before-rebase: " + orig.name() + "\n";
    ChangeMessageModifier modifier2 = (msg, orig, tip, dest) -> msg + "Previous-step-tip: " + tip.name() + "\n";
    ChangeMessageModifier modifier3 = (msg, orig, tip, dest) -> msg + "Dest: " + dest.shortName() + "\n";
    try (Registration registration = extensionRegistry.newRegistration().add(modifier1).add(modifier2).add(modifier3)) {
        ImmutableList<PushOneCommit.Result> changes = submitWithRebase(admin);
        ChangeData cd1 = changes.get(0).getChange();
        ChangeData cd2 = changes.get(1).getChange();
        assertThat(cd2.patchSets()).hasSize(2);
        String change1CurrentCommit = cd1.currentPatchSet().commitId().name();
        String change2Ps1Commit = cd2.patchSet(PatchSet.id(cd2.getId(), 1)).commitId().name();
        assertThat(gApi.changes().id(cd2.getId().get()).revision(2).commit(false).message).isEqualTo("Change 2\n\n" + ("Change-Id: " + cd2.change().getKey() + "\n") + ("Reviewed-on: " + urlFormatter.get().getChangeViewUrl(project, cd2.getId()).get() + "\n") + "Reviewed-by: Administrator <admin@example.com>\n" + ("This-change-before-rebase: " + change2Ps1Commit + "\n") + ("Previous-step-tip: " + change1CurrentCommit + "\n") + "Dest: master\n");
    }
}
Also used : Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DynamicItem(com.google.gerrit.extensions.registration.DynamicItem) Inject(com.google.inject.Inject) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ImmutableList(com.google.common.collect.ImmutableList) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PatchSet(com.google.gerrit.entities.PatchSet) UrlFormatter(com.google.gerrit.server.config.UrlFormatter) Comparator.comparing(java.util.Comparator.comparing) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SubmitType(com.google.gerrit.extensions.client.SubmitType) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) NameKey(com.google.gerrit.entities.Project.NameKey) ChangeData(com.google.gerrit.server.query.change.ChangeData) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) FooterConstants(com.google.gerrit.common.FooterConstants) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeData(com.google.gerrit.server.query.change.ChangeData) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) Test(org.junit.Test)

Example 13 with Registration

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

the class SubmitByRebaseAlwaysIT method failingChangeMessageModifierShortCircuits.

@Test
public void failingChangeMessageModifierShortCircuits() throws Throwable {
    ChangeMessageModifier modifier1 = (msg, orig, tip, dest) -> {
        throw new IllegalStateException("boom");
    };
    ChangeMessageModifier modifier2 = (msg, orig, tip, dest) -> msg + "A-footer: value\n";
    try (Registration registration = extensionRegistry.newRegistration().add(modifier1).add(modifier2)) {
        MergeUpdateException thrown = assertThrows(MergeUpdateException.class, () -> submitWithRebase());
        Throwable cause = Throwables.getRootCause(thrown);
        assertThat(cause).isInstanceOf(RuntimeException.class);
        assertThat(cause).hasMessageThat().isEqualTo("boom");
    }
}
Also used : Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DynamicItem(com.google.gerrit.extensions.registration.DynamicItem) Inject(com.google.inject.Inject) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ImmutableList(com.google.common.collect.ImmutableList) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PatchSet(com.google.gerrit.entities.PatchSet) UrlFormatter(com.google.gerrit.server.config.UrlFormatter) Comparator.comparing(java.util.Comparator.comparing) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SubmitType(com.google.gerrit.extensions.client.SubmitType) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) NameKey(com.google.gerrit.entities.Project.NameKey) ChangeData(com.google.gerrit.server.query.change.ChangeData) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) FooterConstants(com.google.gerrit.common.FooterConstants) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) Test(org.junit.Test)

Example 14 with Registration

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

the class AbstractPushForReview method pushForMasterWithTopic.

@Test
public void pushForMasterWithTopic() throws Exception {
    TopicValidator topicValidator = new TopicValidator();
    try (Registration registration = extensionRegistry.newRegistration().add(topicValidator)) {
        String topic = "my/topic";
        // specify topic as option
        PushOneCommit.Result r = pushTo("refs/for/master%topic=" + topic);
        r.assertOkStatus();
        r.assertChange(Change.Status.NEW, topic);
        assertThat(topicValidator.count()).isEqualTo(1);
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with Registration

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

the class RevisionIT method cherryPickWithValidationOptions.

@Test
public void cherryPickWithValidationOptions() throws Exception {
    PushOneCommit.Result r = createChange();
    CherryPickInput in = new CherryPickInput();
    in.destination = "foo";
    in.message = "Cherry Pick";
    in.validationOptions = ImmutableMap.of("key", "value");
    gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
    TestCommitValidationListener testCommitValidationListener = new TestCommitValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(testCommitValidationListener)) {
        gApi.changes().id(r.getChangeId()).current().cherryPickAsInfo(in);
        assertThat(testCommitValidationListener.receiveEvent.pushOptions).containsExactly("key", "value");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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