Search in sources :

Example 46 with Address

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

the class AddressTest method parse_Email1.

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

Example 47 with Address

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

the class MailHeaderParserTest method parseMetadataFromHeader.

@Test
public void parseMetadataFromHeader() {
    // This tests if the metadata parser is able to parse metadata from the
    // email headers of the message.
    MailMessage.Builder b = MailMessage.builder();
    b.id("");
    b.dateReceived(Instant.now());
    b.subject("");
    b.addAdditionalHeader(MailHeader.CHANGE_NUMBER.fieldWithDelimiter() + "123");
    b.addAdditionalHeader(MailHeader.PATCH_SET.fieldWithDelimiter() + "1");
    b.addAdditionalHeader(MailHeader.MESSAGE_TYPE.fieldWithDelimiter() + "comment");
    b.addAdditionalHeader(MailHeader.COMMENT_DATE.fieldWithDelimiter() + "Tue, 25 Oct 2016 02:11:35 -0700");
    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 48 with Address

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

the class MailHeaderParserTest method parseMetadataFromHTML.

@Test
public void parseMetadataFromHTML() {
    // This tests if the metadata parser is able to parse metadata from the
    // the HTML body of the message.
    MailMessage.Builder b = MailMessage.builder();
    b.id("");
    b.dateReceived(Instant.now());
    b.subject("");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("<div id\"someid\">").append(MailHeader.CHANGE_NUMBER.withDelimiter()).append("123</div>");
    stringBuilder.append("<div>").append(MailHeader.PATCH_SET.withDelimiter()).append("1</div>");
    stringBuilder.append("<div>").append(MailHeader.MESSAGE_TYPE.withDelimiter()).append("comment</div>");
    stringBuilder.append("<div>").append(MailHeader.COMMENT_DATE.withDelimiter()).append("Tue, 25 Oct 2016 02:11:35 -0700").append("</div>");
    b.htmlContent(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 49 with Address

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

the class ChangeNotesStateTest method serializeReviewersByEmailWithNullName.

@Test
public void serializeReviewersByEmailWithNullName() throws Exception {
    ChangeNotesState actual = assertRoundTrip(newBuilder().reviewersByEmail(ReviewerByEmailSet.fromTable(ImmutableTable.of(ReviewerStateInternal.CC, Address.create("emailonly@example.com"), Instant.ofEpochMilli(1212L)))).build(), ChangeNotesStateProto.newBuilder().setMetaId(SHA_BYTES).setChangeId(ID.get()).setColumns(colsProto).addReviewerByEmail(ReviewerByEmailSetEntryProto.newBuilder().setState("CC").setAddress("emailonly@example.com").setTimestampMillis(1212L)).build());
    // Address doesn't consider the name field in equals, so we have to check it manually.
    // TODO(dborowitz): Fix Address#equals.
    ImmutableSet<Address> ccs = actual.reviewersByEmail().byState(ReviewerStateInternal.CC);
    assertThat(ccs).hasSize(1);
    Address address = Iterables.getOnlyElement(ccs);
    assertThat(address.name()).isNull();
    assertThat(address.email()).isEqualTo("emailonly@example.com");
}
Also used : Address(com.google.gerrit.entities.Address) Test(org.junit.Test)

Example 50 with Address

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

the class ProjectWatchIT method newPatchSetsNotifyConfig.

@Test
public void newPatchSetsNotifyConfig() throws Exception {
    ImmutableList<String> messageFilters = ImmutableList.of("message:subject-with-tokens", "message:subject-with-tokens=secret");
    ImmutableList.Builder<Address> watchers = ImmutableList.builder();
    try (ProjectConfigUpdate u = updateProject(project)) {
        for (int i = 0; i < messageFilters.size(); i++) {
            Address addr = Address.create("Watcher#" + i, String.format("watcher-%s@example.com", i));
            watchers.add(addr);
            NotifyConfig.Builder nc = NotifyConfig.builder();
            nc.addAddress(addr);
            nc.setName("new-patch-set" + i);
            nc.setHeader(NotifyConfig.Header.CC);
            nc.setNotify(EnumSet.of(NotifyType.NEW_PATCHSETS));
            nc.setFilter(messageFilters.get(i));
            u.getConfig().putNotifyConfig("watch" + i, nc.build());
        }
        u.save();
    }
    PushOneCommit.Result r = pushFactory.create(admin.newIdent(), testRepo, "original subject", "a", "a1").to("refs/for/master");
    r.assertOkStatus();
    r = pushFactory.create(admin.newIdent(), testRepo, "super sekret subject\n\nsubject-with-tokens=secret subject", "a", "a2", r.getChangeId()).to("refs/for/master");
    r.assertOkStatus();
    r = pushFactory.create(admin.newIdent(), testRepo, "back to original subject", "a", "a3").to("refs/for/master");
    r.assertOkStatus();
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactlyElementsIn(watchers.build());
    assertThat(m.body()).contains("Change subject: super sekret subject\n");
    assertThat(m.body()).contains("Gerrit-PatchSet: 2\n");
}
Also used : Address(com.google.gerrit.entities.Address) Message(com.google.gerrit.testing.FakeEmailSender.Message) ImmutableList(com.google.common.collect.ImmutableList) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) NotifyConfig(com.google.gerrit.entities.NotifyConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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