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");
}
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());
}
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());
}
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");
}
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");
}
Aggregations