-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17286 from mkouba/issue-17185
Mailer templates - make it possible to pass template attributes
- Loading branch information
Showing
8 changed files
with
188 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
extensions/mailer/deployment/src/test/java/io/quarkus/mailer/i18n/AppMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkus.mailer.i18n; | ||
|
||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
|
||
@MessageBundle | ||
public interface AppMessages { | ||
|
||
@Message("Hello {name}!") | ||
String hello_name(String name); | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
extensions/mailer/deployment/src/test/java/io/quarkus/mailer/i18n/MailMessageBundleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.quarkus.mailer.i18n; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.mailer.Mail; | ||
import io.quarkus.mailer.MailTemplate.MailTemplateInstance; | ||
import io.quarkus.mailer.MockMailbox; | ||
import io.quarkus.qute.CheckedTemplate; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MailMessageBundleTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Templates.class, AppMessages.class) | ||
.addAsResource("mock-config.properties", "application.properties") | ||
.addAsResource(new StringAsset( | ||
"hello_name=Hallo {name}!"), | ||
"messages/msg_de.properties") | ||
.addAsResource(new StringAsset("" | ||
+ "{msg:hello_name(name)}"), "templates/MailMessageBundleTest/hello.txt")); | ||
|
||
@Inject | ||
MockMailbox mailbox; | ||
|
||
@Test | ||
public void testSend() { | ||
mailbox.clear(); | ||
|
||
Templates.hello("Lu").to("[email protected]").subject("Test").send().await().indefinitely(); | ||
|
||
List<Mail> sent = mailbox.getMessagesSentTo("[email protected]"); | ||
assertEquals(1, sent.size()); | ||
Mail english = sent.get(0); | ||
assertEquals("Test", english.getSubject()); | ||
assertEquals("Hello Lu!", english.getText()); | ||
|
||
// Set the locale attribute | ||
Templates.hello("Lu").to("[email protected]").subject("Test").setAttribute("locale", Locale.GERMAN).send().await() | ||
.indefinitely(); | ||
|
||
assertEquals(2, sent.size()); | ||
Mail german = sent.get(1); | ||
assertEquals("Test", german.getSubject()); | ||
assertEquals("Hallo Lu!", german.getText()); | ||
} | ||
|
||
@CheckedTemplate | ||
static class Templates { | ||
|
||
static native MailTemplateInstance hello(String name); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters