Search in sources :

Example 26 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class RestApiServletIT method xGerritUpdatedRefSetForDifferentWriteRequests.

@Test
public void xGerritUpdatedRefSetForDifferentWriteRequests() throws Exception {
    Result change = createChange();
    String origin = adminRestSession.url();
    String project = change.getChange().project().get();
    String metaRef = RefNames.changeMetaRef(change.getChange().getId());
    ObjectId originalMetaRefSha1 = getMetaRefSha1(change);
    RestResponse response = adminRestSession.putWithHeaders("/changes/" + change.getChangeId() + "/topic", /* content= */
    "A", new BasicHeader(ORIGIN, origin), X_GERRIT_UPDATED_REF_ENABLED_HEADER);
    response.assertOK();
    assertThat(gApi.changes().id(change.getChangeId()).topic()).isEqualTo("A");
    ObjectId firstMetaRefSha1 = getMetaRefSha1(change);
    // Meta ref updated because of topic update.
    assertThat(response.getHeader(X_GERRIT_UPDATED_REF)).isEqualTo(String.format("%s~%s~%s~%s", Url.encode(project), Url.encode(metaRef), originalMetaRefSha1.getName(), firstMetaRefSha1.getName()));
    response = adminRestSession.putWithHeaders("/changes/" + change.getChangeId() + "/topic", /* content= */
    "B", new BasicHeader(ORIGIN, origin), X_GERRIT_UPDATED_REF_ENABLED_HEADER);
    response.assertOK();
    assertThat(gApi.changes().id(change.getChangeId()).topic()).isEqualTo("B");
    ObjectId secondMetaRefSha1 = getMetaRefSha1(change);
    // Meta ref updated again because of another topic update.
    assertThat(response.getHeader(X_GERRIT_UPDATED_REF)).isEqualTo(String.format("%s~%s~%s~%s", Url.encode(project), Url.encode(metaRef), firstMetaRefSha1.getName(), secondMetaRefSha1.getName()));
    // Ensure the meta ref SHA-1 changed for the project~metaRef which means we return different
    // X-Gerrit-UpdatedRef headers.
    assertThat(secondMetaRefSha1).isNotEqualTo(firstMetaRefSha1);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RestResponse(com.google.gerrit.acceptance.RestResponse) BasicHeader(org.apache.http.message.BasicHeader) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 27 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class RestApiServletIT method xGerritUpdatedRefSetMultipleHeadersForSubmitTopic.

@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void xGerritUpdatedRefSetMultipleHeadersForSubmitTopic() throws Exception {
    String secondProject = "secondProject";
    projectOperations.newProject().name(secondProject).create();
    TestRepository<InMemoryRepository> secondRepo = cloneProject(Project.nameKey("secondProject"), admin);
    String topic = "topic";
    String branch = "refs/heads/master";
    Result change1 = createChange(testRepo, branch, "first change", "a.txt", "message", topic);
    Result change2 = createChange(secondRepo, branch, "second change", "b.txt", "message", topic);
    String metaRef1 = RefNames.changeMetaRef(change1.getChange().getId());
    String metaRef2 = RefNames.changeMetaRef(change2.getChange().getId());
    gApi.changes().id(change1.getChangeId()).current().review(ReviewInput.approve());
    gApi.changes().id(change2.getChangeId()).current().review(ReviewInput.approve());
    Project.NameKey project1 = change1.getChange().project();
    Project.NameKey project2 = change2.getChange().project();
    try (Repository repository1 = repoManager.openRepository(project1);
        Repository repository2 = repoManager.openRepository(project2)) {
        ObjectId originalFirstMetaRefSha1 = getMetaRefSha1(change1);
        ObjectId originalSecondMetaRefSha1 = getMetaRefSha1(change2);
        ObjectId originalDestinationBranchSha1Project1 = repository1.resolve(change1.getChange().change().getDest().branch());
        ObjectId originalDestinationBranchSha1Project2 = repository2.resolve(change2.getChange().change().getDest().branch());
        RestResponse response = adminRestSession.postWithHeaders("/changes/" + change2.getChangeId() + "/submit", /* content = */
        null, X_GERRIT_UPDATED_REF_ENABLED_HEADER);
        response.assertOK();
        assertThat(gApi.changes().id(change1.getChangeId()).get().status).isEqualTo(ChangeStatus.MERGED);
        ObjectId firstMetaRefSha1 = getMetaRefSha1(change1);
        ObjectId secondMetaRefSha1 = getMetaRefSha1(change2);
        List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
        String branchSha1Project1 = repository1.getRefDatabase().exactRef(change1.getChange().change().getDest().branch()).getObjectId().name();
        String branchSha1Project2 = repository2.getRefDatabase().exactRef(change2.getChange().change().getDest().branch()).getObjectId().name();
        // During submit, all relevant meta refs of the latest patchset are updated + the destination
        // branch/es.
        // TODO(paiking): This doesn't work well for torn submissions: If the changes are in
        // different projects in the same topic, and we tried to submit those changes together, it's
        // possible that the first submission only submitted one of the changes, and then the retry
        // submitted the other change. If that happens, when the user retries, they will not get the
        // meta ref updates for the change that got submitted on the previous submission attempt.
        // Ideally, submit should be idempotent and always return all meta refs on all submission
        // attempts.
        assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(metaRef1), originalFirstMetaRefSha1.getName(), firstMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(metaRef2), originalSecondMetaRefSha1.getName(), secondMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(branch), originalDestinationBranchSha1Project1.getName(), branchSha1Project1), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(branch), originalDestinationBranchSha1Project2.getName(), branchSha1Project2));
    }
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ObjectId(org.eclipse.jgit.lib.ObjectId) RestResponse(com.google.gerrit.acceptance.RestResponse) Result(com.google.gerrit.acceptance.PushOneCommit.Result) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 28 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class AbandonRestoreIT method withMessage.

