Search in sources :

Example 61 with Result

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

the class FilesInCommitIT method addCommit.

private ObjectId addCommit(ObjectId parentCommit, ImmutableMap<String, String> files) throws Exception {
    testRepo.reset(parentCommit);
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "Adjust files of repo", files);
    PushOneCommit.Result result = push.to("refs/for/master");
    return result.getCommit();
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 62 with Result

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

the class RestApiServletIT method xGerritUpdatedRefSetMultipleHeadersForSubmit.

@Test
public void xGerritUpdatedRefSetMultipleHeadersForSubmit() throws Exception {
    Result change1 = createChange();
    Result change2 = createChange();
    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 project = change1.getChange().project();
    try (Repository repository = repoManager.openRepository(project)) {
        ObjectId originalFirstMetaRefSha1 = getMetaRefSha1(change1);
        ObjectId originalSecondMetaRefSha1 = getMetaRefSha1(change2);
        ObjectId originalDestinationBranchSha1 = repository.resolve(change1.getChange().change().getDest().branch());
        RestResponse response = adminRestSession.postWithHeaders("/changes/" + change2.getChangeId() + "/submit", /* content = */
        null, X_GERRIT_UPDATED_REF_ENABLED_HEADER);
        response.assertOK();
        ObjectId firstMetaRefSha1 = getMetaRefSha1(change1);
        ObjectId secondMetaRefSha1 = getMetaRefSha1(change2);
        List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
        String branch = change1.getChange().change().getDest().branch();
        String branchSha1 = repository.getRefDatabase().exactRef(change1.getChange().change().getDest().branch()).getObjectId().name();
        // During submit, all relevant meta refs of the latest patchset are updated + the destination
        // branch/es.
        assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(metaRef1), originalFirstMetaRefSha1.getName(), firstMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(metaRef2), originalSecondMetaRefSha1.getName(), secondMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(branch), originalDestinationBranchSha1.getName(), branchSha1));
    }
}
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) ObjectId(org.eclipse.jgit.lib.ObjectId) RestResponse(com.google.gerrit.acceptance.RestResponse) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 63 with Result

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

the class RestApiServletIT method xGerritUpdatedRefDeleted.

@Test
public void xGerritUpdatedRefDeleted() throws Exception {
    Result change = createChange();
    String project = change.getChange().project().get();
    String metaRef = RefNames.changeMetaRef(change.getChange().getId());
    String patchSetRef = RefNames.patchSetRef(change.getPatchSetId());
    ObjectId originalMetaRefSha1 = getMetaRefSha1(change);
    ObjectId originalchangeRefSha1 = change.getCommit().getId();
    RestResponse response = adminRestSession.deleteWithHeaders("/changes/" + change.getChangeId(), X_GERRIT_UPDATED_REF_ENABLED_HEADER);
    response.assertNoContent();
    List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
    // The change was deleted, so the refs were deleted which means they are ObjectId.zeroId().
    assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project), Url.encode(metaRef), originalMetaRefSha1.getName(), ObjectId.zeroId().getName()), String.format("%s~%s~%s~%s", Url.encode(project), Url.encode(patchSetRef), originalchangeRefSha1.getName(), ObjectId.zeroId().getName()));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RestResponse(com.google.gerrit.acceptance.RestResponse) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 64 with Result

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

the class RestApiServletIT method xGerritUpdatedRefWithProjectNameContainingTilde.

@Test
public void xGerritUpdatedRefWithProjectNameContainingTilde() throws Exception {
    Project.NameKey project = createProjectOverAPI("~~pr~oje~ct~~~~", null, true, null);
    Result change = createChange(cloneProject(project, admin));
    String metaRef = RefNames.changeMetaRef(change.getChange().getId());
    String patchSetRef = RefNames.patchSetRef(change.getPatchSetId());
    ObjectId originalMetaRefSha1 = getMetaRefSha1(change);
    ObjectId originalchangeRefSha1 = change.getCommit().getId();
    RestResponse response = adminRestSession.deleteWithHeaders("/changes/" + change.getChangeId(), X_GERRIT_UPDATED_REF_ENABLED_HEADER);
    response.assertNoContent();
    List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
    // The change was deleted, so the refs were deleted which means they are ObjectId.zeroId().
    assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(metaRef), originalMetaRefSha1.getName(), ObjectId.zeroId().getName()), String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(patchSetRef), originalchangeRefSha1.getName(), ObjectId.zeroId().getName()));
    // Ensures ~ gets encoded to %7E.
    assertThat(Url.encode(project.get())).endsWith("%7E%7Epr%7Eoje%7Ect%7E%7E%7E%7E");
}
Also used : Project(com.google.gerrit.entities.Project) ObjectId(org.eclipse.jgit.lib.ObjectId) RestResponse(com.google.gerrit.acceptance.RestResponse) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 65 with Result

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

the class CorsIT method originsOnForbidden.

@Test
public void originsOnForbidden() throws Exception {
    Result change = createChange();
    // Make change private to hide it
    gApi.changes().id(change.getChangeId()).setPrivate(true, "now private");
    String url = "/changes/" + change.getChangeId() + "/detail";
    check(url, true, "http://example.com", anonymousRestSession, 404);
    check(url, false, "http://friendsly", anonymousRestSession, 404);
}
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