Search in sources :

Example 81 with ChangeInput

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);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ExecutorService(java.util.concurrent.ExecutorService) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) CyclicBarrier(java.util.concurrent.CyclicBarrier) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseSystemTime(com.google.gerrit.acceptance.UseSystemTime)

Example 82 with ChangeInput

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);
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) MergeInput(com.google.gerrit.extensions.common.MergeInput) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 83 with ChangeInput

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());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) GitPerson(com.google.gerrit.extensions.common.GitPerson) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AccountInput(com.google.gerrit.extensions.api.accounts.AccountInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 84 with ChangeInput

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");
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 85 with ChangeInput

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();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ChangeInput (com.google.gerrit.extensions.common.ChangeInput)107 Test (org.junit.Test)94 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)89 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)30 Project (com.google.gerrit.entities.Project)10 Result (com.google.gerrit.acceptance.PushOneCommit.Result)7 AccountInput (com.google.gerrit.extensions.api.accounts.AccountInput)7 MergeInput (com.google.gerrit.extensions.common.MergeInput)6 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)6 Change (com.google.gerrit.entities.Change)5 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 StandaloneSiteTest (com.google.gerrit.acceptance.StandaloneSiteTest)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)3 GitPerson (com.google.gerrit.extensions.common.GitPerson)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)2 UseSystemTime (com.google.gerrit.acceptance.UseSystemTime)2 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)2