Search in sources :

Example 1 with ContainerLifecycleObserver.afterBeanDiscovery

use of org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery in project core by weld.

the class WeldBuilderTest method testInterceptorBuilder.

@Test
public void testInterceptorBuilder() {
    try (WeldContainer container = new Weld().disableDiscovery().beanClasses(Coorge.class, BuilderInterceptorBinding.class).addContainerLifecycleObserver(ContainerLifecycleObserver.afterBeanDiscovery((e) -> e.addInterceptor().addBinding(new BuilderInterceptorBinding.BuilderInterceptorBindingLiteral()).priority(2500).intercept(InterceptionType.AROUND_INVOKE, invocationContext -> {
        try {
            Integer result = ((Integer) invocationContext.proceed());
            return result + 10;
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return null;
    }))).initialize()) {
        Coorge coorge = container.select(Coorge.class).get();
        assertEquals(coorge.ping(), 11);
    }
}
Also used : Alpha2(org.jboss.weld.environment.se.test.builder.alphas.Alpha2) ContainerLifecycleObserver.afterBeanDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery) ConfigurationKey(org.jboss.weld.config.ConfigurationKey) Assert.assertTrue(org.junit.Assert.assertTrue) ObserverException(javax.enterprise.event.ObserverException) Test(org.junit.Test) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) WeldContainer(org.jboss.weld.environment.se.WeldContainer) DefinitionException(javax.enterprise.inject.spi.DefinitionException) Alpha1(org.jboss.weld.environment.se.test.builder.alphas.Alpha1) WeldConfiguration(org.jboss.weld.config.WeldConfiguration) Beta2(org.jboss.weld.environment.se.test.builder.alphas.betas.Beta2) ArrayList(java.util.ArrayList) Beta1(org.jboss.weld.environment.se.test.builder.alphas.betas.Beta1) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) ContainerLifecycleObserver(org.jboss.weld.environment.se.ContainerLifecycleObserver) Assert.assertFalse(org.junit.Assert.assertFalse) Any(javax.enterprise.inject.Any) InterceptionType(javax.enterprise.inject.spi.InterceptionType) Assert.assertEquals(org.junit.Assert.assertEquals) Container(org.jboss.weld.Container) Weld(org.jboss.weld.environment.se.Weld) WeldContainer(org.jboss.weld.environment.se.WeldContainer) ObserverException(javax.enterprise.event.ObserverException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ObserverException (javax.enterprise.event.ObserverException)1 Any (javax.enterprise.inject.Any)1 DefinitionException (javax.enterprise.inject.spi.DefinitionException)1 InterceptionType (javax.enterprise.inject.spi.InterceptionType)1 Container (org.jboss.weld.Container)1 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)1 ConfigurationKey (org.jboss.weld.config.ConfigurationKey)1 WeldConfiguration (org.jboss.weld.config.WeldConfiguration)1 ContainerLifecycleObserver (org.jboss.weld.environment.se.ContainerLifecycleObserver)1 ContainerLifecycleObserver.afterBeanDiscovery (org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery)1 Weld (org.jboss.weld.environment.se.Weld)1 WeldContainer (org.jboss.weld.environment.se.WeldContainer)1 Alpha1 (org.jboss.weld.environment.se.test.builder.alphas.Alpha1)1 Alpha2 (org.jboss.weld.environment.se.test.builder.alphas.Alpha2)1 Beta1 (org.jboss.weld.environment.se.test.builder.alphas.betas.Beta1)1 Beta2 (org.jboss.weld.environment.se.test.builder.alphas.betas.Beta2)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1 Assert.assertEquals (org.junit.Assert.assertEquals)1