Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjections;

import jakarta.enterprise.context.Dependent;

@Dependent
public class Alpha {
public String value() {
return "alpha";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjections;

import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class Bravo {
public String value() {
return "bravo";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjections;

import java.lang.annotation.Annotation;

import jakarta.enterprise.context.Dependent;
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 SyntheticInjectionsExtension implements BuildCompatibleExtension {
@Synthesis
public void synthesize(SyntheticComponents syn) {
syn.addBean(SyntheticPojo.class)
.type(SyntheticPojo.class)
.scope(Dependent.class)
.withInjectionPoint(Alpha.class, new Annotation[0])
.withInjectionPoint(Bravo.class, new Annotation[0])
.createWith(SyntheticPojoCreator.class)
.disposeWith(SyntheticPojoDisposer.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjections;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import jakarta.enterprise.inject.Instance;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.cdi.Sections;
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 SyntheticInjectionsTest extends AbstractTest {
@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder()
.withTestClassPackage(SyntheticInjectionsTest.class)
.withBuildCompatibleExtension(SyntheticInjectionsExtension.class)
.build();
}

@Test
@SpecAssertion(section = Sections.SYNTHESIS_PHASE, id = "ca", note = "withInjectionPoint(Class) registers injection points")
@SpecAssertion(section = Sections.SYNTHESIS_PHASE, id = "cb", note = "no qualifier passed, @Default is assumed")
@SpecAssertion(section = Sections.SYNTHESIS_PHASE, id = "cd", note = "SyntheticInjections used in creator")
public void testCreatorReceivesInjections() {
Instance<Object> lookup = getCurrentBeanContainer().createInstance();
Instance.Handle<SyntheticPojo> handle = lookup.select(SyntheticPojo.class).getHandle();
SyntheticPojo pojo = handle.get();
assertEquals(pojo.alphaValue, "alpha");
assertEquals(pojo.bravoValue, "bravo");
handle.destroy();
}

@Test
@SpecAssertion(section = Sections.SYNTHESIS_PHASE, id = "ce", note = "SyntheticInjections used in disposer")
public void testDisposerReceivesInjections() {
Instance<Object> lookup = getCurrentBeanContainer().createInstance();
Instance.Handle<SyntheticPojo> handle = lookup.select(SyntheticPojo.class).getHandle();
handle.get();
SyntheticPojoDisposer.disposed.set(false);
SyntheticPojoDisposer.bravoValueInDisposer = null;
handle.destroy();
assertTrue(SyntheticPojoDisposer.disposed.get());
assertEquals(SyntheticPojoDisposer.bravoValueInDisposer, "bravo");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjections;

public class SyntheticPojo {
public final String alphaValue;
public final String bravoValue;

public SyntheticPojo(String alphaValue, String bravoValue) {
this.alphaValue = alphaValue;
this.bravoValue = bravoValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjections;

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 SyntheticPojoCreator implements SyntheticBeanCreator<SyntheticPojo> {
@Override
public SyntheticPojo create(SyntheticInjections injections, Parameters params) {
Alpha alpha = injections.get(Alpha.class);
Bravo bravo = injections.get(Bravo.class);
return new SyntheticPojo(alpha.value(), bravo.value());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjections;

import java.util.concurrent.atomic.AtomicBoolean;

import jakarta.enterprise.inject.build.compatible.spi.Parameters;
import jakarta.enterprise.inject.build.compatible.spi.SyntheticBeanDisposer;
import jakarta.enterprise.inject.build.compatible.spi.SyntheticInjections;

public class SyntheticPojoDisposer implements SyntheticBeanDisposer<SyntheticPojo> {
static final AtomicBoolean disposed = new AtomicBoolean(false);
static String bravoValueInDisposer = null;

@Override
public void dispose(SyntheticPojo instance, SyntheticInjections injections, Parameters params) {
Bravo bravo = injections.get(Bravo.class);
bravoValueInDisposer = bravo.value();
disposed.set(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjectionsAnnotationInfo;

import java.lang.annotation.Annotation;

import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.build.compatible.spi.AnnotationBuilder;
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 AnnotationInfoExtension implements BuildCompatibleExtension {
@Synthesis
public void synthesize(SyntheticComponents syn) {
syn.addBean(SyntheticPojo.class)
.type(SyntheticPojo.class)
.scope(Dependent.class)
.withInjectionPoint(Widget.class, new Annotation[0])
.withInjectionPoint(Widget.class, AnnotationBuilder.of(Nice.class).build())
.createWith(SyntheticPojoCreator.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjectionsAnnotationInfo;

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.FIELD, ElementType.METHOD, ElementType.PARAMETER })
public @interface Nice {
final class Literal extends AnnotationLiteral<Nice> implements Nice {
public static final Literal INSTANCE = new Literal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjectionsAnnotationInfo;

import jakarta.enterprise.context.Dependent;

@Nice
@Dependent
public class NiceWidget implements Widget {
@Override
public String name() {
return "nice";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjectionsAnnotationInfo;

import jakarta.enterprise.context.Dependent;

@Dependent
public class PlainWidget implements Widget {
@Override
public String name() {
return "plain";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjectionsAnnotationInfo;

import static org.testng.Assert.assertEquals;

import jakarta.enterprise.inject.Instance;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.cdi.Sections;
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 SyntheticInjectionsAnnotationInfoTest extends AbstractTest {
@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder()
.withTestClassPackage(SyntheticInjectionsAnnotationInfoTest.class)
.withBuildCompatibleExtension(AnnotationInfoExtension.class)
.build();
}

@Test
@SpecAssertion(section = Sections.SYNTHESIS_PHASE, id = "ca", note = "withInjectionPoint(Class, AnnotationInfo...) overload")
@SpecAssertion(section = Sections.SYNTHESIS_PHASE, id = "cl", note = "AnnotationInfo qualifier distinguishes beans")
public void testAnnotationInfoQualifier() {
Instance<Object> lookup = getCurrentBeanContainer().createInstance();
Instance.Handle<SyntheticPojo> handle = lookup.select(SyntheticPojo.class).getHandle();
SyntheticPojo pojo = handle.get();
assertEquals(pojo.plainName, "plain");
assertEquals(pojo.niceName, "nice");
handle.destroy();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2026 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.build.compatible.extensions.syntheticBeanInjectionsAnnotationInfo;

public class SyntheticPojo {
public final String plainName;
public final String niceName;

public SyntheticPojo(String plainName, String niceName) {
this.plainName = plainName;
this.niceName = niceName;
}
}
Loading