Search in sources :

Example 16 with TestAccount

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

the class AccountIT method create.

@Test
public void create() throws Exception {
    TestAccount foo = accounts.create("foo");
    AccountInfo info = gApi.accounts().id(foo.id.get()).get();
    assertThat(info.username).isEqualTo("foo");
    if (SshMode.useSsh()) {
        // account creation + adding SSH keys
        accountIndexedCounter.assertReindexOf(foo, 2);
    } else {
        // account creation
        accountIndexedCounter.assertReindexOf(foo, 1);
    }
    // check user branch
    try (Repository repo = repoManager.openRepository(allUsers);
        RevWalk rw = new RevWalk(repo)) {
        Ref ref = repo.exactRef(RefNames.refsUsers(foo.getId()));
        assertThat(ref).isNotNull();
        RevCommit c = rw.parseCommit(ref.getObjectId());
        long timestampDiffMs = Math.abs(c.getCommitTime() * 1000L - accountCache.get(foo.getId()).getAccount().getRegisteredOn().getTime());
        assertThat(timestampDiffMs).isAtMost(ChangeRebuilderImpl.MAX_WINDOW_MS);
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) GitUtil.deleteRef(com.google.gerrit.acceptance.GitUtil.deleteRef) Ref(org.eclipse.jgit.lib.Ref) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TestAccount(com.google.gerrit.acceptance.TestAccount) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 17 with TestAccount

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

the class AccountIT method ignoreChange.

@Test
public void ignoreChange() throws Exception {
    TestAccount user2 = accounts.user2();
    accountIndexedCounter.clear();
    PushOneCommit.Result r = createChange();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    in = new AddReviewerInput();
    in.reviewer = user2.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    setApiUser(user);
    gApi.accounts().self().setStars(r.getChangeId(), new StarsInput(ImmutableSet.of(IGNORE_LABEL)));
    sender.clear();
    setApiUser(admin);
    gApi.changes().id(r.getChangeId()).abandon();
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    assertThat(messages.get(0).rcpt()).containsExactly(user2.emailAddress);
    accountIndexedCounter.assertNoReindex();
}
Also used : Message(com.google.gerrit.testutil.FakeEmailSender.Message) StarsInput(com.google.gerrit.extensions.api.changes.StarsInput) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 18 with TestAccount

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

the class AccountIT method cannotAddNonConfirmedEmailWithoutModifyAccountPermission.

@Test
public void cannotAddNonConfirmedEmailWithoutModifyAccountPermission() throws Exception {
    TestAccount account = accounts.create(name("user"));
    EmailInput input = new EmailInput();
    input.email = "test@test.com";
    input.noConfirmation = true;
    setApiUser(user);
    exception.expect(AuthException.class);
    gApi.accounts().id(account.username).addEmail(input);
}
Also used : EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) TestAccount(com.google.gerrit.acceptance.TestAccount) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 19 with TestAccount

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

the class ChangeIT method deleteVoteNotifyAccount.

@Test
public void deleteVoteNotifyAccount() throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
    DeleteVoteInput in = new DeleteVoteInput();
    in.label = "Code-Review";
    in.notify = NotifyHandling.NONE;
    // notify unrelated account as TO
    TestAccount user2 = accounts.user2();
    setApiUser(user);
    recommend(r.getChangeId());
    setApiUser(admin);
    sender.clear();
    in.notifyDetails = new HashMap<>();
    in.notifyDetails.put(RecipientType.TO, new NotifyInfo(ImmutableList.of(user2.email)));
    gApi.changes().id(r.getChangeId()).reviewer(user.getId().toString()).deleteVote(in);
    assertNotifyTo(user2);
    // notify unrelated account as CC
    setApiUser(user);
    recommend(r.getChangeId());
    setApiUser(admin);
    sender.clear();
    in.notifyDetails = new HashMap<>();
    in.notifyDetails.put(RecipientType.CC, new NotifyInfo(ImmutableList.of(user2.email)));
    gApi.changes().id(r.getChangeId()).reviewer(user.getId().toString()).deleteVote(in);
    assertNotifyCc(user2);
    // notify unrelated account as BCC
    setApiUser(user);
    recommend(r.getChangeId());
    setApiUser(admin);
    sender.clear();
    in.notifyDetails = new HashMap<>();
    in.notifyDetails.put(RecipientType.BCC, new NotifyInfo(ImmutableList.of(user2.email)));
    gApi.changes().id(r.getChangeId()).reviewer(user.getId().toString()).deleteVote(in);
    assertNotifyBcc(user2);
}
Also used : DeleteVoteInput(com.google.gerrit.extensions.api.changes.DeleteVoteInput) NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 20 with TestAccount

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

the class GroupsIT method addMultipleMembers.

@Test
public void addMultipleMembers() throws Exception {
    String g = createGroup("users");
    TestAccount u1 = accounts.create("u1", "u1@example.com", "Full Name 1");
    TestAccount u2 = accounts.create("u2", "u2@example.com", "Full Name 2");
    gApi.groups().id(g).addMembers(u1.username, u2.username);
    assertMembers(g, u1, u2);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

TestAccount (com.google.gerrit.acceptance.TestAccount)30 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 Test (org.junit.Test)28 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)18 Message (com.google.gerrit.testutil.FakeEmailSender.Message)8 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)6 ArrayList (java.util.ArrayList)6 Project (com.google.gerrit.reviewdb.client.Project)5 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)5 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)4 AddReviewerResult (com.google.gerrit.extensions.api.changes.AddReviewerResult)4 NotifyInfo (com.google.gerrit.extensions.api.changes.NotifyInfo)4 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)4 SuggestedReviewerInfo (com.google.gerrit.extensions.common.SuggestedReviewerInfo)4 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)3 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)3 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)2 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)2 GerritConfig (com.google.gerrit.acceptance.GerritConfig)1 GitUtil.deleteRef (com.google.gerrit.acceptance.GitUtil.deleteRef)1