use of jakarta.enterprise.context.spi.CreationalContext in project core by weld.
the class GlueDecoratorExtension method registerDecorator.
void registerDecorator(@Observes AfterBeanDiscovery event, BeanManager manager) {
AnnotatedType<GlueDecorator> annotatedType = manager.createAnnotatedType(GlueDecorator.class);
final BeanAttributes<GlueDecorator> attributes = manager.createBeanAttributes(annotatedType);
final InjectionPoint delegateInjectionPoint = manager.createInjectionPoint(annotatedType.getConstructors().iterator().next().getParameters().get(0));
Decorator<GlueDecorator> decorator = new DecoratorImpl<GlueDecorator>() {
@Override
public Type getDelegateType() {
return Glue.class;
}
@Override
public Set<Annotation> getDelegateQualifiers() {
return Collections.<Annotation>singleton(Any.Literal.INSTANCE);
}
@Override
public Set<Type> getDecoratedTypes() {
return Collections.emptySet();
}
@Override
public Class<?> getBeanClass() {
return GlueDecorator.class;
}
@Override
public Set<InjectionPoint> getInjectionPoints() {
final Decorator<GlueDecorator> decorator = this;
InjectionPoint wrappedInjectionPoint = new ForwardingInjectionPoint() {
@Override
public Bean<?> getBean() {
return decorator;
}
@Override
protected InjectionPoint delegate() {
return delegateInjectionPoint;
}
};
return Collections.singleton(wrappedInjectionPoint);
}
@Override
public GlueDecorator create(CreationalContext<GlueDecorator> creationalContext) {
return new GlueDecorator(null);
}
@Override
public void destroy(GlueDecorator instance, CreationalContext<GlueDecorator> creationalContext) {
creationalContext.release();
}
@Override
protected BeanAttributes<GlueDecorator> attributes() {
return attributes;
}
};
event.addBean(decorator);
}
use of jakarta.enterprise.context.spi.CreationalContext in project core by weld.
the class Ejb3InterceptionModelTest method testSimpleInterceptor3.
@Test
public void testSimpleInterceptor3() {
reset();
Bean bean = beanManager.getBeans(Ball.class).iterator().next();
CreationalContext creationalContext = beanManager.createCreationalContext(bean);
Ball ball = (Ball) bean.create(creationalContext);
ball.lob();
assert !Defender.defended;
assert Ball.played;
assert Goalkeeper.caught;
assert Ball.aroundInvoke;
}
use of jakarta.enterprise.context.spi.CreationalContext in project core by weld.
the class Ejb3InterceptionModelTest method testSimpleInterceptor.
@Test
public void testSimpleInterceptor() {
reset();
Bean bean = beanManager.getBeans(Ball.class).iterator().next();
CreationalContext creationalContext = beanManager.createCreationalContext(bean);
Ball ball = (Ball) bean.create(creationalContext);
ball.shoot();
assert Defender.defended;
assert Ball.played;
assert !Goalkeeper.caught;
assert Ball.aroundInvoke;
}
use of jakarta.enterprise.context.spi.CreationalContext in project core by weld.
the class Ejb3InterceptionModelTest method testSimpleInterceptor2.
@Test
public void testSimpleInterceptor2() {
reset();
Bean bean = beanManager.getBeans(Ball.class).iterator().next();
CreationalContext creationalContext = beanManager.createCreationalContext(bean);
Ball ball = (Ball) bean.create(creationalContext);
ball.pass();
assert Defender.defended;
assert Ball.played;
assert Goalkeeper.caught;
assert Ball.aroundInvoke;
}
use of jakarta.enterprise.context.spi.CreationalContext in project core by weld.
the class PreDestroyTest method testLifecycle.
@Test
@SuppressWarnings({ "unchecked" })
public void testLifecycle(BeanManager bm) throws Exception {
for (Bean b : bm.getBeans(TestBean.class)) {
CreationalContext ctx = bm.createCreationalContext(null);
TestBean testBean = (TestBean) bm.getReference(b, b.getBeanClass(), ctx);
b.destroy(testBean, ctx);
Assert.assertEquals("PreDestroy invocation number.", 1, testBean.getCounter());
}
}
Aggregations