diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/AQualifier.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/AQualifier.java new file mode 100644 index 000000000..3dcd0f2c9 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/AQualifier.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.bean; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.enterprise.util.AnnotationLiteral; +import jakarta.inject.Qualifier; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +public @interface AQualifier { + final class Literal extends AnnotationLiteral implements AQualifier { + static final AQualifier INSTANCE = new Literal(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/EagerBean.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/EagerBean.java new file mode 100644 index 000000000..efd5e3b32 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/EagerBean.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.bean; + +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Eager; + +@ApplicationScoped +@Eager +public class EagerBean { + public static boolean constructed = false; + + @PostConstruct + public void setup() { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/EagerBeanTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/EagerBeanTest.java new file mode 100644 index 000000000..b66a1cb37 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/EagerBeanTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.bean; + +import static org.jboss.cdi.tck.cdi.Sections.BEAN; +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INITIALIZATION; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class EagerBeanTest extends AbstractTest { + @Deployment + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClassPackage(EagerBeanTest.class) + .build(); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "aa") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "b") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "c") + public void testUnqualified() { + assertTrue(EagerBean.constructed); + + assertFalse(LazyBean.constructed); + LazyBean reference = getContextualReference(LazyBean.class); + assertNotNull(reference); + assertFalse(LazyBean.constructed); + assertNotNull(reference.toString()); + assertTrue(LazyBean.constructed); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "aa") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "b") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "c") + public void testQualified() { + assertTrue(QualifiedEagerBean.constructed); + + assertFalse(QualifiedLazyBean.constructed); + QualifiedLazyBean reference = getContextualReference(QualifiedLazyBean.class, AQualifier.Literal.INSTANCE); + assertNotNull(reference); + assertFalse(QualifiedLazyBean.constructed); + assertNotNull(reference.toString()); + assertTrue(QualifiedLazyBean.constructed); + } + + @Test + @SpecAssertion(section = BEAN, id = "bf") + public void testMetadata() { + assertTrue(getUniqueBean(EagerBean.class).isEager()); + assertTrue(getUniqueBean(QualifiedEagerBean.class, AQualifier.Literal.INSTANCE).isEager()); + + assertFalse(getUniqueBean(LazyBean.class).isEager()); + assertFalse(getUniqueBean(QualifiedLazyBean.class, AQualifier.Literal.INSTANCE).isEager()); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/LazyBean.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/LazyBean.java new file mode 100644 index 000000000..f16b114bb --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/LazyBean.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.bean; + +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class LazyBean { + public static boolean constructed = false; + + @PostConstruct + public void setup() { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/QualifiedEagerBean.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/QualifiedEagerBean.java new file mode 100644 index 000000000..7e3511a76 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/QualifiedEagerBean.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.bean; + +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Eager; + +@ApplicationScoped +@Eager +@AQualifier +public class QualifiedEagerBean { + public static boolean constructed = false; + + @PostConstruct + public void setup() { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/QualifiedLazyBean.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/QualifiedLazyBean.java new file mode 100644 index 000000000..7fec84e08 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/bean/QualifiedLazyBean.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.bean; + +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.ApplicationScoped; + +@ApplicationScoped +@AQualifier +public class QualifiedLazyBean { + public static boolean constructed = false; + + @PostConstruct + public void setup() { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/dependent/DependentEagerBean.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/dependent/DependentEagerBean.java new file mode 100644 index 000000000..d5f2d64c9 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/dependent/DependentEagerBean.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.broken.dependent; + +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.context.Eager; + +@Dependent +@Eager +public class DependentEagerBean { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/dependent/DependentEagerBeanTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/dependent/DependentEagerBeanTest.java new file mode 100644 index 000000000..97fce57ab --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/dependent/DependentEagerBeanTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.broken.dependent; + +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INITIALIZATION; + +import jakarta.enterprise.inject.spi.DefinitionException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.ShouldThrowException; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class DependentEagerBeanTest extends AbstractTest { + @Deployment + @ShouldThrowException(DefinitionException.class) + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClassPackage(DependentEagerBeanTest.class) + .build(); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "db") + public void trigger() { + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/EagerClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/EagerClass.java new file mode 100644 index 000000000..fb5ad0259 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/EagerClass.java @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.broken.requestScoped; + +public class EagerClass { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/ProducerMethod.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/ProducerMethod.java new file mode 100644 index 000000000..e0fb54c71 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/ProducerMethod.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.broken.requestScoped; + +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.context.Eager; +import jakarta.enterprise.context.RequestScoped; +import jakarta.enterprise.inject.Produces; + +@Dependent +public class ProducerMethod { + @RequestScoped + @Eager + @Produces + public EagerClass produceEager() { + return new EagerClass(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/RequestScopedEagerBeanTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/RequestScopedEagerBeanTest.java new file mode 100644 index 000000000..4d7e95ac2 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/broken/requestScoped/RequestScopedEagerBeanTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.broken.requestScoped; + +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INITIALIZATION; + +import jakarta.enterprise.inject.spi.DefinitionException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.ShouldThrowException; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class RequestScopedEagerBeanTest extends AbstractTest { + @Deployment + @ShouldThrowException(DefinitionException.class) + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClassPackage(RequestScopedEagerBeanTest.class) + .build(); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "da") + public void trigger() { + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/AQualifier.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/AQualifier.java new file mode 100644 index 000000000..d3f91bc8f --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/AQualifier.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.enterprise.util.AnnotationLiteral; +import jakarta.inject.Qualifier; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +public @interface AQualifier { + final class Literal extends AnnotationLiteral implements AQualifier { + static final AQualifier INSTANCE = new Literal(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerClass.java new file mode 100644 index 000000000..8e547707d --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerClass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +public class EagerClass { + public static boolean constructed = false; + + public EagerClass() { + } + + // the parameter only exists to distinguish a non-default constructor + // that is used to create the contextual instance + // (the client proxy uses the default constructor) + public EagerClass(int unused) { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerProducerField.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerProducerField.java new file mode 100644 index 000000000..8ba9aad41 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerProducerField.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.context.Eager; +import jakarta.enterprise.inject.Produces; + +@Dependent +public class EagerProducerField { + @ApplicationScoped + @Eager + @Produces + public EagerClass produce = new EagerClass(0); +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerProducerFieldTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerProducerFieldTest.java new file mode 100644 index 000000000..b987e5e69 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/EagerProducerFieldTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +import static org.jboss.cdi.tck.cdi.Sections.BEAN; +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INITIALIZATION; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class EagerProducerFieldTest extends AbstractTest { + // note that for this test, each producer field must live in its own bean, to avoid + // initialization of _all_ producer fields when value of _one_ is requested + + @Deployment + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClassPackage(EagerProducerFieldTest.class) + .build(); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "ac") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "b") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "c") + public void testUnqualified() { + assertTrue(EagerClass.constructed); + + assertFalse(LazyClass.constructed); + LazyClass reference = getContextualReference(LazyClass.class); + assertNotNull(reference); + assertFalse(LazyClass.constructed); + assertNotNull(reference.toString()); + assertTrue(LazyClass.constructed); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "ac") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "b") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "c") + public void testQualified() { + assertTrue(QualifiedEagerClass.constructed); + + assertFalse(QualifiedLazyClass.constructed); + QualifiedLazyClass reference = getContextualReference(QualifiedLazyClass.class, AQualifier.Literal.INSTANCE); + assertNotNull(reference); + assertFalse(QualifiedLazyClass.constructed); + assertNotNull(reference.toString()); + assertTrue(QualifiedLazyClass.constructed); + } + + @Test + @SpecAssertion(section = BEAN, id = "bf") + public void testMetadata() { + assertTrue(getUniqueBean(EagerClass.class).isEager()); + assertTrue(getUniqueBean(QualifiedEagerClass.class, AQualifier.Literal.INSTANCE).isEager()); + + assertFalse(getUniqueBean(LazyClass.class).isEager()); + assertFalse(getUniqueBean(QualifiedLazyClass.class, AQualifier.Literal.INSTANCE).isEager()); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/LazyClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/LazyClass.java new file mode 100644 index 000000000..c16ecc000 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/LazyClass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +public class LazyClass { + public static boolean constructed = false; + + public LazyClass() { + } + + // the parameter only exists to distinguish a non-default constructor + // that is used to create the contextual instance + // (the client proxy uses the default constructor) + public LazyClass(int unused) { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/LazyProducerField.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/LazyProducerField.java new file mode 100644 index 000000000..b815d6909 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/LazyProducerField.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.inject.Produces; + +@Dependent +public class LazyProducerField { + @ApplicationScoped + @Produces + public LazyClass produce = new LazyClass(0); +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedEagerClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedEagerClass.java new file mode 100644 index 000000000..3e071ee0d --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedEagerClass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +public class QualifiedEagerClass { + public static boolean constructed = false; + + public QualifiedEagerClass() { + } + + // the parameter only exists to distinguish a non-default constructor + // that is used to create the contextual instance + // (the client proxy uses the default constructor) + public QualifiedEagerClass(int unused) { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedEagerProducerField.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedEagerProducerField.java new file mode 100644 index 000000000..01aaceae1 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedEagerProducerField.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.context.Eager; +import jakarta.enterprise.inject.Produces; + +@Dependent +public class QualifiedEagerProducerField { + @ApplicationScoped + @AQualifier + @Eager + @Produces + public QualifiedEagerClass produce = new QualifiedEagerClass(0); +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedLazyClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedLazyClass.java new file mode 100644 index 000000000..bfb2a4067 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedLazyClass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +public class QualifiedLazyClass { + public static boolean constructed = false; + + public QualifiedLazyClass() { + } + + // the parameter only exists to distinguish a non-default constructor + // that is used to create the contextual instance + // (the client proxy uses the default constructor) + public QualifiedLazyClass(int unused) { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedLazyProducerField.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedLazyProducerField.java new file mode 100644 index 000000000..bdac71aeb --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/field/QualifiedLazyProducerField.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.field; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.inject.Produces; + +@Dependent +public class QualifiedLazyProducerField { + @ApplicationScoped + @AQualifier + @Produces + public QualifiedLazyClass produce = new QualifiedLazyClass(0); +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/AQualifier.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/AQualifier.java new file mode 100644 index 000000000..5910efc5f --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/AQualifier.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.method; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.enterprise.util.AnnotationLiteral; +import jakarta.inject.Qualifier; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +public @interface AQualifier { + final class Literal extends AnnotationLiteral implements AQualifier { + static final AQualifier INSTANCE = new Literal(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/EagerClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/EagerClass.java new file mode 100644 index 000000000..fa7b38d91 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/EagerClass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.method; + +public class EagerClass { + public static boolean constructed = false; + + public EagerClass() { + } + + // the parameter only exists to distinguish a non-default constructor + // that is used to create the contextual instance + // (the client proxy uses the default constructor) + public EagerClass(int unused) { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/EagerProducerMethodTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/EagerProducerMethodTest.java new file mode 100644 index 000000000..aa23df26a --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/EagerProducerMethodTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.method; + +import static org.jboss.cdi.tck.cdi.Sections.BEAN; +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INITIALIZATION; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class EagerProducerMethodTest extends AbstractTest { + @Deployment + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClassPackage(EagerProducerMethodTest.class) + .build(); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "ab") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "b") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "c") + public void testUnqualified() { + assertTrue(EagerClass.constructed); + + assertFalse(LazyClass.constructed); + LazyClass reference = getContextualReference(LazyClass.class); + assertNotNull(reference); + assertFalse(LazyClass.constructed); + assertNotNull(reference.toString()); + assertTrue(LazyClass.constructed); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "ab") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "b") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "c") + public void testQualified() { + assertTrue(QualifiedEagerClass.constructed); + + assertFalse(QualifiedLazyClass.constructed); + QualifiedLazyClass reference = getContextualReference(QualifiedLazyClass.class, AQualifier.Literal.INSTANCE); + assertNotNull(reference); + assertFalse(QualifiedLazyClass.constructed); + assertNotNull(reference.toString()); + assertTrue(QualifiedLazyClass.constructed); + } + + @Test + @SpecAssertion(section = BEAN, id = "bf") + public void testMetadata() { + assertTrue(getUniqueBean(EagerClass.class).isEager()); + assertTrue(getUniqueBean(QualifiedEagerClass.class, AQualifier.Literal.INSTANCE).isEager()); + + assertFalse(getUniqueBean(LazyClass.class).isEager()); + assertFalse(getUniqueBean(QualifiedLazyClass.class, AQualifier.Literal.INSTANCE).isEager()); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/LazyClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/LazyClass.java new file mode 100644 index 000000000..d67ecbd8d --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/LazyClass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.method; + +public class LazyClass { + public static boolean constructed = false; + + public LazyClass() { + } + + // the parameter only exists to distinguish a non-default constructor + // that is used to create the contextual instance + // (the client proxy uses the default constructor) + public LazyClass(int unused) { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/ProducerMethods.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/ProducerMethods.java new file mode 100644 index 000000000..54c764dc1 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/ProducerMethods.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.method; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.context.Eager; +import jakarta.enterprise.inject.Produces; + +@Dependent +public class ProducerMethods { + @ApplicationScoped + @Eager + @Produces + public EagerClass produceEager() { + return new EagerClass(0); + } + + @ApplicationScoped + @Produces + public LazyClass produceLazy() { + return new LazyClass(0); + } + + @ApplicationScoped + @AQualifier + @Eager + @Produces + public QualifiedEagerClass produceQualifiedEager() { + return new QualifiedEagerClass(0); + } + + @ApplicationScoped + @AQualifier + @Produces + public QualifiedLazyClass produceQualifiedLazy() { + return new QualifiedLazyClass(0); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/QualifiedEagerClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/QualifiedEagerClass.java new file mode 100644 index 000000000..59478568e --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/QualifiedEagerClass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.method; + +public class QualifiedEagerClass { + public static boolean constructed = false; + + public QualifiedEagerClass() { + } + + // the parameter only exists to distinguish a non-default constructor + // that is used to create the contextual instance + // (the client proxy uses the default constructor) + public QualifiedEagerClass(int unused) { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/QualifiedLazyClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/QualifiedLazyClass.java new file mode 100644 index 000000000..1c91d5dd4 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/producer/method/QualifiedLazyClass.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.producer.method; + +public class QualifiedLazyClass { + public static boolean constructed = false; + + public QualifiedLazyClass() { + } + + // the parameter only exists to distinguish a non-default constructor + // that is used to create the contextual instance + // (the client proxy uses the default constructor) + public QualifiedLazyClass(int unused) { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotype.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotype.java new file mode 100644 index 000000000..aad430655 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotype.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Eager; +import jakarta.enterprise.inject.Stereotype; + +@Stereotype +@Eager +@ApplicationScoped +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface EagerStereotype { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotypeBean.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotypeBean.java new file mode 100644 index 000000000..176adeb5c --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotypeBean.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype; + +import jakarta.annotation.PostConstruct; + +@EagerStereotype +public class EagerStereotypeBean { + public static boolean constructed = false; + + @PostConstruct + public void setup() { + constructed = true; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotypeBeanTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotypeBeanTest.java new file mode 100644 index 000000000..76999042c --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/EagerStereotypeBeanTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype; + +import static org.jboss.cdi.tck.cdi.Sections.BEAN; +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INIT_STEREOTYPE; +import static org.jboss.cdi.tck.cdi.Sections.STEREOTYPES; +import static org.testng.Assert.assertTrue; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class EagerStereotypeBeanTest extends AbstractTest { + @Deployment + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClassPackage(EagerStereotypeBeanTest.class) + .build(); + } + + @Test + @SpecAssertion(section = STEREOTYPES, id = "ae") + @SpecAssertion(section = EAGER_INIT_STEREOTYPE, id = "a") + public void test() { + assertTrue(EagerStereotypeBean.constructed); + } + + @Test + @SpecAssertion(section = BEAN, id = "bf") + public void testMetadata() { + assertTrue(getUniqueBean(EagerStereotypeBean.class).isEager()); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/DependentEagerBean.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/DependentEagerBean.java new file mode 100644 index 000000000..6323387ff --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/DependentEagerBean.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype.broken.dependentAndEagerOnStereotype; + +import jakarta.enterprise.context.ApplicationScoped; + +@ApplicationScoped +@EagerDependentStereotype +public class DependentEagerBean { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/EagerAndDependentOnStereotypeTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/EagerAndDependentOnStereotypeTest.java new file mode 100644 index 000000000..67e0f9b0d --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/EagerAndDependentOnStereotypeTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype.broken.dependentAndEagerOnStereotype; + +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INIT_STEREOTYPE; + +import jakarta.enterprise.inject.spi.DefinitionException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.ShouldThrowException; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class EagerAndDependentOnStereotypeTest extends AbstractTest { + @Deployment + @ShouldThrowException(DefinitionException.class) + public static WebArchive deploy() { + return new WebArchiveBuilder() + .withTestClassPackage(EagerAndDependentOnStereotypeTest.class) + .build(); + } + + @Test + @SpecAssertion(section = EAGER_INIT_STEREOTYPE, id = "b") + public void trigger() { + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/EagerDependentStereotype.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/EagerDependentStereotype.java new file mode 100644 index 000000000..027680fad --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentAndEagerOnStereotype/EagerDependentStereotype.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype.broken.dependentAndEagerOnStereotype; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.context.Eager; +import jakarta.enterprise.inject.Stereotype; + +@Stereotype +@Eager +@Dependent +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface EagerDependentStereotype { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/DependentEagerBean.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/DependentEagerBean.java new file mode 100644 index 000000000..0a9ee8775 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/DependentEagerBean.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype.broken.dependentOnBeanEagerOnStereotype; + +import jakarta.enterprise.context.Dependent; + +@Dependent +@EagerStereotype +public class DependentEagerBean { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/DependentEagerBeanTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/DependentEagerBeanTest.java new file mode 100644 index 000000000..ddd977276 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/DependentEagerBeanTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype.broken.dependentOnBeanEagerOnStereotype; + +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INITIALIZATION; + +import jakarta.enterprise.inject.spi.DefinitionException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.ShouldThrowException; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class DependentEagerBeanTest extends AbstractTest { + @Deployment + @ShouldThrowException(DefinitionException.class) + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClassPackage(DependentEagerBeanTest.class) + .build(); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "db") + public void trigger() { + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/EagerStereotype.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/EagerStereotype.java new file mode 100644 index 000000000..c22c4a8f5 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/stereotype/broken/dependentOnBeanEagerOnStereotype/EagerStereotype.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.stereotype.broken.dependentOnBeanEagerOnStereotype; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.enterprise.context.Eager; +import jakarta.enterprise.inject.Stereotype; + +@Stereotype +@Eager +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface EagerStereotype { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/AQualifier.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/AQualifier.java new file mode 100644 index 000000000..b2a1933f6 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/AQualifier.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.enterprise.util.AnnotationLiteral; +import jakarta.inject.Qualifier; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +public @interface AQualifier { + final class Literal extends AnnotationLiteral implements AQualifier { + static final AQualifier INSTANCE = new Literal(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerClass.java new file mode 100644 index 000000000..cbe574bca --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerClass.java @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +public class EagerClass { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerClassCreator.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerClassCreator.java new file mode 100644 index 000000000..cd31f6ba3 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerClassCreator.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +import jakarta.enterprise.inject.build.compatible.spi.Parameters; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticBeanCreator; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticInjections; + +public class EagerClassCreator implements SyntheticBeanCreator { + static boolean created = false; + + @Override + public EagerClass create(SyntheticInjections lookup, Parameters params) { + created = true; + return new EagerClass(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerSyntheticBeanTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerSyntheticBeanTest.java new file mode 100644 index 000000000..eb9158410 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/EagerSyntheticBeanTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +import static org.jboss.cdi.tck.cdi.Sections.BEAN; +import static org.jboss.cdi.tck.cdi.Sections.EAGER_INITIALIZATION; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class EagerSyntheticBeanTest extends AbstractTest { + @Deployment + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClassPackage(EagerSyntheticBeanTest.class) + .withBuildCompatibleExtension(SyntheticBeanExtension.class) + .build(); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "ad") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "b") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "c") + public void testUnqualified() { + assertTrue(EagerClassCreator.created); + + assertFalse(LazyClassCreator.created); + LazyClass reference = getContextualReference(LazyClass.class); + assertNotNull(reference); + assertFalse(LazyClassCreator.created); + assertNotNull(reference.toString()); + assertTrue(LazyClassCreator.created); + } + + @Test + @SpecAssertion(section = EAGER_INITIALIZATION, id = "ad") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "b") + @SpecAssertion(section = EAGER_INITIALIZATION, id = "c") + public void testQualified() { + assertTrue(QualifiedEagerClassCreator.created); + + assertFalse(QualifiedLazyClassCreator.created); + QualifiedLazyClass reference = getContextualReference(QualifiedLazyClass.class, AQualifier.Literal.INSTANCE); + assertNotNull(reference); + assertFalse(QualifiedLazyClassCreator.created); + assertNotNull(reference.toString()); + assertTrue(QualifiedLazyClassCreator.created); + } + + @Test + @SpecAssertion(section = BEAN, id = "bf") + public void testMetadata() { + assertTrue(getUniqueBean(EagerClass.class).isEager()); + assertTrue(getUniqueBean(QualifiedEagerClass.class, AQualifier.Literal.INSTANCE).isEager()); + + assertFalse(getUniqueBean(LazyClass.class).isEager()); + assertFalse(getUniqueBean(QualifiedLazyClass.class, AQualifier.Literal.INSTANCE).isEager()); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/LazyClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/LazyClass.java new file mode 100644 index 000000000..18d83a53d --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/LazyClass.java @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +public class LazyClass { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/LazyClassCreator.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/LazyClassCreator.java new file mode 100644 index 000000000..157418c6b --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/LazyClassCreator.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +import jakarta.enterprise.inject.build.compatible.spi.Parameters; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticBeanCreator; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticInjections; + +public class LazyClassCreator implements SyntheticBeanCreator { + static boolean created = false; + + @Override + public LazyClass create(SyntheticInjections lookup, Parameters params) { + created = true; + return new LazyClass(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedEagerClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedEagerClass.java new file mode 100644 index 000000000..2de0680e4 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedEagerClass.java @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +public class QualifiedEagerClass { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedEagerClassCreator.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedEagerClassCreator.java new file mode 100644 index 000000000..2feb114ed --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedEagerClassCreator.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +import jakarta.enterprise.inject.build.compatible.spi.Parameters; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticBeanCreator; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticInjections; + +public class QualifiedEagerClassCreator implements SyntheticBeanCreator { + static boolean created = false; + + @Override + public QualifiedEagerClass create(SyntheticInjections lookup, Parameters params) { + created = true; + return new QualifiedEagerClass(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedLazyClass.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedLazyClass.java new file mode 100644 index 000000000..f05b9d4cd --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedLazyClass.java @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +public class QualifiedLazyClass { +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedLazyClassCreator.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedLazyClassCreator.java new file mode 100644 index 000000000..19fa0d6b3 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/QualifiedLazyClassCreator.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +import jakarta.enterprise.inject.build.compatible.spi.Parameters; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticBeanCreator; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticInjections; + +public class QualifiedLazyClassCreator implements SyntheticBeanCreator { + static boolean created = false; + + @Override + public QualifiedLazyClass create(SyntheticInjections lookup, Parameters params) { + created = true; + return new QualifiedLazyClass(); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/SyntheticBeanExtension.java b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/SyntheticBeanExtension.java new file mode 100644 index 000000000..1d694f003 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/eager/synthetic/bean/SyntheticBeanExtension.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.eager.synthetic.bean; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; +import jakarta.enterprise.inject.build.compatible.spi.Synthesis; +import jakarta.enterprise.inject.build.compatible.spi.SyntheticComponents; + +public class SyntheticBeanExtension implements BuildCompatibleExtension { + @Synthesis + public void synthesize(SyntheticComponents syn) { + syn.addBean(EagerClass.class) + .type(EagerClass.class) + .scope(ApplicationScoped.class) + .eager(true) + .createWith(EagerClassCreator.class); + + syn.addBean(LazyClass.class) + .type(LazyClass.class) + .scope(ApplicationScoped.class) + .eager(false) // not needed, just for extra test coverage + .createWith(LazyClassCreator.class); + + syn.addBean(QualifiedEagerClass.class) + .type(QualifiedEagerClass.class) + .scope(ApplicationScoped.class) + .qualifier(AQualifier.class) + .eager(true) + .createWith(QualifiedEagerClassCreator.class); + + syn.addBean(QualifiedLazyClass.class) + .type(QualifiedLazyClass.class) + .scope(ApplicationScoped.class) + .qualifier(AQualifier.class) + .createWith(QualifiedLazyClassCreator.class); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/reserve/basic/ReserveMetadataTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/reserve/basic/ReserveMetadataTest.java new file mode 100644 index 000000000..427df9db4 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/reserve/basic/ReserveMetadataTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.reserve.basic; + +import static org.jboss.cdi.tck.cdi.Sections.BEAN; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class ReserveMetadataTest extends AbstractTest { + @Deployment + public static WebArchive createTestArchive() { + return new WebArchiveBuilder() + .withTestClass(ReserveMetadataTest.class) + .withClasses(Foo.class, Bar.class, Baz.class, Qux.class) + .build(); + } + + @Test + @SpecAssertion(section = BEAN, id = "be") + public void testMetadata() { + assertTrue(getUniqueBean(Bar.class).isReserve()); + assertFalse(getUniqueBean(Baz.class).isReserve()); + assertFalse(getUniqueBean(Qux.class).isReserve()); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/reserve/selection/stereotype/StereotypeWithReserveSelectedByPriorityTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/reserve/selection/stereotype/StereotypeWithReserveSelectedByPriorityTest.java index f5c8a3a1c..fb9438aa4 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/reserve/selection/stereotype/StereotypeWithReserveSelectedByPriorityTest.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/reserve/selection/stereotype/StereotypeWithReserveSelectedByPriorityTest.java @@ -9,10 +9,17 @@ */ package org.jboss.cdi.tck.tests.reserve.selection.stereotype; +import static org.jboss.cdi.tck.cdi.Sections.BEAN; import static org.jboss.cdi.tck.cdi.Sections.DECLARING_RESERVE; import static org.jboss.cdi.tck.cdi.Sections.DECLARING_SELECTED_RESERVES_APPLICATION; import static org.jboss.cdi.tck.cdi.Sections.STEREOTYPES; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.lang.annotation.Annotation; +import java.util.Set; + +import jakarta.enterprise.inject.spi.Bean; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.cdi.tck.AbstractTest; @@ -46,4 +53,17 @@ public void testStereotypeReserveIsEnabled() { assertEquals(getContextualReference(SomeInterface.class, ProducedByField.Literal.INSTANCE).ping(), "ReserveProducer.producer2"); } + + @Test + @SpecAssertion(section = BEAN, id = "be") + public void testMetadata() { + assertTrue(resolve(SomeInterface.class).isReserve()); + assertTrue(resolve(SomeInterface.class, ProducedByMethod.Literal.INSTANCE).isReserve()); + assertTrue(resolve(SomeInterface.class, ProducedByField.Literal.INSTANCE).isReserve()); + } + + private Bean resolve(Class beanType, Annotation... qualifiers) { + Set> beans = getCurrentBeanContainer().getBeans(beanType, qualifiers); + return getCurrentBeanContainer().resolve(beans); + } } diff --git a/impl/src/main/resources/tck-audit-cdi.xml b/impl/src/main/resources/tck-audit-cdi.xml index 10c814288..1eaec4a34 100644 --- a/impl/src/main/resources/tck-audit-cdi.xml +++ b/impl/src/main/resources/tck-audit-cdi.xml @@ -661,6 +661,49 @@ +
+ + + A bean class of a managed bean, a producer method and a producer field may be annotated |@Eager|. + This annotation marks the bean as _eagerly initialized_. + + + Test with managed bean. + + + Test with producer method. + + + Test with producer field. + + + + + + Contextual instance of an eagerly initialized bean is created no later than at the moment the container fires the |Startup| event. + For example, it is as if an enabled bean existed that declared a synchronous observer with observed event type of |Startup|, no observed event qualifier, priority of |Integer.MIN_VALUE|, and this observer method obtained a contextual instance of the eagerly initialized bean. + + + + Only |@ApplicationScoped| beans may be eagerly initialized. + + + If a bean of any other normal scope or the |@Dependent| pseudo-scope is eagerly initialized, definition error occurs. + + Test with |@RequestScoped| producer method. + + + Test with |@Dependent| managed bean. + + + + If a bean of any other pseudo-scope is eagerly initialized, non-portable behavior results. + Non-portable behavior. + +
+
@@ -679,6 +722,10 @@ A stereotype may specify that all beans with the stereotype are reserves. + + A stereotype may specify that all beans with the stereotype are eagerly initialized. + + A bean may declare zero, one or multiple stereotypes. @@ -826,6 +873,16 @@
+
+ + A stereotype may declare an |@Eager| annotation, which specifies that every bean with the stereotype is eagerly initialized. + + + + If a stereotype declares both |@Eager| and a default scope for which eager initialization is not permitted, the container automatically detects the problem and treats it as a definition error. + +
+
A stereotype may declare other stereotypes. @@ -6646,6 +6703,14 @@ |isAlternative()| must return |true| if the bean is an alternative, and |false| otherwise. + + |isReserve()| must return |true| if the bean is a reserve, and |false| otherwise. + + + + |isEager()| must return |true| if the bean is eagerly initialized, and |false| otherwise. + +