-
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 #41391 from mkouba/issue-41386
Qute: make it possible to supply a template backed by a build item
- Loading branch information
Showing
6 changed files
with
313 additions
and
14 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
60 changes: 60 additions & 0 deletions
60
...va/io/quarkus/qute/deployment/builditemtemplate/AdditionalTemplatePathDuplicatesTest.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,60 @@ | ||
package io.quarkus.qute.deployment.builditemtemplate; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.qute.deployment.TemplatePathBuildItem; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class AdditionalTemplatePathDuplicatesTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addAsResource(new StringAsset("Hi {name}!"), "templates/hi.txt")) | ||
.addBuildChainCustomizer(buildCustomizer()) | ||
.setExpectedException(IllegalStateException.class, true); | ||
|
||
static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<BuildChainBuilder>() { | ||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(TemplatePathBuildItem.builder() | ||
.path("hi.txt") | ||
.extensionInfo("test-ext") | ||
.content("Hello {name}!").build()); | ||
} | ||
}).produces(TemplatePathBuildItem.class) | ||
.build(); | ||
|
||
builder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(TemplatePathBuildItem.builder() | ||
.path("hi.txt") | ||
.extensionInfo("test-ext") | ||
.content("Hello {name}!").build()); | ||
} | ||
}).produces(TemplatePathBuildItem.class) | ||
.build(); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
fail(); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...rc/test/java/io/quarkus/qute/deployment/builditemtemplate/AdditionalTemplatePathTest.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,59 @@ | ||
package io.quarkus.qute.deployment.builditemtemplate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.qute.Engine; | ||
import io.quarkus.qute.deployment.TemplatePathBuildItem; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class AdditionalTemplatePathTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addAsResource(new StringAsset("Hi {name}!"), "templates/hi.txt") | ||
.addAsResource(new StringAsset("And... {#include foo/hello /}"), "templates/include.txt")) | ||
.addBuildChainCustomizer(buildCustomizer()); | ||
|
||
static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<BuildChainBuilder>() { | ||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(TemplatePathBuildItem.builder() | ||
.path("foo/hello.txt") | ||
.extensionInfo("test-ext") | ||
.content("Hello {name}!").build()); | ||
} | ||
}).produces(TemplatePathBuildItem.class) | ||
.build(); | ||
|
||
} | ||
}; | ||
} | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Test | ||
public void testTemplate() { | ||
assertEquals("Hi M!", engine.getTemplate("hi").data("name", "M").render()); | ||
assertEquals("Hello M!", engine.getTemplate("foo/hello.txt").data("name", "M").render()); | ||
assertEquals("Hello M!", engine.getTemplate("foo/hello").data("name", "M").render()); | ||
assertEquals("And... Hello M!", engine.getTemplate("include").data("name", "M").render()); | ||
} | ||
|
||
} |
Oops, something went wrong.