Search in sources :

Example 1 with ThreePidInviteReply

use of io.kamax.mxisd.invitation.ThreePidInviteReply in project mxisd by kamax-io.

the class EmailNotificationTest method forThreepidInvite.

@Test
public void forThreepidInvite() throws MessagingException, IOException {
    String registerUrl = "https://" + RandomStringUtils.randomAlphanumeric(20) + ".example.org/register";
    gm.setUser(user, user);
    _MatrixID sender = MatrixID.asAcceptable(user, domain);
    ThreePidInvite inv = new ThreePidInvite(sender, ThreePidMedium.Email.getId(), target, "!rid:" + domain);
    inv.getProperties().put(PlaceholderNotificationGenerator.RegisterUrl, registerUrl);
    m.getNotif().sendForReply(new ThreePidInviteReply("a", inv, "b", "c", new ArrayList<>()));
    assertEquals(1, gm.getReceivedMessages().length);
    MimeMessage msg = gm.getReceivedMessages()[0];
    assertEquals(1, msg.getFrom().length);
    assertEquals(senderNameEncoded, msg.getFrom()[0].toString());
    assertEquals(1, msg.getRecipients(Message.RecipientType.TO).length);
    // We just check on the text/plain one. HTML is multipart and it's difficult so we skip
    MimeMultipart content = (MimeMultipart) msg.getContent();
    MimeBodyPart mbp = (MimeBodyPart) content.getBodyPart(0);
    String mbpContent = mbp.getContent().toString();
    assertTrue(mbpContent.contains(registerUrl));
}
Also used : ThreePidInvite(io.kamax.mxisd.invitation.ThreePidInvite) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) ArrayList(java.util.ArrayList) MimeBodyPart(javax.mail.internet.MimeBodyPart) io.kamax.matrix._MatrixID(io.kamax.matrix._MatrixID) ThreePidInviteReply(io.kamax.mxisd.invitation.ThreePidInviteReply) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)1 io.kamax.matrix._MatrixID (io.kamax.matrix._MatrixID)1 ThreePidInvite (io.kamax.mxisd.invitation.ThreePidInvite)1 ThreePidInviteReply (io.kamax.mxisd.invitation.ThreePidInviteReply)1 ArrayList (java.util.ArrayList)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 Test (org.junit.Test)1