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.
Merge pull request quarkusio#43069 from manovotn/issue42834
Arc - support @ALL List<X> synthetic injection points
- Loading branch information
Showing
3 changed files
with
166 additions
and
1 deletion.
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
70 changes: 70 additions & 0 deletions
70
...a/io/quarkus/arc/test/buildextension/beans/SyntheticInjectionPointListAllInvalidTest.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,70 @@ | ||
package io.quarkus.arc.test.buildextension.beans; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.util.TypeLiteral; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.ClassType; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.ParameterizedType; | ||
import org.jboss.jandex.WildcardType; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.All; | ||
import io.quarkus.arc.BeanCreator; | ||
import io.quarkus.arc.SyntheticCreationalContext; | ||
import io.quarkus.arc.processor.BeanRegistrar; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class SyntheticInjectionPointListAllInvalidTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanRegistrars(new TestRegistrar()) | ||
.shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testListAllInjection() { | ||
assertNotNull(container.getFailure()); | ||
assertTrue(container.getFailure().getMessage().contains( | ||
"Wildcard is not a legal type argument for a synthetic @All List<?> injection point")); | ||
} | ||
|
||
static class SyntheticBean { | ||
|
||
public SyntheticBean(List<?> list) { | ||
} | ||
} | ||
|
||
static class TestRegistrar implements BeanRegistrar { | ||
|
||
@Override | ||
public void register(RegistrationContext context) { | ||
context.configure(SyntheticBean.class) | ||
.addType(ClassType.create(DotName.createSimple(SyntheticBean.class))) | ||
.creator(SynthBeanCreator.class) | ||
// add injection point for @All List<?> - wildcard is NOT a legal bean type | ||
.addInjectionPoint(ParameterizedType.create(List.class, WildcardType.UNBOUNDED), | ||
AnnotationInstance.builder(All.class).build()) | ||
.unremovable() | ||
.done(); | ||
} | ||
|
||
} | ||
|
||
public static class SynthBeanCreator implements BeanCreator<SyntheticBean> { | ||
|
||
@Override | ||
public SyntheticBean create(SyntheticCreationalContext<SyntheticBean> context) { | ||
return new SyntheticBean(context.getInjectedReference(new TypeLiteral<List<?>>() { | ||
}, All.Literal.INSTANCE)); | ||
} | ||
|
||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...est/java/io/quarkus/arc/test/buildextension/beans/SyntheticInjectionPointListAllTest.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,88 @@ | ||
package io.quarkus.arc.test.buildextension.beans; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.util.TypeLiteral; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.ClassType; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.ParameterizedType; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.All; | ||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.BeanCreator; | ||
import io.quarkus.arc.SyntheticCreationalContext; | ||
import io.quarkus.arc.processor.BeanRegistrar; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class SyntheticInjectionPointListAllTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(SomeBean.class) | ||
.beanRegistrars(new TestRegistrar()).build(); | ||
|
||
@Test | ||
public void testListAllInjection() { | ||
SyntheticBean synthBean = Arc.container().instance(SyntheticBean.class).get(); | ||
assertNotNull(synthBean); | ||
List<SomeBean> list = synthBean.getList(); | ||
assertNotNull(list); | ||
assertEquals(1, list.size()); | ||
} | ||
|
||
@Singleton | ||
static class SomeBean { | ||
|
||
public String ping() { | ||
return SomeBean.class.getSimpleName(); | ||
} | ||
|
||
} | ||
|
||
static class SyntheticBean { | ||
|
||
private List<SomeBean> list; | ||
|
||
public SyntheticBean(List<SomeBean> list) { | ||
this.list = list; | ||
} | ||
|
||
public List<SomeBean> getList() { | ||
return list; | ||
} | ||
} | ||
|
||
static class TestRegistrar implements BeanRegistrar { | ||
|
||
@Override | ||
public void register(RegistrationContext context) { | ||
context.configure(SyntheticBean.class) | ||
.addType(ClassType.create(DotName.createSimple(SyntheticBean.class))) | ||
.creator(SynthBeanCreator.class) | ||
// add injection point for @All List<SomeBean> | ||
.addInjectionPoint(ParameterizedType.create(List.class, ClassType.create(SomeBean.class)), | ||
AnnotationInstance.builder(All.class).build()) | ||
.unremovable() | ||
.done(); | ||
} | ||
|
||
} | ||
|
||
public static class SynthBeanCreator implements BeanCreator<SyntheticBean> { | ||
|
||
@Override | ||
public SyntheticBean create(SyntheticCreationalContext<SyntheticBean> context) { | ||
return new SyntheticBean(context.getInjectedReference(new TypeLiteral<List<SomeBean>>() { | ||
}, All.Literal.INSTANCE)); | ||
} | ||
|
||
} | ||
} |