Search in sources :

Example 6 with ActionInfo

use of com.google.gerrit.extensions.common.ActionInfo in project gerrit by GerritCodeReview.

the class ActionsIT method noSubmitWholeTopicAssertions.

private void noSubmitWholeTopicAssertions(Map<String, ActionInfo> actions, int nrChanges) {
    ActionInfo info = actions.get("submit");
    assertThat(info.enabled).isTrue();
    if (nrChanges == 1) {
        assertThat(info.label).isEqualTo("Submit");
    } else {
        assertThat(info.label).isEqualTo("Submit including parents");
    }
    assertThat(info.method).isEqualTo("POST");
    if (nrChanges == 1) {
        assertThat(info.title).isEqualTo("Submit patch set 1 into master");
    } else {
        assertThat(info.title).isEqualTo(String.format("Submit patch set 1 and ancestors (%d changes altogether) into master", nrChanges));
    }
}
Also used : ActionInfo(com.google.gerrit.extensions.common.ActionInfo)

Example 7 with ActionInfo

use of com.google.gerrit.extensions.common.ActionInfo in project gerrit by GerritCodeReview.

the class ActionsIT method changeActionVisitor.

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

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo) {
            assertThat(changeInfo).isNotNull();
            assertThat(changeInfo._number).isEqualTo(origChange._number);
            if (name.equals("followup")) {
                return false;
            }
            if (name.equals("abandon")) {
                actionInfo.label = "Abandon All Hope";
            }
            return true;
        }

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo, RevisionInfo revisionInfo) {
            throw new UnsupportedOperationException();
        }
    }
    Map<String, ActionInfo> origActions = origChange.actions;
    assertThat(origActions.keySet()).containsAllOf("followup", "abandon");
    assertThat(origActions.get("abandon").label).isEqualTo("Abandon");
    Visitor v = new Visitor();
    visitorHandle = actionVisitors.add(v);
    Map<String, ActionInfo> newActions = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.CHANGE_ACTIONS)).actions;
    Set<String> expectedNames = new TreeSet<>(origActions.keySet());
    expectedNames.remove("followup");
    assertThat(newActions.keySet()).isEqualTo(expectedNames);
    ActionInfo abandon = newActions.get("abandon");
    assertThat(abandon).isNotNull();
    assertThat(abandon.label).isEqualTo("Abandon All Hope");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) TreeSet(java.util.TreeSet) 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 8 with ActionInfo

use of com.google.gerrit.extensions.common.ActionInfo in project gerrit by GerritCodeReview.

the class ActionsIT method revisionActionsTwoChangesInTopic.

@Test
public void revisionActionsTwoChangesInTopic() throws Exception {
    String changeId = createChangeWithTopic().getChangeId();
    approve(changeId);
    String changeId2 = createChangeWithTopic().getChangeId();
    Map<String, ActionInfo> actions = getActions(changeId);
    commonActionsAssertions(actions);
    if (isSubmitWholeTopicEnabled()) {
        ActionInfo info = actions.get("submit");
        assertThat(info.enabled).isNull();
        assertThat(info.label).isEqualTo("Submit whole topic");
        assertThat(info.method).isEqualTo("POST");
        assertThat(info.title).isEqualTo("This change depends on other changes which are not ready");
    } else {
        noSubmitWholeTopicAssertions(actions, 1);
        assertThat(getActions(changeId2).get("submit")).isNull();
        approve(changeId2);
        noSubmitWholeTopicAssertions(getActions(changeId2), 2);
    }
}
Also used : ActionInfo(com.google.gerrit.extensions.common.ActionInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 9 with ActionInfo

use of com.google.gerrit.extensions.common.ActionInfo in project gerrit by GerritCodeReview.

the class ActionsIT method revisionActionsTwoChangesInTopic_conflicting.

@Test
public void revisionActionsTwoChangesInTopic_conflicting() throws Exception {
    String changeId = createChangeWithTopic().getChangeId();
    approve(changeId);
    // create another change with the same topic
    String changeId2 = createChangeWithTopic(testRepo, "foo2", "touching b", "b.txt", "real content").getChangeId();
    approve(changeId2);
    // collide with the other change in the same topic
    testRepo.reset("HEAD~2");
    String collidingChange = createChangeWithTopic(testRepo, "off_topic", "rewriting file b", "b.txt", "garbage\ngarbage\ngarbage").getChangeId();
    gApi.changes().id(collidingChange).current().review(ReviewInput.approve());
    gApi.changes().id(collidingChange).current().submit();
    Map<String, ActionInfo> actions = getActions(changeId);
    commonActionsAssertions(actions);
    if (isSubmitWholeTopicEnabled()) {
        ActionInfo info = actions.get("submit");
        assertThat(info.enabled).isNull();
        assertThat(info.label).isEqualTo("Submit whole topic");
        assertThat(info.method).isEqualTo("POST");
        assertThat(info.title).isEqualTo("Problems with change(s): 2");
    } else {
        noSubmitWholeTopicAssertions(actions, 1);
    }
}
Also used : ActionInfo(com.google.gerrit.extensions.common.ActionInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 10 with ActionInfo

use of com.google.gerrit.extensions.common.ActionInfo in project gerrit by GerritCodeReview.

the class ActionsIT method revisionActionVisitor.

@Test
public void revisionActionVisitor() throws Exception {
    String id = createChange().getChangeId();
    ChangeInfo origChange = gApi.changes().id(id).get(EnumSet.of(ListChangesOption.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("cherrypick")) {
                return false;
            }
            if (name.equals("rebase")) {
                actionInfo.label = "All Your Base";
            }
            return true;
        }
    }
    Map<String, ActionInfo> origActions = gApi.changes().id(id).current().actions();
    assertThat(origActions.keySet()).containsAllOf("cherrypick", "rebase");
    assertThat(origActions.get("rebase").label).isEqualTo("Rebase");
    Visitor v = new Visitor();
    visitorHandle = actionVisitors.add(v);
    // Test different codepaths within ActionJson...
    // ...via revision API.
    visitedRevisionActionsAssertions(origActions, gApi.changes().id(id).current().actions());
    // ...via change API with option.
    EnumSet<ListChangesOption> opts = EnumSet.of(CURRENT_ACTIONS, CURRENT_REVISION);
    ChangeInfo changeInfo = gApi.changes().id(id).get(opts);
    RevisionInfo revisionInfo = Iterables.getOnlyElement(changeInfo.revisions.values());
    visitedRevisionActionsAssertions(origActions, revisionInfo.actions);
    // ...via ChangeJson directly.
    ChangeData cd = changeDataFactory.create(db, project, new Change.Id(origChange._number));
    revisionInfo = changeJsonFactory.create(opts).getRevisionInfo(cd.changeControl(), Iterables.getOnlyElement(cd.patchSets()));
    visitedRevisionActionsAssertions(origActions, revisionInfo.actions);
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) Change(com.google.gerrit.reviewdb.client.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ActionInfo (com.google.gerrit.extensions.common.ActionInfo)10 Test (org.junit.Test)6 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)5 ActionVisitor (com.google.gerrit.extensions.api.changes.ActionVisitor)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)2 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)2 UiAction (com.google.gerrit.extensions.webui.UiAction)2 TreeSet (java.util.TreeSet)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 BranchInfo (com.google.gerrit.extensions.api.projects.BranchInfo)1 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)1 WebLinkInfo (com.google.gerrit.extensions.common.WebLinkInfo)1 PrivateInternals_UiActionDescription (com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription)1 Change (com.google.gerrit.reviewdb.client.Change)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1 LinkedHashMap (java.util.LinkedHashMap)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1