Continue structural port from Spring Boot to Undertow
- Notification template generator - Add tests for email notification handler
This commit is contained in:
@@ -148,6 +148,7 @@ dependencies {
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'com.github.tomakehurst:wiremock:2.8.0'
|
||||
testCompile 'com.unboundid:unboundid-ldapsdk:4.0.9'
|
||||
testCompile 'com.icegreen:greenmail:1.5.9'
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
|
@@ -28,10 +28,10 @@ public class EmailTemplateConfig extends GenericTemplateConfig {
|
||||
private transient final Logger log = LoggerFactory.getLogger(EmailTemplateConfig.class);
|
||||
|
||||
public EmailTemplateConfig() {
|
||||
setInvite("classpath:threepids/email/invite-template.eml");
|
||||
getGeneric().put("matrixId", "classpath:threepids/email/mxid-template.eml");
|
||||
getSession().getValidation().setLocal("classpath:threepids/email/validate-local-template.eml");
|
||||
getSession().getValidation().setRemote("classpath:threepids/email/validate-remote-template.eml");
|
||||
setInvite("classpath:/threepids/email/invite-template.eml");
|
||||
getGeneric().put("matrixId", "classpath:/threepids/email/mxid-template.eml");
|
||||
getSession().getValidation().setLocal("classpath:/threepids/email/validate-local-template.eml");
|
||||
getSession().getValidation().setRemote("classpath:/threepids/email/validate-remote-template.eml");
|
||||
}
|
||||
|
||||
public EmailTemplateConfig build() {
|
||||
|
@@ -28,10 +28,10 @@ public class PhoneSmsTemplateConfig extends GenericTemplateConfig {
|
||||
private transient final Logger log = LoggerFactory.getLogger(EmailTemplateConfig.class);
|
||||
|
||||
public PhoneSmsTemplateConfig() {
|
||||
setInvite("classpath:threepids/sms/invite-template.txt");
|
||||
getGeneric().put("matrixId", "classpath:threepids/email/mxid-template.eml");
|
||||
getSession().getValidation().setLocal("classpath:threepids/sms/validate-local-template.txt");
|
||||
getSession().getValidation().setRemote("classpath:threepids/sms/validate-remote-template.txt");
|
||||
setInvite("classpath:/threepids/sms/invite-template.txt");
|
||||
getGeneric().put("matrixId", "classpath:/threepids/email/mxid-template.eml");
|
||||
getSession().getValidation().setLocal("classpath:/threepids/sms/validate-local-template.txt");
|
||||
getSession().getValidation().setRemote("classpath:/threepids/sms/validate-remote-template.txt");
|
||||
}
|
||||
|
||||
public PhoneSmsTemplateConfig build() {
|
||||
|
@@ -27,11 +27,16 @@ import io.kamax.mxisd.config.threepid.medium.GenericTemplateConfig;
|
||||
import io.kamax.mxisd.exception.InternalServerError;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public abstract class GenericTemplateNotificationGenerator extends PlaceholderNotificationGenerator implements NotificationGenerator {
|
||||
|
||||
@@ -46,13 +51,14 @@ public abstract class GenericTemplateNotificationGenerator extends PlaceholderNo
|
||||
|
||||
private String getTemplateContent(String location) {
|
||||
try {
|
||||
// FIXME make it work again
|
||||
/*
|
||||
InputStream is = StringUtils.startsWith(location, "classpath:") ?
|
||||
app.getResource(location).getInputStream() : new FileInputStream(location);
|
||||
URI loc = URI.create(location);
|
||||
InputStream is;
|
||||
if (StringUtils.equals("classpath", loc.getScheme())) {
|
||||
is = getClass().getResourceAsStream(loc.getSchemeSpecificPart());
|
||||
} else {
|
||||
is = new FileInputStream(location);
|
||||
}
|
||||
return IOUtils.toString(is, StandardCharsets.UTF_8);
|
||||
*/
|
||||
throw new IOException("Not implemented!");
|
||||
} catch (IOException e) {
|
||||
throw new InternalServerError("Unable to read template content at " + location + ": " + e.getMessage());
|
||||
}
|
||||
|
78
src/test/java/io/kamax/mxisd/test/MxisdEmailNotifTest.java
Normal file
78
src/test/java/io/kamax/mxisd/test/MxisdEmailNotifTest.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package io.kamax.mxisd.test;
|
||||
|
||||
import com.icegreen.greenmail.util.GreenMail;
|
||||
import com.icegreen.greenmail.util.ServerSetupTest;
|
||||
import io.kamax.matrix.MatrixID;
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.matrix._MatrixID;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.as.MatrixIdInvite;
|
||||
import io.kamax.mxisd.config.MxisdConfig;
|
||||
import io.kamax.mxisd.config.threepid.connector.EmailSmtpConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
import io.kamax.mxisd.threepid.connector.email.EmailSmtpConnector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.Collections;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class MxisdEmailNotifTest {
|
||||
|
||||
private final String domain = "localhost";
|
||||
private Mxisd m;
|
||||
private GreenMail gm;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
EmailSmtpConfig smtpCfg = new EmailSmtpConfig();
|
||||
smtpCfg.setPort(3025);
|
||||
smtpCfg.setLogin("mxisd");
|
||||
smtpCfg.setPassword("mxisd");
|
||||
|
||||
EmailConfig eCfg = new EmailConfig();
|
||||
eCfg.setConnector(EmailSmtpConnector.ID);
|
||||
eCfg.getIdentity().setFrom("mxisd@" + domain);
|
||||
eCfg.getIdentity().setName("Mxisd Server (Unit Test)");
|
||||
eCfg.getConnectors().put(EmailSmtpConnector.ID, GsonUtil.makeObj(smtpCfg));
|
||||
|
||||
MxisdConfig cfg = new MxisdConfig();
|
||||
cfg.getMatrix().setDomain(domain);
|
||||
cfg.getKey().setPath(":memory:");
|
||||
cfg.getStorage().getProvider().getSqlite().setDatabase(":memory:");
|
||||
cfg.getThreepid().getMedium().put(ThreePidMedium.Email.getId(), GsonUtil.makeObj(eCfg));
|
||||
|
||||
m = new Mxisd(cfg);
|
||||
m.start();
|
||||
|
||||
gm = new GreenMail(ServerSetupTest.SMTP_IMAP);
|
||||
gm.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
gm.stop();
|
||||
m.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forMatrixIdInvite() throws MessagingException {
|
||||
_MatrixID sender = MatrixID.asAcceptable("mxisd", domain);
|
||||
_MatrixID recipient = MatrixID.asAcceptable("john", domain);
|
||||
MatrixIdInvite idInvite = new MatrixIdInvite("!rid:" + domain, sender, recipient, ThreePidMedium.Email.getId(), "john@" + domain, Collections.emptyMap());
|
||||
m.getNotif().sendForInvite(idInvite);
|
||||
|
||||
assertEquals(1, gm.getReceivedMessages().length);
|
||||
MimeMessage msg = gm.getReceivedMessages()[0];
|
||||
assertEquals(1, msg.getFrom().length);
|
||||
assertEquals("\"Mxisd Server (Unit Test)\" <mxisd@localhost>", msg.getFrom()[0].toString());
|
||||
assertEquals(1, msg.getRecipients(Message.RecipientType.TO).length);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user