use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method createWithMergeConflictAuthorAddedAsCcNotNotifiedWithNotifyNone.
@Test
public void createWithMergeConflictAuthorAddedAsCcNotNotifiedWithNotifyNone() throws Exception {
String fileName = "shared.txt";
String sourceBranch = "sourceBranch";
String sourceSubject = "source change";
String sourceContent = "source content";
String targetBranch = "targetBranch";
String targetSubject = "target change";
String targetContent = "target content";
changeInTwoBranches(sourceBranch, sourceSubject, fileName, sourceContent, targetBranch, targetSubject, fileName, targetContent);
ChangeInput input = newMergeChangeInput(targetBranch, sourceBranch, "", true);
input.workInProgress = true;
input.author = new AccountInput();
input.author.email = user.email();
input.author.name = user.fullName();
input.notify = NotifyHandling.NONE;
ChangeInfo info = assertCreateSucceeds(input);
assertThat(info.reviewers.get(ReviewerState.CC)).hasSize(1);
assertThat(Iterables.getOnlyElement(info.reviewers.get(ReviewerState.CC)).email).isEqualTo(user.email());
assertThat(sender.getMessages()).isEmpty();
}
use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method createEmptyChange_NonExistingBranch.
@Test
public void createEmptyChange_NonExistingBranch() throws Exception {
ChangeInput ci = newChangeInput(ChangeStatus.NEW);
ci.branch = "non-existing";
assertCreateFails(ci, BadRequestException.class, "Destination branch does not exist");
}
use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method createMergeChange_ConflictsAllowed.
@Test
public void createMergeChange_ConflictsAllowed() throws Exception {
String fileName = "shared.txt";
String sourceBranch = "sourceBranch";
String sourceSubject = "source change";
String sourceContent = "source content";
String targetBranch = "targetBranch";
String targetSubject = "target change";
String targetContent = "target content";
changeInTwoBranches(sourceBranch, sourceSubject, fileName, sourceContent, targetBranch, targetSubject, fileName, targetContent);
ChangeInput in = newMergeChangeInput(targetBranch, sourceBranch, "", true);
ChangeInfo change = assertCreateSucceedsWithConflicts(in);
// Verify that the file content in the created change is correct.
// We expect that it has conflict markers to indicate the conflict.
BinaryResult bin = gApi.changes().id(change._number).current().file(fileName).content();
ByteArrayOutputStream os = new ByteArrayOutputStream();
bin.writeTo(os);
String fileContent = new String(os.toByteArray(), UTF_8);
String sourceSha1 = abbreviateName(projectOperations.project(project).getHead(sourceBranch), 6);
String targetSha1 = abbreviateName(projectOperations.project(project).getHead(targetBranch), 6);
assertThat(fileContent).isEqualTo("<<<<<<< TARGET BRANCH (" + targetSha1 + " " + targetSubject + ")\n" + targetContent + "\n" + "=======\n" + sourceContent + "\n" + ">>>>>>> SOURCE BRANCH (" + sourceSha1 + " " + sourceSubject + ")\n");
// Verify the message that has been posted on the change.
List<ChangeMessageInfo> messages = gApi.changes().id(change._number).messages();
assertThat(messages).hasSize(1);
assertThat(Iterables.getOnlyElement(messages).message).isEqualTo("Uploaded patch set 1.\n\n" + "The following files contain Git conflicts:\n" + "* " + fileName + "\n");
}
use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method createChangeWithSourceBranch.
@Test
public void createChangeWithSourceBranch() throws Exception {
changeInTwoBranches("branchA", "a.txt", "branchB", "b.txt");
// create a merge change from branchA to master in gerrit
ChangeInput in = new ChangeInput();
in.project = project.get();
in.branch = "branchA";
in.subject = "message";
in.status = ChangeStatus.NEW;
MergeInput mergeInput = new MergeInput();
String mergeRev = gApi.projects().name(project.get()).branch("branchB").get().revision;
mergeInput.source = mergeRev;
in.merge = mergeInput;
assertCreateSucceeds(in);
// Succeeds with a visible branch
in.merge.sourceBranch = "refs/heads/branchB";
gApi.changes().create(in);
// Make it invisible
projectOperations.project(project).forUpdate().add(block(READ).ref(in.merge.sourceBranch).group(REGISTERED_USERS)).update();
// Now it fails.
assertThrows(BadRequestException.class, () -> gApi.changes().create(in));
}
use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method createAuthorPermission.
@Test
public void createAuthorPermission() throws Exception {
ChangeInput input = newChangeInput(ChangeStatus.NEW);
input.author = new AccountInput();
input.author.name = "Jane";
input.author.email = "jane@invalid";
projectOperations.project(project).forUpdate().add(block(Permission.FORGE_AUTHOR).ref("refs/*").group(REGISTERED_USERS)).update();
assertCreateFails(input, AuthException.class, "forge author");
}
Aggregations