Search in sources :

Example 1 with Address

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

the class AbstractDaemonTest method assertNotifyCc.

protected void assertNotifyCc(String expectedEmail, String expectedFullname) {
    Address expectedAddress = Address.create(expectedFullname, expectedEmail);
    assertNotifyCc(expectedAddress);
}
Also used : Address(com.google.gerrit.entities.Address)

Example 2 with Address

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

the class AbstractDaemonTest method assertNotifyTo.

protected void assertNotifyTo(String expectedEmail, String expectedFullname) {
    Address expectedAddress = Address.create(expectedFullname, expectedEmail);
    assertThat(sender.getMessages()).hasSize(1);
    Message m = sender.getMessages().get(0);
    assertThat(m.rcpt()).containsExactly(expectedAddress);
    assertThat(((EmailHeader.AddressList) m.headers().get("To")).getAddressList()).containsExactly(expectedAddress);
    assertThat(m.headers().get("Cc").isEmpty()).isTrue();
}
Also used : Address(com.google.gerrit.entities.Address) Message(com.google.gerrit.testing.FakeEmailSender.Message) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage)

Example 3 with Address

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

the class AddReviewersOp method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws RestApiException, IOException {
    change = ctx.getChange();
    if (!accountIds.isEmpty()) {
        if (state == CC) {
            addedCCs = approvalsUtil.addCcs(ctx.getNotes(), ctx.getUpdate(change.currentPatchSetId()), accountIds, forGroup);
        } else {
            addedReviewers = approvalsUtil.addReviewers(ctx.getNotes(), ctx.getUpdate(change.currentPatchSetId()), projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject())).getLabelTypes(change.getDest()), change, accountIds);
        }
    }
    ReviewerStateInternal internalState = ReviewerStateInternal.fromReviewerState(state);
    // TODO(dborowitz): This behavior should live in ApprovalsUtil or something, like addCcs does.
    ImmutableSet<Address> existing = ctx.getNotes().getReviewersByEmail().byState(internalState);
    ImmutableList<Address> addressesToAdd = addresses.stream().filter(a -> !existing.contains(a)).collect(toImmutableList());
    if (state == CC) {
        addedCCsByEmail = addressesToAdd;
    } else {
        addedReviewersByEmail = addressesToAdd;
    }
    for (Address a : addressesToAdd) {
        ctx.getUpdate(change.currentPatchSetId()).putReviewerByEmail(a, internalState);
    }
    if (addedCCs.isEmpty() && addedReviewers.isEmpty() && addressesToAdd.isEmpty()) {
        return false;
    }
    checkAdded();
    if (patchSet == null) {
        patchSet = requireNonNull(psUtil.current(ctx.getNotes()));
    }
    return true;
}
Also used : AccountCache(com.google.gerrit.server.account.AccountCache) CC(com.google.gerrit.extensions.client.ReviewerState.CC) ProjectCache(com.google.gerrit.server.project.ProjectCache) Inject(com.google.inject.Inject) REVIEWER(com.google.gerrit.extensions.client.ReviewerState.REVIEWER) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Assisted(com.google.inject.assistedinject.Assisted) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) PostUpdateContext(com.google.gerrit.server.update.PostUpdateContext) Objects.requireNonNull(java.util.Objects.requireNonNull) Change(com.google.gerrit.entities.Change) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Address(com.google.gerrit.entities.Address) ChangeContext(com.google.gerrit.server.update.ChangeContext) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) ImmutableSet(com.google.common.collect.ImmutableSet) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) ReviewerAdded(com.google.gerrit.server.extensions.events.ReviewerAdded) Account(com.google.gerrit.entities.Account) Set(java.util.Set) IOException(java.io.IOException) Streams(com.google.common.collect.Streams) ApprovalsUtil(com.google.gerrit.server.approval.ApprovalsUtil) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) AccountState(com.google.gerrit.server.account.AccountState) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) Address(com.google.gerrit.entities.Address) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal)

Example 4 with Address

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

the class ChangeNotesTest method putReviewerByEmailAndChangeToCc.

@Test
public void putReviewerByEmailAndChangeToCc() throws Exception {
    Address adr = Address.create("Foo Bar", "foo.bar@gerritcodereview.com");
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putReviewerByEmail(adr, ReviewerStateInternal.REVIEWER);
    update.commit();
    update = newUpdate(c, changeOwner);
    update.putReviewerByEmail(adr, ReviewerStateInternal.CC);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getReviewersByEmail().byState(ReviewerStateInternal.REVIEWER)).isEmpty();
    assertThat(notes.getReviewersByEmail().byState(ReviewerStateInternal.CC)).containsExactly(adr);
    assertThat(notes.getReviewersByEmail().all()).containsExactly(adr);
}
Also used : Address(com.google.gerrit.entities.Address) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 5 with Address

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

the class ChangeNotesTest method putReviewerByEmail.

@Test
public void putReviewerByEmail() throws Exception {
    Address adr = Address.create("Foo Bar", "foo.bar@gerritcodereview.com");
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putReviewerByEmail(adr, ReviewerStateInternal.REVIEWER);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getReviewersByEmail().all()).containsExactly(adr);
}
Also used : Address(com.google.gerrit.entities.Address) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Aggregations

Address (com.google.gerrit.entities.Address)61 Test (org.junit.Test)45 Account (com.google.gerrit.entities.Account)22 Change (com.google.gerrit.entities.Change)9 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)7 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 NotifyConfig (com.google.gerrit.entities.NotifyConfig)6 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 ArrayList (java.util.ArrayList)5 ReviewerStateInternal (com.google.gerrit.server.notedb.ReviewerStateInternal)4 ImmutableList (com.google.common.collect.ImmutableList)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableTable (com.google.common.collect.ImmutableTable)2 Lists (com.google.common.collect.Lists)2 Table (com.google.common.collect.Table)2 FluentLogger (com.google.common.flogger.FluentLogger)2 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)2 GroupReference (com.google.gerrit.entities.GroupReference)2 PatchSet (com.google.gerrit.entities.PatchSet)2