Search in sources :

Example 16 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, "topic", "touching b", "b.txt", "real content").getChangeId();
    int changeNum2 = gApi.changes().id(changeId2).info()._number;
    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): " + changeNum2);
    } else {
        noSubmitWholeTopicAssertions(actions, 1);
    }
}
Also used : ActionInfo(com.google.gerrit.extensions.common.ActionInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 17 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);
    PushOneCommit.Result change2 = createChangeWithTopic();
    int legacyId2 = change2.getChange().getId().get();
    String changeId2 = change2.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).matches("Change " + legacyId2 + " is not ready: submit requirement 'Code-Review' is unsatisfied.");
    } 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) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 18 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(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()).containsAtLeast("followup", "abandon");
    assertThat(origActions.get("abandon").label).isEqualTo("Abandon");
    try (Registration registration = extensionRegistry.newRegistration().add(new Visitor())) {
        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) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) 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)

Aggregations

ActionInfo (com.google.gerrit.extensions.common.ActionInfo)18 Test (org.junit.Test)10 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 ActionVisitor (com.google.gerrit.extensions.api.changes.ActionVisitor)6 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 UiAction (com.google.gerrit.extensions.webui.UiAction)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)4 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)3 TreeSet (java.util.TreeSet)3 BranchInfo (com.google.gerrit.extensions.api.projects.BranchInfo)2 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)2 WebLinkInfo (com.google.gerrit.extensions.common.WebLinkInfo)2 PrivateInternals_UiActionDescription (com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 LinkedHashMap (java.util.LinkedHashMap)2 BooleanProjectConfig (com.google.gerrit.entities.BooleanProjectConfig)1 Change (com.google.gerrit.entities.Change)1 Project (com.google.gerrit.entities.Project)1 CommentLinkInfo (com.google.gerrit.extensions.api.projects.CommentLinkInfo)1