@Test
public void withMessage() throws Exception {
    Result result = createChange();
    String commit = result.getCommit().name();
    executeCmd(commit, "abandon", "'abandon it'");
    executeCmd(commit, "restore", "'restore it'");
    assertChangeMessages(result.getChangeId(), ImmutableList.of("Uploaded patch set 1.", "Abandoned\n\nabandon it", "Restored\n\nrestore it"));
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 29 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class AbandonRestoreIT method withoutMessage.

@Test
public void withoutMessage() throws Exception {
    Result result = createChange();
    String commit = result.getCommit().name();
    executeCmd(commit, "abandon", null);
    executeCmd(commit, "restore", null);
    assertChangeMessages(result.getChangeId(), ImmutableList.of("Uploaded patch set 1.", "Abandoned", "Restored"));
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 30 with Result

use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.

the class CommitIT method includedInMergedChange_filtersOutNonVisibleBranches.

@Test
public void includedInMergedChange_filtersOutNonVisibleBranches() throws Exception {
    Result baseChange = createAndSubmitChange("refs/for/master");
    createBranch(BranchNameKey.create(project, "test-branch-1"));
    createBranch(BranchNameKey.create(project, "test-branch-2"));
    createAndSubmitChange("refs/for/test-branch-1");
    createAndSubmitChange("refs/for/test-branch-2");
    assertThat(getIncludedIn(baseChange.getCommit().getId()).branches).containsExactly("master", "test-branch-1", "test-branch-2");
    projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/heads/test-branch-1").group(REGISTERED_USERS)).update();
    assertThat(getIncludedIn(baseChange.getCommit().getId()).branches).containsExactly("master", "test-branch-2");
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Result (com.google.gerrit.acceptance.PushOneCommit.Result)75 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)59 Test (org.junit.Test)59 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)28 RestResponse (com.google.gerrit.acceptance.RestResponse)17 ObjectId (org.eclipse.jgit.lib.ObjectId)11 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)9 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)8 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)7 BasicHeader (org.apache.http.message.BasicHeader)7 Request (org.apache.http.client.fluent.Request)6 FileInfo (com.google.gerrit.extensions.common.FileInfo)5 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)4 TagInput (com.google.gerrit.extensions.api.projects.TagInput)4 Project (com.google.gerrit.entities.Project)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)3 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)3 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Before (org.junit.Before)3