Search in sources :

Example 11 with RestResponse

use of com.google.gerrit.acceptance.RestResponse in project gerrit by GerritCodeReview.

the class ChangeEditIT method files.

@Test
public void files() throws Exception {
    createEmptyEditFor(changeId);
    gApi.changes().id(changeId).edit().modifyFile(FILE_NAME, RawInputUtil.create(CONTENT_NEW));
    Optional<EditInfo> edit = getEdit(changeId);
    assertThat(edit).isPresent();
    String editCommitId = edit.get().commit.commit;
    RestResponse r = adminRestSession.getJsonAccept(urlRevisionFiles(changeId, editCommitId));
    Map<String, FileInfo> files = readContentFromJson(r, new TypeToken<Map<String, FileInfo>>() {
    });
    assertThat(files).containsKey(FILE_NAME);
    r = adminRestSession.getJsonAccept(urlRevisionFiles(changeId));
    files = readContentFromJson(r, new TypeToken<Map<String, FileInfo>>() {
    });
    assertThat(files).containsKey(FILE_NAME);
}
Also used : FileInfo(com.google.gerrit.extensions.common.FileInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) EditInfo(com.google.gerrit.extensions.common.EditInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with RestResponse

use of com.google.gerrit.acceptance.RestResponse in project gerrit by GerritCodeReview.

the class ChangeEditIT method updateMessageRest.

@Test
public void updateMessageRest() throws Exception {
    adminRestSession.get(urlEditMessage(changeId, false)).assertNotFound();
    EditMessage.Input in = new EditMessage.Input();
    in.message = String.format("New commit message\n\n" + CONTENT_NEW2_STR + "\n\nChange-Id: %s\n", changeId);
    adminRestSession.put(urlEditMessage(changeId, false), in).assertNoContent();
    RestResponse r = adminRestSession.getJsonAccept(urlEditMessage(changeId, false));
    r.assertOK();
    assertThat(readContentFromJson(r)).isEqualTo(in.message);
    String commitMessage = gApi.changes().id(changeId).edit().getCommitMessage();
    assertThat(commitMessage).isEqualTo(in.message);
    in.message = String.format("New commit message2\n\nChange-Id: %s\n", changeId);
    adminRestSession.put(urlEditMessage(changeId, false), in).assertNoContent();
    String updatedCommitMessage = gApi.changes().id(changeId).edit().getCommitMessage();
    assertThat(updatedCommitMessage).isEqualTo(in.message);
    r = adminRestSession.getJsonAccept(urlEditMessage(changeId, true));
    try (Repository repo = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(repo)) {
        RevCommit commit = rw.parseCommit(ObjectId.fromString(ps.getRevision().get()));
        assertThat(readContentFromJson(r)).isEqualTo(commit.getFullMessage());
    }
    PublishChangeEditInput publishInput = new PublishChangeEditInput();
    publishInput.notify = NotifyHandling.NONE;
    gApi.changes().id(changeId).edit().publish(publishInput);
    assertChangeMessages(changeId, ImmutableList.of("Uploaded patch set 1.", "Uploaded patch set 2.", "Patch Set 3: Commit message was updated."));
}
Also used : AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) RestResponse(com.google.gerrit.acceptance.RestResponse) EditMessage(com.google.gerrit.server.change.ChangeEdits.EditMessage) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with RestResponse

use of com.google.gerrit.acceptance.RestResponse in project gerrit by GerritCodeReview.

the class BanCommitIT method banCommit.

@Test
public void banCommit() throws Exception {
    RevCommit c = commitBuilder().add("a.txt", "some content").create();
    RestResponse r = adminRestSession.put("/projects/" + project.get() + "/ban/", BanCommit.Input.fromCommits(c.name()));
    r.assertOK();
    BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
    assertThat(Iterables.getOnlyElement(info.newlyBanned)).isEqualTo(c.name());
    assertThat(info.alreadyBanned).isNull();
    assertThat(info.ignored).isNull();
    RemoteRefUpdate u = pushHead(testRepo, "refs/heads/master", false).getRemoteUpdate("refs/heads/master");
    assertThat(u).isNotNull();
    assertThat(u.getStatus()).isEqualTo(REJECTED_OTHER_REASON);
    assertThat(u.getMessage()).startsWith("contains banned commit");
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) RestResponse(com.google.gerrit.acceptance.RestResponse) BanResultInfo(com.google.gerrit.server.project.BanCommit.BanResultInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with RestResponse

use of com.google.gerrit.acceptance.RestResponse in project gerrit by GerritCodeReview.

the class CheckMergeabilityIT method assertBadRequest.

private void assertBadRequest(String targetBranch, String source, String strategy, String errMsg) throws Exception {
    String url = "/projects/" + project.get() + "/branches/" + targetBranch;
    url += "/mergeable?source=" + source;
    if (!Strings.isNullOrEmpty(strategy)) {
        url += "&strategy=" + strategy;
    }
    RestResponse r = userRestSession.get(url);
    r.assertBadRequest();
    assertThat(r.getEntityContent()).isEqualTo(errMsg);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse)

Example 15 with RestResponse

use of com.google.gerrit.acceptance.RestResponse in project gerrit by GerritCodeReview.

the class CacheOperationsIT method flush_UnprocessableEntity.

@Test
public void flush_UnprocessableEntity() throws Exception {
    RestResponse r = adminRestSession.getOK("/config/server/caches/projects");
    CacheInfo cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(cacheInfo.entries.mem).isGreaterThan((long) 0);
    r = adminRestSession.post("/config/server/caches/", new PostCaches.Input(FLUSH, Arrays.asList("projects", "unprocessable")));
    r.assertUnprocessableEntity();
    r.consume();
    r = adminRestSession.getOK("/config/server/caches/projects");
    cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(cacheInfo.entries.mem).isGreaterThan((long) 0);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) CacheInfo(com.google.gerrit.server.config.ListCaches.CacheInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

RestResponse (com.google.gerrit.acceptance.RestResponse)79 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)67 Test (org.junit.Test)67 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)17 TypeToken (com.google.gson.reflect.TypeToken)15 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)9 CacheInfo (com.google.gerrit.server.config.ListCaches.CacheInfo)6 TaskInfo (com.google.gerrit.server.config.ListTasks.TaskInfo)6 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)5 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 Result (com.google.gerrit.acceptance.PushOneCommit.Result)4 AccountExternalIdInfo (com.google.gerrit.extensions.common.AccountExternalIdInfo)4 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)4 ArrayList (java.util.ArrayList)4 ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)2 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)2 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)2 PublishChangeEditInput (com.google.gerrit.extensions.api.changes.PublishChangeEditInput)2