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: add Singleton scope to a Named Java record
- so that it can be easily used as an intermediate CDI bean for beans that are not annotated with jakarta.inject.Named - related to quarkusio#41932
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 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
52 changes: 52 additions & 0 deletions
52
...ions/qute/deployment/src/test/java/io/quarkus/qute/deployment/inject/NamedRecordTest.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,52 @@ | ||
package io.quarkus.qute.deployment.inject; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.Engine; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class NamedRecordTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(Beans.class, ListProducer.class) | ||
.addAsResource( | ||
new StringAsset( | ||
"{#each cdi:beans.names}{it}::{/each}"), | ||
"templates/foo.html")); | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Test | ||
public void testResult() { | ||
assertEquals("Jachym::Vojtech::Ondrej::", engine.getTemplate("foo").render()); | ||
} | ||
|
||
// @Singleton is added automatically | ||
@Named | ||
public record Beans(List<String> names) { | ||
} | ||
|
||
@Singleton | ||
public static class ListProducer { | ||
|
||
@Produces | ||
List<String> names() { | ||
return List.of("Jachym", "Vojtech", "Ondrej"); | ||
} | ||
} | ||
|
||
} |