-
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 #23473 from mkouba/issue-19617
Type-safe message bundles - add a missing validation for localized files
- Loading branch information
Showing
6 changed files
with
251 additions
and
6 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
55 changes: 55 additions & 0 deletions
55
...c/test/java/io/quarkus/qute/deployment/i18n/LocalizedBundleDefaultLocaleConflictTest.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,55 @@ | ||
package io.quarkus.qute.deployment.i18n; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.deployment.MessageBundleException; | ||
import io.quarkus.qute.i18n.Localized; | ||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
import io.quarkus.runtime.util.ExceptionUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class LocalizedBundleDefaultLocaleConflictTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(Messages.class, EnMessages.class)) | ||
.overrideConfigKey("quarkus.default-locale", "en") | ||
.assertException(t -> { | ||
Throwable rootCause = ExceptionUtil.getRootCause(t); | ||
if (rootCause instanceof MessageBundleException) { | ||
assertEquals( | ||
"Locale of [io.quarkus.qute.deployment.i18n.LocalizedBundleDefaultLocaleConflictTest$EnMessages] conflicts with the locale [en] of the default message bundle [io.quarkus.qute.deployment.i18n.LocalizedBundleDefaultLocaleConflictTest$Messages]", | ||
rootCause.getMessage()); | ||
} else { | ||
fail("No message bundle exception thrown: " + t); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testValidation() { | ||
fail(); | ||
} | ||
|
||
@MessageBundle | ||
public interface Messages { | ||
|
||
@Message("Ahoj svete!") | ||
String helloWorld(); | ||
|
||
} | ||
|
||
@Localized("en") | ||
public interface EnMessages extends Messages { | ||
|
||
@Message("Hello world!") | ||
String helloWorld(); | ||
|
||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...ment/src/test/java/io/quarkus/qute/deployment/i18n/LocalizedBundleLocaleConflictTest.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,61 @@ | ||
package io.quarkus.qute.deployment.i18n; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.deployment.MessageBundleException; | ||
import io.quarkus.qute.i18n.Localized; | ||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
import io.quarkus.runtime.util.ExceptionUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class LocalizedBundleLocaleConflictTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(Messages.class, EnMessages.class, AnotherEnMessages.class)) | ||
.overrideConfigKey("quarkus.default-locale", "cs") | ||
.assertException(t -> { | ||
Throwable rootCause = ExceptionUtil.getRootCause(t); | ||
if (rootCause instanceof MessageBundleException) { | ||
assertTrue(rootCause.getMessage().contains("a localized message bundle interface exists for locale [en]")); | ||
} else { | ||
fail("No message bundle exception thrown: " + t); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testValidation() { | ||
fail(); | ||
} | ||
|
||
@MessageBundle | ||
public interface Messages { | ||
|
||
@Message("Ahoj svete!") | ||
String helloWorld(); | ||
|
||
} | ||
|
||
@Localized("en") | ||
public interface EnMessages extends Messages { | ||
|
||
@Message("Hello world!") | ||
String helloWorld(); | ||
|
||
} | ||
|
||
@Localized("en") | ||
public interface AnotherEnMessages extends Messages { | ||
|
||
@Message("Hello world!") | ||
String helloWorld(); | ||
|
||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
.../src/test/java/io/quarkus/qute/deployment/i18n/LocalizedFileBundleLocaleConflictTest.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,61 @@ | ||
package io.quarkus.qute.deployment.i18n; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.deployment.MessageBundleException; | ||
import io.quarkus.qute.i18n.Localized; | ||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
import io.quarkus.runtime.util.ExceptionUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class LocalizedFileBundleLocaleConflictTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Messages.class, EnMessages.class) | ||
// This localized file conflicts with the default locale | ||
.addAsResource(new StringAsset( | ||
"hello=Hello!"), | ||
"messages/msg_en.properties")) | ||
.overrideConfigKey("quarkus.default-locale", "cs") | ||
.assertException(t -> { | ||
Throwable rootCause = ExceptionUtil.getRootCause(t); | ||
if (rootCause instanceof MessageBundleException) { | ||
assertEquals( | ||
"Cannot register [msg_en.properties] - a localized message bundle interface exists for locale [en]: io.quarkus.qute.deployment.i18n.LocalizedFileBundleLocaleConflictTest$EnMessages", | ||
rootCause.getMessage()); | ||
} else { | ||
fail("No message bundle exception thrown: " + t); | ||
} | ||
|
||
});; | ||
|
||
@Test | ||
public void testValidation() { | ||
fail(); | ||
} | ||
|
||
@MessageBundle | ||
public interface Messages { | ||
|
||
@Message("Ahoj svete!") | ||
String helloWorld(); | ||
|
||
} | ||
|
||
@Localized("en") | ||
public interface EnMessages extends Messages { | ||
|
||
@Message("Hello world!") | ||
String helloWorld(); | ||
|
||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...src/test/java/io/quarkus/qute/deployment/i18n/LocalizedFileDefaultLocaleConflictTest.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,51 @@ | ||
package io.quarkus.qute.deployment.i18n; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.deployment.MessageBundleException; | ||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
import io.quarkus.runtime.util.ExceptionUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class LocalizedFileDefaultLocaleConflictTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Messages.class) | ||
// This localized file conflicts with the default locale | ||
.addAsResource(new StringAsset( | ||
"hello=Hello!"), | ||
"messages/msg_en.properties")) | ||
.overrideConfigKey("quarkus.default-locale", "en") | ||
.assertException(t -> { | ||
Throwable rootCause = ExceptionUtil.getRootCause(t); | ||
if (rootCause instanceof MessageBundleException) { | ||
assertEquals( | ||
"Locale of [msg_en.properties] conflicts with the locale [en] of the default message bundle [io.quarkus.qute.deployment.i18n.LocalizedFileDefaultLocaleConflictTest$Messages]", | ||
rootCause.getMessage()); | ||
} else { | ||
fail("No message bundle exception thrown: " + t); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testValidation() { | ||
fail(); | ||
} | ||
|
||
@MessageBundle | ||
public interface Messages { | ||
|
||
@Message("Hello world!") | ||
String helloWorld(); | ||
|
||
} | ||
|
||
} |
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