-
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.
Qute - Validate DataNamespace expression if var has param declaration
Resolves: #20771 DataNamespace is currently not validated, this PR adds validation if parameter declaration is bound to the variable.
- Loading branch information
1 parent
50333c9
commit a4b40ed
Showing
10 changed files
with
441 additions
and
40 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
47 changes: 47 additions & 0 deletions
47
...est/java/io/quarkus/qute/deployment/typesafe/DataNamespaceArrayValidationFailureTest.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,47 @@ | ||
package io.quarkus.qute.deployment.typesafe; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
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.test.QuarkusUnitTest; | ||
|
||
public class DataNamespaceArrayValidationFailureTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Item.class, OtherItem.class) | ||
.addAsResource(new StringAsset( | ||
"{@io.quarkus.qute.deployment.typesafe.Item item}\n" + | ||
"{item.name}\n" + | ||
" {#for item in item.otherItems}\n" + | ||
" {data:item.otherItems[0].name}\n" + | ||
" {/for}\n"), | ||
"templates/item.html")) | ||
.assertException(t -> { | ||
Throwable e = t; | ||
TemplateException te = null; | ||
while (e != null) { | ||
if (e instanceof TemplateException) { | ||
te = (TemplateException) e; | ||
break; | ||
} | ||
e = e.getCause(); | ||
} | ||
assertNotNull(te); | ||
assertTrue( | ||
te.getMessage().contains( | ||
"Property/method [name] not found on class [io.quarkus.qute.deployment.typesafe.OtherItem]"), | ||
te.getMessage()); | ||
}); | ||
|
||
@Test | ||
public void test() { | ||
fail(); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...est/java/io/quarkus/qute/deployment/typesafe/DataNamespaceCheckedTemplateFailureTest.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.typesafe; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
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.CheckedTemplate; | ||
import io.quarkus.qute.TemplateException; | ||
import io.quarkus.qute.TemplateInstance; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DataNamespaceCheckedTemplateFailureTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Templates.class, Item.class, OtherItem.class) | ||
.addAsResource(new StringAsset("Hello {data:item.unknownProperty}!"), | ||
"templates/DataNamespaceCheckedTemplateFailureTest/greetings.txt")) | ||
.assertException(t -> { | ||
Throwable e = t; | ||
TemplateException te = null; | ||
while (e != null) { | ||
if (e instanceof TemplateException) { | ||
te = (TemplateException) e; | ||
break; | ||
} | ||
e = e.getCause(); | ||
} | ||
assertNotNull(te); | ||
assertTrue(te.getMessage().contains( | ||
"Property/method [unknownProperty] not found on class [io.quarkus.qute.deployment.typesafe.Item] nor handled by an extension method"), | ||
te.getMessage()); | ||
}); | ||
|
||
@Test | ||
public void test() { | ||
fail(); | ||
} | ||
|
||
@CheckedTemplate | ||
public static class Templates { | ||
|
||
static native TemplateInstance greetings(Item item); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.