-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Greatly simplify TemplateInstance passing of locale and renderArgs
Fixes localisation via type-safe messages for emails
- Loading branch information
Showing
6 changed files
with
67 additions
and
114 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package io.quarkiverse.renarde.test; | ||
|
||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
|
@@ -16,11 +18,15 @@ | |
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.renarde.Controller; | ||
import io.quarkiverse.renarde.util.I18N; | ||
import io.quarkus.mailer.Mail; | ||
import io.quarkus.mailer.MailTemplate.MailTemplateInstance; | ||
import io.quarkus.mailer.MockMailbox; | ||
import io.quarkus.qute.CheckedTemplate; | ||
import io.quarkus.qute.TemplateInstance; | ||
import io.quarkus.qute.i18n.Message; | ||
|
@@ -67,6 +73,9 @@ public class LanguageTest { | |
+ "{m:my.params('STEF')}\n" | ||
+ "{m:missing}"), | ||
"templates/MyController/typeUnsafe.txt") | ||
.addAsResource(new StringAsset("{m:my_greeting}\n" | ||
+ "{msg:my_greeting}"), | ||
"templates/MyController/mail.txt") | ||
|
||
.addAsResource(new StringAsset("quarkus.locales=en,fr\n" | ||
+ "quarkus.default-locale=en"), "application.properties") | ||
|
@@ -75,6 +84,9 @@ public class LanguageTest { | |
@TestHTTPResource | ||
URL url; | ||
|
||
@Inject | ||
MockMailbox mailbox; | ||
|
||
@Test | ||
public void testDefaultLanguage() { | ||
RestAssured | ||
|
@@ -197,6 +209,30 @@ public void testTypeUnsafeLanguage() { | |
.statusCode(500); | ||
} | ||
|
||
@Test | ||
public void testMail() { | ||
mailbox.clear(); | ||
RestAssured | ||
.get("/mail").then() | ||
.statusCode(200) | ||
.body(Matchers.is("OK")); | ||
List<Mail> mails = mailbox.getMailsSentTo("[email protected]"); | ||
Assertions.assertEquals(1, mails.size()); | ||
Assertions.assertEquals("english message\nenglish message", mails.get(0).getText()); | ||
|
||
mailbox.clear(); | ||
RestAssured | ||
.given() | ||
.cookie(I18N.LOCALE_COOKIE_NAME, "fr") | ||
.get("/mail").then() | ||
.statusCode(200) | ||
.body(Matchers.is("OK")); | ||
|
||
mails = mailbox.getMailsSentTo("[email protected]"); | ||
Assertions.assertEquals(1, mails.size()); | ||
Assertions.assertEquals("message français\nmessage français", mails.get(0).getText()); | ||
} | ||
|
||
@Test | ||
public void testValidationLanguage() { | ||
RestAssured | ||
|
@@ -220,6 +256,8 @@ public static class Templates { | |
public static native TemplateInstance qute(); | ||
|
||
public static native TemplateInstance typeUnsafe(Object val); | ||
|
||
public static native MailTemplateInstance mail(); | ||
} | ||
|
||
@Path("/qute") | ||
|
@@ -258,6 +296,12 @@ public String validation(@NotEmpty @RestForm String param) { | |
return validation.getError("param"); | ||
} | ||
|
||
@Path("/mail") | ||
public String mail() { | ||
Templates.mail().to("[email protected]").send().await().indefinitely(); | ||
return "OK"; | ||
} | ||
|
||
@Path("/lang") | ||
public String lang() { | ||
return i18n.getLanguage(); | ||
|
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
47 changes: 0 additions & 47 deletions
47
runtime/src/main/java/io/quarkiverse/renarde/util/TemplateResponseHandler.java
This file was deleted.
Oops, something went wrong.