-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 #12428 from mkouba/issue-7376
Qute type-safe templates: generate optimized value resolvers
- Loading branch information
Showing
5 changed files
with
305 additions
and
105 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
79 changes: 79 additions & 0 deletions
79
...deployment/src/test/java/io/quarkus/qute/deployment/generatedresolvers/HierarchyTest.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,79 @@ | ||
package io.quarkus.qute.deployment.generatedresolvers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.Engine; | ||
import io.quarkus.qute.Template; | ||
import io.quarkus.qute.TemplateData; | ||
import io.quarkus.qute.ValueResolver; | ||
import io.quarkus.qute.generator.ValueResolverGenerator; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class HierarchyTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Foo.class, Bar.class) | ||
.addAsResource(new StringAsset("{foo.name}"), "templates/test.html")); | ||
|
||
@Inject | ||
Template test; | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Test | ||
public void testGeneratedResolvers() { | ||
List<ValueResolver> resolvers = engine.getValueResolvers(); | ||
ValueResolver fooResolver = null; | ||
ValueResolver barResolver = null; | ||
for (ValueResolver valueResolver : resolvers) { | ||
if (valueResolver.getClass().getName().endsWith(ValueResolverGenerator.SUFFIX) | ||
&& valueResolver.getClass().getName().contains("Foo")) { | ||
fooResolver = valueResolver; | ||
} | ||
if (valueResolver.getClass().getName().endsWith(ValueResolverGenerator.SUFFIX) | ||
&& valueResolver.getClass().getName().contains("Bar")) { | ||
barResolver = valueResolver; | ||
} | ||
} | ||
assertNotNull(fooResolver); | ||
assertNotNull(barResolver); | ||
assertTrue(barResolver.getPriority() > fooResolver.getPriority(), "Bar resolver priority " + barResolver.getPriority() | ||
+ " is not higher than Foo resolver priority " + fooResolver.getPriority()); | ||
assertEquals("bar", test.data("foo", new Bar()).render()); | ||
} | ||
|
||
@TemplateData | ||
public static class Foo { | ||
|
||
public String getName() { | ||
return "foo"; | ||
} | ||
|
||
} | ||
|
||
@TemplateData | ||
public static class Bar extends Foo { | ||
|
||
@Override | ||
public String getName() { | ||
return "bar"; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.