quarkiverse / quarkus-renarde

Server-side Web Framework with Qute templating, magic/easier controllers, auth, reverse-routing
Apache License 2.0
78 stars 19 forks source link

Locale is not set in testing #177

Closed gbourant closed 11 months ago

gbourant commented 11 months ago

I'm testing the following service which sends Qute emails with i18n messages.

class AuthService {
 public void sendVerificationEmail(String email) {
  // sends Qute emails with i18n messages
 }
}

The email template is using i18n messages but i get the error java.lang.NullPointerException: Cannot invoke "java.util.Locale.getLanguage()" because "this.locale" is null.

This is caused because the locale is set by Filters.filterRequest(ResteasyReactiveContainerRequestContext requestContext, HttpServerRequest req) which in it's turn calls i18n.readLanguageCookie() and in my case i do not make any http request, i'm testing directly the AuthService.

FroMage commented 11 months ago

Ah. Well, it's true that an NPE is not good. I could start it with the default locale. But I also think that mails won't use the request locale if it's overridden, because there's no hook yet. I have to fix this.

FroMage commented 11 months ago

I've filed https://github.com/quarkusio/quarkus/issues/36749 for the Qute side to add an SPI. I'll fix the NPE for now, but it won't allow you to use the locale cookie or even request headers from emails without explicitely setting the locale on MailTemplateInstance.