Search in sources :

Example 26 with Address

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

the class AddressTest method parse_Email2.

@Test
public void parse_Email2() {
    final Address a = Address.parse("a@b");
    assertThat(a.name()).isNull();
    assertThat(a.email()).isEqualTo("a@b");
}
Also used : Address(com.google.gerrit.entities.Address) Test(org.junit.Test)

Example 27 with Address

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

the class AddressTest method parse_NameEmail5.

@Test
public void parse_NameEmail5() {
    final Address a = Address.parse("A U Thor  <author@example.com>");
    assertThat(a.name()).isEqualTo("A U Thor");
    assertThat(a.email()).isEqualTo("author@example.com");
}
Also used : Address(com.google.gerrit.entities.Address) Test(org.junit.Test)

Example 28 with Address

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

the class AddressTest method parse_NameEmail2.

@Test
public void parse_NameEmail2() {
    final Address a = Address.parse("A <a@b>");
    assertThat(a.name()).isEqualTo("A");
    assertThat(a.email()).isEqualTo("a@b");
}
Also used : Address(com.google.gerrit.entities.Address) Test(org.junit.Test)

Example 29 with Address

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

the class MailHeaderParserTest method parseMetadataFromText.

@Test
public void parseMetadataFromText() {
    // This tests if the metadata parser is able to parse metadata from the
    // the text body of the message.
    MailMessage.Builder b = MailMessage.builder();
    b.id("");
    b.dateReceived(Instant.now());
    b.subject("");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(MailHeader.CHANGE_NUMBER.withDelimiter()).append("123\r\n");
    stringBuilder.append("> ").append(MailHeader.PATCH_SET.withDelimiter()).append("1\n");
    stringBuilder.append(MailHeader.MESSAGE_TYPE.withDelimiter()).append("comment\n");
    stringBuilder.append(MailHeader.COMMENT_DATE.withDelimiter()).append("Tue, 25 Oct 2016 02:11:35 -0700\r\n");
    b.textContent(stringBuilder.toString());
    Address author = Address.create("Diffy", "test@gerritcodereview.com");
    b.from(author);
    MailMetadata meta = MailHeaderParser.parse(b.build());
    assertThat(meta.author).isEqualTo(author.email());
    assertThat(meta.changeNumber).isEqualTo(123);
    assertThat(meta.patchSet).isEqualTo(1);
    assertThat(meta.messageType).isEqualTo("comment");
    assertThat(meta.timestamp.toInstant()).isEqualTo(LocalDateTime.of(2016, Month.OCTOBER, 25, 9, 11, 35).atOffset(ZoneOffset.UTC).toInstant());
}
Also used : Address(com.google.gerrit.entities.Address) Test(org.junit.Test)

Example 30 with Address

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

the class DeleteReviewersUtil method addDeleteReviewerOpToBatchUpdate.

public void addDeleteReviewerOpToBatchUpdate(BatchUpdate batchUpdate, ChangeNotes changeNotes, ReviewerInput reviewerInput) throws IOException, ConfigInvalidException, AuthException, ResourceNotFoundException {
    try {
        AccountResolver.Result result = accountResolver.resolveIgnoreVisibility(reviewerInput.reviewer);
        if (fetchAccountIds(changeNotes).contains(result.asUniqueUser().getAccountId())) {
            DeleteReviewerInput deleteReviewerInput = new DeleteReviewerInput();
            deleteReviewerInput.notify = reviewerInput.notify;
            deleteReviewerInput.notifyDetails = reviewerInput.notifyDetails;
            batchUpdate.addOp(changeNotes.getChangeId(), deleteReviewerOpFactory.create(result.asUnique().account(), deleteReviewerInput));
            return;
        }
        return;
    } catch (AccountResolver.UnresolvableAccountException e) {
        if (e.isSelf()) {
            throw new AuthException(e.getMessage(), e);
        }
    }
    Address address = Address.tryParse(reviewerInput.reviewer);
    if (address != null && changeNotes.getReviewersByEmail().all().contains(address)) {
        batchUpdate.addOp(changeNotes.getChangeId(), deleteReviewerByEmailOpFactory.create(address));
        return;
    }
    throw new ResourceNotFoundException(reviewerInput.reviewer);
}
Also used : Address(com.google.gerrit.entities.Address) AccountResolver(com.google.gerrit.server.account.AccountResolver) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) AuthException(com.google.gerrit.extensions.restapi.AuthException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

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