Search in sources :

Example 71 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class AbstractSubmitByRebase method submitChangesAfterBranchOnSecond.

@Test
public void submitChangesAfterBranchOnSecond() throws Throwable {
    RevCommit initialHead = projectOperations.project(project).getHead("master");
    PushOneCommit.Result change = createChange();
    approve(change.getChangeId());
    PushOneCommit.Result change2 = createChange();
    approve(change2.getChangeId());
    Project.NameKey project = change2.getChange().change().getProject();
    BranchNameKey branch = BranchNameKey.create(project, "branch");
    createBranchWithRevision(branch, change2.getCommit().getName());
    gApi.changes().id(change2.getChangeId()).current().submit();
    assertMerged(change2.getChangeId());
    assertMerged(change.getChangeId());
    RevCommit newHead = projectOperations.project(this.project).getHead("master");
    assertRefUpdatedEvents(initialHead, newHead);
    assertChangeMergedEvents(change.getChangeId(), newHead.name(), change2.getChangeId(), newHead.name());
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 72 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class AbstractSubmit method noSelfSubmit.

@Test
public void noSelfSubmit() throws Throwable {
    // create project where submit is blocked for the change owner
    Project.NameKey p = projectOperations.newProject().create();
    projectOperations.project(p).forUpdate().add(block(Permission.SUBMIT).ref("refs/*").group(CHANGE_OWNER)).add(allow(Permission.SUBMIT).ref("refs/heads/*").group(REGISTERED_USERS)).add(allowLabel(LabelId.CODE_REVIEW).ref("refs/*").group(REGISTERED_USERS).range(-2, +2)).update();
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(admin.newIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id().get());
    submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
    requestScopeOperations.setApiUser(user.id());
    submit(result.getChangeId());
}
Also used : TestSubmitInput(com.google.gerrit.server.change.TestSubmitInput) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 73 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class AbstractSubmit method onlySelfSubmit.

@Test
public void onlySelfSubmit() throws Throwable {
    // create project where only the change owner can submit
    Project.NameKey p = projectOperations.newProject().create();
    projectOperations.project(p).forUpdate().add(block(Permission.SUBMIT).ref("refs/*").group(REGISTERED_USERS)).add(allow(Permission.SUBMIT).ref("refs/*").group(CHANGE_OWNER)).add(allowLabel(LabelId.CODE_REVIEW).ref("refs/*").group(REGISTERED_USERS).range(-2, +2)).update();
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(admin.newIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id().get());
    requestScopeOperations.setApiUser(user.id());
    submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
    requestScopeOperations.setApiUser(admin.id());
    submit(result.getChangeId());
}
Also used : TestSubmitInput(com.google.gerrit.server.change.TestSubmitInput) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 74 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class CommentContextSerializerTest method roundTripKey.

@Test
public void roundTripKey() {
    Project.NameKey proj = Project.NameKey.parse("project");
    Change.Id changeId = Change.Id.tryParse("1234").get();
    CommentContextKey k = CommentContextKey.builder().project(proj).changeId(changeId).id("commentId").path("pathHash").patchset(1).contextPadding(3).build();
    byte[] serialized = CommentContextKey.Serializer.INSTANCE.serialize(k);
    assertThat(k).isEqualTo(CommentContextKey.Serializer.INSTANCE.deserialize(serialized));
}
Also used : Project(com.google.gerrit.entities.Project) CommentContextKey(com.google.gerrit.server.comment.CommentContextKey) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 75 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class WatchConfigTest method parseWatchConfig.

@Test
public void parseWatchConfig() throws Exception {
    Config cfg = new Config();
    cfg.fromText("[project \"myProject\"]\n" + "  notify = * [ALL_COMMENTS, NEW_PATCHSETS]\n" + "  notify = branch:master [NEW_CHANGES]\n" + "  notify = branch:master [NEW_PATCHSETS]\n" + "  notify = branch:foo []\n" + "[project \"otherProject\"]\n" + "  notify = [NEW_PATCHSETS]\n" + "  notify = * [NEW_PATCHSETS, ALL_COMMENTS]\n");
    Map<ProjectWatchKey, ImmutableSet<NotifyType>> projectWatches = ProjectWatches.parse(Account.id(1000000), cfg, this);
    assertThat(validationErrors).isEmpty();
    Project.NameKey myProject = Project.nameKey("myProject");
    Project.NameKey otherProject = Project.nameKey("otherProject");
    Map<ProjectWatchKey, Set<NotifyType>> expectedProjectWatches = new HashMap<>();
    expectedProjectWatches.put(ProjectWatchKey.create(myProject, null), EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS));
    expectedProjectWatches.put(ProjectWatchKey.create(myProject, "branch:master"), EnumSet.of(NotifyType.NEW_CHANGES, NotifyType.NEW_PATCHSETS));
    expectedProjectWatches.put(ProjectWatchKey.create(myProject, "branch:foo"), EnumSet.noneOf(NotifyType.class));
    expectedProjectWatches.put(ProjectWatchKey.create(otherProject, null), EnumSet.of(NotifyType.NEW_PATCHSETS));
    expectedProjectWatches.put(ProjectWatchKey.create(otherProject, null), EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS));
    assertThat(projectWatches).containsExactlyEntriesIn(expectedProjectWatches);
}
Also used : Project(com.google.gerrit.entities.Project) NotifyType(com.google.gerrit.entities.NotifyConfig.NotifyType) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(java.util.HashMap) Config(org.eclipse.jgit.lib.Config) ProjectWatchKey(com.google.gerrit.server.account.ProjectWatches.ProjectWatchKey) Test(org.junit.Test)

Aggregations

Project (com.google.gerrit.entities.Project)184 Test (org.junit.Test)109 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)67 Change (com.google.gerrit.entities.Change)43 Repository (org.eclipse.jgit.lib.Repository)34 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)33 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)32 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)31 BranchNameKey (com.google.gerrit.entities.BranchNameKey)30 Config (org.eclipse.jgit.lib.Config)26 ObjectId (org.eclipse.jgit.lib.ObjectId)26 IOException (java.io.IOException)25 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)24 ProjectState (com.google.gerrit.server.project.ProjectState)23 Inject (com.google.inject.Inject)23 List (java.util.List)23 AuthException (com.google.gerrit.extensions.restapi.AuthException)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)22 PatchSet (com.google.gerrit.entities.PatchSet)20