Search in sources :

Example 1 with MailService

use of com.enonic.xp.mail.MailService in project xp by enonic.

the class SendMailScriptTest method testFailMissingTo.

@Test
public void testFailMissingTo() throws Exception {
    final MailService mailService = message -> {
        throw new RuntimeException("Error sending mail");
    };
    addService(MailService.class, mailService);
    try {
        runFunction("/test/send-test.js", "sendWithoutRequiredTo");
        fail("Expected exception");
    } catch (ResourceProblemException e) {
        assertEquals("Parameter 'to' is required", e.getMessage());
    }
    assertNull(this.actualMessage);
}
Also used : Message(javax.mail.Message) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MimeMultipart(javax.mail.internet.MimeMultipart) AddressException(javax.mail.internet.AddressException) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) MailService(com.enonic.xp.mail.MailService) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) MimeMessage(javax.mail.internet.MimeMessage) InputStreamReader(java.io.InputStreamReader) MailMessage(com.enonic.xp.mail.MailMessage) StandardCharsets(java.nio.charset.StandardCharsets) BodyPart(javax.mail.BodyPart) InternetAddress(javax.mail.internet.InternetAddress) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Stream(java.util.stream.Stream) ScriptTestSupport(com.enonic.xp.testing.ScriptTestSupport) CharStreams(com.google.common.io.CharStreams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Session(javax.mail.Session) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) InputStream(java.io.InputStream) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) MailService(com.enonic.xp.mail.MailService) Test(org.junit.jupiter.api.Test)

Example 2 with MailService

use of com.enonic.xp.mail.MailService in project xp by enonic.

the class SendMailScriptTest method testFailMissingFrom.

@Test
public void testFailMissingFrom() throws Exception {
    final MailService mailService = message -> {
        throw new RuntimeException("Error sending mail");
    };
    addService(MailService.class, mailService);
    try {
        runFunction("/test/send-test.js", "sendWithoutRequiredFrom");
        fail("Expected exception");
    } catch (ResourceProblemException e) {
        assertEquals("Parameter 'from' is required", e.getMessage());
    }
    assertNull(this.actualMessage);
}
Also used : Message(javax.mail.Message) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MimeMultipart(javax.mail.internet.MimeMultipart) AddressException(javax.mail.internet.AddressException) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) MailService(com.enonic.xp.mail.MailService) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) MimeMessage(javax.mail.internet.MimeMessage) InputStreamReader(java.io.InputStreamReader) MailMessage(com.enonic.xp.mail.MailMessage) StandardCharsets(java.nio.charset.StandardCharsets) BodyPart(javax.mail.BodyPart) InternetAddress(javax.mail.internet.InternetAddress) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Stream(java.util.stream.Stream) ScriptTestSupport(com.enonic.xp.testing.ScriptTestSupport) CharStreams(com.google.common.io.CharStreams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Session(javax.mail.Session) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) InputStream(java.io.InputStream) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) MailService(com.enonic.xp.mail.MailService) Test(org.junit.jupiter.api.Test)

Example 3 with MailService

use of com.enonic.xp.mail.MailService in project xp by enonic.

the class SendMailScriptTest method initialize.

@Override
public void initialize() throws Exception {
    super.initialize();
    final MailService mailService = message -> this.actualMessage = message;
    addService(MailService.class, mailService);
}
Also used : Message(javax.mail.Message) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MimeMultipart(javax.mail.internet.MimeMultipart) AddressException(javax.mail.internet.AddressException) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) MailService(com.enonic.xp.mail.MailService) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) MimeMessage(javax.mail.internet.MimeMessage) InputStreamReader(java.io.InputStreamReader) MailMessage(com.enonic.xp.mail.MailMessage) StandardCharsets(java.nio.charset.StandardCharsets) BodyPart(javax.mail.BodyPart) InternetAddress(javax.mail.internet.InternetAddress) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Stream(java.util.stream.Stream) ScriptTestSupport(com.enonic.xp.testing.ScriptTestSupport) CharStreams(com.google.common.io.CharStreams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Session(javax.mail.Session) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) InputStream(java.io.InputStream) MailService(com.enonic.xp.mail.MailService)

Example 4 with MailService

use of com.enonic.xp.mail.MailService in project xp by enonic.

the class SendMailScriptTest method testFailSendMail.

@Test
public void testFailSendMail() throws Exception {
    final MailService mailService = message -> {
        throw new RuntimeException("Error sending mail");
    };
    addService(MailService.class, mailService);
    runFunction("/test/send-test.js", "failSendMail");
    assertNull(this.actualMessage);
}
Also used : Message(javax.mail.Message) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MimeMultipart(javax.mail.internet.MimeMultipart) AddressException(javax.mail.internet.AddressException) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) MailService(com.enonic.xp.mail.MailService) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) MimeMessage(javax.mail.internet.MimeMessage) InputStreamReader(java.io.InputStreamReader) MailMessage(com.enonic.xp.mail.MailMessage) StandardCharsets(java.nio.charset.StandardCharsets) BodyPart(javax.mail.BodyPart) InternetAddress(javax.mail.internet.InternetAddress) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Stream(java.util.stream.Stream) ScriptTestSupport(com.enonic.xp.testing.ScriptTestSupport) CharStreams(com.google.common.io.CharStreams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Session(javax.mail.Session) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) InputStream(java.io.InputStream) MailService(com.enonic.xp.mail.MailService) Test(org.junit.jupiter.api.Test)

Aggregations

MailMessage (com.enonic.xp.mail.MailMessage)4 MailService (com.enonic.xp.mail.MailService)4 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)4 ScriptTestSupport (com.enonic.xp.testing.ScriptTestSupport)4 ByteSource (com.google.common.io.ByteSource)4 CharStreams (com.google.common.io.CharStreams)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Stream (java.util.stream.Stream)4 BodyPart (javax.mail.BodyPart)4 Message (javax.mail.Message)4 Session (javax.mail.Session)4 AddressException (javax.mail.internet.AddressException)4 InternetAddress (javax.mail.internet.InternetAddress)4 MimeMessage (javax.mail.internet.MimeMessage)4 MimeMultipart (javax.mail.internet.MimeMultipart)4 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)4