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");
}
}
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);
}
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");
}
}
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);
}
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");
}
Aggregations