forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qute: make it possible to supply a template backed by a build item
- resolves quarkusio#41386
- Loading branch information
Showing
6 changed files
with
222 additions
and
16 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
54 changes: 54 additions & 0 deletions
54
...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,54 @@ | ||
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(new TemplatePathBuildItem("hi.txt", "test-ext", "Hello {name}!")); | ||
} | ||
}).produces(TemplatePathBuildItem.class) | ||
.build(); | ||
|
||
builder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(new TemplatePathBuildItem("hi.txt", "test-ext", "Hello {name}!")); | ||
} | ||
}).produces(TemplatePathBuildItem.class) | ||
.build(); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
fail(); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
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(new TemplatePathBuildItem("foo/hello.txt", "test-ext", "Hello {name}!")); | ||
} | ||
}).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()); | ||
} | ||
|
||
} |
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