-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
MessageBundleExpressionValidationTest.java
68 lines (55 loc) · 2.42 KB
/
MessageBundleExpressionValidationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package io.quarkus.qute.deployment.i18n;
import static org.junit.jupiter.api.Assertions.assertTrue;
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.TemplateException;
import io.quarkus.qute.TemplateGlobal;
import io.quarkus.qute.i18n.Message;
import io.quarkus.qute.i18n.MessageBundle;
import io.quarkus.test.QuarkusUnitTest;
public class MessageBundleExpressionValidationTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(WrongBundle.class, Item.class, MyGlobals.class)
.addAsResource(new StringAsset(
// foo is not a parameter of WrongBundle.hello()
"hello=Hallo {foo}!"),
"messages/msg_de.properties"))
.assertException(t -> {
Throwable e = t;
TemplateException te = null;
while (e != null) {
if (e instanceof TemplateException) {
te = (TemplateException) e;
break;
}
e = e.getCause();
}
if (te == null) {
fail("No template exception thrown: " + t);
}
assertTrue(te.getMessage().contains("Found incorrect expressions (5)"), te.getMessage());
assertTrue(te.getMessage().contains("item.foo"), te.getMessage());
assertTrue(te.getMessage().contains("bar"), te.getMessage());
assertTrue(te.getMessage().contains("foo"), te.getMessage());
assertTrue(te.getMessage().contains("baf"), te.getMessage());
assertTrue(te.getMessage().contains("it.baz"), te.getMessage());
});
@Test
public void testValidation() {
fail();
}
@MessageBundle
public interface WrongBundle {
// item has no "foo" property, "bar" and "baf" are not parameters, string has no "baz" property
@Message("Hello {item.foo} {bar} {#each item.names}{it}{it.baz}{it_hasNext}{baf}{/each}{level}")
String hello(Item item);
}
@TemplateGlobal
static class MyGlobals {
static int level = 5;
}
}