Search in sources :

Example 1 with TestProjectInput

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

the class AbstractPushForReview method pushInitialCommitForMasterBranch.

@Test
@TestProjectInput(createEmptyCommit = false)
public void pushInitialCommitForMasterBranch() throws Exception {
    RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
    String id = GitUtil.getChangeId(testRepo, c).get();
    testRepo.reset(c);
    String r = "refs/for/master";
    PushResult pr = pushHead(testRepo, r, false);
    assertPushOk(pr, r);
    ChangeInfo change = gApi.changes().id(id).info();
    assertThat(change.branch).isEqualTo("master");
    assertThat(change.status).isEqualTo(ChangeStatus.NEW);
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.resolve("master")).isNull();
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushResult(org.eclipse.jgit.transport.PushResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with TestProjectInput

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

the class ConfigChangeIT method onlyAdminMayUpdateProjectParent.

@Test
@TestProjectInput(cloneAs = "user")
public void onlyAdminMayUpdateProjectParent() throws Exception {
    setApiUser(admin);
    ProjectInput parent = new ProjectInput();
    parent.name = name("parent");
    parent.permissionsOnly = true;
    gApi.projects().create(parent);
    setApiUser(user);
    Config cfg = readProjectConfig();
    assertThat(cfg.getString("access", null, "inheritFrom")).isAnyOf(null, allProjects.get());
    cfg.setString("access", null, "inheritFrom", parent.name);
    PushOneCommit.Result r = createConfigChange(cfg);
    String id = r.getChangeId();
    gApi.changes().id(id).current().review(ReviewInput.approve());
    try {
        gApi.changes().id(id).current().submit();
        fail("expected submit to fail");
    } catch (ResourceConflictException e) {
        int n = gApi.changes().id(id).info()._number;
        assertThat(e).hasMessageThat().isEqualTo("Failed to submit 1 change due to the following problems:\n" + "Change " + n + ": Change contains a project configuration that" + " changes the parent project.\n" + "The change must be submitted by a Gerrit administrator.");
    }
    assertThat(gApi.projects().name(project.get()).get().parent).isEqualTo(allProjects.get());
    fetchRefsMetaConfig();
    assertThat(readProjectConfig().getString("access", null, "inheritFrom")).isAnyOf(null, allProjects.get());
    setApiUser(admin);
    gApi.changes().id(id).current().submit();
    assertThat(gApi.changes().id(id).info().status).isEqualTo(ChangeStatus.MERGED);
    assertThat(gApi.projects().name(project.get()).get().parent).isEqualTo(parent.name);
    fetchRefsMetaConfig();
    assertThat(readProjectConfig().getString("access", null, "inheritFrom")).isEqualTo(parent.name);
}
Also used : TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Config(org.eclipse.jgit.lib.Config) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with TestProjectInput

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

the class SubmittedTogetherIT method testCherryPickWithoutAncestors.

@Test
@TestProjectInput(submitType = SubmitType.CHERRY_PICK)
public void testCherryPickWithoutAncestors() throws Exception {
    // Create two commits and push.
    RevCommit c1_1 = commitBuilder().add("a.txt", "1").message("subject: 1").create();
    String id1 = getChangeId(c1_1);
    RevCommit c2_1 = commitBuilder().add("b.txt", "2").message("subject: 2").create();
    String id2 = getChangeId(c2_1);
    pushHead(testRepo, "refs/for/master", false);
    assertSubmittedTogether(id1);
    assertSubmittedTogether(id2);
}
Also used : RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with TestProjectInput

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

the class SubmitByRebaseIfNecessaryIT method submitWithFastForward.

@Test
@TestProjectInput(useContentMerge = InheritableBoolean.TRUE)
public void submitWithFastForward() throws Exception {
    RevCommit oldHead = getRemoteHead();
    PushOneCommit.Result change = createChange();
    submit(change.getChangeId());
    RevCommit head = getRemoteHead();
    assertThat(head.getId()).isEqualTo(change.getCommit());
    assertThat(head.getParent(0)).isEqualTo(oldHead);
    assertApproved(change.getChangeId());
    assertCurrentRevision(change.getChangeId(), 1, head);
    assertSubmitter(change.getChangeId(), 1);
    assertPersonEquals(admin.getIdent(), head.getAuthorIdent());
    assertPersonEquals(admin.getIdent(), head.getCommitterIdent());
    assertRefUpdatedEvents(oldHead, head);
    assertChangeMergedEvents(change.getChangeId(), head.name());
}
Also used : PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Test(org.junit.Test)

Example 5 with TestProjectInput

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

the class ChangeIT method deleteChangeAsUserWithDeleteOwnChangesPermission.

@Test
@TestProjectInput(cloneAs = "user")
public void deleteChangeAsUserWithDeleteOwnChangesPermission() throws Exception {
    allow(Permission.DELETE_OWN_CHANGES, REGISTERED_USERS, "refs/*");
    try {
        PushOneCommit.Result changeResult = pushFactory.create(db, user.getIdent(), testRepo).to("refs/for/master");
        String changeId = changeResult.getChangeId();
        int id = changeResult.getChange().getId().id;
        RevCommit commit = changeResult.getCommit();
        setApiUser(user);
        gApi.changes().id(changeId).delete();
        assertThat(query(changeId)).isEmpty();
        String ref = new Change.Id(id).toRefPrefix() + "1";
        eventRecorder.assertRefUpdatedEvents(project.get(), ref, null, commit, commit, null);
    } finally {
        removePermission(project, "refs/*", Permission.DELETE_OWN_CHANGES);
    }
}
Also used : LabelId(com.google.gerrit.reviewdb.client.LabelId) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)22 Test (org.junit.Test)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)7 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)4 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)2 PushResult (org.eclipse.jgit.transport.PushResult)2 SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)1 ProjectInput (com.google.gerrit.extensions.api.projects.ProjectInput)1 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)1 RegistrationHandle (com.google.gerrit.extensions.registration.RegistrationHandle)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 Branch (com.google.gerrit.reviewdb.client.Branch)1 Change (com.google.gerrit.reviewdb.client.Change)1 LabelId (com.google.gerrit.reviewdb.client.LabelId)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 TestSubmitInput (com.google.gerrit.server.change.Submit.TestSubmitInput)1 ChangeMessageModifier (com.google.gerrit.server.git.ChangeMessageModifier)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1