use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method sha1sOfTwoNewChangesDifferIfCreatedConcurrently.
@Test
@UseSystemTime
public void sha1sOfTwoNewChangesDifferIfCreatedConcurrently() throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(2);
try {
for (int i = 0; i < 10; i++) {
ChangeInput changeInput = newChangeInput(ChangeStatus.NEW);
CyclicBarrier sync = new CyclicBarrier(2);
Callable<ChangeInfo> createChange = () -> {
requestScopeOperations.setApiUser(admin.id());
sync.await();
return assertCreateSucceeds(changeInput);
};
Future<ChangeInfo> changeInfo1 = executor.submit(createChange);
Future<ChangeInfo> changeInfo2 = executor.submit(createChange);
assertThat(changeInfo1.get().currentRevision).isNotEqualTo(changeInfo2.get().currentRevision);
}
} finally {
executor.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
}
}
use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method createChangeWithSubmittedMergeSource.
@Test
public void createChangeWithSubmittedMergeSource() throws Exception {
// Provide coverage for a performance optimization in CommitsCollection#canRead.
BranchInput branchInput = new BranchInput();
String mergeTarget = "refs/heads/new-branch";
RevCommit startCommit = projectOperations.project(project).getHead("master");
branchInput.revision = startCommit.name();
branchInput.ref = mergeTarget;
gApi.projects().name(project.get()).branch(mergeTarget).create(branchInput);
// To create a merge commit, create two changes from the same parent,
// and submit them one after the other.
PushOneCommit.Result result1 = pushFactory.create(admin.newIdent(), testRepo, "subject1", ImmutableMap.of("file1.txt", "content 1")).to("refs/for/master");
result1.assertOkStatus();
testRepo.branch("HEAD").update(startCommit);
PushOneCommit.Result result2 = pushFactory.create(admin.newIdent(), testRepo, "subject2", ImmutableMap.of("file2.txt", "content 2")).to("refs/for/master");
result2.assertOkStatus();
ReviewInput reviewInput = ReviewInput.approve().label("Code-Review", 2);
gApi.changes().id(result1.getChangeId()).revision("current").review(reviewInput);
gApi.changes().id(result1.getChangeId()).revision("current").submit();
gApi.changes().id(result2.getChangeId()).revision("current").review(reviewInput);
gApi.changes().id(result2.getChangeId()).revision("current").submit();
String mergeRev = gApi.projects().name(project.get()).branch("master").get().revision;
RevCommit mergeCommit = projectOperations.project(project).getHead("master");
assertThat(mergeCommit.getParents().length).isEqualTo(2);
testRepo.git().fetch().call();
testRepo.branch("HEAD").update(mergeCommit);
PushOneCommit.Result result3 = pushFactory.create(admin.newIdent(), testRepo, "subject3", ImmutableMap.of("file1.txt", "content 3")).to("refs/for/master");
result2.assertOkStatus();
gApi.changes().id(result3.getChangeId()).revision("current").review(reviewInput);
gApi.changes().id(result3.getChangeId()).revision("current").submit();
// Now master doesn't point directly to mergeRev
ChangeInput in = new ChangeInput();
in.branch = mergeTarget;
in.merge = new MergeInput();
in.project = project.get();
in.merge.source = mergeRev;
in.subject = "propagate merge";
gApi.changes().create(in);
}
use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method createMergeChangeAuthor.
@Test
public void createMergeChangeAuthor() throws Exception {
changeInTwoBranches("branchA", "a.txt", "branchB", "b.txt");
ChangeInput in = newMergeChangeInput("branchA", "branchB", "");
in.author = new AccountInput();
in.author.name = "Gerritless Jane";
in.author.email = "gerritlessjane@invalid";
ChangeInfo change = assertCreateSucceeds(in);
RevisionApi rApi = gApi.changes().id(change.id).current();
GitPerson author = rApi.commit(false).author;
assertThat(author).email().isEqualTo(in.author.email);
GitPerson committer = rApi.commit(false).committer;
assertThat(committer).email().isEqualTo(admin.getNameEmail().email());
}
use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class PrivateByDefaultIT method createChangeWithPrivateByDefaultAndDisablePrivateChangesTrue.
@Test
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
public void createChangeWithPrivateByDefaultAndDisablePrivateChangesTrue() throws Exception {
setPrivateByDefault(project2, InheritableBoolean.TRUE);
ChangeInput input = new ChangeInput(project2.get(), "master", "empty change");
MethodNotAllowedException thrown = assertThrows(MethodNotAllowedException.class, () -> gApi.changes().create(input));
assertThat(thrown).hasMessageThat().contains("private changes are disabled");
}
use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.
the class PrivateByDefaultIT method createChangeWithPrivateByDefaultDisabled.
@Test
public void createChangeWithPrivateByDefaultDisabled() throws Exception {
ChangeInfo info = gApi.changes().create(new ChangeInput(project2.get(), "master", "empty change")).get();
assertThat(info.isPrivate).isNull();
}
Aggregations